fitMeasures for multiple group model

222 views
Skip to first unread message

DeAnne Hunter

unread,
Jun 8, 2021, 8:02:39 PM6/8/21
to blavaan
I am trying to run a multiple group bcfa and I've gotten all the way through my posterior distribution summary just fine, but now I'm getting error messages when attempting to generate model fit indices to compare the two. I'm pretty new to blavaan, so any help would be appreciated. 

It's telling me that it can't run when "test = none", which I'm assuming is because I don't know how to set one as the baseline model. But I'm unclear as to whether that's correct or how to do that if so. 

Thanks in advance! 

(code attached for reference)
BIWM_for Google Group Support.txt

Ed Merkle

unread,
Jun 9, 2021, 12:50:40 AM6/9/21
to DeAnne Hunter, blavaan
DeAnne,

Try removing test="standard" from your bcfa command. That part is not needed, and it seems to be interfering with something. I might have to fix something there...

Ed
--
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/1a7ff425-5d84-4ebe-97ea-3c6d82757a3fn%40googlegroups.com.

DeAnne Hunter

unread,
Jun 9, 2021, 3:48:12 PM6/9/21
to blavaan
I removed test = "standard" and got the following error code while it was trying to compute posterior predictives: 

Error in getGlobalsAndPackages(expr, envir = envir, globals = globals) : The total size of the 13 globals that need to be exported for the future expression (‘FUN()’) is 1.24 GiB. This exceeds the maximum allowed size of 500.00 MiB (option 'future.globals.maxSize'). The three largest globals are ‘lavmcmc’ (1.24 GiB of class ‘list’), ‘get_ll’ (466.15 KiB of class ‘function’) and ‘itnums’ (390.67 KiB of class ‘numeric’).

Ed Merkle

unread,
Jun 10, 2021, 12:25:22 AM6/10/21
to DeAnne Hunter, blavaan
Looking more closely at the code, I think you are getting this error because you are drawing 50k samples after burnin/warmup, which causes memory problems after estimation. An advantage of Stan is that the posterior sampling is more efficient than other software, which means that you can usually get by with many fewer samples. I might start with 1000 samples after burnin (per chain), then increasing that a bit if effective sample size are low or if you are comparing models with information criteria.

Ed

DeAnne Hunter

unread,
Jun 10, 2021, 12:29:49 AM6/10/21
to Ed Merkle, blavaan
The 50,000 samples choice was the result of incrementally increasing the number of samples to get rid of Tail ESS and Bulk ESS errors.

Is there anything else that I could try? 

Best,

DeAnne

-This message was sent using my mobile device. Please excuse any typos. 

From: Ed Merkle <ecme...@gmail.com>
Sent: Wednesday, June 9, 2021 9:25:18 PM
To: DeAnne Hunter <deanne....@gmail.com>; blavaan <bla...@googlegroups.com>
Subject: Re: fitMeasures for multiple group model
 

Mauricio Garnier-Villarreal

unread,
Jun 10, 2021, 7:57:01 AM6/10/21
to blavaan
The general recommendation with ESS is to have at least 100 per chain, so if you run 3 chains look to have 300 in ESS. Another thing you can do is to thin the chains, this will let you save less iterations and reduce the correlation between draws, increasing ESS

deanne....@gmail.com

unread,
Jun 10, 2021, 3:58:43 PM6/10/21
to Mauricio Garnier-Villarreal, blavaan

Ok, I’ve found a way to resolve the ESS issue.

 

But I am still unable to generate the fit measures that I need to compare the two groups.

 

Thanks for help in advance!

 

Best,

 

DeAnne

--
You received this message because you are subscribed to a topic in the Google Groups "blavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blavaan/ZpCTZGN9IAs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blavaan+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blavaan/293fb816-95fb-4f3f-9cca-7ad04225f987n%40googlegroups.com.

Ed Merkle

unread,
Jun 10, 2021, 6:12:15 PM6/10/21
to deanne....@gmail.com, Mauricio Garnier-Villarreal, blavaan
DeAnne,

Is it the same error message from before, related to out of memory, or is it something new?

In my experience, if you need to go past 5k samples (say) to avoid ESS warnings, then there is some other issue with the model to figure out. One place to check is whether there is a conflict between priors and your data. For example, if your variables can take on large values (say, above 10), the priors on SDs/variances/precisions can cause problems.

If you are able to post your data, I could take a look.

Ed
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/00ea01d75e33%240365b860%240a312920%24%40gmail.com.

DeAnne Hunter

unread,
Jul 12, 2021, 1:19:38 PM7/12/21
to blavaan
So now I keep getting the following error message when running a multiple group bcfa. 

Error in `[<-`(`*tmp*`, -empties, , value = etamat) : 
  only 0's may be mixed with negative subscripts

I installed the most recent update to blavaan (version 03-16) yesterday, but the error has persisted. 

Script attached. Please advise. 

Thanks! 

BIWM Script for blavaan group.txt

Ed Merkle

unread,
Jul 12, 2021, 2:09:18 PM7/12/21
to DeAnne Hunter, blavaan
Hi DeAnne,

Thanks for the report, and sorry you are having trouble. 

I think this error is related to the save.lvs=TRUE part of your command, but I am not quite sure what is specifically wrong. Is there any way you could send the data file off list, so I could look at it more?

Thanks,
Ed
--
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.

Ed Merkle

unread,
Jul 12, 2021, 4:33:40 PM7/12/21
to DeAnne Hunter, blavaan
DeAnne,

The issue was that one row of your dataset (row 233) was missing all variables in the model, and blavaan choked on that. This should now be fixed on github. 

