Error in dim(sssf)

Hi,

I am dealing with an error message that I do not fully understand and I am also unable to get my model to work.

Whenever I run a Stan model in R with thin=5 I get this error message:
Error in dim(sssf) <- c(n2, object@sim$chains, length(tidx)) :
dims [product 0] do not match the length of object [2584]

I assume the error comes from code line 481 here: https://github.com/cran/rstan/blob/master/R/stanfit-class.R

When I set thin=1 I end up with this error:
Error in FUN(newX[, i], …) : is.atomic(x) is not TRUE

Both error appear after the all chains have ran.

But I do not understand how I caused this error and also not how to fix it.

I updated all packages and the error persists.

Best,
Lucas

  • Operating System: Mac OSX Catalina
  • RStan Version: 2.19.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    CXXFLAGS=-O3 -mtune=native -march=native
    CXXFLAGS= -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256

CXXFLAGS=-O3 -mtune=native -march=native
CXXFLAGS= -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined

CXX14FLAGS=-O3 -march=native -mtune=native
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

  • Output of devtools::session_info("rstan")

─ Session info ───────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 3.6.1 (2019-07-05)
os macOS Catalina 10.15.1
system x86_64, darwin15.6.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Zurich
date 2019-12-07

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0)
BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.6.0)
callr 3.3.2 2019-09-22 [1] CRAN (R 3.6.1)
checkmate 1.9.4 2019-07-04 [1] CRAN (R 3.6.0)
cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.0)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0)
fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)
farver 2.0.1 2019-11-13 [1] CRAN (R 3.6.0)
ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.0)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)
inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.0)
labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.1)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0)
lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.0)
loo 2.1.0 2019-03-13 [1] CRAN (R 3.6.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
MASS * 7.3-51.4 2019-03-31 [1] CRAN (R 3.6.0)
Matrix 1.2-18 2019-11-27 [1] CRAN (R 3.6.0)
matrixStats 0.55.0 2019-09-07 [1] CRAN (R 3.6.0)
mgcv 1.8-31 2019-11-09 [1] CRAN (R 3.6.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
nlme 3.1-142 2019-11-07 [1] CRAN (R 3.6.0)
pillar 1.4.2 2019-06-29 [1] CRAN (R 3.6.0)
pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
plyr 1.8.4 2016-06-08 [1] CRAN (R 3.6.0)
prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0)
ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)
Rcpp * 1.0.3 2019-11-08 [1] CRAN (R 3.6.0)
RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 3.6.0)
reshape2 * 1.4.3 2017-12-11 [1] CRAN (R 3.6.0)
rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.0)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
rstan * 2.19.2 2019-07-09 [1] CRAN (R 3.6.0)
scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.0)
StanHeaders * 2.19.0 2019-09-07 [1] CRAN (R 3.6.0)
stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0)
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
vctrs 0.2.0 2019-07-05 [1] CRAN (R 3.6.0)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0)

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

I would leave thin at 1. When you get an error from that, what is the output of

traceback()

?

Thank you very much for responding.

For “thin=1” it is:

traceback()
9: stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call§))
8: stopifnot(is.atomic(x))
7: FUN(newX[, i], …)
6: apply(E, 2, var)
5: throw_sampler_warnings(nfits)
4: .local(object, …)
3: sampling(sm, data, pars, chains, iter, warmup, thin, seed, init,
check_data = TRUE, sample_file = sample_file, diagnostic_file = diagnostic_file,
verbose = verbose, algorithm = match.arg(algorithm), control = control,
check_unknown_args = FALSE, cores = cores, open_progress = open_progress,
include = include, …)
2: sampling(sm, data, pars, chains, iter, warmup, thin, seed, init,
check_data = TRUE, sample_file = sample_file, diagnostic_file = diagnostic_file,
verbose = verbose, algorithm = match.arg(algorithm), control = control,
check_unknown_args = FALSE, cores = cores, open_progress = open_progress,
include = include, …)
1: stan(file = “Lucas Playground/Code/Stan2d.stan”, data = CH_data,
iter = 1000, warmup = 1000, chains = 4, thin = 1, init = “random”,
verbose = TRUE, cores = 4, seed = 4321, save_warmup = TRUE)

For “thin=5”

I get these warning messages:
Registered S3 method overwritten by ‘xts’:
method from
as.zoo.xts zoo

and this is the traceback output:

traceback()
10: .local(object, …)
9: extract(x, permuted = FALSE, inc_warmup = FALSE, …)
8: extract(x, permuted = FALSE, inc_warmup = FALSE, …)
7: as.array.stanfit(object)
6: as.array(object)
5: throw_sampler_warnings(nfits)
4: .local(object, …)
3: sampling(sm, data, pars, chains, iter, warmup, thin, seed, init,
check_data = TRUE, sample_file = sample_file, diagnostic_file = diagnostic_file,
verbose = verbose, algorithm = match.arg(algorithm), control = control,
check_unknown_args = FALSE, cores = cores, open_progress = open_progress,
include = include, …)
2: sampling(sm, data, pars, chains, iter, warmup, thin, seed, init,
check_data = TRUE, sample_file = sample_file, diagnostic_file = diagnostic_file,
verbose = verbose, algorithm = match.arg(algorithm), control = control,
check_unknown_args = FALSE, cores = cores, open_progress = open_progress,
include = include, …)
1: stan(file = “Lucas Playground/Code/Stan2d.stan”, data = CH_data,
iter = 1000, warmup = 1000, chains = 4, thin = 5, init = “random”,
verbose = TRUE, cores = 4, seed = 4321, save_warmup = TRUE)

Best wishes,
Lucas

You set warmup=1000 and iter=1000, but what you probably mean is iter=2000, because iter is the total number of iterations including warmup. This will produce a better error in the next version (https://github.com/stan-dev/rstan/issues/693).

Perhaps there’s a strange interaction with thin which could be a different bug.

That is it - thank you!