ecmerkle/blavaan

seed different chains while using Stan

LaurentSmeets opened this issue · 2 comments

I have written some basic tutorials on how to use blavaan (with jags) in the past: https://www.rensvandeschoot.com/tutorials/bayesian-regression-blavaan/ and now I am trying to also create a blavaan (Stan) version of these. However, some of the commands when switching from jags to Stan no longer work.

for example this works:

model.informative.priors1 <- 
                    '#the regression model with priors
                    diff ~ prior("dnorm(3,2.5)")*age + prior("dnorm(0,10)")*age2

                    #show that dependent variable has variance
                    diff ~~ diff

                    #we want to have an intercept (with normal prior)
                    diff ~ 1'

fit.bayes.infprior1 <- blavaan(model.informative.priors1, data=data, convergence= "auto",  test="none", seed=c(21,08,2018))

summary(fit.bayes.infprior1, fit.measures=TRUE, ci = TRUE, rsquare=TRUE)

But this no longer works:

model.informative.priors1 <- 
                    '#the regression model with priors
                    diff ~ prior("normal(3, 0.632)")*age + prior("normal(0, 0.316 )")*age2

                    #show that dependent variable has variance
                    diff ~~ diff

                    #we want to have an intercept (with normal prior)
                    diff ~ 1'

fit.bayes.infprior1 <- blavaan(model.informative.priors1, data=data,  target= "stan",  test="none", seed=c(21,08,2018))

summary(fit.bayes.infprior1, fit.measures=TRUE, ci = TRUE, rsquare=TRUE)

I understand from error messages that autoconvergence is not surported using stan, which is no problem, but I can also not het the seed to work. If I try to set a seed, when using stan, I get the following error:

Error in rsmcmc[1, 1, ] : incorrect number of dimensions

How can I still set a seed for the chains, in order to get a reproducible example while using Stan as a sampler?

The tutorials look nice! Stan only needs a single integer for the seed, instead of a separate number for each chain. I just updated the documentation for this.

Thank you for the clarification, this works.