If you have problems installing blavaan from github, you could also simply remove that row from the dataset, something like

biwm_all <- biwm_all[-233,]

Thanks,
Ed


On Mon, 2021-07-12 at 10:19 -0700, DeAnne Hunter wrote:
--
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.

DeAnne Hunter

unread,
Jul 26, 2021, 4:19:16 PM7/26/21
to blavaan

Hello,

 

I am trying to run ppmc(combined.config.model, thin = 1, fit.measures = c("srmr","rmsea","cfi","chisq"), discFUN = NULL) to get fit indices, but it’s throwing an error lavaan WARNING: estimation of the baseline model failed and the  .out file I tried to create with the fit indices output is blank.

 

I already scaled the data because of an earlier error code saying “lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others”, but I am still unable to get the fit indices that I need.

 

Please advise.

 

Best,

 

DeAnne

--
You received this message because you are subscribed to a topic in the Google Groups "blavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blavaan/ZpCTZGN9IAs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blavaan+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blavaan/1a7ff425-5d84-4ebe-97ea-3c6d82757a3fn%40googlegroups.com.

 

Mauricio Garnier-Villarreal

unread,
Jul 27, 2021, 7:57:28 AM7/27/21
to blavaan
DeAnne

Can you share more information, like the model, data summary information, and the sessionInfo?

With more details we can figure out better what might be the issue

Mauricio Garnier-Villarreal

unread,
Jul 27, 2021, 8:36:37 AM7/27/21
to blavaan
For example, when I run this example, everything works fine for me



library(blavaan)

?bcfa
HS.null <- '
x1 ~~ x1
x2 ~~ x2
x3 ~~ x3
x4 ~~ x4
x5 ~~ x5
x6 ~~ x6
x7 ~~ x7
x8 ~~ x8
x9 ~~ x9
'

fit_null <- bcfa(HS.null, group="school",
            data=HolzingerSwineford1939, orthogonal=T)
summary(fit_null)



HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '

fit <- bcfa(HS.model, std.lv=T, group="school",
            data=HolzingerSwineford1939)
summary(fit)
fitMeasures(fit)


out <- ppmc(fit, thin = 1,
     fit.measures = c("srmr","rmsea","cfi","chisq"), discFUN = NULL)
summary(out)

bfits <- blavFitIndices(fit, baseline.model = fit_null)
summary(bfits)


> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] coda_0.19-4        blavaan_0.3-17     RcppParallel_5.1.4 Rcpp_1.0.7         lavaan_0.6-9      

loaded via a namespace (and not attached):
 [1] jsonlite_1.7.2       tmvnsim_1.0-2        modeest_2.4.0        StanHeaders_2.21.0-7
 [5] assertthat_0.2.1     runjags_2.2.0-2      stats4_4.1.0         globals_0.14.0      
 [9] pbivnorm_0.6.0       pillar_1.6.1         lattice_0.20-44      rmutil_1.1.5        
[13] quantreg_5.86        glue_1.4.2           digest_0.6.27        colorspace_2.0-2    
[17] sandwich_3.0-1       Matrix_1.3-3         plyr_1.8.6           timeDate_3043.102   
[21] conquer_1.0.2        pkgconfig_2.0.3      rstan_2.21.2         SparseM_1.81        
[25] listenv_0.8.0        nonnest2_0.5-5       purrr_0.3.4          mvtnorm_1.1-2       
[29] scales_1.1.1         processx_3.5.2       MatrixModels_0.5-0   stable_1.1.4        
[33] tibble_3.1.2         spatial_7.3-14       bayesplot_1.8.1      generics_0.1.0      
[37] ggplot2_3.3.5        ellipsis_0.3.2       withr_2.4.2          cli_3.0.1           
[41] mnormt_2.0.2         magrittr_2.0.1       crayon_1.4.1         mcmc_0.9-7          
[45] ps_1.6.0             fansi_0.5.0          future_1.21.0        parallelly_1.27.0   
[49] MASS_7.3-54          pkgbuild_1.2.0       tools_4.1.0          loo_2.4.1           
[53] prettyunits_1.1.1    lifecycle_1.0.0      matrixStats_0.59.0   MCMCpack_1.5-0      
[57] V8_3.4.2             munsell_0.5.0        cluster_2.1.2        stabledist_0.7-1    
[61] callr_3.7.0          compiler_4.1.0       timeSeries_3062.100  rlang_0.4.11        
[65] grid_4.1.0           ggridges_0.5.3       CompQuadForm_1.4.3   gtable_0.3.0        
[69] codetools_0.2-18     inline_0.3.19        DBI_1.1.1            curl_4.3.2          
[73] statip_0.2.3         R6_2.5.0             gridExtra_2.3        rstantools_2.1.1    
[77] zoo_1.8-9            dplyr_1.0.7          future.apply_1.7.0   utf8_1.2.1          
[81] clue_0.3-59          fBasics_3042.89.1    parallel_4.1.0       rpart_4.1-15        
[85] vctrs_0.3.8          tidyselect_1.1.1    
>

Terrence Jorgensen

unread,
Sep 2, 2021, 2:53:35 PM9/2/21
to blavaan

it’s throwing an error

You posted a warning, not an error, so there should still be output, but...

the  .out file I tried to create with the fit indices output is blank.

 What is the .out file?  Are you talking about your use of sink() in the script attached to your original post?  I would instead try inspecting the R object itself.  Assign the output to an object, then use something like str() to see what it contains.

lavaan WARNING: estimation of the baseline model failed

 This indicates the problem occurs when lavaan tries to fit a baseline model in (at least) one MCMC iteration.  I don't remember what blavaan does in this case.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages