Hello everyone,
I’m a beginner to Bayesian latent variable modeling, and I’ve been trying to use blavaan for a research project. Currently, as a proof of concept, I’m fitting a linear-Gaussian SEM on a synthetic dataset, where we have two features X_1 and X_2, one latent variable C, and two outcome variables D and Y. The values for the dataset are generated from a given SEM.
One really important point to note is that there is deterministic missingness in Y: if the value of D is 0 in the dataset, then Y is missing. (But D has no other direct effect on Y.) Currently, I am using the default FIML method to handle missingness, but perhaps FIML isn’t built for this situation?
The following plot is the SEM that I’m trying to estimate.

Below are plots of the values in this synthetic dataset, with the points’ position given by X, and colored by D in the first plot, and Y in the second. (Note that due to deterministic missingness, all the points in the graph colored by Y come from the subset of points where D = 1.)


The point is: the model takes longer than I believe it should to converge, often using over 10,000 iterations to converge (per the blavaan documentation, “If your model is not converging after 1,000 burnin samples, it is likely that the default prior distributions clash with your data.”) I’ve tried tightening the priors, and while that hasn’t improved convergence, I haven’t messed with the priors in any very structured way, so perhaps that is still the solution.
I was hoping someone could advise me on whether I’m making any mistakes using the package, or whether this is just inherent to the problem I'm trying to specify. The following is the model I’m using to specify the model, and the code I’m running to estimate it in blavaan.
# import dataset
data <- read.csv('data/dataset_current.csv', header = TRUE)
# create lavaan model
model <- '
C =~ NA*X_1 + X_2 + D + Y
D ~ X_1 + X_2
# everything has variance
C ~~ C
D ~~ D
Y ~~ Y
X_1 ~~ X_1
X_2 ~~ X_2
# correlations between features
X_1 ~~ X_2
# and everything has an intercept
C ~ 1
D ~ 1
Y ~ 1
X_1 ~ 1
X_2 ~ 1
'
BURN <- 1000
rhat <- 20
while(rhat > 1.01) {
BURN <- BURN + 1000
fit_continuous <- bsem(model, data = data, n.chains = 4, sample = 1000, burnin = BURN, bcontrol = list(cores = 4), mcmcfile = TRUE, save.lvs = TRUE)
rhat <- max(blavInspect(fit_continuous, "psrf"), na.rm = TRUE)
print(paste0("Rhat=", rhat))
}
Thank you in advance for your help, and for the work and support y'all provide in creating and maintaining a solution like blavaan!
Hicould you show the summary() of your model? I think you might have an unidentified model because you relaease the constraint on the first factor loading (C =~ NA*X_1 + X_2 + D + Y), but didnt add any other identification method. Try adding the argument std.lv=T to the bsem function to identofy it by fixing the latent variance to 1
If that still doesnt work, we can look at using the priors to constraint the parameter space.About the missing structucture. These missing patterns are notoriously problemaic. If you use the default FIMCMC (full information MCMC, is what I call the approach used in blavaan as it is similar to FIML but is not ML) would estimate the model as if everyone had answer everything to estimate the parameters. But would lead to interpretatibility issuesOn Friday, December 1, 2023 at 4:51:58 AM UTC+1 prn...@ucsd.edu wrote:
Hello everyone,I’m a beginner to Bayesian latent variable modeling, and I’ve been trying to use blavaan for a research project. Currently, as a proof of concept, I’m fitting a linear-Gaussian SEM on a synthetic dataset, where we have two features X_1 and X_2, one latent variable C, and two outcome variables D and Y. The values for the dataset are generated from a given SEM.One really important point to note is that there is deterministic missingness in Y: if the value of D is 0 in the dataset, then Y is missing. (But D has no other direct effect on Y.) Currently, I am using the default FIML method to handle missingness, but perhaps FIML isn’t built for this situation?The following plot is the SEM that I’m trying to estimate.
sem.pngBelow are plots of the values in this synthetic dataset, with the points’ position given by X, and colored by D in the first plot, and Y in the second. (Note that due to deterministic missingness, all the points in the graph colored by Y come from the subset of points where D = 1.)
D_graph.pngY_graph.png
--You received this message because you are subscribed to the Google Groups "blavaan" group.To unsubscribe from this group and stop receiving emails from it, send an email to blavaan+u...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/blavaan/7c95b4a1-9dea-4757-8a4b-9f7d5c61c39fn%40googlegroups.com.