diff --git a/pkgdown.yml b/pkgdown.yml index 629535a9..95561f2e 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -19,7 +19,7 @@ articles: resources: resources.html start: start.html summaries: summaries.html -last_built: 2024-10-20T17:04Z +last_built: 2024-10-25T15:07Z urls: reference: http://ecmerkle.github.io/blavaan/reference article: http://ecmerkle.github.io/blavaan/articles diff --git a/reference/bcfa.html b/reference/bcfa.html index 1fe2cf4c..268c91fa 100644 --- a/reference/bcfa.html +++ b/reference/bcfa.html @@ -245,8 +245,8 @@

Examples#> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: -#> Chain 1: Gradient evaluation took 0.000358 seconds -#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.58 seconds. +#> Chain 1: Gradient evaluation took 0.00034 seconds +#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.4 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: @@ -271,15 +271,15 @@

Examples#> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: -#> Chain 1: Elapsed Time: 0.429 seconds (Warm-up) -#> Chain 1: 0.447 seconds (Sampling) -#> Chain 1: 0.876 seconds (Total) +#> Chain 1: Elapsed Time: 0.432 seconds (Warm-up) +#> Chain 1: 0.45 seconds (Sampling) +#> Chain 1: 0.882 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: -#> Chain 2: Gradient evaluation took 0.000256 seconds -#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.56 seconds. +#> Chain 2: Gradient evaluation took 0.000254 seconds +#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.54 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: @@ -304,9 +304,9 @@

Examples#> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: -#> Chain 2: Elapsed Time: 0.737 seconds (Warm-up) -#> Chain 2: 0.413 seconds (Sampling) -#> Chain 2: 1.15 seconds (Total) +#> Chain 2: Elapsed Time: 0.741 seconds (Warm-up) +#> Chain 2: 0.416 seconds (Sampling) +#> Chain 2: 1.157 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is NA, indicating chains have not mixed. #> Running the chains for more iterations may help. See diff --git a/reference/bsem.html b/reference/bsem.html index 6a4ef021..2f65a438 100644 --- a/reference/bsem.html +++ b/reference/bsem.html @@ -261,8 +261,8 @@

Examples#> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: -#> Chain 1: Gradient evaluation took 0.000315 seconds -#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.15 seconds. +#> Chain 1: Gradient evaluation took 0.000313 seconds +#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.13 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: @@ -287,15 +287,15 @@

Examples#> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: -#> Chain 1: Elapsed Time: 0.829 seconds (Warm-up) -#> Chain 1: 0.629 seconds (Sampling) -#> Chain 1: 1.458 seconds (Total) +#> Chain 1: Elapsed Time: 0.825 seconds (Warm-up) +#> Chain 1: 0.631 seconds (Sampling) +#> Chain 1: 1.456 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: -#> Chain 2: Gradient evaluation took 0.000281 seconds -#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.81 seconds. +#> Chain 2: Gradient evaluation took 0.00028 seconds +#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.8 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: @@ -320,9 +320,9 @@

Examples#> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: -#> Chain 2: Elapsed Time: 0.707 seconds (Warm-up) -#> Chain 2: 0.665 seconds (Sampling) -#> Chain 2: 1.372 seconds (Total) +#> Chain 2: Elapsed Time: 0.709 seconds (Warm-up) +#> Chain 2: 0.666 seconds (Sampling) +#> Chain 2: 1.375 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is 1.05, indicating chains have not mixed. #> Running the chains for more iterations may help. See diff --git a/search.json b/search.json index ca47950b..3e3b7c0f 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Approximate fit indices","text":"SEM, one first steps evaluate model’s global fit. commonly done presenting multiple fit indices, common based model’s χ2\\chi^2. developed Bayesian versions indices (Garnier-Villarreal Jorgensen 2020) can computed blavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"noncentrality-based-fit-indices","dir":"Articles","previous_headings":"","what":"Noncentrality-Based Fit Indices","title":"Approximate fit indices","text":"group indices compares hypothesized model perfect saturated model. specifically uses noncentrality parameter λ̂=χ2−df\\hat{\\lambda} = \\chi^2 - df, df adjusted different model/data characterictics. Specific indices include Root Mean Square Error approximation (RMSEA), McDonald’s centrality index (Mc), gamma-hat (Γ̂\\hat{\\Gamma}), adjusted gamma-hat (Γ̂adj\\hat{\\Gamma}_{adj}). show example Holzinger Swineford (1939) example. first estimate SEM/CFA model usual need pass model blavFitIndices() function Finally, can describe posterior distribution indices summary() function. call, see 3 central tendency measures (mean median, mode), standard deviation, 90% Credible Interval","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE) gl_fits <- blavFitIndices(fit) summary(gl_fits, central.tendency = c(\"mean\",\"median\",\"mode\"), prob = .90) ## ## Posterior summary statistics and highest posterior density (HPD) ## 90% credible intervals for devm-based fit indices: ## ## EAP Median MAP SD lower upper ## BRMSEA 0.099 0.098 0.097 0.005 0.090 0.107 ## BGammaHat 0.956 0.957 0.958 0.005 0.949 0.963 ## adjBGammaHat 0.907 0.908 0.910 0.010 0.891 0.922 ## BMc 0.902 0.904 0.906 0.010 0.886 0.918"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"incremental-fit-indices","dir":"Articles","previous_headings":"","what":"Incremental Fit Indices","title":"Approximate fit indices","text":"Another group fit indices compares hypothesized model worst possible model, called incremental indices. indices compare model’s χH2\\chi^2_H null model’s χ02\\chi^2_0 different ways. Indices include Comparative Fit Index (CFI), Tucker-Lewis Index (TLI), Normed Fit Index (NFI). estimate indices need define estimate respective null model. standard null model used default frequentist SEM programs (like lavaan) includes indicators variances intercepts, covariances items. can specify null model including respective indicator variances model syntax, hypothesized null models, pass blavFitIndices function, now provide types fit indices summary() method now presents central tendency measure asked , standard deviation, credible interval noncentrality incremental fit indices.","code":"HS.model_null <- ' x1 ~~ x1 x2 ~~ x2 x3 ~~ x3 x4 ~~ x4 x5 ~~ x5 x6 ~~ x6 x7 ~~ x7 x8 ~~ x8 x9 ~~ x9 ' fit_null <- bcfa(HS.model_null, data=HolzingerSwineford1939) gl_fits_all <- blavFitIndices(fit, baseline.model = fit_null) summary(gl_fits_all, central.tendency = c(\"mean\",\"median\",\"mode\"), prob = .90) ## ## Posterior summary statistics and highest posterior density (HPD) ## 90% credible intervals for devm-based fit indices: ## ## EAP Median MAP SD lower upper ## BRMSEA 0.099 0.098 0.097 0.005 0.090 0.107 ## BGammaHat 0.956 0.957 0.958 0.005 0.949 0.963 ## adjBGammaHat 0.907 0.908 0.910 0.010 0.891 0.922 ## BMc 0.902 0.904 0.906 0.010 0.886 0.918 ## BCFI 0.930 0.931 0.933 0.008 0.917 0.942 ## BTLI 0.883 0.884 0.888 0.013 0.862 0.903 ## BNFI 0.910 0.910 0.912 0.007 0.897 0.921"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"access-the-indices-posterior-distributions","dir":"Articles","previous_headings":"","what":"Access the indices posterior distributions","title":"Approximate fit indices","text":"can also extract posterior distributions respective indices, way can explore details. example, diagnostic plots using bayesplot package. saved posterior distributions, can explore histogram scatterplots indices.","code":"dist_fits <- data.frame(gl_fits_all@indices) head(dist_fits) ## BRMSEA BGammaHat adjBGammaHat BMc BCFI BTLI BNFI ## 1 0.10593079 0.9499973 0.8933976 0.8883160 0.9187946 0.8644212 0.8988141 ## 2 0.10014752 0.9550694 0.9042111 0.8995598 0.9274858 0.8789319 0.9071878 ## 3 0.09712886 0.9576242 0.9096576 0.9052313 0.9319535 0.8863909 0.9115299 ## 4 0.09818988 0.9567336 0.9077589 0.9032536 0.9308408 0.8845333 0.9105678 ## 5 0.09633310 0.9582868 0.9110703 0.9067033 0.9334671 0.8889181 0.9131040 ## 6 0.09211234 0.9617252 0.9184007 0.9143465 0.9386225 0.8975255 0.9178845 mcmc_pairs(dist_fits, pars = c(\"BRMSEA\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"hist\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Approximate fit indices","text":"can estimate posterior distributions χ2\\chi^2 based global fit indices. Notice presented fit indices based recommended method devM recommended number parameters metric loo. can adjusted user desired. general recommendation prefer Γ̂\\hat{\\Gamma} CFI, shown less sensitive model data characteristics. defaults recommendations made based previous simulation research. details fit indices please see Garnier-Villarreal Jorgensen (2020).","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Convergence and Efficiency Evaluation","text":"Bayesian models estimated Markov-Chain Monte Carlo (MCMC) sampler, model estimation doesn’t stop achieved convergence criteria. run long desired (determined burnin sample arguments), need evaluate convergence efficiency estimated posterior distributions. analyze results convergence achieved, judged metrics described . example use Industrialization Political Democracy example (Bollen 1989).","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"convergence","dir":"Articles","previous_headings":"","what":"Convergence","title":"Convergence and Efficiency Evaluation","text":"primary convergence diagnostic R̂\\hat{R}, compares - within-chain samples model parameters univariate quantities interest (Vehtari et al. 2021). chains mixed well (ie, - within-chain estimates don’t agree), R̂\\hat{R} larger 1. recommend running least three chains default using posterior samples R̂<1.05\\hat{R} < 1.05 parameters. blavaan presents R̂\\hat{R} reported underlying MCMC program, either Stan JAGS (Stan default). can obtain R̂\\hat{R} summary() function, can also extract blavInspect() function large models can cumbersome look entries. can instead find largest R̂\\hat{R} see less 1.051.05 R̂<1.05\\hat{R} < 1.05 can establish MCMC chains converged stable solution. model converged, might increase number burnin iterations /change model priors dpriors() function. address issues model failed converge due needing iterations due model misspecification (bad priors). rule thumb, seldom see model require 1,000 burnin samples Stan. model converging 1,000 burnin samples, likely default prior distributions clash data. can happen, e.g., variables contain values 100s 1000s.","code":"blavInspect(fit, \"rhat\") ## ind60=~x1 ind60=~x2 ind60=~x3 a b c ## 1.0021155 1.0014028 1.0011210 0.9994694 1.0005097 0.9998649 ## d a b c d dem60~ind60 ## 1.0038308 0.9994694 1.0005097 0.9998649 1.0038308 1.0002757 ## dem65~ind60 dem65~dem60 y1~~y5 y2~~y4 y2~~y6 y3~~y7 ## 1.0011541 0.9999180 1.0009617 1.0030341 0.9993406 1.0003294 ## y4~~y8 y6~~y8 x1~~x1 x2~~x2 x3~~x3 y1~~y1 ## 1.0003158 0.9996220 1.0012237 1.0020556 0.9998015 1.0003578 ## y2~~y2 y3~~y3 y4~~y4 y5~~y5 y6~~y6 y7~~y7 ## 0.9995107 0.9996011 1.0032729 0.9998450 1.0003404 0.9994630 ## y8~~y8 x1~1 x2~1 x3~1 y1~1 y2~1 ## 1.0001286 1.0006249 1.0005780 1.0000013 1.0006972 1.0000931 ## y3~1 y4~1 y5~1 y6~1 y7~1 y8~1 ## 0.9998330 1.0004696 1.0011070 0.9998333 1.0006884 1.0010911 max(blavInspect(fit, \"psrf\")) ## [1] 1.003831 fit <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=1000, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"efficiency","dir":"Articles","previous_headings":"","what":"Efficiency","title":"Convergence and Efficiency Evaluation","text":"also evaluate efficiency posterior samples. Effective sample size (ESS) useful measure sampling efficiency, well defined even chains finite mean variance (Vehtari et al. 2021). short, posterior samples produced MCMC autocorrelated. means , draw 500 posterior samples, 500 independent pieces information posterior distribution, samples autocorlated. ESS metric like currency conversion, telling much autocorrelated samples worth convert independent samples. blavaan can print summary function neff argument can also extract blavInspect() function ESS sample size, least 100 (optimally, much 100) times number chains order reliable indicate estimates posterior quantiles reliable. example, 3 chains, want see least neff=300 every parameter. can easily find lowest ESS min() function:","code":"summary(fit, neff=T) blavInspect(fit, \"neff\") ## ind60=~x1 ind60=~x2 ind60=~x3 a b c ## 1639.120 1444.645 1631.786 1947.795 1807.270 2129.132 ## d a b c d dem60~ind60 ## 1543.688 1947.795 1807.270 2129.132 1543.688 2089.569 ## dem65~ind60 dem65~dem60 y1~~y5 y2~~y4 y2~~y6 y3~~y7 ## 2840.737 2441.160 2394.304 2015.814 2738.832 2425.830 ## y4~~y8 y6~~y8 x1~~x1 x2~~x2 x3~~x3 y1~~y1 ## 1881.706 1876.226 2571.538 2008.444 3976.143 2592.135 ## y2~~y2 y3~~y3 y4~~y4 y5~~y5 y6~~y6 y7~~y7 ## 3092.750 3255.657 1780.215 2389.160 2825.048 2645.932 ## y8~~y8 x1~1 x2~1 x3~1 y1~1 y2~1 ## 1785.457 1206.981 1247.654 1295.642 1362.742 1690.638 ## y3~1 y4~1 y5~1 y6~1 y7~1 y8~1 ## 1528.945 1293.889 1204.344 1298.091 1153.531 1091.060 min(blavInspect(fit, \"neff\")) ## [1] 1091.06"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Convergence loop","text":"many cases need run BSEM models multiple times converged. can take might want R . tutorial shows use loop increase number burnin samples model converges, can let run without adjust every time","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"convergence-loop","dir":"Articles","previous_headings":"","what":"Convergence loop","title":"Convergence loop","text":"start writing model syntax always. instead running blavaan functions usual, run inside loop follows. loop starts need define starting BURN <- 0 number iterations, convergence value higher desired rhat <- 20. loop set stop convergence criteria (rhat) lower desired value, like R̂<1.05\\hat{R} < 1.05, specify (rhat > 1.05), meaning loop continue long rhat higher 1.05. inside loop increase number BURN iterations 1000 example. estimating model, evaluate convergence getting highest estimated R̂\\hat{R}, printing screen see far model converging. Note increasing number burnin iterations, keeping number saved samples (1000 case). want can increase decrease number saved iterations according case. can visualize convergence trace plots","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' BURN <- 0 rhat <- 20 while(rhat > 1.05) { BURN <- BURN + 1000 ### increase burn in by 1000 iterations every time fit <- bcfa(HS.model, std.lv=T, data=HolzingerSwineford1939, n.chains = 3, burnin = BURN, sample=1000) rhat <- max(blavInspect(fit, \"psrf\"), na.rm=T) print(paste0(\"Rhat=\",rhat)) } print(paste0(\"Rhat=\",rhat)) ## [1] \"Rhat=1.00191591415435\" plot(fit, pars = 1:9, plot.type = \"trace\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"convergence-criteria","dir":"Articles","previous_headings":"","what":"Convergence criteria","title":"Convergence loop","text":"example use R̂<1.05\\hat{R} < 1.05 convergence criteria. recommend use R̂<1.01\\hat{R} < 1.01 convergence criteria, higher. R̂\\hat{R} approximates 1, can argue model converged estimates achieve stability within chains (Gelman et al. 2014)","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Cross-loadings with strong priors","text":"advantage BSEM can use priors set soft constraints model, estimating parameter strong prior. way parameter estimated, prior restrict possible values. suggested Muthén Asparouhov (2012), way estimate possible cross-loadings CFA. way, posterior distribution restricted parameters includes values outside strong prior, can interpreted model modification. means parameters less restricted, prior distribution relaxed. tutorial present estimate CFA possible cross-loadings restricted strong priors.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"cross-loadings","dir":"Articles","previous_headings":"","what":"Cross-loadings","title":"Cross-loadings with strong priors","text":"show example Holzinger Swineford (1939) data. First estimate regular model cross-loadings default priors. can see overall model results summary() function, looking posterior distribution factor loadings, correlations, intercepts variances. Next, add possible cross-loadings strong prior N(0,σ=0.08)N(0, \\sigma = 0.08). prior centers loadings around 0 allows little space move. important , factor, first variable =~ one whose loading expect far 0. , model, specified regular cfa first (whose loadings expect larger), loadings small-variance priors separate line. important , blavaan, first loading either constrained positive fixed 1 (depending std.lv). posterior distribution constrained loading centered near 0, may experience identification problems. Reverse-coded variables can also problematic , positive constraint reverse-coded loading can lead loadings assume negative values. use informative priors situation, verify prior density correct side 0. estimation, can look summary() model evaluate cross-loadings. can specifically see whether cross-loadings seem large enough suggest kept model, looking posterior mean (Estimate) credible interval. suggest simply look whether CI excludes 0 (similar null hypothesis), evaluate whether minimum value CI (value closer 0) far enough away 0 relavant instead just different 0.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit_df <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T) summary(fit_df) ## blavaan 0.5.6.1311 ended normally after 1000 iterations ## ## Estimator BAYES ## Optimization method MCMC ## Number of model parameters 30 ## ## Number of observations 301 ## ## Statistic MargLogLik PPP ## Value -3871.046 0.000 ## ## Parameter Estimates: ## ## ## Latent Variables: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual =~ ## x1 0.912 0.086 0.744 1.086 1.001 normal(0,10) ## x2 0.500 0.082 0.340 0.660 1.000 normal(0,10) ## x3 0.661 0.078 0.512 0.815 1.000 normal(0,10) ## textual =~ ## x4 1.002 0.058 0.891 1.119 1.000 normal(0,10) ## x5 1.116 0.064 0.995 1.242 1.000 normal(0,10) ## x6 0.928 0.056 0.823 1.042 1.001 normal(0,10) ## speed =~ ## x7 0.619 0.077 0.463 0.765 1.001 normal(0,10) ## x8 0.733 0.079 0.573 0.887 1.000 normal(0,10) ## x9 0.681 0.079 0.530 0.840 1.000 normal(0,10) ## ## Covariances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual ~~ ## textual 0.449 0.067 0.311 0.576 1.000 lkj_corr(1) ## speed 0.462 0.086 0.292 0.622 1.000 lkj_corr(1) ## textual ~~ ## speed 0.278 0.071 0.135 0.417 1.000 lkj_corr(1) ## ## Intercepts: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 4.936 0.067 4.803 5.064 0.999 normal(0,32) ## .x2 6.089 0.069 5.961 6.230 0.999 normal(0,32) ## .x3 2.251 0.065 2.123 2.385 1.000 normal(0,32) ## .x4 3.061 0.067 2.929 3.193 1.000 normal(0,32) ## .x5 4.340 0.074 4.194 4.481 1.000 normal(0,32) ## .x6 2.186 0.064 2.061 2.312 1.000 normal(0,32) ## .x7 4.185 0.062 4.062 4.309 1.000 normal(0,32) ## .x8 5.527 0.058 5.416 5.638 0.999 normal(0,32) ## .x9 5.374 0.057 5.261 5.488 1.000 normal(0,32) ## visual 0.000 ## textual 0.000 ## speed 0.000 ## ## Variances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 0.551 0.127 0.290 0.791 1.000 gamma(1,.5)[sd] ## .x2 1.153 0.107 0.954 1.383 1.000 gamma(1,.5)[sd] ## .x3 0.859 0.100 0.674 1.062 1.000 gamma(1,.5)[sd] ## .x4 0.378 0.050 0.284 0.484 1.000 gamma(1,.5)[sd] ## .x5 0.453 0.061 0.337 0.578 1.000 gamma(1,.5)[sd] ## .x6 0.365 0.045 0.281 0.458 1.000 gamma(1,.5)[sd] ## .x7 0.820 0.092 0.653 1.016 1.000 gamma(1,.5)[sd] ## .x8 0.502 0.095 0.317 0.697 1.001 gamma(1,.5)[sd] ## .x9 0.567 0.093 0.374 0.738 1.002 gamma(1,.5)[sd] ## visual 1.000 ## textual 1.000 ## speed 1.000 HS.model.cl<-' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ## Cross-loadings visual =~ prior(\"normal(0,.08)\")*x4 + prior(\"normal(0,.08)\")*x5 + prior(\"normal(0,.08)\")*x6 + prior(\"normal(0,.08)\")*x7 + prior(\"normal(0,.08)\")*x8 + prior(\"normal(0,.08)\")*x9 textual =~ prior(\"normal(0,.08)\")*x1 + prior(\"normal(0,.08)\")*x2 + prior(\"normal(0,.08)\")*x3 + prior(\"normal(0,.08)\")*x7 + prior(\"normal(0,.08)\")*x8 + prior(\"normal(0,.08)\")*x9 speed =~ prior(\"normal(0,.08)\")*x1 + prior(\"normal(0,.08)\")*x2 + prior(\"normal(0,.08)\")*x3 + prior(\"normal(0,.08)\")*x4 + prior(\"normal(0,.08)\")*x5 + prior(\"normal(0,.08)\")*x6' fit_cl <- bcfa(HS.model.cl, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T) summary(fit_cl) ## blavaan 0.5.6.1311 ended normally after 1000 iterations ## ## Estimator BAYES ## Optimization method MCMC ## Number of model parameters 48 ## ## Number of observations 301 ## ## Statistic MargLogLik PPP ## Value -3858.912 0.138 ## ## Parameter Estimates: ## ## ## Latent Variables: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual =~ ## x1 0.759 0.097 0.581 0.963 1.000 normal(0,10) ## x2 0.567 0.089 0.394 0.741 1.000 normal(0,10) ## x3 0.771 0.095 0.586 0.955 1.001 normal(0,10) ## textual =~ ## x4 0.982 0.066 0.860 1.115 1.000 normal(0,10) ## x5 1.156 0.072 1.020 1.302 1.000 normal(0,10) ## x6 0.893 0.061 0.779 1.018 1.000 normal(0,10) ## speed =~ ## x7 0.727 0.085 0.571 0.900 1.000 normal(0,10) ## x8 0.793 0.084 0.635 0.961 1.000 normal(0,10) ## x9 0.542 0.073 0.400 0.687 0.999 normal(0,10) ## visual =~ ## x4 0.032 0.057 -0.080 0.139 1.000 normal(0,.08) ## x5 -0.073 0.063 -0.199 0.048 1.000 normal(0,.08) ## x6 0.063 0.055 -0.046 0.166 0.999 normal(0,.08) ## x7 -0.130 0.063 -0.259 -0.010 1.000 normal(0,.08) ## x8 -0.007 0.066 -0.139 0.119 1.000 normal(0,.08) ## x9 0.194 0.058 0.073 0.309 1.000 normal(0,.08) ## textual =~ ## x1 0.110 0.064 -0.013 0.234 0.999 normal(0,.08) ## x2 0.007 0.059 -0.110 0.123 1.000 normal(0,.08) ## x3 -0.085 0.062 -0.213 0.031 1.000 normal(0,.08) ## x7 0.016 0.061 -0.107 0.129 1.000 normal(0,.08) ## x8 -0.038 0.061 -0.161 0.081 0.999 normal(0,.08) ## x9 0.032 0.056 -0.079 0.141 0.999 normal(0,.08) ## speed =~ ## x1 0.045 0.066 -0.085 0.174 0.999 normal(0,.08) ## x2 -0.048 0.064 -0.173 0.073 0.999 normal(0,.08) ## x3 0.029 0.066 -0.099 0.161 1.000 normal(0,.08) ## x4 -0.005 0.057 -0.116 0.104 0.999 normal(0,.08) ## x5 0.008 0.062 -0.114 0.127 1.001 normal(0,.08) ## x6 0.001 0.056 -0.112 0.110 1.001 normal(0,.08) ## ## Covariances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual ~~ ## textual 0.373 0.091 0.190 0.543 0.999 lkj_corr(1) ## speed 0.351 0.109 0.120 0.545 1.000 lkj_corr(1) ## textual ~~ ## speed 0.255 0.104 0.049 0.453 0.999 lkj_corr(1) ## ## Intercepts: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 4.935 0.068 4.803 5.065 1.000 normal(0,32) ## .x2 6.089 0.070 5.946 6.226 0.999 normal(0,32) ## .x3 2.250 0.066 2.121 2.384 0.999 normal(0,32) ## .x4 3.061 0.066 2.928 3.185 1.000 normal(0,32) ## .x5 4.340 0.075 4.197 4.487 1.000 normal(0,32) ## .x6 2.186 0.064 2.059 2.308 1.002 normal(0,32) ## .x7 4.187 0.062 4.066 4.306 1.000 normal(0,32) ## .x8 5.528 0.060 5.410 5.645 1.000 normal(0,32) ## .x9 5.375 0.056 5.266 5.484 0.999 normal(0,32) ## visual 0.000 ## textual 0.000 ## speed 0.000 ## ## Variances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 0.680 0.107 0.469 0.891 1.000 gamma(1,.5)[sd] ## .x2 1.091 0.109 0.885 1.321 0.999 gamma(1,.5)[sd] ## .x3 0.713 0.112 0.497 0.936 1.001 gamma(1,.5)[sd] ## .x4 0.389 0.051 0.297 0.491 1.000 gamma(1,.5)[sd] ## .x5 0.411 0.066 0.289 0.543 0.999 gamma(1,.5)[sd] ## .x6 0.374 0.043 0.295 0.465 1.000 gamma(1,.5)[sd] ## .x7 0.712 0.094 0.524 0.900 0.999 gamma(1,.5)[sd] ## .x8 0.434 0.092 0.243 0.610 1.000 gamma(1,.5)[sd] ## .x9 0.589 0.063 0.475 0.723 0.999 gamma(1,.5)[sd] ## visual 1.000 ## textual 1.000 ## speed 1.000"},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"caveats","dir":"Articles","previous_headings":"","what":"Caveats","title":"Cross-loadings with strong priors","text":"model possible cross-loadings kept final analysis model, used step make decisions model changes. two main reasons, (1) model overfitted present good overall fit just due inclusion lot nuisance parameters. example posterior predictive p-value goes ppp = 0 ppp = 0.138, model better theoretically inflating model fit. (2), addition small-variance priors can prevent detection important misspecifications Bayesian confirmatory factor analysis, can obscure underlying problems model diluting large number nuisance parameters (Jorgensen et al. 2019).","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"primary-arguments","dir":"Articles","previous_headings":"","what":"Primary arguments","title":"Model Estimation","text":"Primary arguments model estimation commands include burnin, sample, n.chains, target. burnin sample arguments used specify desired number burn-iterations posterior samples n.chains chains (burnin argument controls warm-iterations Stan). target argument, hand, used specify MCMC strategy used estimation. default, target = \"stan\", tends fastest efficient. options slightly flexible, including target = \"stanclassic\" target = \"jags\". approaches sample latent variables model parameters, whereas target = \"stan\" marginalizes latent variables. detail approaches, see JSS paper.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"secondary-arguments","dir":"Articles","previous_headings":"","what":"Secondary arguments","title":"Model Estimation","text":"Noteworthy secondary arguments include save.lvs, mcmcfile, mcmcextra, inits. save.lvs argument controls whether latent variables sampled model estimation. defaults FALSE latent variable sampling can take large amount memory, can slow post-estimation summaries. setting save.lvs = TRUE allows model summaries latent variables observed variable predictions using blavPredict() functions. setting mcmcfile = TRUE, users can obtain Stan (JAGS) code data specified model. files written lavExport folder within user’s working directory. One file extension .jag .stan, second file R data file (extension .rda). rda file can loaded R (via load()) list including elements data, monitors, inits. elements can supplied stan() model estimation outside blavaan. mcmcextra argument used supply extra information Stan JAGS. Users can supply list element names monitor, data, syntax, llnsamp. elements respectively used specify extra parameters monitor, extra data pass model estimation, extra syntax include model file (JAGS ), number importance samples likelihood approximation (relevant models ordinal variables). inits argument used control starting values MCMC estimation. can sometimes salvage model immediately crashes. default, inits = \"simple\", initializes model parameters 0 1 fashion similar lavaan’s use argument. second option, inits = \"prior\", draws initial values prior distributions. user can also specify list initial values via argument, though required list format somewhat cumbersome. recommend exporting model data using mcmcfile = TRUE, loading resulting rda file, looking format initial values blavaan created .","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"parallelization","dir":"Articles","previous_headings":"","what":"Parallelization","title":"Model Estimation","text":"Speed always issue sample via MCMC, especially using software like Stan JAGS. computers multiple cores, estimation can sped sending MCMC chain separate core. accomplished bcontrol argument, list whose elements correspond stan() run.jags() arguments. parallelizing chains Stan, want use argument bcontrol = list(cores = 3). Many arguments available control aspects estimation; see ?stan ?run.jags possibilities. Parallelization can also helpful speed post-estimation computations. future package controls parallelization, requires extra command prior estimation. common commands ","code":"library(\"future\") plan(\"multicore\") ## mac or linux plan(\"multisession\") ## windows"},{"path":"http://ecmerkle.github.io/blavaan/articles/invariance.html","id":"model-estimation","dir":"Articles","previous_headings":"","what":"Model Estimation","title":"Measurement Invariance","text":"Consider measurement invariance study Holzinger Swineford (1939) data. lavaan, may first estimate two models: examine absolute fit fit1. also compare fit2 fit1 via Likelihood Ratio Test. Instead , wish something similar via Bayesian methods. accomplish via blavaan, can fit Bayesian versions fit1 fit2 using similar syntax. Model fit comparison statistics available via fitMeasures() blavCompare() functions:","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit1 <- cfa(HS.model, data = HolzingerSwineford1939, group = \"school\") fit2 <- cfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = \"loadings\") bfit1 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\") bfit2 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = \"loadings\") fitMeasures(bfit1) fitMeasures(bfit2) blavCompare(bfit1, bfit2)"},{"path":"http://ecmerkle.github.io/blavaan/articles/invariance.html","id":"approximate-invariance","dir":"Articles","previous_headings":"","what":"Approximate Invariance","title":"Measurement Invariance","text":"approximate measurement invariance studies, replace hard equality constraints soft constraints using informative prior distributions. wiggle argument can used invoke types constraints. example: constrains loadings associated x2 x3 approximately equal across groups, informative priors associated constraints normal standard deviations 0.05. Using strategy, syntax can become cumbersome. many cases, group.equal argument can help . example: example, model intercepts loadings across-group constraints. loadings approximately equal across groups, due argument wiggle = \"loadings\". intercepts constrained exactly equal across groups. way, becomes easy use exact approximate equality constraints model, desired.","code":"HS.model <- ' visual =~ x1 + c(\"a\", \"a\")*x2 + c(\"b\", \"b\")*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' bfit3 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", wiggle = c(\"a\", \"b\"), wiggle.sd = 0.05) HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' bfit4 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = c(\"intercepts\", \"loadings\"), wiggle = \"loadings\", wiggle.sd = 0.05)"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Modification indices","text":"SEM, one first steps evaluate model’s global fit. global fit, need evaluate local fit model, meaning model reproduces specific correlations observed variables. couple common methods , () testing high residual correlations, (b) modification indices. tutorial focuses second. Modification indices test likely change model fit single parameter added model originally included. test can carried every possible parameter included (Bentler 1990).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"modification-indices","dir":"Articles","previous_headings":"","what":"Modification Indices","title":"Modification indices","text":"Modification indices present different indices quantify effect parameter, focus two . () modification index (MI) Lagrange multiplier, estimates extent model’s chi-square (χ2\\chi^2) test statistic decrease parameter added model freely estimated, (b) standardized expected parameter change (SEPC), approximated standardized value parameter estimated model (Whittaker 2012). MI presents possible effect overall model, SEPC presents effect size missed parameter. show example Holzinger Swineford (1939) model. first estimate SEM/CFA model usual need write discrepancy function collect modification indices. list contains two functions estimate save MI SEPC. pass function ppmc() function blavaan. function, MI SEPC computed posterior sample, leading posterior distributions . view top 5 parameters arrange posterior mean (EAP) MI, case shows parameter highest impact overall model fit (according EAP) visual=~x9, cross-loading Visual factor item x9. according posterior median, parameter highest impact residual correlation indicators x7 x8 MI still recommended best metric indicate parameter best include next, can use SEPC evaluate likely effect size respective parameters. see 2 highest parameters, likely SEPC x7~~x8 = 0.793876155456826 visual=~x9 = 0.516400919262519. information can decide include one new parameters model (one time). example, factor loadings larger impact model-implied covariance matrix, choose visual=~x9 can check added parameter expected impact overall fit blavFitIndices() summary() functions. important consider also theoretical relevance suggested parameters, ensure make sense, instead just adding parameters good fit.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE) discFUN <- list( mod.ind_mi = function(object){ temp <- modificationindices(object, free.remove = F) mods <- temp$mi names(mods) <- paste0(temp$lhs, temp$op, temp$rhs) return(mods) }, mod.ind_sepc.all = function(object){ temp <- modificationindices(object, free.remove = F) sepc.all <- temp$sepc.all names(sepc.all) <- paste0(temp$lhs, temp$op, temp$rhs) return(sepc.all) } ) out <- ppmc(fit, discFUN = discFUN) summary(out, prob=.9, discFUN = \"mod.ind_mi\", sort.by=\"EAP\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## visual=~x9 35.164 35.119 35.213 11.223 16.637 52.245 0.014 ## x7~~x8 32.981 35.507 39.796 14.528 8.480 56.405 0.076 ## x8~~x9 26.437 11.969 2.849 43.335 0.000 65.993 0.327 ## x4~~x6 19.620 6.387 2.223 35.491 0.000 52.799 0.457 ## visual=~x7 18.284 16.753 13.244 9.849 3.525 31.902 0.015 ## PPP_sim_LessThan_obs ## visual=~x9 0.986 ## x7~~x8 0.924 ## x8~~x9 0.673 ## x4~~x6 0.543 ## visual=~x7 0.985 summary(out, prob=.9, discFUN = \"mod.ind_mi\", sort.by=\"Median\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## x7~~x8 32.981 35.507 39.796 14.528 8.480 56.405 0.076 ## visual=~x9 35.164 35.119 35.213 11.223 16.637 52.245 0.014 ## visual=~x7 18.284 16.753 13.244 9.849 3.525 31.902 0.015 ## x8~~x9 26.437 11.969 2.849 43.335 0.000 65.993 0.327 ## textual=~x1 11.052 9.906 2.014 8.385 0.000 22.615 0.227 ## PPP_sim_LessThan_obs ## x7~~x8 0.924 ## visual=~x9 0.986 ## visual=~x7 0.985 ## x8~~x9 0.673 ## textual=~x1 0.773 summary(out, prob=.9, discFUN = \"mod.ind_sepc.all\", sort.by=\"EAP\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## x7~~x8 0.794 0.786 0.755 0.410 0.502 1.323 0.043 ## visual=~x9 0.516 0.496 0.465 0.134 0.341 0.704 0.010 ## textual=~x1 0.268 0.298 0.312 0.188 0.024 0.531 0.137 ## x1~~x9 0.249 0.247 0.246 0.043 0.200 0.304 0.016 ## x2~~x3 0.223 0.223 0.223 0.037 0.167 0.274 0.021 ## PPP_sim_LessThan_obs ## x7~~x8 0.957 ## visual=~x9 0.990 ## textual=~x1 0.863 ## x1~~x9 0.984 ## x2~~x3 0.979 HS.model <- ' visual =~ x1 + x2 + x3 + x9 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit2 <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE)"},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Modification indices","text":"tutorial show calculate MI SEPC across posterior distributions, evaluate parameters can added. ppmc() function able calculate relevant information model estimation, build posterior distributions . general recommendations use MI identify likely parameter add, SEPC effect size new parameter.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Model Comparison","text":"traditional method model comparison frequentist SEM (fSEM) χ2\\chi^2 (Likelihood Ratio Test) variations. BSEM, take Bayesian model comparison methods, apply SEM. Specifically, focus two information criteria, (1) Widely Applicable Information Criterion (WAIC), (2) Leave-One-cross-validation (LOO). methods intend evaluate --sample predictive accuracy models, compare performance. ability predict datapoint hasn’t used training model (McElreath 2020) example use Industrialization Political Democracy example (Bollen 1989).","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit1 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"widely-applicable-information-criterion","dir":"Articles","previous_headings":"","what":"Widely Applicable Information Criterion","title":"Model Comparison","text":"WAIC (Watanabe 2010) can seen fully Bayesian generalization Akaike Information Criteria (AIC), measure uncertainty/information model prediction row data across posterior draws. Log-Pointwise-Predictive-Density (lppd). WAIC defined WAIC=−2lppd+2efpWAIC,\\begin{equation} WAIC= -2lppd + 2efp_{WAIC}, \\end{equation} first term involves log-likelihoods observed data (marginal latent variables) second term effective number parameters. first term, lppdlppd, estimated : lppd̂=∑=1nlog(1S∑S=1Sf(yi|θS))\\begin{equation} \\widehat{lppd} = \\sum^{n}_{= 1} log \\Bigg(\\frac{1}{S}\\sum^{S}_{S=1}f(y_{}|\\theta^{S}) \\Bigg) \\end{equation} SS number posterior draws f(yi|θS)f(y_{}|\\theta^{S}) density observation ii respect parameter sampled iteration ss. effective number parameter (efpWAICefp_{WAIC}) calculated : efpWAIC=∑=1nvars(logf(yi|θ))\\begin{equation}\\label{eq:efpWAIC} efp_{WAIC} = \\sum^n_{=1}var_{s}(logf(y_{}|\\theta)) \\end{equation} separate variance estimated observation ii across SS posterior draws.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"leave-one-out-cross-validation","dir":"Articles","previous_headings":"","what":"Leave-One-Out cross-validation","title":"Model Comparison","text":"LOO measures predictive density observation holding one observation time use rest observations update prior. estimation calculated via (Vehtari, Gelman, Gabry 2017): LOO=−2∑=1nlog(∑s=1Swisf(yi|θs)∑s=1swis)\\begin{equation} LOO = -2\\sum_{=1}^{n} log \\Bigg(\\frac{\\sum^{S}_{s =1} w^{s}_{}f(y_{}|\\theta^{s})}{\\sum^{s}_{s=1} w^{s}_{}}\\Bigg) \\end{equation} wisw^s_{} Pareto-smoothed sampling weights based relative magnitude individual ii density function across SS posterior samples. LOO effective number parameters involves lppdlppd term WAIC: efpLOO=lppd+LOO/2\\begin{equation} efp_{LOO} = lppd + LOO/2 \\end{equation}","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"model-comparison","dir":"Articles","previous_headings":"","what":"Model comparison","title":"Model Comparison","text":"WAIC LOO approximate models’ performance across posterior draws, able calculate standard error model comparisons involving . model differences estimate differences across Expected Log-Pointwise-Predictive-Density (elpd), standard error respective difference. clear cutoff rules interpret present comparisons, researchers need use expert knowledge part decision process. best recommendation present differences elpd Δelpd\\Delta elpd, standard error, ratio . ratio least 2 can consider evidence differences models, ratio 4 considered stronger evidence. first example, compare standard political democracy model, model factor regressions fixed 0. 2 models, can compare blavCompare looking comparison object, can see WAIC, LOO, estimates, respective differences . information criteria, best model one lowest value case can see model 1 lower LOOIC, ratio shows LOO differences 5 SE magnitude. indicates model estimated regressions better Now, lets look example smaller difference models, smallest regression (dem65~ind60) fixed 0. see LOOIC, see difference two models minimal, ratio 0.21. indicates models functionally equivalent. case like , researchers decide model better representation, theoretically stronger. Lets one last model, largest regression (dem65~dem60) fixed 0. case, looking LOOIC, see model one better (lower value), ratio difference shows model 5 SE magnitude. Indicating evidence model predictive differences","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ 0*ind60 dem65 ~ 0*ind60 + 0*dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit2 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc12 <- blavCompare(fit1, fit2) bc12 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1646.9 18.9 ## p_loo 34.6 2.7 ## looic 3293.8 37.8 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.2]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -40.6 7.9 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1646.7 18.9 ## p_waic 34.4 2.7 ## waic 3293.4 37.7 ## ## 33 (44.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -40.7 7.9 abs(bc12$diff_loo[,\"elpd_diff\"] / bc12$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 5.119273 model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ 0*ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit3 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc13 <- blavCompare(fit1, fit3) bc13 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.7 19.4 ## p_loo 37.6 2.9 ## looic 3213.5 38.9 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.5, 1.3]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -0.4 0.9 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.5 19.4 ## p_waic 37.3 2.9 ## waic 3212.9 38.8 ## ## 39 (52.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -0.5 0.9 abs(bc13$diff_loo[,\"elpd_diff\"] / bc13$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 0.4547628 model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + 0*dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit4 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc14 <- blavCompare(fit1, fit4) bc14 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1630.1 19.9 ## p_loo 38.3 3.0 ## looic 3260.1 39.7 ## ------ ## MCSE of elpd_loo is 0.3. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.2, 1.3]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -23.8 4.0 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1629.7 19.8 ## p_waic 38.0 3.0 ## waic 3259.4 39.6 ## ## 39 (52.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -23.7 4.0 abs(bc14$diff_loo[,\"elpd_diff\"] / bc14$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 5.957015"},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"bayes-factor","dir":"Articles","previous_headings":"","what":"Bayes factor","title":"Model Comparison","text":"Bayesian literature make use Bayes factor (BF) compare models. number criticisms related use BF BSEM, including (1) BF unstable large models (like SEMs), (2) highly sensitive model priors, (3) requires strong priors stable estimation , (4) can require large number posterior draws, (5) estimation using marginal likelihood ignores lot information posterior distributions. details discussion please see Tendeiro Kiers (2019) Schad et al. (2022). criticisms lead us recommend use BF everyday BSEM estimation. researchers commit prior distributions commit exploring noise computations, BF can used describe relative odds one model another, intuitive model comparison metrics.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Model Comparison","text":"recommend use LOO WAIC general model comparison metrics BSEM. allow us estimate models’ --sample predictive accuracy, respective differences across posterior draws. also provide us uncertainty estimates comparison. cases LOO WAIC lead similar results, LOO recommended stable metric (Vehtari, Gelman, Gabry 2017). general, Δelpd\\Delta elpd least 2 standard errors preferably 4 standard errors can interpreted evidence differential predictive accuracy.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"blavaan-coverage","dir":"Articles","previous_headings":"","what":"blavaan Coverage","title":"Two-level SEM","text":"version 0.5-1, blavaan handles two-level, random intercept models complete, continuous data. Handling missing data (assuming missingness random) come future release. meantime, multiple imputation might used combination current blavaan functionality (though currently automatic way ). Alternatively, much missing data occurs lower-level units, listwise deletion work. blavaan approach model estimation mimics lavaan approach, uses matrix results (see Rosseel 2021) enable us efficiently evaluate multilevel SEM likelihood. often lead efficient MCMC estimation, compared sampling level 1 level 2 latent variables working conditional likelihoods (see Merkle et al. 2021 discussion marginal vs conditional likelihoods). Similar single-level models, users can sample latent variables using save.lvs = TRUE argument bcfa/bsem/bgrowth/blavaan commands. Marginal information criteria (marginal latent variables) also automatically computed, information criteria generally preferred condition latent variables (see Merkle, Furr, Rabe-Hesketh 2019 detail context single-level models).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"bayes-specific-options","dir":"Articles","previous_headings":"","what":"Bayes-specific Options","title":"Two-level SEM","text":"Bayesian models require prior distributions. previous blavaan defaults single-level models now used two-level models. can continue use commands like dpriors(lambda = \"normal(1,.5)\") specify Normal(1,.5) prior factor loadings , two-level models, specification apply level 1 level 2 loadings. Depending model, may also useful specify priors individual parameters via prior() argument inside model specification syntax. default prior distributions always work well observed variables whose values far 0. continue encourage users consider prior distributions, possibly using prisamp = TRUE option draw samples prior (used prior predictive checking). Model checking also differs Bayesian frequentist methods. Just like one-level models, blavaan reports posterior predictive p-value general model assessment. computed comparing marginal likelihood observed data (marginal latent variables) marginal likelihood artificial data, iteration MCMC sampling. finer-grained model assessment, encourage users try ppmc(). allows compute posterior predictive p-value using , custom model assessment (defined R function).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"concluding-thoughts","dir":"Articles","previous_headings":"","what":"Concluding Thoughts","title":"Two-level SEM","text":"think new blavaan functionality provides viable option Bayesian two-level SEM, provide solid base future model developments. always, underlying Stan files supporting data available via mcmcfile = TRUE argument, blavaan code available Github. Bug reports appreciated, either blavaan Google group Github issue.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Ordinal Models in blavaan","text":"Structural equation models ordinal observed variables supported starting blavaan 0.4-1 (target=\"stan\" ). document describes overall approach, includes model estimation, threshold parameters, log-likelihood calculation, posterior predictive p-values, Jacobians. assume somewhat familiar layout SEM; , technical detail examples found Merkle Rosseel (2018) , recently, Merkle et al. (2021) (links papers references section). aim provide enough detail elucidate new blavaan features, informal enough get () bored.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"estimation","dir":"Articles","previous_headings":"","what":"Estimation","title":"Ordinal Models in blavaan","text":"Ordinal observed variables handled via data augmentation, style Chib Greenberg (1998). might already know , phrase data augmentation imprecise context SEM. many possible things augmented, can make model estimation easier. augmenting observed data predictions missing data, related multiple imputation methods. augmenting observed data latent variables, can simplify likelihood calculation (leading sometimes called conditional likelihood, though conditional also many meanings). augmenting categorical observed variables underlying, latent continuous variables. last type augmentation . testing, found faster efficient approaches sample latent variables alongside model parameters (latent variables integrated likelihoods ; similar description Merkle et al. (2021)). data augmentation implementation, ordinal observation (e.g., yy) used generate continuous, underlying counterpart (e.g., y*y^\\ast). y*y^\\ast must obey model’s threshold parameters (commonly denoted 𝛕\\mathbf{\\tau}), based value observed data. example, ignoring subscripts y*y^\\ast assuming ordinal variable 4 categories, y*<τ1 y=1τ1τ3 y=4\\begin{align*} y^* < \\tau_1 &\\text{ }y = 1 \\\\ \\tau_1 <\\ y^* < \\tau_2 &\\text{ }y = 2 \\\\ \\tau_2 <\\ y^* < \\tau_3 &\\text{ }y = 3 \\\\ y^* >\\ \\tau_3 &\\text{ }y = 4 \\end{align*} require τ1<τ2<τ3\\tau_1 < \\tau_2 < \\tau_3. generate y*y^* separately ordinal observation dataset. become additional, bounded parameters Stan file. Stan User’s Guide helpful example multivariate probit regression using related approach; see https://mc-stan.org/docs/2_27/stan-users-guide/multivariate-outcomes.html. trickiest parts involve enforcing boundaries y*y^* variables, ensuring threshold parameters ordinal variable ordered correctly (allowing possibility different ordinal variables different numbers thresholds). require Jacobian adjustments took good deal time code correctly (detail appears later section). parameters defined generated, remainder model estimation similar simpler situation observed variables continuous. terms Stan file, ordinal overhead comes transformed parameters block. get model block, things operate continuous data.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"thresholds-priors","dir":"Articles","previous_headings":"","what":"Thresholds & Priors","title":"Ordinal Models in blavaan","text":"prior distributions threshold (τ\\tau) parameters involved may appear. , described previous section, threshold parameters single variable must ordered. say, example, thresholds normal(0,1) prior distribution, ignoring fact one threshold’s value influences size thresholds’ values. Michael Betancourt describes Stan Discourse, prior “interacts (ordering) constraint enforce sort uniform repulsion interior points, resulting rigid differences.” quote https://discourse.mc-stan.org/t/prior-choice--ordered-inverse-transformed-parameters/16378/3 address issue, first define unconstrained, unordered parameter vector whose length equals number thresholds model. Call vector 𝛕*\\mathbf{\\tau}^*. obtain ordered thresholds exponentiating unordered parameter vector specific manner. manner works exactly Stan defines parameter type ordered. See https://mc-stan.org/docs/2_28/reference-manual/ordered-vector.html. Additionally, similar idea independently developed signal detection models Paulewicz Blaut (2020) (see bhsdtr package). idea easily shown via example. Say ordinal variable 4 categories. three thresholds variable obtained via: τ1=τ1*τ2=τ1*+exp(τ2*)τ3=τ1*+exp(τ2*)+exp(τ3*).\\begin{align*} \\tau_1 &= \\tau^*_1 \\\\ \\tau_2 &= \\tau^*_1 + \\exp(\\tau^*_2) \\\\ \\tau_3 &= \\tau^*_1 + \\exp(\\tau^*_2) + \\exp(\\tau^*_3). \\end{align*} place normal prior distributions unordered τ*\\tau^* parameters, opposed placing priors ordered τ\\tau parameters. normal priors imply lowest threshold (τ1\\tau_1 ) normal prior, differences successive τ\\tau’s log-normal priors. blavaan, priors can specified usual two ways. First, add dp argument model estimation command follows. assign prior unordered τ*\\tau^* parameters model. Second, specify priors specific threshold parameters model specification syntax. example, say 4-category observed variable called x1. unique priors three thresholds specified model syntax via clear time priors τ*\\tau^* parameters best option. 2019 paper, Michael Betancourt describes Dirichlet prior regularizes thresholds ordinal regression model. strategy seem work SEM, especially useful datasets categories ordinal variable sparse. issues warrant study. https://betanalpha.github.io/assets/case_studies/ordinal_regression.html","code":"dp = dpriors(tau = \"normal(0, .5)\") x1 | prior(\"normal(-1, 1)\") * t1 + prior(\"normal(0, .5)\") * t2 + prior(\"normal(0, 1)\") * t3"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"likelihood-computations","dir":"Articles","previous_headings":"","what":"Likelihood Computations","title":"Ordinal Models in blavaan","text":"get continuous data model block, seems reasonable expect simple likelihood computations. depends likelihood want compute. likelihood used sampling Stan simple multivariate normal y*y^* observations, combined continuous observed variables model. indeed simple compute. likelihood want use model comparison. one thing, y*y^* parameters associated ordinal data involved likelihood, quantities like effective number parameters become inflated. number parameters involved likelihood also increases sample size, generally bad land model comparison metrics. See Merkle, Furr, Rabe-Hesketh (2019) detail . means , quantities like WAIC PSIS-LOO, must compute second model likelihood involves observed, ordinal yy variables integrates latent y*y^* variables. difficult problem amounts evaluating CDF sometimes-high-dimensional, multivariate normal distribution (see Chib Greenberg 1998, Equation 11). multiple possibilities approximating CDF. currently rely sadmvn() function mnormt package (Azzalini Genz 2020), uses subregion adaptive integration method Genz (1992) fast accurate (15 fewer ordinal variables model). second possibility involves Monte Carlo simulation, implemented tmvnsim package (Bhattacjarjee 2016). case, generate many random samples appropriate truncated multivariate normal average resulting importance sampling weights. procedure computationally intensive also time intensive, balance number random samples drawn amount time takes. users wish use tmvnsim(), must declare number importance samples draw. accomplished setting llnsamp within mcmcextra$data argument. example, draw 100 samples approximation, call bsem() similar functions include argument Beyond two methods, also possible use quadrature latent variables. Many people consider quadrature gold standard , quadrature reduce dimension integration many models (usually fewer latent variables observed variables). quadrature specific SEM, fast, efficient, open implementations method appear currently exist (implementations hidden blavaan, pure R implementations fairly slow). hand, approximation multivariate normal CDF general problem multiple fast, efficient, open implementations, long many ordinal variables model. also exists relatively new method Z. . Botev (2017) evaluating CDF multivariate normal, implementation method appearing package TruncatedNormal (Z. Botev Belzile 2021). method especially useful evaluating high-dimensional normal distributions (case, 15 ordinal variables), may incorporated future versions blavaan.","code":"mcmcextra = list(data = list(llnsamp = 100))"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"comparison-to-lavaan","dir":"Articles","previous_headings":"","what":"Comparison to lavaan","title":"Ordinal Models in blavaan","text":"Ordinal SEM associated two types model parameterizations: delta theta. refer different scale parameterizations y*y^* variables: delta refers total standard deviation y*y^* (including variability due latent variables), theta refers residual standard deviation y*y^*. blavaan, theta parameterization implemented. , want compare lavaan results blavaan results, need use argument parameterization = \"theta\" estimate lavaan model. Also, default lavaan estimator ordinal models multiple-step procedure involves weighted least squares discrepancy function. resulting parameter estimates sometimes far posterior means reported blavaan. blavaan estimates usually closer estimator=\"PML\" lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"posterior-predictive-p-values","dir":"Articles","previous_headings":"","what":"Posterior Predictive p-values","title":"Ordinal Models in blavaan","text":"Posterior predictive p-value (ppp) computations receive speed boost 0.4 series. computations now occur Stan, whereas previously occurred R model estimation. discussed Asparouhov Muthén (2021), ppp computations needed models missing data can excessively slow, requiring us run EM algorithm posterior sample order find “H1” (“saturated”) model covariance matrix. solution Asparouhov Muthén (2021) involves realization need use fully-optimized H1 covariance matrix order compute ppp. blavaan, consequently run EM algorithm fixed number iterations order compute H1 covariance matrix “good enough” ppp. default number iterations set 20, users can change default supplying emiter value via mcmcextra argument. example,","code":"mcmcextra = list(data = list(emiter = 50))"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"jacobians","dir":"Articles","previous_headings":"","what":"Jacobians","title":"Ordinal Models in blavaan","text":"(section likely relevant editing/writing Stan models.) Stan model underlying blavaan currently requires Jacobian adjustments two places. section briefly reviews ideas underneath adjustments, future self may wish remember. need Jacobian adjustment place prior something appear Stan parameters block. Jacobian tells us implied priors things parameters block, based priors appear model block. Jacobian comes statistics literature “change variables”: applying function random variables, finding distribution function based original distribution random variables. comes Stan models, means starting priors model block finding implied priors parameters block. confused long time , Stan file, functions naturally go opposite direction: starting parameters block, moving model block. fact functions go model parameters convenient, though, Jacobian adjustments require inverse functions. inverse functions move us parameters model, already exist Stan model. just need find appropriate derivatives functions, lead Jacobian. example, consider fact blavaan allows users choose whether priors go standard deviation, variance, precision parameters. standard deviations appear parameters block regardless user chooses (Stan model precompiled time package installation). Say user wants priors precisions. transform standard deviations precisions model block, put prior precision. addition prior, need Jacobian function starts standard deviation (call σ\\sigma) transforms precision (σ−2\\sigma^{-2}). derivative σ−2\\sigma^{-2} respect σ\\sigma −2σ−3-2 \\sigma^{-3}. simple function mapping single parameter different value, Jacobian absolute value derivative, 2σ−32 \\sigma^{-3}. Stan file, add log Jacobian target: examples discussion can found : https://mc-stan.org/users/documentation/case-studies/mle-params.html","code":"target += log(2) - 3*log(sigma)"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Ordinal Models in blavaan","text":"blavaan 0.4 series offers enhanced functionality variety areas. computational decisions made reflect balance estimation precision estimation speed. case software defaults behave poorly situations. example, default prior distributions can problematic certain situations, likelihood approximations ordinal models may precise desired, new ppp computations may behave differently previous computations. encourage users carry sensitivity analyses, also report bugs!","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/plotting.html","id":"basics","dir":"Articles","previous_headings":"","what":"Basics","title":"Plot Functionality","text":"many blavaan models many parameters, users generally need specify parameters wish plot. accomplished supplying numbers pars argument, numbers correspond order parameters coef() command (numbers also appear free column parameter table). Users must also specify type plot desire via plot.type argument. , example, trace plot first four model parameters looks like Many plot types available, coming bayesplot package. general, bayesplot functions begin mcmc_, corresponding plot.type remainder function name without leading mcmc_. Examples many plots can found bayesplot vignette.","code":"plot(fit, pars = 1:4, plot.type = \"trace\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/plotting.html","id":"customization","dir":"Articles","previous_headings":"","what":"Customization","title":"Plot Functionality","text":"Users may wish customize aspects resulting plots. , plot() function output ggplot object. makes possible modify plot ggplot object, allows many possibilities. One starting point exploring ggplot2 . Alternatively, users may wish create plot entirely different available via plot(). can facilitated extracting posterior samples Stan model, via blavInspect():","code":"p <- plot(fit, pars = 1:4, plot.type = \"trace\", showplot = FALSE) p + facet_text(size=15) + legend_none() ## list of draws ## (one list entry per chain): draws <- blavInspect(fit, \"mcmc\") ## convert the list to a matrix ## (each row is a sample, ## each column is a parameter) draws <- do.call(\"rbind\", draws) ## Stan (or JAGS) model modobj <- blavInspect(fit, \"mcobj\")"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"defaults","dir":"Articles","previous_headings":"","what":"Defaults","title":"Specifying Prior Distributions","text":"default priors can seen via important note prior distributions correspond Stan parameterizations. similar R parameterizations necessarily exactly . Greek(ish) names correspond following parameter types (MV manifest/observed variable LV latent variable): information priors thresholds, see ordinal modeling details. target = \"stan\" (default), priors currently restricted one distribution per parameter type. can change prior distribution parameters (example, mean standard deviation normal), change prior distribution type. exceptions “theta” “psi” parameters: , can use modifiers “[sd]”, “[var]”, “[prec]” specify whether want priors apply standard deviation, variance, precision. require flexibility prior specification, change target either \"stanclassic\" (old Stan approach) \"jags\" (JAGS approach). Alternatively, can export Stan model via mcmcfile = TRUE, edit file needed, fit via rstan package. modify prior distributions, simply supply new text string dpriors() like : default prior loadings now normal mean 1 standard deviation 2, rest parameters remain original defaults. next time estimate model (via bsem(), bcfa(), bgrowth(), blavaan()), add argument dp=mydp use new set default priors.","code":"dpriors() ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(0,10)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\" ## nu alpha lambda beta ## \"MV intercept\" \"LV intercept\" \"Loading\" \"Regression\" ## theta psi rho ibpsi ## \"MV precision\" \"LV precision\" \"Correlation\" \"Covariance matrix\" ## tau ## \"Threshold\" mydp <- dpriors(lambda=\"normal(1,2)\") mydp ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(1,2)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"individual-parameters","dir":"Articles","previous_headings":"","what":"Individual Parameters","title":"Specifying Prior Distributions","text":"addition setting prior one type model parameter, user may wish set prior specific model parameter. accomplished using prior() modifier within model specification. example, consider following syntax Holzinger Swineford (1939) confirmatory factor model: loading visual x2 now normal prior mean 1 standard deviation 2, loading textual x6 normal prior mean 3 standard deviation 1.5. loadings default prior distribution. syntax, additionally specified gamma(3,3) prior associated residual x1. [sd] text end distribution says prior goes residual standard deviation, opposed residual precision residual variance. exist two options : [var] option residual variance, brackets precision (also use [prec]). bracketed text can used model variance/SD/precision parameter also used default prior specification desired.","code":"HS.model <- ' visual =~ x1 + prior(\"normal(1,2)\")*x2 + x3 textual =~ x4 + x5 + prior(\"normal(3,1.5)\")*x6 speed =~ x7 + x8 + x9 x1 ~~ prior(\"gamma(3,3)[sd]\")*x1 '"},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"covariance-parameters","dir":"Articles","previous_headings":"","what":"Covariance Parameters","title":"Specifying Prior Distributions","text":"One additional note covariance parameters defined model syntax: prior() syntax specifies prior correlation associated covariance parameter, opposed covariance . specified distribution support (0,1), blavaan automatically translates prior equivalent distribution support (-1,1). safest stick beta priors . example, syntax places Beta(1,1) (uniform) prior correlation visual textual factors. desired, also specify priors standard deviations (variances precisions) visual textual factors. Together prior correlation, priors imply prior covariance visual textual.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 visual ~~ prior(\"beta(1,1)\")*textual '"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Prior Predictive Checks","text":"Bayesian models need specify priors model parameters. Priors distribution think parameters follow, even data. can represent high low uncertainty, diffuse prior indicates don know lot parameter behave, informative prior means quite certain expected distribution.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"prior-predictive-checks","dir":"Articles","previous_headings":"","what":"Prior Predictive Checks","title":"Prior Predictive Checks","text":"Prior predictive checks (PPC) generate data according prior order asses whether prior appropriate (Gabry et al. 2019). posterior predictive check generates replicated data according posterior predictive distribution. contrast, prior predictive check generates data according prior predictive distribution ysim∼p(y)y^{sim} ∼ p(y). prior predictive distribution just like posterior predictive distribution observed data, prior predictive check nothing limiting case posterior predictive check data. easy carry mechanically simulating parameters θsim∼p(θ)θ^{sim}∼p(\\theta) according priors, simulating data ysim∼p(y∣θsim)y^{sim}∼p(y∣ \\theta^{sim}) according sampling distribution given simulated parameters. result simulation joint distribution, (ysim,θsim)∼p(y,θ)(y^{sim},θ^{sim})∼p(y,\\theta) thus ysim∼p(y)y^{sim}∼p(y) simulation prior predictive distribution. blavaan can get PPC use argument prisamp=TRUE , tell blavaan ignore data build distributions priors. start adjusting priors, instead using default priors.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"weakly-informative-priors","dir":"Articles","previous_headings":"Prior Predictive Checks","what":"Weakly informative priors","title":"Prior Predictive Checks","text":"show example Holzinger Swineford (1939) data, first case weakly informative priors. stpecifying observeded variable intercepts prior N(3,2)N(3, 2), factor loadings prior N(0.4,2)N(0.4, 2), residual standard deviation prior Γ(1,1)\\Gamma(1,1). estimate BSEM model respective priors dp argument, prisamp=TRUE, getting PPC instead posterior distributions. might get warning messages either divergent /failed convergence. ignore messages likely issues evaluations prior predictions. now blavaan object prior predictive distributions, can use package functions describe , see parameters within expected ranges. example can get PPC density distributions first 9 parameters (factor loadings case). basic plot() method calls functions bayesplot package (Gabry Mahr 2021) plot.type = \"dens\" argument can plot density distributions can also pick parameters plot, like factor correlations chossing parameters 19:21 case factor loading distributions see first loading factor bounded 0, due modeling identification constraint blavaan, maximum value around 6. distributions range -6 6 -4 4, priors likely value around 0. described weakly informative allows negative positive values without allowing crazy high/low values. realistic range depend parameter, model specification, data. , consider priors function characteristics. factor correlations kept default diffuse priors, allowed high low correlation, prior distributions flat across possible correlation values.","code":"priors <- dpriors(nu=\"normal(3,2)\", lambda=\"normal(0.4, 2)\", theta=\"gamma(1,1)[sd]\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit_wi <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T, test = \"none\", dp=priors, prisamp = T) plot(fit_wi, pars=1:9, plot.type = \"dens\") plot(fit_wi, pars=19:21, plot.type = \"dens\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"default-priors","dir":"Articles","previous_headings":"Prior Predictive Checks","what":"Default priors","title":"Prior Predictive Checks","text":"next example, estimate PPC package default priors, consider diffuse priors. can see blavaan default priors function dpriors() estimate BSEM model ignore dp argument letting run default priors, prisamp=TRUE, getting PPC instead posterior distributions. can plot density distributions compare . see default diffuse priors, model allows high values -30 30 way can see diffuse priors allows higher range values. researcher decide range priors better present expectations. important note PPC allows see expected distributions based priors, might priors used estimation process, priors interact model specification constraints (o bound constraint first factor loading) (Merkle et al. 2023)","code":"dpriors() ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(0,10)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\" fit_df <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T, test = \"none\", prisamp = T) plot(fit_df, pars=1:9, plot.type = \"dens\")"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Probability of Direction","text":"Probability Direction (pd) index effect existence, ranging 0% 100%, representing certainty effect goes particular direction (.e., positive negative) (Makowski et al. 2019). Beyond simplicity interpretation, understanding computation, index also presents interesting properties: independent model: solely based posterior distributions require additional information data model. robust scale response variable predictors. *strongly correlated frequentist p-value, can thus used draw parallels give reference readers non-familiar Bayesian statistics. Can interpreted probability parameter (described posterior distribution) chosen cutoff, explicit hypothesis. mathematically defined proportion posterior distribution satisfies specified hypothesis. Although differently expressed, index fairly similar (.e., strongly correlated) frequentist p-value.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"probability-of-direction-pd","dir":"Articles","previous_headings":"","what":"Probability of Direction (pd)","title":"Probability of Direction","text":"example use Industrialization Political Democracy example (Bollen 1989). first estimate latent regression model can look overall model results summary function, case also asking standardized estimates, R2R^2 calculate probability direction use function package brms (Bürkner 2017) need extract posterior draws matrix, also important note parameters posterior draws named Stan underlying object names, instead (b)lavaan parameter names. due argument add.labels = FALSE used avoid trouble parameter names tildes equal signs . can see parameter name equates partable() function, follows example focus regressions factors Now, can calculate pd, hypothesis() function brms. can ask specific questions posterior distributions, example want know proportion regression dem65~ind60 higher 0. function requires 2 arguments, posterior draws (mc_out) hypothesis (bet_sign[2] > 0). also adding ``alpha``` argument specifies size credible intervals estimate presents mean posterior distribution, respective measures variability (deviation credible interval). Post.Prob pd stated hypothesis, example can say 91% posterior distribution dem65~ind60 lower 0. equivalent one-tail test. Evid.Ratio evidence ratio hypothesis, hypothesis form >ba > b, evidence ratio ratio posterior probability >ba > b posterior probability ## 33 dem60 ~~ dem60 ## 34 dem65 ~~ dem65 ## 35 x1 ~1 Nu_free[1] ## 36 x2 ~1 Nu_free[2] ## 37 x3 ~1 Nu_free[3] ## 38 y1 ~1 Nu_free[4] ## 39 y2 ~1 Nu_free[5] ## 40 y3 ~1 Nu_free[6] ## 41 y4 ~1 Nu_free[7] ## 42 y5 ~1 Nu_free[8] ## 43 y6 ~1 Nu_free[9] ## 44 y7 ~1 Nu_free[10] ## 45 y8 ~1 Nu_free[11] ## 46 ind60 ~1 ## 47 dem60 ~1 ## 48 dem65 ~1 ## 49 .p4. == .p8. ## 50 .p5. == .p9. ## 51 .p6. == .p10. ## 52 .p7. == .p11. pt[pt$op==\"~\",] ## lhs op rhs pxnames ## 12 dem60 ~ ind60 bet_sign[1] ## 13 dem65 ~ ind60 bet_sign[2] ## 14 dem65 ~ dem60 bet_sign[3] hypothesis(mc_out, \"bet_sign[2] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob ## 1 (bet_sign[2]) > 0 0.25 0.17 -0.03 0.54 13.49 0.93 ## Star ## 1 ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities. hypothesis(mc_out, \"bet_sign[1] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob ## 1 (bet_sign[1]) > 0 0.7 0.18 0.43 1.01 Inf 1 ## Star ## 1 * ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities. hypothesis(mc_out, \"bet_sign[1] - bet_sign[2] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio ## 1 (bet_sign[1]-bet_... > 0 0.45 0.26 0.05 0.89 30.91 ## Post.Prob Star ## 1 0.97 * ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities."},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"region-of-practical-equivalence-rope","dir":"Articles","previous_headings":"","what":"Region of Practical Equivalence (ROPE)","title":"Probability of Direction","text":"Note far tested hypothesis 0, equivalent frequentist null hypothesis tests. can test . Bayesian inference based statistical significance, effects tested “zero”. Indeed, Bayesian framework offers probabilistic view parameters, allowing assessment uncertainty related . Thus, rather concluding effect present simply differs zero, conclude probability outside specific range can considered “practically effect” (.e., negligible magnitude) sufficient. range called region practical equivalence (ROPE). Indeed, statistically, probability posterior distribution different 0 make much sense (probability different single point infinite). Therefore, idea underlining ROPE let user define area around null value enclosing values equivalent null value practical purposes (Kruschke Liddell 2018) examples, change value tested, common recommendations use |0.1| minimally relevant value standardized regressions, case find 0.79 proportion posterior 0.1","code":"hypothesis(mc_out, \"bet_sign[2] > .1\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio ## 1 (bet_sign[2])-(.1) > 0 0.15 0.17 -0.13 0.44 4.34 ## Post.Prob Star ## 1 0.81 ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities."},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"vs--95-ci","dir":"Articles","previous_headings":"","what":"89% vs. 95% CI","title":"Probability of Direction","text":"commonly frequentist tradition see use 95% Credible interval. Using 89% another popular choice, used default long time. start? Naturally, came choosing CI level report default, people started using 95%, arbitrary convention used frequentist world. However, authors suggested 95% might appropriate Bayesian posterior distributions, potentially lacking stability enough posterior samples drawn (McElreath 2020). proposition use 90% instead 95%. However, recently, McElreath (2020) suggested use arbitrary thresholds first place, use 89%? Moreover, 89 highest prime number exceed already unstable 95% threshold. anything? Nothing, reminds us total arbitrariness conventions (McElreath 2020). can use argument alpha argument hypothesis function, interpretation values Post.Prob","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"caveats","dir":"Articles","previous_headings":"","what":"Caveats","title":"Probability of Direction","text":"Although allows testing hypotheses similar manner frequentist null-hypothesis testing framework, strongly argue using arbitrary cutoffs (e.g., p < .05) determine ‘existence’ effect. ROPE sensitive scale, aware value interest representative respective scale. , standardize parameters useful commonly used scale","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/start.html","id":"installation","dir":"Articles","previous_headings":"","what":"Installation","title":"Getting Started with blavaan","text":"blavaan can installed CRAN usual way: situations, may wish install blavaan GitHub. GitHub version sometimes contains bug fixes yet CRAN, though can also less stable. install GitHub, use following command. command requires system can compile Stan models, guaranteed usually install blavaan CRAN. trouble, may help look RStan Getting Started page.","code":"install.packages(\"blavaan\") remotes::install_github(\"ecmerkle/blavaan\", INSTALL_opts = \"--no-multiarch\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/start.html","id":"commands-and-syntax","dir":"Articles","previous_headings":"","what":"Commands and Syntax","title":"Getting Started with blavaan","text":"blavaan package depends lavaan package model specification computations. means , already know lavaan, already able many things blavaan. particular, many blavaan commands add letter “b” start lavaan command. example, sem() becomes bsem(), lavInspect() becomes blavInspect(). also sometimes possible use lavaan command blavaan object, though results may always expect. details mind, look lavaan tutorial many examples models. can translate many examples blavaan adding “b” start commands. look pages , learn additional blavaan arguments specific Bayesian methods.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"convergence","dir":"Articles","previous_headings":"","what":"Convergence","title":"Model Summaries","text":"Following model estimation, immediately wish look “goodness” posterior samples, including convergence stationary distribution autocorrelation. Popular convergence metrics available via blavInspect() function: R-hat values near 1.00 indicate convergence, large effective sample sizes (hundreds ) preferred. details metrics, see, e.g., Posterior Analysis section Stan Reference Manual. model definitely converged (judged Rhat), blavaan issue multiple warnings. Lack convergence sometimes caused bad initial values chain strays extreme region posterior space. cases, can helpful re-estimate model second time. also helpful specify mildly-informative priors loading parameters, chains wander extreme loading values. example, expect variables positively correlated loadings fixed 1 identification, Normal(1,.5) often mildly-informative prior. Otherwise, lack convergence may imply prior distributions severely conflict data, ill-defined model. sometimes helpful try fit model lavaan, observe whether errors occur .","code":"blavInspect(fit, 'rhat') blavInspect(fit, 'neff')"},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"model-fit-comparison","dir":"Articles","previous_headings":"","what":"Model Fit & Comparison","title":"Model Summaries","text":"Next, may wish examine model fit metrics. many metrics available summary() output, available fitMeasures() function: judging absolute fit, blavaan supplies posterior predictive p-value based likelihood ratio statistic. Good-fitting models values near 0.5 metric. examining models’ relative fits, blavaan supplies DIC, WAIC, LOOIC. latter two metrics computed help loo package (Vehtari et al. 2020). Comparison multiple models criteria facilitated via blavCompare(), provides standard errors difference two criteria. notable functions include blavFitIndices() alternative measures absolute fit ppmc() general posterior predictive checks.","code":"summary(fit) fitMeasures(fit)"},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"latent-variables-standardization","dir":"Articles","previous_headings":"","what":"Latent Variables & Standardization","title":"Model Summaries","text":"often-discussed advantage Bayesian models abilities describe uncertainty “random” parameters, including random effects latent variables. access functionality blavaan, users must set save.lvs = TRUE model estimation, done top page. model estimation, uses can access information via blavInspect() blavPredict(). Relevant arguments blavInspect() include lvmeans lvs. former returns posterior means latent variables, similar predictions supplied frequentist models. latter returns posterior samples latent variables, users summarize uncertainties functions latent variables. posterior samples returned list length n.chains, list entry row per posterior sample (number columns total number latent variables model): related, different, information can obtained blavPredict(). function also return posterior samples latent variables, matrix instead list: blavPredict() function also return predictions observed variables conditioned sampled latent variables. type = \"yhat\" argument returns expected values observed variables conditioned latent variable samples; type = \"ypred\" argument returns posterior predictions observed variables including residual noise (essentially yhat + error); type = \"ymis\" argument returns posterior predictions missing variables conditioned observed. expected values predictions returned list format; matrix, see last line code . Finally, fully related latent variables: standardizedPosterior() function return standardized posterior draws. calls lavaan function standardizedSolution() background function’s flexibility.","code":"postmns <- blavInspect(fit, what = \"lvmeans\") postsamps <- blavInspect(fit, what = \"lvs\") postsamps <- blavPredict(fit, type = \"lv\") evpreds <- blavPredict(fit, type = \"yhat\") postpreds <- blavPredict(fit, type = \"ypred\") mispreds <- blavPredict(fit, type = \"ymis\") ## convert to matrix from list: evpreds <- do.call(\"rbind\", evpreds)"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Edgar Merkle. Author, maintainer. Yves Rosseel. Author. Ben Goodrich. Author. Mauricio Garnier-Villarreal. Contributor. R/blav_compare.RR/ctr_bayes_fit.Rvignettes Terrence D. Jorgensen. Contributor. R/ctr_bayes_fit.RR/ctr_ppmc.RR/blav_predict.R Huub Hoofs. Contributor. R/ctr_bayes_fit.R Rens van de Schoot. Contributor. R/ctr_bayes_fit.R Andrew Johnson. Contributor. Makevars Matthew Emery. Contributor. loo moment_match","code":""},{"path":"http://ecmerkle.github.io/blavaan/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Merkle EC, Fitzsimmons E, Uanhoro J, Goodrich B (2021). “Efficient Bayesian Structural Equation Modeling Stan.” Journal Statistical Software, 100(6), 1–22. doi:10.18637/jss.v100.i06. Merkle EC, Rosseel Y (2018). “blavaan: Bayesian Structural Equation Models via Parameter Expansion.” Journal Statistical Software, 85(4), 1–30. doi:10.18637/jss.v085.i04.","code":"@Article{, title = {Efficient {Bayesian} Structural Equation Modeling in {Stan}}, author = {Edgar C. Merkle and Ellen Fitzsimmons and James Uanhoro and Ben Goodrich}, journal = {Journal of Statistical Software}, year = {2021}, volume = {100}, number = {6}, pages = {1--22}, doi = {10.18637/jss.v100.i06}, } @Article{, title = {{blavaan: Bayesian} Structural Equation Models via Parameter Expansion}, author = {Edgar C. Merkle and Yves Rosseel}, journal = {Journal of Statistical Software}, year = {2018}, volume = {85}, number = {4}, pages = {1--30}, doi = {10.18637/jss.v085.i04}, }"},{"path":"http://ecmerkle.github.io/blavaan/index.html","id":"blavaan","dir":"","previous_headings":"","what":"Bayesian Latent Variable Analysis","title":"Bayesian Latent Variable Analysis","text":"blavaan free, open source R package Bayesian latent variable analysis. relies JAGS Stan estimate models via MCMC. blavaan functions syntax similar lavaan. example, consider Political Democracy example Bollen (1989): development version blavaan (containing updates yet CRAN) can installed via command . Compilation required; may problem users currently rely binary version blavaan CRAN. information, see: Merkle, E. C., Fitzsimmons, E., Uanhoro, J., & Goodrich, B. (2021). Efficient Bayesian structural equation modeling Stan. Journal Statistical Software, 100(6), 1–22. Merkle, E. C., & Rosseel, Y. (2018). blavaan: Bayesian structural equation models via parameter expansion. Journal Statistical Software, 85(4), 1–30. blavaan supported Institute Education Sciences, U.S. Department Education, Grant R305D210044, well NSF grants SES-1061334 1460719.","code":"library(lavaan) # for the PoliticalDemocracy data library(blavaan) model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + y2 + y3 + y4 dem65 =~ y5 + y6 + y7 + y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual covariances y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data = PoliticalDemocracy) summary(fit) remotes::install_github(\"ecmerkle/blavaan\", INSTALL_opts = \"--no-multiarch\")"},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Confirmatory Factor Analysis Models — bcfa","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"Fit Confirmatory Factor Analysis (CFA) model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"","code":"bcfa(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"bcfa function wrapper general blavaan function, using following default lavaan arguments: int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"object inherits class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"","code":"data(HolzingerSwineford1939, package = \"lavaan\") # The Holzinger and Swineford (1939) example HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' if (FALSE) { # \\dontrun{ fit <- bcfa(HS.model, data = HolzingerSwineford1939) summary(fit) } # } # A short run for rough results fit <- bcfa(HS.model, data = HolzingerSwineford1939, burnin = 100, sample = 100, n.chains = 2) #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: #> Chain 1: Gradient evaluation took 0.000358 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.58 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: #> Chain 1: WARNING: There aren't enough warmup iterations to fit the #> Chain 1: three stages of adaptation as currently configured. #> Chain 1: Reducing each adaptation stage to 15%/75%/10% of #> Chain 1: the given number of warmup iterations: #> Chain 1: init_buffer = 15 #> Chain 1: adapt_window = 75 #> Chain 1: term_buffer = 10 #> Chain 1: #> Chain 1: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 1: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 1: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 1: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 1: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 1: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 1: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 1: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 1: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 1: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: #> Chain 1: Elapsed Time: 0.429 seconds (Warm-up) #> Chain 1: 0.447 seconds (Sampling) #> Chain 1: 0.876 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: #> Chain 2: Gradient evaluation took 0.000256 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.56 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: #> Chain 2: WARNING: There aren't enough warmup iterations to fit the #> Chain 2: three stages of adaptation as currently configured. #> Chain 2: Reducing each adaptation stage to 15%/75%/10% of #> Chain 2: the given number of warmup iterations: #> Chain 2: init_buffer = 15 #> Chain 2: adapt_window = 75 #> Chain 2: term_buffer = 10 #> Chain 2: #> Chain 2: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 2: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 2: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 2: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 2: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 2: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 2: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 2: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 2: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 2: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: #> Chain 2: Elapsed Time: 0.737 seconds (Warm-up) #> Chain 2: 0.413 seconds (Sampling) #> Chain 2: 1.15 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is NA, indicating chains have not mixed. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#r-hat #> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#bulk-ess #> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#tail-ess #> Computing post-estimation metrics (including lvs if requested)... summary(fit) #> blavaan 0.5.6.1311 ended normally after 100 iterations #> #> Estimator BAYES #> Optimization method MCMC #> Number of model parameters 21 #> #> Number of observations 301 #> #> Statistic MargLogLik PPP #> Value -3806.252 0.000 #> #> Parameter Estimates: #> #> #> Latent Variables: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> visual =~ #> x1 1.000 #> x2 0.572 0.121 0.359 0.805 1.003 normal(0,10) #> x3 0.739 0.131 0.498 1.045 1.014 normal(0,10) #> textual =~ #> x4 1.000 #> x5 1.116 0.060 0.995 1.231 1.000 normal(0,10) #> x6 0.933 0.055 0.831 1.027 0.992 normal(0,10) #> speed =~ #> x7 1.000 #> x8 1.267 0.178 0.905 1.615 1.005 normal(0,10) #> x9 1.219 0.289 0.769 2.041 1.015 normal(0,10) #> #> Covariances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> visual ~~ #> textual 0.386 0.079 0.225 0.556 0.996 lkj_corr(1) #> speed 0.240 0.052 0.158 0.350 1.005 lkj_corr(1) #> textual ~~ #> speed 0.159 0.051 0.065 0.266 0.995 lkj_corr(1) #> #> Variances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .x1 0.569 0.143 0.242 0.820 1.020 gamma(1,.5)[sd] #> .x2 1.149 0.093 0.957 1.327 0.998 gamma(1,.5)[sd] #> .x3 0.855 0.105 0.656 1.078 1.009 gamma(1,.5)[sd] #> .x4 0.380 0.047 0.294 0.475 0.994 gamma(1,.5)[sd] #> .x5 0.450 0.053 0.355 0.566 0.993 gamma(1,.5)[sd] #> .x6 0.361 0.049 0.276 0.469 1.007 gamma(1,.5)[sd] #> .x7 0.839 0.092 0.670 1.022 1.004 gamma(1,.5)[sd] #> .x8 0.505 0.098 0.327 0.726 1.006 gamma(1,.5)[sd] #> .x9 0.549 0.101 0.328 0.736 1.012 gamma(1,.5)[sd] #> visual 0.796 0.164 0.533 1.171 1.009 gamma(1,.5)[sd] #> textual 0.981 0.104 0.789 1.182 1.000 gamma(1,.5)[sd] #> speed 0.342 0.097 0.154 0.525 1.038 gamma(1,.5)[sd] #>"},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Growth Curve Models — bgrowth","title":"Fit Growth Curve Models — bgrowth","text":"Fit Growth Curve model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Growth Curve Models — bgrowth","text":"","code":"bgrowth(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Growth Curve Models — bgrowth","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Growth Curve Models — bgrowth","text":"bgrowth function wrapper general blavaan function, using following default lavaan arguments: meanstructure = TRUE, int.ov.free = FALSE, int.lv.free = TRUE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Growth Curve Models — bgrowth","text":"object class blavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Growth Curve Models — bgrowth","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Growth Curve Models — bgrowth","text":"","code":"if (FALSE) { # \\dontrun{ ## linear growth model with a time-varying covariate data(Demo.growth, package = \"lavaan\") model.syntax <- ' # intercept and slope with fixed coefficients i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4 # regressions i ~ x1 + x2 s ~ x1 + x2 # time-varying covariates t1 ~ c1 t2 ~ c2 t3 ~ c3 t4 ~ c4 ' fit <- bgrowth(model.syntax, data = Demo.growth) summary(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":null,"dir":"Reference","previous_headings":"","what":"Bayesian model comparisons — blavCompare","title":"Bayesian model comparisons — blavCompare","text":"Bayesian model comparisons, including WAIC, LOO, Bayes factor approximation.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bayesian model comparisons — blavCompare","text":"","code":"blavCompare(object1, object2, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bayesian model comparisons — blavCompare","text":"object1 object class blavaan. object2 second object class blavaan. ... arguments loo().","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Bayesian model comparisons — blavCompare","text":"function computes Bayesian model comparison metrics, including Bayes factor approximation, WAIC, LOOIC. log-Bayes factor two models based Laplace approximation model's marginal log-likelihood. WAIC LOOIC metrics come loo package. ELPD difference SE specifically come loo::loo_compare().","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bayesian model comparisons — blavCompare","text":"list containing separate results log-Bayes factor, WAIC, LOOIC, differences WAIC LOOIC.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Bayesian model comparisons — blavCompare","text":"Raftery, . E. (1993). Bayesian model selection structural equation models. K. . Bollen & J. S. Long (Eds.), Testing structural equation models (pp. 163-180). Beverly Hills, CA: Sage. Vehtari ., Gelman ., Gabry J. (2017). Practical Bayesian model evaluation using leave-one-cross-validation WAIC. Statistics Computing, 27, 1413-1432.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bayesian model comparisons — blavCompare","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") hsm1 <- ' visual =~ x1 + x2 + x3 + x4 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit1 <- bcfa(hsm1, data = HolzingerSwineford1939) hsm2 <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 + x7 speed =~ x7 + x8 + x9 ' fit2 <- bcfa(hsm2, data = HolzingerSwineford1939) blavCompare(fit1, fit2) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":null,"dir":"Reference","previous_headings":"","what":"SEM Fit Indices for Bayesian SEM — blavFitIndices","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"function provides posterior distribution \\(\\chi^2\\)-based fit indices assess global fit latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"","code":"blavFitIndices(object, thin = 1L, pD = c(\"loo\",\"waic\",\"dic\"), rescale = c(\"devM\",\"ppmc\",\"mcmc\"), fit.measures = \"all\", baseline.model = NULL) ## S4 method for signature 'blavFitIndices' # S4 method for class 'blavFitIndices' summary(object, ...) # S3 method for class 'bfi' summary(object, central.tendency = c(\"mean\",\"median\",\"mode\"), hpd = TRUE, prob = .90)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"object object class blavaan. thin Optional integer indicating much thin chain. Default 1L, indicating thin chains. pD character indicating information criterion returned fitMeasures(object) use estimated number parameters. default leave-one-information criterion (LOO-IC), highly recommended Vehtari et al. (2017). rescale character indicating method used calculate fit indices. rescale = \"devM\" (default), Bayesian analog \\(\\chi^2\\) statistic (deviance evaluated posterior mean model parameters) approximated rescaling deviance iteration subtracting estimated number parameters. rescale = \"PPMC\", deviance iteration rescaled subtracting deviance data simulated posterior predictive distribution (posterior predictive model checking; see Hoofs et al., 2017). rescale = \"MCMC\", fit measures simply calculated using fitMeasures iteration Markov chain(s), based model-implied moments iteration (advised model includes informative priors, case model's estimated pD deviate number parameters used calculate df fitMeasures). fit.measures \"\", fit measures available returned. single fit measures specified name, computed returned. rescale = \"devM\" \"PPMC\", currently available indices \"BRMSEA\", \"BGammaHat\", \"adjBGammaHat\", \"BMc\", \"BCFI\", \"BTLI\", \"BNFI\". rescale = \"MCMC\", user may request indices returned fitMeasures objects class lavaan. baseline.model NULL, object class blavaan, representing user-specified baseline model. baseline.model provided, incremental fit indices (BCFI, BTLI, BNFI) can requested fit.measures. Ignored rescale = \"MCMC\". ... Additional arguments summary method: central.tendency Takes values \"mean\", \"median\", \"mode\", indicating statistics used characterize location posterior distribution. default, 3 statistics returned. posterior mean labeled EAP expected posteriori estimate, mode labeled MAP modal posteriori estimate. hpd logical indicating whether calculate highest posterior density (HPD) credible interval fit index (defaults TRUE). prob \"confidence\" level credible interval(s) (defaults 0.9).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"S4 object class blavFitIndices consisting 2 slots: @details list containing choices made user (defaults; e.g., values pD rescale set), well posterior distribution \\(\\chi^2\\) (deviance) statistic (rescaled, rescale = \"devM\" \"PPMC\"). @indices list containing posterior distribution requested fit.measure. summary() method returns data.frame containing one row requested fit.measure, columns containing specified measure(s) central.tendency, posterior SD, (requested) HPD credible-interval limits.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"Mauricio Garnier-Villareal (Vrije Universiteit Amsterdam; mgv@pm.) Terrence D. Jorgensen (University Amsterdam; TJorgensen314@gmail.com)","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"rescale = \"PPMC\" based : Hoofs, H., van de Schoot, R., Jansen, N. W., & Kant, . (2017). Evaluating model fit Bayesian confirmatory factor analysis large samples: Simulation study introducing BRMSEA. Educational Psychological Measurement. doi:10.1177/0013164417709314 rescale = \"devM\" based : Garnier-Villarreal, M., & Jorgensen, T. D. (2020). Adapting Fit Indices Bayesian Structural Equation Modeling: Comparison Maximum Likelihood. Psychological Methods, 25(1), 46–70. https://doi.org/dx.doi.org/10.1037/met0000224 (See also https://osf.io/afkcw/) references: Vehtari, ., Gelman, ., & Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-cross-validation WAIC. Statistics Computing, 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' ## fit target model fit1 <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 1000) ## fit null model to calculate CFI, TLI, and NFI null.model <- c(paste0(\"x\", 1:9, \" ~~ x\", 1:9), paste0(\"x\", 1:9, \" ~ 1\")) fit0 <- bcfa(null.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 1000) ## calculate posterior distributions of fit indices ## The default method mimics fit indices derived from ML estimation ML <- blavFitIndices(fit1, baseline.model = fit0) ML summary(ML) ## other options: ## - use Hoofs et al.'s (2017) PPMC-based method ## - use the estimated number of parameters from WAIC instead of LOO-IC PPMC <- blavFitIndices(fit1, baseline.model = fit0, pD = \"waic\", rescale = \"PPMC\") ## issues a warning about using rescale=\"PPMC\" with N < 1000 (see Hoofs et al.) ## - specify only the desired measures of central tendency ## - specify a different \"confidence\" level for the credible intervals summary(PPMC, central.tendency = c(\"mean\",\"mode\"), prob = .95) ## Access the posterior distributions for further investigation head(distML <- data.frame(ML@indices)) ## For example, diagnostic plots using the bayesplot package: ## distinguish chains nChains <- blavInspect(fit1, \"n.chains\") distML$Chain <- rep(1:nChains, each = nrow(distML) / nChains) library(bayesplot) mcmc_pairs(distML, pars = c(\"BRMSEA\",\"BMc\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"hist\") ## Indices are highly correlated across iterations in both chains ## Compare to PPMC method distPPMC <- data.frame(PPMC@indices) distPPMC$Chain <- rep(1:nChains, each = nrow(distPPMC) / nChains) mcmc_pairs(distPPMC, pars = c(\"BRMSEA\",\"BMc\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"dens\") ## nonlinear relation between BRMSEA, related to the floor effect of BRMSEA ## that Hoofs et al. found for larger (12-indicator) models } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":null,"dir":"Reference","previous_headings":"","what":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"blavInspect() blavTech() functions can used inspect/extract information stored inside (can computed ) fitted blavaan object. similar lavaan's lavInspect() function.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"","code":"blavInspect(blavobject, what, ...) blavTech(blavobject, what, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"blavobject object class blavaan. Character. needs inspected/extracted? See Details Bayes-specific options, see lavaan's lavInspect() additional options. Note: argument case-sensitive (everything converted lower case.) ... lavaan arguments supplied lavInspect(); see lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"list Bayesian-specific values argument; additional values can found lavInspect() documentation. \"start\": list starting values chain, unless inits=\"jags\" used model estimation. Aliases: \"starting.values\", \"inits\". \"rhat\": parameter's potential scale reduction factor convergence assessment. Can also use \"psrf\" instead \"rhat\" \"ac.10\": parameter's estimated lag-10 autocorrelation. \"neff\": parameters effective sample size, taking account autocorrelation. \"mcmc\": object class mcmc containing individual parameter draws MCMC run. Aliases: \"draws\", \"samples\". \"mcobj\": underlying run.jags stan object resulted MCMC run. \"n.chains\": number chains sampled. \"cp\": approach used estimating covariance parameters (\"srs\" \"fa\"); relevant using JAGS. \"dp\": Default prior distributions used type model parameter. \"postmode\": Estimated posterior mode free parameter. \"postmean\": Estimated posterior mean free parameter. \"postmedian\": Estimated posterior median free parameter. \"lvs\": object class mcmc containing latent variable (factor score) draws. two-level models, use level = 1 level = 2 specify factor scores want. \"lvmeans\": matrix mean factor scores (rows observations, columns variables). Use additional level argument way. \"hpd\": HPD interval free parameter. case, prob argument can used specify number (0,1) reflecting desired percentage interval.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"","code":"if (FALSE) { # \\dontrun{ # The Holzinger and Swineford (1939) example data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939, bcontrol = list(method = \"rjparallel\")) # extract information blavInspect(fit, \"psrf\") blavInspect(fit, \"hpd\", prob = .9) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"purpose blavPredict() function compute various types model predictions, conditioned observed data. differs somewhat lavPredict() lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"","code":"blavPredict(object, newdata = NULL, type = \"lv\", level = 1L)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"object object class blavaan. newdata optional data.frame, containing variables data.frame used fitting model object. type character string. \"lv\", estimated values latent variables model computed. \"ov\" \"yhat\", predicted means observed variables model computed. \"ypred\" \"ydist\", predicted values observed variables (including residual noise) computed. \"ymis\" \"ovmis\", model predicted values (\"imputations\") missing data computed. See details information. level type = \"lv\", used specify whether one desires level 1 latent variables level 2 latent variables.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"predict() function calls blavPredict() function default options. , provide information type option. options work target=\"stan\", \"number samples\" defined number posterior samples across chains. type=\"lv\": posterior distribution latent variables conditioned observed variables. Returns list \"number samples\" entries, entry matrix rows observations columns latent variables. type=\"yhat\": posterior expected value observed variables conditioned sampled latent variables. Returns list \"number samples\" entries, entry matrix rows observations columns observed variables. type=\"ypred\": posterior predictive distribution observed variables conditioned sampled latent variables (including residual variability). Returns list \"number samples\" entries, entry data frame rows observations columns observed variables. type=\"ymis\": posterior predictive distribution missing values conditioned observed variables. Returns matrix \"number samples\" rows \"number missing variables\" columns.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") ## fit model HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939, save.lvs = TRUE) lapply(blavPredict(fit)[1:2], head) # first 6 rows of first 10 posterior samples head(blavPredict(fit, type = \"yhat\")[[1]]) # top of first posterior sample ## multigroup models return a list of factor scores (one per group) mgfit <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = c(\"loadings\",\"intercepts\"), save.lvs = TRUE) lapply(blavPredict(fit)[1:2], head) head(blavPredict(fit, type = \"ypred\")[[1]]) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blav_internal.html","id":null,"dir":"Reference","previous_headings":"","what":"blavaan internal functions — blav_internal","title":"blavaan internal functions — blav_internal","text":"Internal functions related Bayesian model estimation. called user.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":null,"dir":"Reference","previous_headings":"","what":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"blavaan class contains lavaan class, representing (fitted) Bayesian latent variable model. contains description model specified user, summary data, internal matrix representation, model fitted, fitting results.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"objects-from-the-class","dir":"Reference","previous_headings":"","what":"Objects from the Class","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"Objects can created via bcfa, bsem, bgrowth blavaan functions.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"slots","dir":"Reference","previous_headings":"","what":"Slots","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"version: lavaan package version used create objects call: function call returned match.call(). timing: elapsed time (user+system) various parts program list, including total time. Options: Named list options provided user, filled-automatically. ParTable: Named list describing model parameters. Can coerced data.frame. documentation, called `parameter table'. pta: Named list containing parameter table attributes. Data: Object internal class \"Data\": information data. SampleStats: Object internal class \"SampleStats\": sample statistics Model: Object internal class \"Model\": internal (matrix) representation model Cache: List using objects try compute , reuse many times. Fit: Object internal class \"Fit\": results fitting model. longer used. boot: List. Unused Bayesian models. optim: List. Information optimization. loglik: List. Information loglikelihood model (maximum likelihood used). implied: List. Model implied statistics. vcov: List. Information variance matrix (vcov) model parameters. test: List. Different test statistics. h1: List. Information unrestricted h1 model (available). baseline: List. Information baseline model (often independence model) (available). external: List. Includes Stan JAGS objects used MCMC.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"coef signature(object = \"blavaan\", type = \"free\"): Returns estimates parameters model named numeric vector. type=\"free\", free parameters returned. type=\"user\", parameters listed parameter table returned, including constrained fixed parameters. vcov signature(object = \"lavaan\"): returns covariance matrix estimated parameters. show signature(object = \"blavaan\"): Print short summary model fit summary signature(object = \"blavaan\", header = TRUE, fit.measures = FALSE, estimates = TRUE, ci = TRUE, standardized = FALSE, rsquare = FALSE, std.nox = FALSE, psrf = TRUE, neff = FALSE, postmedian = FALSE, postmode = FALSE, priors = TRUE, bf = FALSE, nd = 3L): Print nice summary model estimates. header = TRUE, header section (including fit measures) printed. fit.measures = TRUE, additional fit measures added header section. estimates = TRUE, print parameter estimates section. ci = TRUE, add confidence intervals parameter estimates section. standardized = TRUE, standardized solution also printed. Note SEs tests still based unstandardized estimates. Use standardizedSolution obtain SEs test statistics standardized estimates. rsquare=TRUE, R-Square values dependent variables model printed. std.nox = TRUE, std.column contains std.nox column parameterEstimates() output. psrf = TRUE, potential scale reduction factors (Rhats) printed. neff = TRUE, effective sample sizes printed. postmedian postmode TRUE, posterior medians modes printed instead posterior means. priors = TRUE, parameter prior distributions printed. bf = TRUE, Savage-Dickey approximations Bayes factor printed certain parameters. Nothing returned (use lavInspect another extractor function extract information fitted model).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"","code":"if (FALSE) { # \\dontrun{ HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939) summary(fit, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE) coef(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit a Bayesian Latent Variable Model — blavaan","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"Fit Bayesian latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"","code":"blavaan(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model data written files (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"object inherits class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") # The Holzinger and Swineford (1939) example HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- blavaan(HS.model, data = HolzingerSwineford1939, auto.var = TRUE, auto.fix.first = TRUE, auto.cov.lv.x = TRUE) summary(fit) coef(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Structural Equation Models — bsem","title":"Fit Structural Equation Models — bsem","text":"Fit Structural Equation Model (SEM).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Structural Equation Models — bsem","text":"","code":"bsem(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Structural Equation Models — bsem","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Structural Equation Models — bsem","text":"bsem function wrapper general blavaan function, using following default lavaan arguments: int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Structural Equation Models — bsem","text":"object class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Structural Equation Models — bsem","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Structural Equation Models — bsem","text":"","code":"# The industrialization and Political Democracy Example # Bollen (1989), page 332 data(PoliticalDemocracy, package = \"lavaan\") model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + a*y2 + b*y3 + c*y4 dem65 =~ y5 + a*y6 + b*y7 + c*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' if (FALSE) { # \\dontrun{ # mildly informative priors for mv intercepts and loadings fit <- bsem(model, data = PoliticalDemocracy, dp = dpriors(nu = \"normal(5,10)\", lambda = \"normal(1,.5)\")) summary(fit) } # } # A short run for rough results fit <- bsem(model, data = PoliticalDemocracy, burnin = 100, sample = 100, dp = dpriors(nu = \"normal(5,10)\", lambda = \"normal(1,.5)\"), n.chains = 2) #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: #> Chain 1: Gradient evaluation took 0.000315 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.15 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: #> Chain 1: WARNING: There aren't enough warmup iterations to fit the #> Chain 1: three stages of adaptation as currently configured. #> Chain 1: Reducing each adaptation stage to 15%/75%/10% of #> Chain 1: the given number of warmup iterations: #> Chain 1: init_buffer = 15 #> Chain 1: adapt_window = 75 #> Chain 1: term_buffer = 10 #> Chain 1: #> Chain 1: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 1: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 1: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 1: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 1: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 1: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 1: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 1: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 1: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 1: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: #> Chain 1: Elapsed Time: 0.829 seconds (Warm-up) #> Chain 1: 0.629 seconds (Sampling) #> Chain 1: 1.458 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: #> Chain 2: Gradient evaluation took 0.000281 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.81 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: #> Chain 2: WARNING: There aren't enough warmup iterations to fit the #> Chain 2: three stages of adaptation as currently configured. #> Chain 2: Reducing each adaptation stage to 15%/75%/10% of #> Chain 2: the given number of warmup iterations: #> Chain 2: init_buffer = 15 #> Chain 2: adapt_window = 75 #> Chain 2: term_buffer = 10 #> Chain 2: #> Chain 2: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 2: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 2: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 2: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 2: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 2: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 2: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 2: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 2: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 2: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: #> Chain 2: Elapsed Time: 0.707 seconds (Warm-up) #> Chain 2: 0.665 seconds (Sampling) #> Chain 2: 1.372 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is 1.05, indicating chains have not mixed. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#r-hat #> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#bulk-ess #> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#tail-ess #> Computing post-estimation metrics (including lvs if requested)... #> Warning: blavaan WARNING: As specified, the theta covariance matrix is neither diagonal nor unrestricted, so the actual prior might differ from the stated prior. See #> https://arxiv.org/abs/2301.08667 summary(fit) #> blavaan 0.5.6.1311 ended normally after 100 iterations #> #> Estimator BAYES #> Optimization method MCMC #> Number of model parameters 31 #> Number of equality constraints 3 #> #> Number of observations 75 #> #> Statistic MargLogLik PPP #> Value NA 0.520 #> #> Parameter Estimates: #> #> #> Latent Variables: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> ind60 =~ #> x1 1.000 #> x2 2.102 0.134 1.859 2.357 0.996 normal(1,.5) #> x3 1.724 0.157 1.447 2.054 0.999 normal(1,.5) #> dem60 =~ #> y1 1.000 #> y2 (a) 1.172 0.132 0.943 1.437 1.010 normal(1,.5) #> y3 (b) 1.172 0.117 0.946 1.406 1.007 normal(1,.5) #> y4 (c) 1.250 0.119 1.011 1.512 1.037 normal(1,.5) #> dem65 =~ #> y5 1.000 #> y6 (a) 1.172 0.132 0.943 1.437 1.010 #> y7 (b) 1.172 0.117 0.946 1.406 1.007 #> y8 (c) 1.250 0.119 1.011 1.512 1.037 #> #> Regressions: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> dem60 ~ #> ind60 1.406 0.416 0.653 2.260 0.994 normal(0,10) #> dem65 ~ #> ind60 0.545 0.269 0.045 1.061 0.997 normal(0,10) #> dem60 0.874 0.081 0.739 1.042 0.993 normal(0,10) #> #> Covariances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .y1 ~~ #> .y5 0.597 0.368 -0.029 1.424 1.001 beta(1,1) #> .y2 ~~ #> .y4 1.450 0.711 0.244 3.072 1.027 beta(1,1) #> .y6 2.272 0.789 0.974 3.822 0.996 beta(1,1) #> .y3 ~~ #> .y7 0.856 0.698 -0.349 2.230 0.992 beta(1,1) #> .y4 ~~ #> .y8 0.426 0.488 -0.446 1.472 1.004 beta(1,1) #> .y6 ~~ #> .y8 1.374 0.723 0.074 3.018 0.992 beta(1,1) #> #> Variances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .x1 0.084 0.022 0.048 0.125 1.019 gamma(1,.5)[sd] #> .x2 0.144 0.072 0.023 0.310 1.010 gamma(1,.5)[sd] #> .x3 0.498 0.093 0.334 0.706 0.993 gamma(1,.5)[sd] #> .y1 1.992 0.515 1.240 3.288 1.011 gamma(1,.5)[sd] #> .y2 7.941 1.451 5.490 10.723 0.996 gamma(1,.5)[sd] #> .y3 5.190 1.098 3.446 7.739 1.000 gamma(1,.5)[sd] #> .y4 3.469 0.867 1.984 5.343 1.018 gamma(1,.5)[sd] #> .y5 2.419 0.573 1.578 3.662 0.993 gamma(1,.5)[sd] #> .y6 5.175 1.009 3.463 7.460 1.002 gamma(1,.5)[sd] #> .y7 3.750 0.767 2.154 5.378 1.007 gamma(1,.5)[sd] #> .y8 3.577 0.863 2.079 5.364 0.999 gamma(1,.5)[sd] #> ind60 0.490 0.100 0.326 0.702 0.996 gamma(1,.5)[sd] #> .dem60 3.971 0.919 2.452 5.931 1.001 gamma(1,.5)[sd] #> .dem65 0.255 0.228 0.008 0.827 1.013 gamma(1,.5)[sd] #>"},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":null,"dir":"Reference","previous_headings":"","what":"Specify Default Prior Distributions — dpriors","title":"Specify Default Prior Distributions — dpriors","text":"Specify \"default\" prior distributions classes model parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Specify Default Prior Distributions — dpriors","text":"","code":"dpriors(..., target = \"stan\")"},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Specify Default Prior Distributions — dpriors","text":"... Parameter names paired desired priors (see example ). target priors jags, stan (default), stanclassic?","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Specify Default Prior Distributions — dpriors","text":"prior distributions always use JAGS/Stan syntax parameterizations. example, normal distribution JAGS parameterized via precision, whereas normal distribution Stan parameterized via standard deviation. User-specified prior distributions specific parameters (using prior() operator within model syntax) always override prior distributions set using dpriors(). parameter names : nu: Observed variable intercept parameters. alpha: Latent variable intercept parameters. lambda: Loading parameters. beta: Regression parameters. itheta: Observed variable precision parameters. ipsi: Latent variable precision parameters. rho: Correlation parameters (associated covariance parameters). ibpsi: Inverse covariance matrix blocks latent variables (used target=\"jags\"). tau: Threshold parameters (ordinal data ). delta: Delta parameters (ordinal data ).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Specify Default Prior Distributions — dpriors","text":"character vector containing prior distribution type parameter.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Specify Default Prior Distributions — dpriors","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Specify Default Prior Distributions — dpriors","text":"","code":"dpriors(nu = \"normal(0,10)\", lambda = \"normal(0,1)\", rho = \"beta(3,3)\") #> nu alpha lambda beta #> \"normal(0,10)\" \"normal(0,10)\" \"normal(0,1)\" \"normal(0,10)\" #> theta psi rho ibpsi #> \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(3,3)\" \"wishart(3,iden)\" #> tau #> \"normal(0,1.5)\""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"blavaan Diagnostic Plots — plot.blavaan","title":"blavaan Diagnostic Plots — plot.blavaan","text":"Convenience functions create plots blavaan objects, via bayesplot package.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"blavaan Diagnostic Plots — plot.blavaan","text":"","code":"# S3 method for class 'blavaan' plot(x, pars = NULL, plot.type = \"trace\", showplot = TRUE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"blavaan Diagnostic Plots — plot.blavaan","text":"x object class blavaan. pars Parameter numbers plot, numbers correspond order parameters reported coef() (also shown 'free' column parTable). numbers provided, free parameters plotted. plot.type type plot desired. name MCMC function, without mcmc_ prefix. showplot plot sent graphic device? Defaults TRUE. ... arguments sent bayesplot function.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"blavaan Diagnostic Plots — plot.blavaan","text":"previous versions blavaan, plotting functionality handled separately JAGS Stan (using plot functionality packages runjags rstan, respectively). uniformity, plotting functionality now handled bayesplot. users desire additional functionality immediately available, can extract matrix MCMC draws via .matrix(blavInspect(x, 'mcmc')).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"blavaan Diagnostic Plots — plot.blavaan","text":"invisible ggplot object , desired, can customized.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"blavaan Diagnostic Plots — plot.blavaan","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939) # trace plots of free loadings plot(fit, pars = 1:6) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":null,"dir":"Reference","previous_headings":"","what":"Posterior Predictive Model Checks — ppmc","title":"Posterior Predictive Model Checks — ppmc","text":"function allows users conduct posterior predictive model check assess global local fit latent variable model using discrepancy function can applied lavaan model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Posterior Predictive Model Checks — ppmc","text":"","code":"ppmc(object, thin = 1, fit.measures = c(\"srmr\",\"chisq\"), discFUN = NULL, conditional = FALSE) # S4 method for class 'blavPPMC' summary(object, ...) # S3 method for class 'ppmc' summary(object, discFUN, dist = c(\"obs\",\"sim\"), central.tendency = c(\"mean\",\"median\",\"mode\"), hpd = TRUE, prob = .95, to.data.frame = FALSE, diag = TRUE, sort.by = NULL, decreasing = FALSE) # S3 method for class 'blavPPMC' plot(x, ..., discFUN, element, central.tendency = \"\", hpd = TRUE, prob = .95, nd = 3) # S3 method for class 'blavPPMC' hist(x, ..., discFUN, element, hpd = TRUE, prob = .95, printLegend = TRUE, legendArgs = list(x = \"topleft\"), densityArgs = list(), nd = 3) # S3 method for class 'blavPPMC' pairs(x, discFUN, horInd = 1:DIM, verInd = 1:DIM, printLegend = FALSE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Posterior Predictive Model Checks — ppmc","text":"object,x object class blavaan. thin Optional integer indicating much thin chain. Default 1L, indicating thin chains object. fit.measures character vector indicating names global discrepancy measures returned fitMeasures. Ignored unless discFUN NULL, users may include fitMeasures list discrepancy functions discFUN. ordinal models, \"logl\" \"chisq\" computations done via lavaan. discFUN function, list functions, can called object class lavaan. function must return object whose mode numeric, may vector, matrix, multidimensional array. summary plot methods, discFUN character indicating discrepancy function summarize. conditional logical indicating whether , artificial data generation, condition estimated latent variables. Requires model estimated save.lvs = TRUE. element numeric character indicating index ( dimension discFUN output, multiple) plot. horInd,verInd Similar element, numeric character vector indicating indices matrix plot scatterplot matrix. horInd==verInd, histograms plotted upper triangle. dist character indicating whether summarize distribution discFUN either observed simulated data. central.tendency character indicating statistics used characterize location posterior (predictive) distribution. default, 3 statistics returned summary method, none plot method. posterior mean labeled EAP expected posteriori estimate, mode labeled MAP modal posteriori estimate. hpd logical indicating whether calculate highest posterior density (HPD) credible interval discFUN. prob \"confidence\" level credible interval(s). nd number digits print scatterplot. .data.frame logical indicating whether summary symmetric 2-dimensional matrix returned discFUN unique elements stored rows data.frame can sorted convenience identifying large discrepancies. discFUN returns asymmetric 2-dimensional matrix, list matrices returned summary can also converted data.frame. diag Passed lower.tri .data.frame=TRUE. sort.character. summary returns data.frame, can sorted column name using order. Note discFUN returns asymmetric 2-dimensional matrix, data.frame returned list sorted independently, rows unlikely consistent across summary statistics. decreasing Passed order !.null(sort.). ... Additional graphical parameters passed plot.default. printLegend logical. TRUE (default), legend printed histogram legendArgs list arguments passed legend function. default argument list placing legend top-left figure. densityArgs list arguments passed density function, used obtain densities hist method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Posterior Predictive Model Checks — ppmc","text":"S4 object class blavPPMC consisting 5 list slots: @discFUN user-supplied discFUN, call fitMeasures returns fit.measures. @dims dimensions object returned discFUN. @PPP posterior predictive p value discFUN element. @obsDist posterior distribution realize values discFUN applied observed data. @simDist posterior predictive distribution values discFUN applied data simulated posterior samples. summary() method returns numeric vector discFUN returns scalar, data.frame one discrepancy function per row discFUN returns numeric vector, list one summary statistic per element discFUN returns matrix multidimensional array. plot pairs methods invisibly return NULL, printing plot (scatterplot matrix) current device. hist method invisibly returns list arguments can passed function list element named. Users can edit arguments list customize histograms.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Posterior Predictive Model Checks — ppmc","text":"Terrence D. Jorgensen (University Amsterdam; TJorgensen314@gmail.com)","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Posterior Predictive Model Checks — ppmc","text":"Levy, R. (2011). Bayesian data–model fit assessment structural equation modeling. Structural Equation Modeling, 18(4), 663–685. doi:10.1080/10705511.2011.607723","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Posterior Predictive Model Checks — ppmc","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' ## fit single-group model fit <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 500) ## fit multigroup model fitg <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 500, group = \"school\") ## Use fit.measures as a shortcut for global fitMeasures only ## - Note that indices calculated from the \"df\" are only appropriate under ## noninformative priors, such that pD approximates the number of estimated ## parameters counted under ML estimation; incremental fit indices ## introduce further complications) AFIs <- ppmc(fit, thin = 10, fit.measures = c(\"srmr\",\"chisq\",\"rmsea\",\"cfi\")) summary(AFIs) # summarize the whole vector in a data.frame hist(AFIs, element = \"rmsea\") # only plot one discrepancy function at a time plot(AFIs, element = \"srmr\") ## define a list of custom discrepancy functions ## - (global) fit measures ## - (local) standardized residuals discFUN <- list(global = function(fit) { fitMeasures(fit, fit.measures = c(\"cfi\",\"rmsea\",\"srmr\",\"chisq\")) }, std.cov.resid = function(fit) lavResiduals(fit, zstat = FALSE, summary = FALSE)$cov, std.mean.resid = function(fit) lavResiduals(fit, zstat = FALSE, summary = FALSE)$mean) out1g <- ppmc(fit, discFUN = discFUN) ## summarize first discrepancy by default (fit indices) summary(out1g) ## some model-implied correlations look systematically over/underestimated summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\") hist(out1g, discFUN = \"std.cov.resid\", element = c(1, 7)) plot(out1g, discFUN = \"std.cov.resid\", element = c(\"x1\",\"x7\")) ## For ease of investigation, optionally export summary as a data.frame, ## sorted by size of average residual summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\", to.data.frame = TRUE, sort.by = \"EAP\") ## or sorted by size of PPP summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\", to.data.frame = TRUE, sort.by = \"PPP_sim_LessThan_obs\") ## define a list of custom discrepancy functions for multiple groups ## (return each group's numeric output using a different function) disc2g <- list(global = function(fit) { fitMeasures(fit, fit.measures = c(\"cfi\",\"rmsea\",\"mfi\",\"srmr\",\"chisq\")) }, cor.resid1 = function(fit) lavResiduals(fit, zstat = FALSE, type = \"cor.bollen\", summary = FALSE)[[1]]$cov, cor.resid2 = function(fit) lavResiduals(fit, zstat = FALSE, type = \"cor.bollen\", summary = FALSE)[[2]]$cov) out2g <- ppmc(fitg, discFUN = disc2g, thin = 2) ## some residuals look like a bigger problem in one group than another pairs(out2g, discFUN = \"cor.resid1\", horInd = 1:3, verInd = 7:9) # group 1 pairs(out2g, discFUN = \"cor.resid2\", horInd = 1:3, verInd = 7:9) # group 2 ## print all to file: must be a LARGE picture. First group 1 ... png(\"cor.resid1.png\", width = 1600, height = 1200) pairs(out2g, discFUN = \"cor.resid1\") dev.off() ## ... then group 2 png(\"cor.resid2.png\", width = 1600, height = 1200) pairs(out2g, discFUN = \"cor.resid2\") dev.off() } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample data from the posterior (or prior) distribution. — sampleData","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"purpose sampleData() function simulate new data model already estimated. can faciliate posterior predictive checks, well prior predictive checks (setting prisamp = TRUE model estimation).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"","code":"sampleData(object, nrep = NULL, conditional = FALSE, type = \"response\", simplify = FALSE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"object object class blavaan. nrep many datasets generate? supplied, defaults total number posterior samples. conditional Logical indicating whether sample distribution marginal latent variables (FALSE; default) distribution conditions latent variables (TRUE). TRUE, must set save.lvs = TRUE model estimation. type type data desired (relevant ordinal data). type = \"response\" option generates ordinal data. type = \"link\" option generates continuous variables underlying ordinal data (cut thresholds yield ordinal data). simplify single-group models, list structure simplified? makes dataset single list entry, instead list within list (reflects group 1 dataset 1). Defaults FALSE. ... arguments, now parallel. Parallelization via future_lapply() available setting parallel = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"convenience function generate data posterior prior predictive checking. underlying code also used generate data posterior predictive p-value computation.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") ## fit model HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939) ## 1 dataset generated from the posterior out <- sampleData(fit, nrep = 1) ## nested lists: 1 list entry per nrep. ## then, within a rep, 1 list entry per group ## so our dataset is here: dim(out[[1]][[1]]) ## 1 posterior dataset per posterior sample: out <- sampleData(fit) ## obtain the data on x1 across reps and summarize: x1dat <- sapply(out, function(x) x[[1]][,1]) summary( as.numeric(x1dat) ) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":null,"dir":"Reference","previous_headings":"","what":"Standardized Posterior — standardizedPosterior","title":"Standardized Posterior — standardizedPosterior","text":"Standardized posterior distribution latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Standardized Posterior — standardizedPosterior","text":"","code":"standardizedPosterior(object, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Standardized Posterior — standardizedPosterior","text":"object object class blavaan. ... Additional arguments passed lavaan's standardizedSolution()","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Standardized Posterior — standardizedPosterior","text":"allowed standardizedSolution() arguments type, cov.std, remove.eq, remove.ineq, remove.def. arguments immediately suited posterior distributions.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Standardized Posterior — standardizedPosterior","text":"matrix containing standardized posterior draws, rows draws columns parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Standardized Posterior — standardizedPosterior","text":"","code":"if (FALSE) { # \\dontrun{ data(PoliticalDemocracy, package = \"lavaan\") model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + a*y2 + b*y3 + c*y4 dem65 =~ y5 + a*y6 + b*y7 + c*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data = PoliticalDemocracy, dp = dpriors(nu = \"normal(5, 10)\")) standardizedPosterior(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-6","dir":"Changelog","previous_headings":"","what":"Version 0.5-6","title":"Version 0.5-6","text":"CRAN release: 2024-09-04","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-6","text":"release contains minor improvements bug fixes.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-6","text":"Models <~ operator fail target = “jags” (reported Thomas Riecke).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-5","dir":"Changelog","previous_headings":"","what":"Version 0.5-5","title":"Version 0.5-5","text":"CRAN release: 2024-06-09","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-5","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-5","text":"Minor changes ensure compatibility lavaan 0.6-18. Bugs 0.5-4 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-5","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-5","text":"systems, blavaan installation fails “parser failed badly” message rstan (reported Larry Hunsicker). blavPredict(, type=“ov”/“ypred”) can fail sample size newdata differs sample size original data (reported Niels Skovgaard-Olsen).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-4","dir":"Changelog","previous_headings":"","what":"Version 0.5-4","title":"Version 0.5-4","text":"CRAN release: 2024-04-15","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-4","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-4","text":"New function sampleData() generating data blavaan object. Functionality newdata argument blavPredict(), can generate lv () predictions new data model already estimated (continuous data , target = “stan” ). Refinements two-level models (handle missingness via listwise deletion; lvs one level; improved messaging) Bugs 0.5-3 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-4","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-4","text":"sampleData() ignores thinning determining number posterior samples (reported Luna Fazio). two-level models fail one observed variable appears level (reported Carl Falk). target = “stan”, models fail loadings equality constrained std.lv = TRUE (reported Amos Pagin).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-3","dir":"Changelog","previous_headings":"","what":"Version 0.5-3","title":"Version 0.5-3","text":"CRAN release: 2024-01-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-3","text":"Functionality find unrestricted blocks model’s psi matrix (lv covariance matrix). lkj priors assigned unrestricted blocks, improving positive definite issue described “Opaque priors” paper. Improved functionality obtaining posterior modes via, e.g., summary(., postmode = TRUE) blavCompare() messaging improved clarify ELPD differences, function returns output. Bug fix two-level models within-observed variables, messaging added unstable ppp. extracting posterior draws via blavInspect(., “mcmc”), column names now match lavaan parameter names. old behavior involving Stan parameter names, use argument add.labels = FALSE Bugs 0.5-2 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-3","text":"models exogenous covariates, fixed.x=TRUE, missing data fail converge yield implausible parameter values (reported DeAnne Hunter).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-2","dir":"Changelog","previous_headings":"","what":"Version 0.5-2","title":"Version 0.5-2","text":"CRAN release: 2023-09-25","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-2","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-2","text":"maintenance release, primarily adding new array declaration syntax Stan models (syntax became available new version rstan).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-2","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-2","text":"blavCompare() work models meanstructure = FALSE (reported Pedro Ribeiro). target=“jags”, posterior modes obtained via postmode = TRUE (reported Giada Venaruzzo). models continuous ordinal variables fail cases ordinal variables missing (reported Sonja Winter). certain equality constraints involving named parameters fail target=“stan” (reported Niels Skovgaard-Olsen)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-1","dir":"Changelog","previous_headings":"","what":"Version 0.5-1","title":"Version 0.5-1","text":"CRAN release: 2023-08-29","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-1","text":"Two-level models now supported (complete, continuous data) via cluster argument.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-1","text":"two-level model specification, levels labeled “within” “”. restrictive lavaan specification. target=“jags”, latent variable extraction via blavInspect(, “lvs”) fails (reported Joseph Saraceno).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-8","dir":"Changelog","previous_headings":"","what":"Version 0.4-8","title":"Version 0.4-8","text":"CRAN release: 2023-06-12","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-8","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-8","text":"maintenance release bug fixes changes compiler settings","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-8","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-8","text":"certain models residual correlations /correlated factors, initial values target=‘stan’ lead non-positive definite matrices (reported Yuanyuan Hu). models latent variable regressed observed variable (lv ~ ov), latent variable samples account mean observed variable (centered around 0 constant).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-7","dir":"Changelog","previous_headings":"","what":"Version 0.4-7","title":"Version 0.4-7","text":"CRAN release: 2023-03-01","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-7","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-7","text":"primarily update address C++14 vs C++17 compilation issue identified CRAN bugs 0.4-6 also fixed","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-7","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-7","text":"Sampling priors (prisamp = TRUE) fails models meanstructure = FALSE; posterior still estimated (reported Armel Brizuela Rodríguez). target = “jags”, models single-indicator latent variable, latent variable regressed variables, return incorrect parameter estimates (reported Brad Cosentino).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-6","dir":"Changelog","previous_headings":"","what":"Version 0.4-6","title":"Version 0.4-6","text":"CRAN release: 2023-02-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-6","text":"target = “stan”, meanstructure=FALSE allowed, along use sample.cov sample.nobs instead raw data Users warned priors covariance matrices neither diagonal unrestricted models observed variable intercepts appear latent intercept vector (alpha), default priors come observed intercept vector nu (user expect) inits = “simple” now default (instead “prior”), address convergence problems stan targets, “:=” can now used identity function target = “stan”, fix missing data issue 0.4-3 (complete data one group ) Column names added blavPredict(, type=“lv”)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-6","text":"blavFitIndices() save.lvs = TRUE work correctly models without meanstructure. Workaround use meanstructure = TRUE model estimation command (reported Charles Hofacker). lavaan summary() method sometimes called instead blavaan summary() method (reported multiple users, Shu Fai Cheung providing helpful examples).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-3","dir":"Changelog","previous_headings":"","what":"Version 0.4-3","title":"Version 0.4-3","text":"CRAN release: 2022-05-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-3","text":"target = “stan”, models run faster earlier versions (use sufficient statistics) Posterior summaries faster ordinal models (using mnormt::sadmvn() default) Variational Bayes option added: target=“vb”, uses rstan::vb() cmdstanr functionality added: target=“cmdstanr”, uses model target=“stan” Fix blavInspect(., “lvs”/“lvmeans”) multiple groups + missing data Fixes ppmc() ordinal models; blavFitIndices() turned ordinal models (research needed) loo() moment matching available passing mcmcextra = list(data = list(moment_match_k_threshold))","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-3","text":"target = “stan” fails complete data one group missing data another group (reported Ronja Runge). blavPredict(, type=“ymis”) still available models ordinal variables","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-1","dir":"Changelog","previous_headings":"","what":"Version 0.4-1","title":"Version 0.4-1","text":"CRAN release: 2022-01-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-1","text":"Functionality ordinal observed variables now available. models missing data, posterior summaries sped (log-likelihood computations now done Stan).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-1","text":"blavPredict(, type=“ymis”) working models ordinal variables blavInspect(, ‘lvs’) (, ‘lvmeans’) can fail models combination multiple groups, missing values, excluded cases blavFitIndices() ppmc() working models ordinal variables, may indicate excessively bad fit blavFitIndices(, rescale=“mcmc”) fails","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-18","dir":"Changelog","previous_headings":"","what":"Version 0.3-18","title":"Version 0.3-18","text":"CRAN release: 2021-11-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-18","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-18","text":"version adds reference new JSS paper, including DOI, corrects inconsistent version dependency. changes compared 0.3-17.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-17","dir":"Changelog","previous_headings":"","what":"Version 0.3-17","title":"Version 0.3-17","text":"CRAN release: 2021-07-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-17","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-17","text":"maintenance release correct major bugs previous version.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-16","dir":"Changelog","previous_headings":"","what":"Version 0.3-16","title":"Version 0.3-16","text":"CRAN release: 2021-07-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-16","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-16","text":"blavPredict() function added predicting latent variables missing data. posterior summaries sped . (fitMeasures available test=“none”) bug fixes previous version.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-16","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-16","text":"certain models missing data, ppp-values incorrect (sometimes equaling 1.0). target=“stan”, multiple group models fail cases missing observed variables (reported DeAnne Hunter).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-15","dir":"Changelog","previous_headings":"","what":"Version 0.3-15","title":"Version 0.3-15","text":"CRAN release: 2021-02-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-15","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-15","text":"Added S3 summary() method ppmc Posterior intervals summary() bug fixed","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-15","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-15","text":"summary() method ppmc() fitIndices() always work correctly. Jacobian incorrect target=“stan”, (non-default) priors placed precisions variances instead standard deviations. impact estimates posterior variability (reported Roy Levy).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-14","dir":"Changelog","previous_headings":"","what":"Version 0.3-14","title":"Version 0.3-14","text":"CRAN release: 2021-01-20 (version 0.3-13 violated CRAN policy)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-14","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-14","text":"maintenance release response change package Matrix.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-14","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-14","text":"Posterior intervals NA summary(). Workarounds use parameterEstimates() (intervals assuming posterior normality) compute using posterior samples (`blavInspect(fit, “mcmc”)’)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-12","dir":"Changelog","previous_headings":"","what":"Version 0.3-12","title":"Version 0.3-12","text":"CRAN release: 2020-11-12 (version 0.3-11 failed Windows CRAN checks)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-12","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-12","text":"vector values wiggle.sd allowed different priors approximate equality constraints logical argument “prisamp” added, sampling model’s prior target=“stan”, lkj prior used unrestricted lv correlation matrices default priors conditional approaches (targets jags stanclassic) revert placed precisions (opposed SDs), improvement sampling efficiency","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-10","dir":"Changelog","previous_headings":"","what":"Version 0.3-10","title":"Version 0.3-10","text":"CRAN release: 2020-08-03","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-10","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-10","text":"save.lvs=TRUE works missing data target=“stan” new arguments “wiggle” “wiggle.sd” approximate equality constraints target=“stan”","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-10","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-10","text":"plot labels target=“stan” sometimes incorrect (displaying parameter different panel label). complex equality constraints sometimes ignored (target=“jags” “stanclassic”) equality constraints std.lv=TRUE sometimes fail (target=“stan”) placing priors variances precisions yields incorrect results (target=“stan”; reported Roy Levy)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-9","dir":"Changelog","previous_headings":"","what":"Version 0.3-9","title":"Version 0.3-9","text":"CRAN release: 2020-03-09","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-9","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-9","text":"improvements save.lvs=TRUE target=“stan”. target=“stancond” added, experimental, noncentered Stan approach. bug fixes prior settings std.lv target=“stan”, defined parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-9","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-9","text":"target=“stan”, problems sampling lvs multiple groups missing data. Errors blavCompare() blavFitIndices() due version updates packages. target=“stan”, models std.lv=TRUE converge.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-8","dir":"Changelog","previous_headings":"","what":"Version 0.3-8","title":"Version 0.3-8","text":"CRAN release: 2019-11-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-8","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-8","text":"post-estimation, posterior predictive computations sped considerably. 0.3-7 bugs fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-8","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-8","text":"target=“stan” std.lv=TRUE, estimation fails certain (growth) models (reported Mauricio Garnier-Villareal). defined variables fail target=“jags” “stanclassic” (reported Mariëlle Zondervan-Zwijnenburg). User-specified priors sometimes placed wrong parameter, related 0.3-7 bug (reported Mauricio Garnier-Villareal). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-7","dir":"Changelog","previous_headings":"","what":"Version 0.3-7","title":"Version 0.3-7","text":"CRAN release: 2019-09-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-7","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-7","text":"target=“stan”, gamma priors can now placed user’s choice variances, standard deviations, precisions. plot() now works uniformly across Stan JAGS, relying bayesplot. post-MCMC parallelization now handled via future.apply package (requires extra “plan” command user, works windows). 0.3-6 bugs fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-7","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-7","text":"blavInspect(, ‘lvmeans’) returns rows wrong order target=“stan” (reported Mehdi Momen). User-specified priors sometimes placed wrong parameter, target=“stan” (reported Enrico Toffalini). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-6","dir":"Changelog","previous_headings":"","what":"Version 0.3-6","title":"Version 0.3-6","text":"CRAN release: 2019-08-08","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-6","text":"fixes stan plot bug 0.3-5.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-6","text":"user-specified priors correlation parameters silently ignored target=“stan” (reported James Uanhoro). save.lvs=TRUE work target=“stan” (reported Mauricio Garnier-Villareal). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-5","dir":"Changelog","previous_headings":"","what":"Version 0.3-5","title":"Version 0.3-5","text":"CRAN release: 2019-08-03","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-5","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-5","text":"target=“stan” now default, using pre-compiled Stan model instead “fly” code. ppmc() function added Terrence Jorgensen, facilitating posterior predictive checks. default priors changed gamma precisions gamma standard deviations.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-5","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-5","text":"Stan plot method silently fails (reported Matt Yalch). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-4","dir":"Changelog","previous_headings":"","what":"Version 0.3-4","title":"Version 0.3-4","text":"CRAN release: 2019-01-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-4","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-4","text":"Add function standardizedPosterior() standardizing posterior draws. Turn posterior modes target=“jags”, due conflict current versions runjags modeest. Rearrange posterior predictive internals.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-4","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-4","text":"dpriors() issue 0.3-3 remains. target=“jags”, lv means obtained blavInspect() (via argument ‘lvmeans’) incorrect. (reported Mauricio Garnier-Villareal) Use plot() target=“stan” causes problems future blavInspect() calls.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-3","dir":"Changelog","previous_headings":"","what":"Version 0.3-3","title":"Version 0.3-3","text":"CRAN release: 2018-10-31","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-3","text":"convergence=“auto”, max time previously 5 min (undocumented). now Inf. Axis labels (parameter names) now sensible convergence plots. Relative effective sample size now used compute loo/waic SEs, SEs now returned via fitMeasures(). Added unit testing via package testthat. Fixed bugs 0.3-2 (exception identity assignments using ‘:=’)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-3","text":"Use ‘dpriors()’: observed variable precisions assigned latent precision (ipsi) prior; latent means assigned observed mean (nu) prior.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-2","dir":"Changelog","previous_headings":"","what":"Version 0.3-2","title":"Version 0.3-2","text":"CRAN release: 2018-06-10","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-2","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-2","text":"Conditional (latent variables) information criteria available save.lvs = TRUE. Experimental function ‘blavFitIndices()’ added Bayesian versions SEM metrics, contributed Terrence Jorgensen. blavaan “intelligently” chooses target, either runjags rstan () installed. Fixed bugs 0.3-1, especially related missing data Stan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-2","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-2","text":"Errors Stan models std.lv=TRUE, observed variable regressed latent variable (reported Bo Zhang). Error identity assignments using ‘:=’ (reported Marco Tullio Liuzza). Explicitly adding argument ‘.fit=TRUE’ fails (reported Esteban Montenegro).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-1","dir":"Changelog","previous_headings":"","what":"Version 0.3-1","title":"Version 0.3-1","text":"CRAN release: 2018-01-12","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-1","text":"Stan export now supported; use target=“stan”. Improved handling complex models, including growth/change models. Sampling factor scores (lvs) available via ‘save.lvs=TRUE’. Samples/means can obtained supplying arguments ‘lvs’ ‘lvmeans’ ‘blavInspect()’. Fixed bugs 0.2-4.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-1","text":"Errors Stan models missing data, exogenous (“x”) variables. Errors multi-group Stan models std.lv=TRUE.","code":""}] +[{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Approximate fit indices","text":"SEM, one first steps evaluate model’s global fit. commonly done presenting multiple fit indices, common based model’s χ2\\chi^2. developed Bayesian versions indices (Garnier-Villarreal Jorgensen 2020) can computed blavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"noncentrality-based-fit-indices","dir":"Articles","previous_headings":"","what":"Noncentrality-Based Fit Indices","title":"Approximate fit indices","text":"group indices compares hypothesized model perfect saturated model. specifically uses noncentrality parameter λ̂=χ2−df\\hat{\\lambda} = \\chi^2 - df, df adjusted different model/data characterictics. Specific indices include Root Mean Square Error approximation (RMSEA), McDonald’s centrality index (Mc), gamma-hat (Γ̂\\hat{\\Gamma}), adjusted gamma-hat (Γ̂adj\\hat{\\Gamma}_{adj}). show example Holzinger Swineford (1939) example. first estimate SEM/CFA model usual need pass model blavFitIndices() function Finally, can describe posterior distribution indices summary() function. call, see 3 central tendency measures (mean median, mode), standard deviation, 90% Credible Interval","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE) gl_fits <- blavFitIndices(fit) summary(gl_fits, central.tendency = c(\"mean\",\"median\",\"mode\"), prob = .90) ## ## Posterior summary statistics and highest posterior density (HPD) ## 90% credible intervals for devm-based fit indices: ## ## EAP Median MAP SD lower upper ## BRMSEA 0.099 0.098 0.097 0.005 0.090 0.107 ## BGammaHat 0.956 0.957 0.958 0.005 0.949 0.963 ## adjBGammaHat 0.907 0.908 0.910 0.010 0.891 0.922 ## BMc 0.902 0.904 0.906 0.010 0.886 0.918"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"incremental-fit-indices","dir":"Articles","previous_headings":"","what":"Incremental Fit Indices","title":"Approximate fit indices","text":"Another group fit indices compares hypothesized model worst possible model, called incremental indices. indices compare model’s χH2\\chi^2_H null model’s χ02\\chi^2_0 different ways. Indices include Comparative Fit Index (CFI), Tucker-Lewis Index (TLI), Normed Fit Index (NFI). estimate indices need define estimate respective null model. standard null model used default frequentist SEM programs (like lavaan) includes indicators variances intercepts, covariances items. can specify null model including respective indicator variances model syntax, hypothesized null models, pass blavFitIndices function, now provide types fit indices summary() method now presents central tendency measure asked , standard deviation, credible interval noncentrality incremental fit indices.","code":"HS.model_null <- ' x1 ~~ x1 x2 ~~ x2 x3 ~~ x3 x4 ~~ x4 x5 ~~ x5 x6 ~~ x6 x7 ~~ x7 x8 ~~ x8 x9 ~~ x9 ' fit_null <- bcfa(HS.model_null, data=HolzingerSwineford1939) gl_fits_all <- blavFitIndices(fit, baseline.model = fit_null) summary(gl_fits_all, central.tendency = c(\"mean\",\"median\",\"mode\"), prob = .90) ## ## Posterior summary statistics and highest posterior density (HPD) ## 90% credible intervals for devm-based fit indices: ## ## EAP Median MAP SD lower upper ## BRMSEA 0.099 0.098 0.097 0.005 0.090 0.107 ## BGammaHat 0.956 0.957 0.958 0.005 0.949 0.963 ## adjBGammaHat 0.907 0.908 0.910 0.010 0.891 0.922 ## BMc 0.902 0.904 0.906 0.010 0.886 0.918 ## BCFI 0.930 0.931 0.933 0.008 0.917 0.942 ## BTLI 0.883 0.884 0.888 0.013 0.862 0.903 ## BNFI 0.910 0.910 0.912 0.007 0.897 0.921"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"access-the-indices-posterior-distributions","dir":"Articles","previous_headings":"","what":"Access the indices posterior distributions","title":"Approximate fit indices","text":"can also extract posterior distributions respective indices, way can explore details. example, diagnostic plots using bayesplot package. saved posterior distributions, can explore histogram scatterplots indices.","code":"dist_fits <- data.frame(gl_fits_all@indices) head(dist_fits) ## BRMSEA BGammaHat adjBGammaHat BMc BCFI BTLI BNFI ## 1 0.10593079 0.9499973 0.8933976 0.8883160 0.9187946 0.8644212 0.8988141 ## 2 0.10014752 0.9550694 0.9042111 0.8995598 0.9274858 0.8789319 0.9071878 ## 3 0.09712886 0.9576242 0.9096576 0.9052313 0.9319535 0.8863909 0.9115299 ## 4 0.09818988 0.9567336 0.9077589 0.9032536 0.9308408 0.8845333 0.9105678 ## 5 0.09633310 0.9582868 0.9110703 0.9067033 0.9334671 0.8889181 0.9131040 ## 6 0.09211234 0.9617252 0.9184007 0.9143465 0.9386225 0.8975255 0.9178845 mcmc_pairs(dist_fits, pars = c(\"BRMSEA\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"hist\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/approx_fi.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Approximate fit indices","text":"can estimate posterior distributions χ2\\chi^2 based global fit indices. Notice presented fit indices based recommended method devM recommended number parameters metric loo. can adjusted user desired. general recommendation prefer Γ̂\\hat{\\Gamma} CFI, shown less sensitive model data characteristics. defaults recommendations made based previous simulation research. details fit indices please see Garnier-Villarreal Jorgensen (2020).","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Convergence and Efficiency Evaluation","text":"Bayesian models estimated Markov-Chain Monte Carlo (MCMC) sampler, model estimation doesn’t stop achieved convergence criteria. run long desired (determined burnin sample arguments), need evaluate convergence efficiency estimated posterior distributions. analyze results convergence achieved, judged metrics described . example use Industrialization Political Democracy example (Bollen 1989).","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"convergence","dir":"Articles","previous_headings":"","what":"Convergence","title":"Convergence and Efficiency Evaluation","text":"primary convergence diagnostic R̂\\hat{R}, compares - within-chain samples model parameters univariate quantities interest (Vehtari et al. 2021). chains mixed well (ie, - within-chain estimates don’t agree), R̂\\hat{R} larger 1. recommend running least three chains default using posterior samples R̂<1.05\\hat{R} < 1.05 parameters. blavaan presents R̂\\hat{R} reported underlying MCMC program, either Stan JAGS (Stan default). can obtain R̂\\hat{R} summary() function, can also extract blavInspect() function large models can cumbersome look entries. can instead find largest R̂\\hat{R} see less 1.051.05 R̂<1.05\\hat{R} < 1.05 can establish MCMC chains converged stable solution. model converged, might increase number burnin iterations /change model priors dpriors() function. address issues model failed converge due needing iterations due model misspecification (bad priors). rule thumb, seldom see model require 1,000 burnin samples Stan. model converging 1,000 burnin samples, likely default prior distributions clash data. can happen, e.g., variables contain values 100s 1000s.","code":"blavInspect(fit, \"rhat\") ## ind60=~x1 ind60=~x2 ind60=~x3 a b c ## 1.0021155 1.0014028 1.0011210 0.9994694 1.0005097 0.9998649 ## d a b c d dem60~ind60 ## 1.0038308 0.9994694 1.0005097 0.9998649 1.0038308 1.0002757 ## dem65~ind60 dem65~dem60 y1~~y5 y2~~y4 y2~~y6 y3~~y7 ## 1.0011541 0.9999180 1.0009617 1.0030341 0.9993406 1.0003294 ## y4~~y8 y6~~y8 x1~~x1 x2~~x2 x3~~x3 y1~~y1 ## 1.0003158 0.9996220 1.0012237 1.0020556 0.9998015 1.0003578 ## y2~~y2 y3~~y3 y4~~y4 y5~~y5 y6~~y6 y7~~y7 ## 0.9995107 0.9996011 1.0032729 0.9998450 1.0003404 0.9994630 ## y8~~y8 x1~1 x2~1 x3~1 y1~1 y2~1 ## 1.0001286 1.0006249 1.0005780 1.0000013 1.0006972 1.0000931 ## y3~1 y4~1 y5~1 y6~1 y7~1 y8~1 ## 0.9998330 1.0004696 1.0011070 0.9998333 1.0006884 1.0010911 max(blavInspect(fit, \"psrf\")) ## [1] 1.003831 fit <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=1000, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_efficiency.html","id":"efficiency","dir":"Articles","previous_headings":"","what":"Efficiency","title":"Convergence and Efficiency Evaluation","text":"also evaluate efficiency posterior samples. Effective sample size (ESS) useful measure sampling efficiency, well defined even chains finite mean variance (Vehtari et al. 2021). short, posterior samples produced MCMC autocorrelated. means , draw 500 posterior samples, 500 independent pieces information posterior distribution, samples autocorlated. ESS metric like currency conversion, telling much autocorrelated samples worth convert independent samples. blavaan can print summary function neff argument can also extract blavInspect() function ESS sample size, least 100 (optimally, much 100) times number chains order reliable indicate estimates posterior quantiles reliable. example, 3 chains, want see least neff=300 every parameter. can easily find lowest ESS min() function:","code":"summary(fit, neff=T) blavInspect(fit, \"neff\") ## ind60=~x1 ind60=~x2 ind60=~x3 a b c ## 1639.120 1444.645 1631.786 1947.795 1807.270 2129.132 ## d a b c d dem60~ind60 ## 1543.688 1947.795 1807.270 2129.132 1543.688 2089.569 ## dem65~ind60 dem65~dem60 y1~~y5 y2~~y4 y2~~y6 y3~~y7 ## 2840.737 2441.160 2394.304 2015.814 2738.832 2425.830 ## y4~~y8 y6~~y8 x1~~x1 x2~~x2 x3~~x3 y1~~y1 ## 1881.706 1876.226 2571.538 2008.444 3976.143 2592.135 ## y2~~y2 y3~~y3 y4~~y4 y5~~y5 y6~~y6 y7~~y7 ## 3092.750 3255.657 1780.215 2389.160 2825.048 2645.932 ## y8~~y8 x1~1 x2~1 x3~1 y1~1 y2~1 ## 1785.457 1206.981 1247.654 1295.642 1362.742 1690.638 ## y3~1 y4~1 y5~1 y6~1 y7~1 y8~1 ## 1528.945 1293.889 1204.344 1298.091 1153.531 1091.060 min(blavInspect(fit, \"neff\")) ## [1] 1091.06"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Convergence loop","text":"many cases need run BSEM models multiple times converged. can take might want R . tutorial shows use loop increase number burnin samples model converges, can let run without adjust every time","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"convergence-loop","dir":"Articles","previous_headings":"","what":"Convergence loop","title":"Convergence loop","text":"start writing model syntax always. instead running blavaan functions usual, run inside loop follows. loop starts need define starting BURN <- 0 number iterations, convergence value higher desired rhat <- 20. loop set stop convergence criteria (rhat) lower desired value, like R̂<1.05\\hat{R} < 1.05, specify (rhat > 1.05), meaning loop continue long rhat higher 1.05. inside loop increase number BURN iterations 1000 example. estimating model, evaluate convergence getting highest estimated R̂\\hat{R}, printing screen see far model converging. Note increasing number burnin iterations, keeping number saved samples (1000 case). want can increase decrease number saved iterations according case. can visualize convergence trace plots","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' BURN <- 0 rhat <- 20 while(rhat > 1.05) { BURN <- BURN + 1000 ### increase burn in by 1000 iterations every time fit <- bcfa(HS.model, std.lv=T, data=HolzingerSwineford1939, n.chains = 3, burnin = BURN, sample=1000) rhat <- max(blavInspect(fit, \"psrf\"), na.rm=T) print(paste0(\"Rhat=\",rhat)) } print(paste0(\"Rhat=\",rhat)) ## [1] \"Rhat=1.00191591415435\" plot(fit, pars = 1:9, plot.type = \"trace\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/convergence_loop.html","id":"convergence-criteria","dir":"Articles","previous_headings":"","what":"Convergence criteria","title":"Convergence loop","text":"example use R̂<1.05\\hat{R} < 1.05 convergence criteria. recommend use R̂<1.01\\hat{R} < 1.01 convergence criteria, higher. R̂\\hat{R} approximates 1, can argue model converged estimates achieve stability within chains (Gelman et al. 2014)","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Cross-loadings with strong priors","text":"advantage BSEM can use priors set soft constraints model, estimating parameter strong prior. way parameter estimated, prior restrict possible values. suggested Muthén Asparouhov (2012), way estimate possible cross-loadings CFA. way, posterior distribution restricted parameters includes values outside strong prior, can interpreted model modification. means parameters less restricted, prior distribution relaxed. tutorial present estimate CFA possible cross-loadings restricted strong priors.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"cross-loadings","dir":"Articles","previous_headings":"","what":"Cross-loadings","title":"Cross-loadings with strong priors","text":"show example Holzinger Swineford (1939) data. First estimate regular model cross-loadings default priors. can see overall model results summary() function, looking posterior distribution factor loadings, correlations, intercepts variances. Next, add possible cross-loadings strong prior N(0,σ=0.08)N(0, \\sigma = 0.08). prior centers loadings around 0 allows little space move. important , factor, first variable =~ one whose loading expect far 0. , model, specified regular cfa first (whose loadings expect larger), loadings small-variance priors separate line. important , blavaan, first loading either constrained positive fixed 1 (depending std.lv). posterior distribution constrained loading centered near 0, may experience identification problems. Reverse-coded variables can also problematic , positive constraint reverse-coded loading can lead loadings assume negative values. use informative priors situation, verify prior density correct side 0. estimation, can look summary() model evaluate cross-loadings. can specifically see whether cross-loadings seem large enough suggest kept model, looking posterior mean (Estimate) credible interval. suggest simply look whether CI excludes 0 (similar null hypothesis), evaluate whether minimum value CI (value closer 0) far enough away 0 relavant instead just different 0.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit_df <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T) summary(fit_df) ## blavaan 0.5.6.1311 ended normally after 1000 iterations ## ## Estimator BAYES ## Optimization method MCMC ## Number of model parameters 30 ## ## Number of observations 301 ## ## Statistic MargLogLik PPP ## Value -3871.046 0.000 ## ## Parameter Estimates: ## ## ## Latent Variables: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual =~ ## x1 0.912 0.086 0.744 1.086 1.001 normal(0,10) ## x2 0.500 0.082 0.340 0.660 1.000 normal(0,10) ## x3 0.661 0.078 0.512 0.815 1.000 normal(0,10) ## textual =~ ## x4 1.002 0.058 0.891 1.119 1.000 normal(0,10) ## x5 1.116 0.064 0.995 1.242 1.000 normal(0,10) ## x6 0.928 0.056 0.823 1.042 1.001 normal(0,10) ## speed =~ ## x7 0.619 0.077 0.463 0.765 1.001 normal(0,10) ## x8 0.733 0.079 0.573 0.887 1.000 normal(0,10) ## x9 0.681 0.079 0.530 0.840 1.000 normal(0,10) ## ## Covariances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual ~~ ## textual 0.449 0.067 0.311 0.576 1.000 lkj_corr(1) ## speed 0.462 0.086 0.292 0.622 1.000 lkj_corr(1) ## textual ~~ ## speed 0.278 0.071 0.135 0.417 1.000 lkj_corr(1) ## ## Intercepts: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 4.936 0.067 4.803 5.064 0.999 normal(0,32) ## .x2 6.089 0.069 5.961 6.230 0.999 normal(0,32) ## .x3 2.251 0.065 2.123 2.385 1.000 normal(0,32) ## .x4 3.061 0.067 2.929 3.193 1.000 normal(0,32) ## .x5 4.340 0.074 4.194 4.481 1.000 normal(0,32) ## .x6 2.186 0.064 2.061 2.312 1.000 normal(0,32) ## .x7 4.185 0.062 4.062 4.309 1.000 normal(0,32) ## .x8 5.527 0.058 5.416 5.638 0.999 normal(0,32) ## .x9 5.374 0.057 5.261 5.488 1.000 normal(0,32) ## visual 0.000 ## textual 0.000 ## speed 0.000 ## ## Variances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 0.551 0.127 0.290 0.791 1.000 gamma(1,.5)[sd] ## .x2 1.153 0.107 0.954 1.383 1.000 gamma(1,.5)[sd] ## .x3 0.859 0.100 0.674 1.062 1.000 gamma(1,.5)[sd] ## .x4 0.378 0.050 0.284 0.484 1.000 gamma(1,.5)[sd] ## .x5 0.453 0.061 0.337 0.578 1.000 gamma(1,.5)[sd] ## .x6 0.365 0.045 0.281 0.458 1.000 gamma(1,.5)[sd] ## .x7 0.820 0.092 0.653 1.016 1.000 gamma(1,.5)[sd] ## .x8 0.502 0.095 0.317 0.697 1.001 gamma(1,.5)[sd] ## .x9 0.567 0.093 0.374 0.738 1.002 gamma(1,.5)[sd] ## visual 1.000 ## textual 1.000 ## speed 1.000 HS.model.cl<-' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ## Cross-loadings visual =~ prior(\"normal(0,.08)\")*x4 + prior(\"normal(0,.08)\")*x5 + prior(\"normal(0,.08)\")*x6 + prior(\"normal(0,.08)\")*x7 + prior(\"normal(0,.08)\")*x8 + prior(\"normal(0,.08)\")*x9 textual =~ prior(\"normal(0,.08)\")*x1 + prior(\"normal(0,.08)\")*x2 + prior(\"normal(0,.08)\")*x3 + prior(\"normal(0,.08)\")*x7 + prior(\"normal(0,.08)\")*x8 + prior(\"normal(0,.08)\")*x9 speed =~ prior(\"normal(0,.08)\")*x1 + prior(\"normal(0,.08)\")*x2 + prior(\"normal(0,.08)\")*x3 + prior(\"normal(0,.08)\")*x4 + prior(\"normal(0,.08)\")*x5 + prior(\"normal(0,.08)\")*x6' fit_cl <- bcfa(HS.model.cl, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T) summary(fit_cl) ## blavaan 0.5.6.1311 ended normally after 1000 iterations ## ## Estimator BAYES ## Optimization method MCMC ## Number of model parameters 48 ## ## Number of observations 301 ## ## Statistic MargLogLik PPP ## Value -3858.912 0.138 ## ## Parameter Estimates: ## ## ## Latent Variables: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual =~ ## x1 0.759 0.097 0.581 0.963 1.000 normal(0,10) ## x2 0.567 0.089 0.394 0.741 1.000 normal(0,10) ## x3 0.771 0.095 0.586 0.955 1.001 normal(0,10) ## textual =~ ## x4 0.982 0.066 0.860 1.115 1.000 normal(0,10) ## x5 1.156 0.072 1.020 1.302 1.000 normal(0,10) ## x6 0.893 0.061 0.779 1.018 1.000 normal(0,10) ## speed =~ ## x7 0.727 0.085 0.571 0.900 1.000 normal(0,10) ## x8 0.793 0.084 0.635 0.961 1.000 normal(0,10) ## x9 0.542 0.073 0.400 0.687 0.999 normal(0,10) ## visual =~ ## x4 0.032 0.057 -0.080 0.139 1.000 normal(0,.08) ## x5 -0.073 0.063 -0.199 0.048 1.000 normal(0,.08) ## x6 0.063 0.055 -0.046 0.166 0.999 normal(0,.08) ## x7 -0.130 0.063 -0.259 -0.010 1.000 normal(0,.08) ## x8 -0.007 0.066 -0.139 0.119 1.000 normal(0,.08) ## x9 0.194 0.058 0.073 0.309 1.000 normal(0,.08) ## textual =~ ## x1 0.110 0.064 -0.013 0.234 0.999 normal(0,.08) ## x2 0.007 0.059 -0.110 0.123 1.000 normal(0,.08) ## x3 -0.085 0.062 -0.213 0.031 1.000 normal(0,.08) ## x7 0.016 0.061 -0.107 0.129 1.000 normal(0,.08) ## x8 -0.038 0.061 -0.161 0.081 0.999 normal(0,.08) ## x9 0.032 0.056 -0.079 0.141 0.999 normal(0,.08) ## speed =~ ## x1 0.045 0.066 -0.085 0.174 0.999 normal(0,.08) ## x2 -0.048 0.064 -0.173 0.073 0.999 normal(0,.08) ## x3 0.029 0.066 -0.099 0.161 1.000 normal(0,.08) ## x4 -0.005 0.057 -0.116 0.104 0.999 normal(0,.08) ## x5 0.008 0.062 -0.114 0.127 1.001 normal(0,.08) ## x6 0.001 0.056 -0.112 0.110 1.001 normal(0,.08) ## ## Covariances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## visual ~~ ## textual 0.373 0.091 0.190 0.543 0.999 lkj_corr(1) ## speed 0.351 0.109 0.120 0.545 1.000 lkj_corr(1) ## textual ~~ ## speed 0.255 0.104 0.049 0.453 0.999 lkj_corr(1) ## ## Intercepts: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 4.935 0.068 4.803 5.065 1.000 normal(0,32) ## .x2 6.089 0.070 5.946 6.226 0.999 normal(0,32) ## .x3 2.250 0.066 2.121 2.384 0.999 normal(0,32) ## .x4 3.061 0.066 2.928 3.185 1.000 normal(0,32) ## .x5 4.340 0.075 4.197 4.487 1.000 normal(0,32) ## .x6 2.186 0.064 2.059 2.308 1.002 normal(0,32) ## .x7 4.187 0.062 4.066 4.306 1.000 normal(0,32) ## .x8 5.528 0.060 5.410 5.645 1.000 normal(0,32) ## .x9 5.375 0.056 5.266 5.484 0.999 normal(0,32) ## visual 0.000 ## textual 0.000 ## speed 0.000 ## ## Variances: ## Estimate Post.SD pi.lower pi.upper Rhat Prior ## .x1 0.680 0.107 0.469 0.891 1.000 gamma(1,.5)[sd] ## .x2 1.091 0.109 0.885 1.321 0.999 gamma(1,.5)[sd] ## .x3 0.713 0.112 0.497 0.936 1.001 gamma(1,.5)[sd] ## .x4 0.389 0.051 0.297 0.491 1.000 gamma(1,.5)[sd] ## .x5 0.411 0.066 0.289 0.543 0.999 gamma(1,.5)[sd] ## .x6 0.374 0.043 0.295 0.465 1.000 gamma(1,.5)[sd] ## .x7 0.712 0.094 0.524 0.900 0.999 gamma(1,.5)[sd] ## .x8 0.434 0.092 0.243 0.610 1.000 gamma(1,.5)[sd] ## .x9 0.589 0.063 0.475 0.723 0.999 gamma(1,.5)[sd] ## visual 1.000 ## textual 1.000 ## speed 1.000"},{"path":"http://ecmerkle.github.io/blavaan/articles/cross_loadings_strong_priors.html","id":"caveats","dir":"Articles","previous_headings":"","what":"Caveats","title":"Cross-loadings with strong priors","text":"model possible cross-loadings kept final analysis model, used step make decisions model changes. two main reasons, (1) model overfitted present good overall fit just due inclusion lot nuisance parameters. example posterior predictive p-value goes ppp = 0 ppp = 0.138, model better theoretically inflating model fit. (2), addition small-variance priors can prevent detection important misspecifications Bayesian confirmatory factor analysis, can obscure underlying problems model diluting large number nuisance parameters (Jorgensen et al. 2019).","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"primary-arguments","dir":"Articles","previous_headings":"","what":"Primary arguments","title":"Model Estimation","text":"Primary arguments model estimation commands include burnin, sample, n.chains, target. burnin sample arguments used specify desired number burn-iterations posterior samples n.chains chains (burnin argument controls warm-iterations Stan). target argument, hand, used specify MCMC strategy used estimation. default, target = \"stan\", tends fastest efficient. options slightly flexible, including target = \"stanclassic\" target = \"jags\". approaches sample latent variables model parameters, whereas target = \"stan\" marginalizes latent variables. detail approaches, see JSS paper.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"secondary-arguments","dir":"Articles","previous_headings":"","what":"Secondary arguments","title":"Model Estimation","text":"Noteworthy secondary arguments include save.lvs, mcmcfile, mcmcextra, inits. save.lvs argument controls whether latent variables sampled model estimation. defaults FALSE latent variable sampling can take large amount memory, can slow post-estimation summaries. setting save.lvs = TRUE allows model summaries latent variables observed variable predictions using blavPredict() functions. setting mcmcfile = TRUE, users can obtain Stan (JAGS) code data specified model. files written lavExport folder within user’s working directory. One file extension .jag .stan, second file R data file (extension .rda). rda file can loaded R (via load()) list including elements data, monitors, inits. elements can supplied stan() model estimation outside blavaan. mcmcextra argument used supply extra information Stan JAGS. Users can supply list element names monitor, data, syntax, llnsamp. elements respectively used specify extra parameters monitor, extra data pass model estimation, extra syntax include model file (JAGS ), number importance samples likelihood approximation (relevant models ordinal variables). inits argument used control starting values MCMC estimation. can sometimes salvage model immediately crashes. default, inits = \"simple\", initializes model parameters 0 1 fashion similar lavaan’s use argument. second option, inits = \"prior\", draws initial values prior distributions. user can also specify list initial values via argument, though required list format somewhat cumbersome. recommend exporting model data using mcmcfile = TRUE, loading resulting rda file, looking format initial values blavaan created .","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/estimate.html","id":"parallelization","dir":"Articles","previous_headings":"","what":"Parallelization","title":"Model Estimation","text":"Speed always issue sample via MCMC, especially using software like Stan JAGS. computers multiple cores, estimation can sped sending MCMC chain separate core. accomplished bcontrol argument, list whose elements correspond stan() run.jags() arguments. parallelizing chains Stan, want use argument bcontrol = list(cores = 3). Many arguments available control aspects estimation; see ?stan ?run.jags possibilities. Parallelization can also helpful speed post-estimation computations. future package controls parallelization, requires extra command prior estimation. common commands ","code":"library(\"future\") plan(\"multicore\") ## mac or linux plan(\"multisession\") ## windows"},{"path":"http://ecmerkle.github.io/blavaan/articles/invariance.html","id":"model-estimation","dir":"Articles","previous_headings":"","what":"Model Estimation","title":"Measurement Invariance","text":"Consider measurement invariance study Holzinger Swineford (1939) data. lavaan, may first estimate two models: examine absolute fit fit1. also compare fit2 fit1 via Likelihood Ratio Test. Instead , wish something similar via Bayesian methods. accomplish via blavaan, can fit Bayesian versions fit1 fit2 using similar syntax. Model fit comparison statistics available via fitMeasures() blavCompare() functions:","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit1 <- cfa(HS.model, data = HolzingerSwineford1939, group = \"school\") fit2 <- cfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = \"loadings\") bfit1 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\") bfit2 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = \"loadings\") fitMeasures(bfit1) fitMeasures(bfit2) blavCompare(bfit1, bfit2)"},{"path":"http://ecmerkle.github.io/blavaan/articles/invariance.html","id":"approximate-invariance","dir":"Articles","previous_headings":"","what":"Approximate Invariance","title":"Measurement Invariance","text":"approximate measurement invariance studies, replace hard equality constraints soft constraints using informative prior distributions. wiggle argument can used invoke types constraints. example: constrains loadings associated x2 x3 approximately equal across groups, informative priors associated constraints normal standard deviations 0.05. Using strategy, syntax can become cumbersome. many cases, group.equal argument can help . example: example, model intercepts loadings across-group constraints. loadings approximately equal across groups, due argument wiggle = \"loadings\". intercepts constrained exactly equal across groups. way, becomes easy use exact approximate equality constraints model, desired.","code":"HS.model <- ' visual =~ x1 + c(\"a\", \"a\")*x2 + c(\"b\", \"b\")*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' bfit3 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", wiggle = c(\"a\", \"b\"), wiggle.sd = 0.05) HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' bfit4 <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = c(\"intercepts\", \"loadings\"), wiggle = \"loadings\", wiggle.sd = 0.05)"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Modification indices","text":"SEM, one first steps evaluate model’s global fit. global fit, need evaluate local fit model, meaning model reproduces specific correlations observed variables. couple common methods , () testing high residual correlations, (b) modification indices. tutorial focuses second. Modification indices test likely change model fit single parameter added model originally included. test can carried every possible parameter included (Bentler 1990).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"modification-indices","dir":"Articles","previous_headings":"","what":"Modification Indices","title":"Modification indices","text":"Modification indices present different indices quantify effect parameter, focus two . () modification index (MI) Lagrange multiplier, estimates extent model’s chi-square (χ2\\chi^2) test statistic decrease parameter added model freely estimated, (b) standardized expected parameter change (SEPC), approximated standardized value parameter estimated model (Whittaker 2012). MI presents possible effect overall model, SEPC presents effect size missed parameter. show example Holzinger Swineford (1939) model. first estimate SEM/CFA model usual need write discrepancy function collect modification indices. list contains two functions estimate save MI SEPC. pass function ppmc() function blavaan. function, MI SEPC computed posterior sample, leading posterior distributions . view top 5 parameters arrange posterior mean (EAP) MI, case shows parameter highest impact overall model fit (according EAP) visual=~x9, cross-loading Visual factor item x9. according posterior median, parameter highest impact residual correlation indicators x7 x8 MI still recommended best metric indicate parameter best include next, can use SEPC evaluate likely effect size respective parameters. see 2 highest parameters, likely SEPC x7~~x8 = 0.793876155456826 visual=~x9 = 0.516400919262519. information can decide include one new parameters model (one time). example, factor loadings larger impact model-implied covariance matrix, choose visual=~x9 can check added parameter expected impact overall fit blavFitIndices() summary() functions. important consider also theoretical relevance suggested parameters, ensure make sense, instead just adding parameters good fit.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE) discFUN <- list( mod.ind_mi = function(object){ temp <- modificationindices(object, free.remove = F) mods <- temp$mi names(mods) <- paste0(temp$lhs, temp$op, temp$rhs) return(mods) }, mod.ind_sepc.all = function(object){ temp <- modificationindices(object, free.remove = F) sepc.all <- temp$sepc.all names(sepc.all) <- paste0(temp$lhs, temp$op, temp$rhs) return(sepc.all) } ) out <- ppmc(fit, discFUN = discFUN) summary(out, prob=.9, discFUN = \"mod.ind_mi\", sort.by=\"EAP\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## visual=~x9 35.164 35.119 35.213 11.223 16.637 52.245 0.014 ## x7~~x8 32.981 35.507 39.796 14.528 8.480 56.405 0.076 ## x8~~x9 26.437 11.969 2.849 43.335 0.000 65.993 0.327 ## x4~~x6 19.620 6.387 2.223 35.491 0.000 52.799 0.457 ## visual=~x7 18.284 16.753 13.244 9.849 3.525 31.902 0.015 ## PPP_sim_LessThan_obs ## visual=~x9 0.986 ## x7~~x8 0.924 ## x8~~x9 0.673 ## x4~~x6 0.543 ## visual=~x7 0.985 summary(out, prob=.9, discFUN = \"mod.ind_mi\", sort.by=\"Median\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## x7~~x8 32.981 35.507 39.796 14.528 8.480 56.405 0.076 ## visual=~x9 35.164 35.119 35.213 11.223 16.637 52.245 0.014 ## visual=~x7 18.284 16.753 13.244 9.849 3.525 31.902 0.015 ## x8~~x9 26.437 11.969 2.849 43.335 0.000 65.993 0.327 ## textual=~x1 11.052 9.906 2.014 8.385 0.000 22.615 0.227 ## PPP_sim_LessThan_obs ## x7~~x8 0.924 ## visual=~x9 0.986 ## visual=~x7 0.985 ## x8~~x9 0.673 ## textual=~x1 0.773 summary(out, prob=.9, discFUN = \"mod.ind_sepc.all\", sort.by=\"EAP\", decreasing=T)[1:5,] ## ## Posterior summary statistics and highest posterior density (HPD) 90% credible intervals ## for the posterior distribution of realized discrepancy-function values based on observed data, ## along with posterior predictive p values to test hypotheses in either direction: ## ## ## EAP Median MAP SD lower upper PPP_sim_GreaterThan_obs ## x7~~x8 0.794 0.786 0.755 0.410 0.502 1.323 0.043 ## visual=~x9 0.516 0.496 0.465 0.134 0.341 0.704 0.010 ## textual=~x1 0.268 0.298 0.312 0.188 0.024 0.531 0.137 ## x1~~x9 0.249 0.247 0.246 0.043 0.200 0.304 0.016 ## x2~~x3 0.223 0.223 0.223 0.037 0.167 0.274 0.021 ## PPP_sim_LessThan_obs ## x7~~x8 0.957 ## visual=~x9 0.990 ## textual=~x1 0.863 ## x1~~x9 0.984 ## x2~~x3 0.979 HS.model <- ' visual =~ x1 + x2 + x3 + x9 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit2 <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE)"},{"path":"http://ecmerkle.github.io/blavaan/articles/mod_indices.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Modification indices","text":"tutorial show calculate MI SEPC across posterior distributions, evaluate parameters can added. ppmc() function able calculate relevant information model estimation, build posterior distributions . general recommendations use MI identify likely parameter add, SEPC effect size new parameter.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Model Comparison","text":"traditional method model comparison frequentist SEM (fSEM) χ2\\chi^2 (Likelihood Ratio Test) variations. BSEM, take Bayesian model comparison methods, apply SEM. Specifically, focus two information criteria, (1) Widely Applicable Information Criterion (WAIC), (2) Leave-One-cross-validation (LOO). methods intend evaluate --sample predictive accuracy models, compare performance. ability predict datapoint hasn’t used training model (McElreath 2020) example use Industrialization Political Democracy example (Bollen 1989).","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit1 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000)"},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"widely-applicable-information-criterion","dir":"Articles","previous_headings":"","what":"Widely Applicable Information Criterion","title":"Model Comparison","text":"WAIC (Watanabe 2010) can seen fully Bayesian generalization Akaike Information Criteria (AIC), measure uncertainty/information model prediction row data across posterior draws. Log-Pointwise-Predictive-Density (lppd). WAIC defined WAIC=−2lppd+2efpWAIC,\\begin{equation} WAIC= -2lppd + 2efp_{WAIC}, \\end{equation} first term involves log-likelihoods observed data (marginal latent variables) second term effective number parameters. first term, lppdlppd, estimated : lppd̂=∑=1nlog(1S∑S=1Sf(yi|θS))\\begin{equation} \\widehat{lppd} = \\sum^{n}_{= 1} log \\Bigg(\\frac{1}{S}\\sum^{S}_{S=1}f(y_{}|\\theta^{S}) \\Bigg) \\end{equation} SS number posterior draws f(yi|θS)f(y_{}|\\theta^{S}) density observation ii respect parameter sampled iteration ss. effective number parameter (efpWAICefp_{WAIC}) calculated : efpWAIC=∑=1nvars(logf(yi|θ))\\begin{equation}\\label{eq:efpWAIC} efp_{WAIC} = \\sum^n_{=1}var_{s}(logf(y_{}|\\theta)) \\end{equation} separate variance estimated observation ii across SS posterior draws.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"leave-one-out-cross-validation","dir":"Articles","previous_headings":"","what":"Leave-One-Out cross-validation","title":"Model Comparison","text":"LOO measures predictive density observation holding one observation time use rest observations update prior. estimation calculated via (Vehtari, Gelman, Gabry 2017): LOO=−2∑=1nlog(∑s=1Swisf(yi|θs)∑s=1swis)\\begin{equation} LOO = -2\\sum_{=1}^{n} log \\Bigg(\\frac{\\sum^{S}_{s =1} w^{s}_{}f(y_{}|\\theta^{s})}{\\sum^{s}_{s=1} w^{s}_{}}\\Bigg) \\end{equation} wisw^s_{} Pareto-smoothed sampling weights based relative magnitude individual ii density function across SS posterior samples. LOO effective number parameters involves lppdlppd term WAIC: efpLOO=lppd+LOO/2\\begin{equation} efp_{LOO} = lppd + LOO/2 \\end{equation}","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"model-comparison","dir":"Articles","previous_headings":"","what":"Model comparison","title":"Model Comparison","text":"WAIC LOO approximate models’ performance across posterior draws, able calculate standard error model comparisons involving . model differences estimate differences across Expected Log-Pointwise-Predictive-Density (elpd), standard error respective difference. clear cutoff rules interpret present comparisons, researchers need use expert knowledge part decision process. best recommendation present differences elpd Δelpd\\Delta elpd, standard error, ratio . ratio least 2 can consider evidence differences models, ratio 4 considered stronger evidence. first example, compare standard political democracy model, model factor regressions fixed 0. 2 models, can compare blavCompare looking comparison object, can see WAIC, LOO, estimates, respective differences . information criteria, best model one lowest value case can see model 1 lower LOOIC, ratio shows LOO differences 5 SE magnitude. indicates model estimated regressions better Now, lets look example smaller difference models, smallest regression (dem65~ind60) fixed 0. see LOOIC, see difference two models minimal, ratio 0.21. indicates models functionally equivalent. case like , researchers decide model better representation, theoretically stronger. Lets one last model, largest regression (dem65~dem60) fixed 0. case, looking LOOIC, see model one better (lower value), ratio difference shows model 5 SE magnitude. Indicating evidence model predictive differences","code":"model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ 0*ind60 dem65 ~ 0*ind60 + 0*dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit2 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc12 <- blavCompare(fit1, fit2) bc12 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1646.9 18.9 ## p_loo 34.6 2.7 ## looic 3293.8 37.8 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.2]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -40.6 7.9 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1646.7 18.9 ## p_waic 34.4 2.7 ## waic 3293.4 37.7 ## ## 33 (44.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -40.7 7.9 abs(bc12$diff_loo[,\"elpd_diff\"] / bc12$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 5.119273 model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ 0*ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit3 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc13 <- blavCompare(fit1, fit3) bc13 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.7 19.4 ## p_loo 37.6 2.9 ## looic 3213.5 38.9 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.5, 1.3]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -0.4 0.9 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.5 19.4 ## p_waic 37.3 2.9 ## waic 3212.9 38.8 ## ## 39 (52.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -0.5 0.9 abs(bc13$diff_loo[,\"elpd_diff\"] / bc13$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 0.4547628 model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ a*y1 + b*y2 + c*y3 + d*y4 dem65 =~ a*y5 + b*y6 + c*y7 + d*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + 0*dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit4 <- bsem(model, data=PoliticalDemocracy, std.lv=T, meanstructure=T, n.chains=3, burnin=500, sample=1000) bc14 <- blavCompare(fit1, fit4) bc14 ## $bf ## bf mll1 mll2 ## NA NA NA ## ## $loo ## $loo[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1606.3 19.5 ## p_loo 37.8 2.9 ## looic 3212.6 39.1 ## ------ ## MCSE of elpd_loo is 0.2. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.4]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## $loo[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_loo -1630.1 19.9 ## p_loo 38.3 3.0 ## looic 3260.1 39.7 ## ------ ## MCSE of elpd_loo is 0.3. ## MCSE and ESS estimates assume MCMC draws (r_eff in [0.2, 1.3]). ## ## All Pareto k estimates are good (k < 0.7). ## See help('pareto-k-diagnostic') for details. ## ## ## $diff_loo ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -23.8 4.0 ## ## $waic ## $waic[[1]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1606.0 19.5 ## p_waic 37.5 2.9 ## waic 3211.9 39.0 ## ## 38 (50.7%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## $waic[[2]] ## ## Computed from 3000 by 75 log-likelihood matrix. ## ## Estimate SE ## elpd_waic -1629.7 19.8 ## p_waic 38.0 3.0 ## waic 3259.4 39.6 ## ## 39 (52.0%) p_waic estimates greater than 0.4. We recommend trying loo instead. ## ## ## $diff_waic ## elpd_diff se_diff ## model1 0.0 0.0 ## model2 -23.7 4.0 abs(bc14$diff_loo[,\"elpd_diff\"] / bc14$diff_loo[,\"se_diff\"]) ## model1 model2 ## NaN 5.957015"},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"bayes-factor","dir":"Articles","previous_headings":"","what":"Bayes factor","title":"Model Comparison","text":"Bayesian literature make use Bayes factor (BF) compare models. number criticisms related use BF BSEM, including (1) BF unstable large models (like SEMs), (2) highly sensitive model priors, (3) requires strong priors stable estimation , (4) can require large number posterior draws, (5) estimation using marginal likelihood ignores lot information posterior distributions. details discussion please see Tendeiro Kiers (2019) Schad et al. (2022). criticisms lead us recommend use BF everyday BSEM estimation. researchers commit prior distributions commit exploring noise computations, BF can used describe relative odds one model another, intuitive model comparison metrics.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/model_comparison.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Model Comparison","text":"recommend use LOO WAIC general model comparison metrics BSEM. allow us estimate models’ --sample predictive accuracy, respective differences across posterior draws. also provide us uncertainty estimates comparison. cases LOO WAIC lead similar results, LOO recommended stable metric (Vehtari, Gelman, Gabry 2017). general, Δelpd\\Delta elpd least 2 standard errors preferably 4 standard errors can interpreted evidence differential predictive accuracy.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"blavaan-coverage","dir":"Articles","previous_headings":"","what":"blavaan Coverage","title":"Two-level SEM","text":"version 0.5-1, blavaan handles two-level, random intercept models complete, continuous data. Handling missing data (assuming missingness random) come future release. meantime, multiple imputation might used combination current blavaan functionality (though currently automatic way ). Alternatively, much missing data occurs lower-level units, listwise deletion work. blavaan approach model estimation mimics lavaan approach, uses matrix results (see Rosseel 2021) enable us efficiently evaluate multilevel SEM likelihood. often lead efficient MCMC estimation, compared sampling level 1 level 2 latent variables working conditional likelihoods (see Merkle et al. 2021 discussion marginal vs conditional likelihoods). Similar single-level models, users can sample latent variables using save.lvs = TRUE argument bcfa/bsem/bgrowth/blavaan commands. Marginal information criteria (marginal latent variables) also automatically computed, information criteria generally preferred condition latent variables (see Merkle, Furr, Rabe-Hesketh 2019 detail context single-level models).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"bayes-specific-options","dir":"Articles","previous_headings":"","what":"Bayes-specific Options","title":"Two-level SEM","text":"Bayesian models require prior distributions. previous blavaan defaults single-level models now used two-level models. can continue use commands like dpriors(lambda = \"normal(1,.5)\") specify Normal(1,.5) prior factor loadings , two-level models, specification apply level 1 level 2 loadings. Depending model, may also useful specify priors individual parameters via prior() argument inside model specification syntax. default prior distributions always work well observed variables whose values far 0. continue encourage users consider prior distributions, possibly using prisamp = TRUE option draw samples prior (used prior predictive checking). Model checking also differs Bayesian frequentist methods. Just like one-level models, blavaan reports posterior predictive p-value general model assessment. computed comparing marginal likelihood observed data (marginal latent variables) marginal likelihood artificial data, iteration MCMC sampling. finer-grained model assessment, encourage users try ppmc(). allows compute posterior predictive p-value using , custom model assessment (defined R function).","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/multilevel.html","id":"concluding-thoughts","dir":"Articles","previous_headings":"","what":"Concluding Thoughts","title":"Two-level SEM","text":"think new blavaan functionality provides viable option Bayesian two-level SEM, provide solid base future model developments. always, underlying Stan files supporting data available via mcmcfile = TRUE argument, blavaan code available Github. Bug reports appreciated, either blavaan Google group Github issue.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Ordinal Models in blavaan","text":"Structural equation models ordinal observed variables supported starting blavaan 0.4-1 (target=\"stan\" ). document describes overall approach, includes model estimation, threshold parameters, log-likelihood calculation, posterior predictive p-values, Jacobians. assume somewhat familiar layout SEM; , technical detail examples found Merkle Rosseel (2018) , recently, Merkle et al. (2021) (links papers references section). aim provide enough detail elucidate new blavaan features, informal enough get () bored.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"estimation","dir":"Articles","previous_headings":"","what":"Estimation","title":"Ordinal Models in blavaan","text":"Ordinal observed variables handled via data augmentation, style Chib Greenberg (1998). might already know , phrase data augmentation imprecise context SEM. many possible things augmented, can make model estimation easier. augmenting observed data predictions missing data, related multiple imputation methods. augmenting observed data latent variables, can simplify likelihood calculation (leading sometimes called conditional likelihood, though conditional also many meanings). augmenting categorical observed variables underlying, latent continuous variables. last type augmentation . testing, found faster efficient approaches sample latent variables alongside model parameters (latent variables integrated likelihoods ; similar description Merkle et al. (2021)). data augmentation implementation, ordinal observation (e.g., yy) used generate continuous, underlying counterpart (e.g., y*y^\\ast). y*y^\\ast must obey model’s threshold parameters (commonly denoted 𝛕\\mathbf{\\tau}), based value observed data. example, ignoring subscripts y*y^\\ast assuming ordinal variable 4 categories, y*<τ1 y=1τ1τ3 y=4\\begin{align*} y^* < \\tau_1 &\\text{ }y = 1 \\\\ \\tau_1 <\\ y^* < \\tau_2 &\\text{ }y = 2 \\\\ \\tau_2 <\\ y^* < \\tau_3 &\\text{ }y = 3 \\\\ y^* >\\ \\tau_3 &\\text{ }y = 4 \\end{align*} require τ1<τ2<τ3\\tau_1 < \\tau_2 < \\tau_3. generate y*y^* separately ordinal observation dataset. become additional, bounded parameters Stan file. Stan User’s Guide helpful example multivariate probit regression using related approach; see https://mc-stan.org/docs/2_27/stan-users-guide/multivariate-outcomes.html. trickiest parts involve enforcing boundaries y*y^* variables, ensuring threshold parameters ordinal variable ordered correctly (allowing possibility different ordinal variables different numbers thresholds). require Jacobian adjustments took good deal time code correctly (detail appears later section). parameters defined generated, remainder model estimation similar simpler situation observed variables continuous. terms Stan file, ordinal overhead comes transformed parameters block. get model block, things operate continuous data.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"thresholds-priors","dir":"Articles","previous_headings":"","what":"Thresholds & Priors","title":"Ordinal Models in blavaan","text":"prior distributions threshold (τ\\tau) parameters involved may appear. , described previous section, threshold parameters single variable must ordered. say, example, thresholds normal(0,1) prior distribution, ignoring fact one threshold’s value influences size thresholds’ values. Michael Betancourt describes Stan Discourse, prior “interacts (ordering) constraint enforce sort uniform repulsion interior points, resulting rigid differences.” quote https://discourse.mc-stan.org/t/prior-choice--ordered-inverse-transformed-parameters/16378/3 address issue, first define unconstrained, unordered parameter vector whose length equals number thresholds model. Call vector 𝛕*\\mathbf{\\tau}^*. obtain ordered thresholds exponentiating unordered parameter vector specific manner. manner works exactly Stan defines parameter type ordered. See https://mc-stan.org/docs/2_28/reference-manual/ordered-vector.html. Additionally, similar idea independently developed signal detection models Paulewicz Blaut (2020) (see bhsdtr package). idea easily shown via example. Say ordinal variable 4 categories. three thresholds variable obtained via: τ1=τ1*τ2=τ1*+exp(τ2*)τ3=τ1*+exp(τ2*)+exp(τ3*).\\begin{align*} \\tau_1 &= \\tau^*_1 \\\\ \\tau_2 &= \\tau^*_1 + \\exp(\\tau^*_2) \\\\ \\tau_3 &= \\tau^*_1 + \\exp(\\tau^*_2) + \\exp(\\tau^*_3). \\end{align*} place normal prior distributions unordered τ*\\tau^* parameters, opposed placing priors ordered τ\\tau parameters. normal priors imply lowest threshold (τ1\\tau_1 ) normal prior, differences successive τ\\tau’s log-normal priors. blavaan, priors can specified usual two ways. First, add dp argument model estimation command follows. assign prior unordered τ*\\tau^* parameters model. Second, specify priors specific threshold parameters model specification syntax. example, say 4-category observed variable called x1. unique priors three thresholds specified model syntax via clear time priors τ*\\tau^* parameters best option. 2019 paper, Michael Betancourt describes Dirichlet prior regularizes thresholds ordinal regression model. strategy seem work SEM, especially useful datasets categories ordinal variable sparse. issues warrant study. https://betanalpha.github.io/assets/case_studies/ordinal_regression.html","code":"dp = dpriors(tau = \"normal(0, .5)\") x1 | prior(\"normal(-1, 1)\") * t1 + prior(\"normal(0, .5)\") * t2 + prior(\"normal(0, 1)\") * t3"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"likelihood-computations","dir":"Articles","previous_headings":"","what":"Likelihood Computations","title":"Ordinal Models in blavaan","text":"get continuous data model block, seems reasonable expect simple likelihood computations. depends likelihood want compute. likelihood used sampling Stan simple multivariate normal y*y^* observations, combined continuous observed variables model. indeed simple compute. likelihood want use model comparison. one thing, y*y^* parameters associated ordinal data involved likelihood, quantities like effective number parameters become inflated. number parameters involved likelihood also increases sample size, generally bad land model comparison metrics. See Merkle, Furr, Rabe-Hesketh (2019) detail . means , quantities like WAIC PSIS-LOO, must compute second model likelihood involves observed, ordinal yy variables integrates latent y*y^* variables. difficult problem amounts evaluating CDF sometimes-high-dimensional, multivariate normal distribution (see Chib Greenberg 1998, Equation 11). multiple possibilities approximating CDF. currently rely sadmvn() function mnormt package (Azzalini Genz 2020), uses subregion adaptive integration method Genz (1992) fast accurate (15 fewer ordinal variables model). second possibility involves Monte Carlo simulation, implemented tmvnsim package (Bhattacjarjee 2016). case, generate many random samples appropriate truncated multivariate normal average resulting importance sampling weights. procedure computationally intensive also time intensive, balance number random samples drawn amount time takes. users wish use tmvnsim(), must declare number importance samples draw. accomplished setting llnsamp within mcmcextra$data argument. example, draw 100 samples approximation, call bsem() similar functions include argument Beyond two methods, also possible use quadrature latent variables. Many people consider quadrature gold standard , quadrature reduce dimension integration many models (usually fewer latent variables observed variables). quadrature specific SEM, fast, efficient, open implementations method appear currently exist (implementations hidden blavaan, pure R implementations fairly slow). hand, approximation multivariate normal CDF general problem multiple fast, efficient, open implementations, long many ordinal variables model. also exists relatively new method Z. . Botev (2017) evaluating CDF multivariate normal, implementation method appearing package TruncatedNormal (Z. Botev Belzile 2021). method especially useful evaluating high-dimensional normal distributions (case, 15 ordinal variables), may incorporated future versions blavaan.","code":"mcmcextra = list(data = list(llnsamp = 100))"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"comparison-to-lavaan","dir":"Articles","previous_headings":"","what":"Comparison to lavaan","title":"Ordinal Models in blavaan","text":"Ordinal SEM associated two types model parameterizations: delta theta. refer different scale parameterizations y*y^* variables: delta refers total standard deviation y*y^* (including variability due latent variables), theta refers residual standard deviation y*y^*. blavaan, theta parameterization implemented. , want compare lavaan results blavaan results, need use argument parameterization = \"theta\" estimate lavaan model. Also, default lavaan estimator ordinal models multiple-step procedure involves weighted least squares discrepancy function. resulting parameter estimates sometimes far posterior means reported blavaan. blavaan estimates usually closer estimator=\"PML\" lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"posterior-predictive-p-values","dir":"Articles","previous_headings":"","what":"Posterior Predictive p-values","title":"Ordinal Models in blavaan","text":"Posterior predictive p-value (ppp) computations receive speed boost 0.4 series. computations now occur Stan, whereas previously occurred R model estimation. discussed Asparouhov Muthén (2021), ppp computations needed models missing data can excessively slow, requiring us run EM algorithm posterior sample order find “H1” (“saturated”) model covariance matrix. solution Asparouhov Muthén (2021) involves realization need use fully-optimized H1 covariance matrix order compute ppp. blavaan, consequently run EM algorithm fixed number iterations order compute H1 covariance matrix “good enough” ppp. default number iterations set 20, users can change default supplying emiter value via mcmcextra argument. example,","code":"mcmcextra = list(data = list(emiter = 50))"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"jacobians","dir":"Articles","previous_headings":"","what":"Jacobians","title":"Ordinal Models in blavaan","text":"(section likely relevant editing/writing Stan models.) Stan model underlying blavaan currently requires Jacobian adjustments two places. section briefly reviews ideas underneath adjustments, future self may wish remember. need Jacobian adjustment place prior something appear Stan parameters block. Jacobian tells us implied priors things parameters block, based priors appear model block. Jacobian comes statistics literature “change variables”: applying function random variables, finding distribution function based original distribution random variables. comes Stan models, means starting priors model block finding implied priors parameters block. confused long time , Stan file, functions naturally go opposite direction: starting parameters block, moving model block. fact functions go model parameters convenient, though, Jacobian adjustments require inverse functions. inverse functions move us parameters model, already exist Stan model. just need find appropriate derivatives functions, lead Jacobian. example, consider fact blavaan allows users choose whether priors go standard deviation, variance, precision parameters. standard deviations appear parameters block regardless user chooses (Stan model precompiled time package installation). Say user wants priors precisions. transform standard deviations precisions model block, put prior precision. addition prior, need Jacobian function starts standard deviation (call σ\\sigma) transforms precision (σ−2\\sigma^{-2}). derivative σ−2\\sigma^{-2} respect σ\\sigma −2σ−3-2 \\sigma^{-3}. simple function mapping single parameter different value, Jacobian absolute value derivative, 2σ−32 \\sigma^{-3}. Stan file, add log Jacobian target: examples discussion can found : https://mc-stan.org/users/documentation/case-studies/mle-params.html","code":"target += log(2) - 3*log(sigma)"},{"path":"http://ecmerkle.github.io/blavaan/articles/ordinal.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Ordinal Models in blavaan","text":"blavaan 0.4 series offers enhanced functionality variety areas. computational decisions made reflect balance estimation precision estimation speed. case software defaults behave poorly situations. example, default prior distributions can problematic certain situations, likelihood approximations ordinal models may precise desired, new ppp computations may behave differently previous computations. encourage users carry sensitivity analyses, also report bugs!","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/plotting.html","id":"basics","dir":"Articles","previous_headings":"","what":"Basics","title":"Plot Functionality","text":"many blavaan models many parameters, users generally need specify parameters wish plot. accomplished supplying numbers pars argument, numbers correspond order parameters coef() command (numbers also appear free column parameter table). Users must also specify type plot desire via plot.type argument. , example, trace plot first four model parameters looks like Many plot types available, coming bayesplot package. general, bayesplot functions begin mcmc_, corresponding plot.type remainder function name without leading mcmc_. Examples many plots can found bayesplot vignette.","code":"plot(fit, pars = 1:4, plot.type = \"trace\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/plotting.html","id":"customization","dir":"Articles","previous_headings":"","what":"Customization","title":"Plot Functionality","text":"Users may wish customize aspects resulting plots. , plot() function output ggplot object. makes possible modify plot ggplot object, allows many possibilities. One starting point exploring ggplot2 . Alternatively, users may wish create plot entirely different available via plot(). can facilitated extracting posterior samples Stan model, via blavInspect():","code":"p <- plot(fit, pars = 1:4, plot.type = \"trace\", showplot = FALSE) p + facet_text(size=15) + legend_none() ## list of draws ## (one list entry per chain): draws <- blavInspect(fit, \"mcmc\") ## convert the list to a matrix ## (each row is a sample, ## each column is a parameter) draws <- do.call(\"rbind\", draws) ## Stan (or JAGS) model modobj <- blavInspect(fit, \"mcobj\")"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"defaults","dir":"Articles","previous_headings":"","what":"Defaults","title":"Specifying Prior Distributions","text":"default priors can seen via important note prior distributions correspond Stan parameterizations. similar R parameterizations necessarily exactly . Greek(ish) names correspond following parameter types (MV manifest/observed variable LV latent variable): information priors thresholds, see ordinal modeling details. target = \"stan\" (default), priors currently restricted one distribution per parameter type. can change prior distribution parameters (example, mean standard deviation normal), change prior distribution type. exceptions “theta” “psi” parameters: , can use modifiers “[sd]”, “[var]”, “[prec]” specify whether want priors apply standard deviation, variance, precision. require flexibility prior specification, change target either \"stanclassic\" (old Stan approach) \"jags\" (JAGS approach). Alternatively, can export Stan model via mcmcfile = TRUE, edit file needed, fit via rstan package. modify prior distributions, simply supply new text string dpriors() like : default prior loadings now normal mean 1 standard deviation 2, rest parameters remain original defaults. next time estimate model (via bsem(), bcfa(), bgrowth(), blavaan()), add argument dp=mydp use new set default priors.","code":"dpriors() ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(0,10)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\" ## nu alpha lambda beta ## \"MV intercept\" \"LV intercept\" \"Loading\" \"Regression\" ## theta psi rho ibpsi ## \"MV precision\" \"LV precision\" \"Correlation\" \"Covariance matrix\" ## tau ## \"Threshold\" mydp <- dpriors(lambda=\"normal(1,2)\") mydp ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(1,2)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"individual-parameters","dir":"Articles","previous_headings":"","what":"Individual Parameters","title":"Specifying Prior Distributions","text":"addition setting prior one type model parameter, user may wish set prior specific model parameter. accomplished using prior() modifier within model specification. example, consider following syntax Holzinger Swineford (1939) confirmatory factor model: loading visual x2 now normal prior mean 1 standard deviation 2, loading textual x6 normal prior mean 3 standard deviation 1.5. loadings default prior distribution. syntax, additionally specified gamma(3,3) prior associated residual x1. [sd] text end distribution says prior goes residual standard deviation, opposed residual precision residual variance. exist two options : [var] option residual variance, brackets precision (also use [prec]). bracketed text can used model variance/SD/precision parameter also used default prior specification desired.","code":"HS.model <- ' visual =~ x1 + prior(\"normal(1,2)\")*x2 + x3 textual =~ x4 + x5 + prior(\"normal(3,1.5)\")*x6 speed =~ x7 + x8 + x9 x1 ~~ prior(\"gamma(3,3)[sd]\")*x1 '"},{"path":"http://ecmerkle.github.io/blavaan/articles/prior.html","id":"covariance-parameters","dir":"Articles","previous_headings":"","what":"Covariance Parameters","title":"Specifying Prior Distributions","text":"One additional note covariance parameters defined model syntax: prior() syntax specifies prior correlation associated covariance parameter, opposed covariance . specified distribution support (0,1), blavaan automatically translates prior equivalent distribution support (-1,1). safest stick beta priors . example, syntax places Beta(1,1) (uniform) prior correlation visual textual factors. desired, also specify priors standard deviations (variances precisions) visual textual factors. Together prior correlation, priors imply prior covariance visual textual.","code":"HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 visual ~~ prior(\"beta(1,1)\")*textual '"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Prior Predictive Checks","text":"Bayesian models need specify priors model parameters. Priors distribution think parameters follow, even data. can represent high low uncertainty, diffuse prior indicates don know lot parameter behave, informative prior means quite certain expected distribution.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"prior-predictive-checks","dir":"Articles","previous_headings":"","what":"Prior Predictive Checks","title":"Prior Predictive Checks","text":"Prior predictive checks (PPC) generate data according prior order asses whether prior appropriate (Gabry et al. 2019). posterior predictive check generates replicated data according posterior predictive distribution. contrast, prior predictive check generates data according prior predictive distribution ysim∼p(y)y^{sim} ∼ p(y). prior predictive distribution just like posterior predictive distribution observed data, prior predictive check nothing limiting case posterior predictive check data. easy carry mechanically simulating parameters θsim∼p(θ)θ^{sim}∼p(\\theta) according priors, simulating data ysim∼p(y∣θsim)y^{sim}∼p(y∣ \\theta^{sim}) according sampling distribution given simulated parameters. result simulation joint distribution, (ysim,θsim)∼p(y,θ)(y^{sim},θ^{sim})∼p(y,\\theta) thus ysim∼p(y)y^{sim}∼p(y) simulation prior predictive distribution. blavaan can get PPC use argument prisamp=TRUE , tell blavaan ignore data build distributions priors. start adjusting priors, instead using default priors.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"weakly-informative-priors","dir":"Articles","previous_headings":"Prior Predictive Checks","what":"Weakly informative priors","title":"Prior Predictive Checks","text":"show example Holzinger Swineford (1939) data, first case weakly informative priors. stpecifying observeded variable intercepts prior N(3,2)N(3, 2), factor loadings prior N(0.4,2)N(0.4, 2), residual standard deviation prior Γ(1,1)\\Gamma(1,1). estimate BSEM model respective priors dp argument, prisamp=TRUE, getting PPC instead posterior distributions. might get warning messages either divergent /failed convergence. ignore messages likely issues evaluations prior predictions. now blavaan object prior predictive distributions, can use package functions describe , see parameters within expected ranges. example can get PPC density distributions first 9 parameters (factor loadings case). basic plot() method calls functions bayesplot package (Gabry Mahr 2021) plot.type = \"dens\" argument can plot density distributions can also pick parameters plot, like factor correlations chossing parameters 19:21 case factor loading distributions see first loading factor bounded 0, due modeling identification constraint blavaan, maximum value around 6. distributions range -6 6 -4 4, priors likely value around 0. described weakly informative allows negative positive values without allowing crazy high/low values. realistic range depend parameter, model specification, data. , consider priors function characteristics. factor correlations kept default diffuse priors, allowed high low correlation, prior distributions flat across possible correlation values.","code":"priors <- dpriors(nu=\"normal(3,2)\", lambda=\"normal(0.4, 2)\", theta=\"gamma(1,1)[sd]\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit_wi <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T, test = \"none\", dp=priors, prisamp = T) plot(fit_wi, pars=1:9, plot.type = \"dens\") plot(fit_wi, pars=19:21, plot.type = \"dens\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/prior_pred_checks.html","id":"default-priors","dir":"Articles","previous_headings":"Prior Predictive Checks","what":"Default priors","title":"Prior Predictive Checks","text":"next example, estimate PPC package default priors, consider diffuse priors. can see blavaan default priors function dpriors() estimate BSEM model ignore dp argument letting run default priors, prisamp=TRUE, getting PPC instead posterior distributions. can plot density distributions compare . see default diffuse priors, model allows high values -30 30 way can see diffuse priors allows higher range values. researcher decide range priors better present expectations. important note PPC allows see expected distributions based priors, might priors used estimation process, priors interact model specification constraints (o bound constraint first factor loading) (Merkle et al. 2023)","code":"dpriors() ## nu alpha lambda beta ## \"normal(0,32)\" \"normal(0,10)\" \"normal(0,10)\" \"normal(0,10)\" ## theta psi rho ibpsi ## \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(1,1)\" \"wishart(3,iden)\" ## tau ## \"normal(0,1.5)\" fit_df <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE, meanstructure=T, test = \"none\", prisamp = T) plot(fit_df, pars=1:9, plot.type = \"dens\")"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Probability of Direction","text":"Probability Direction (pd) index effect existence, ranging 0% 100%, representing certainty effect goes particular direction (.e., positive negative) (Makowski et al. 2019). Beyond simplicity interpretation, understanding computation, index also presents interesting properties: independent model: solely based posterior distributions require additional information data model. robust scale response variable predictors. *strongly correlated frequentist p-value, can thus used draw parallels give reference readers non-familiar Bayesian statistics. Can interpreted probability parameter (described posterior distribution) chosen cutoff, explicit hypothesis. mathematically defined proportion posterior distribution satisfies specified hypothesis. Although differently expressed, index fairly similar (.e., strongly correlated) frequentist p-value.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"probability-of-direction-pd","dir":"Articles","previous_headings":"","what":"Probability of Direction (pd)","title":"Probability of Direction","text":"example use Industrialization Political Democracy example (Bollen 1989). first estimate latent regression model can look overall model results summary function, case also asking standardized estimates, R2R^2 calculate probability direction use function package brms (Bürkner 2017) need extract posterior draws matrix, also important note parameters posterior draws named Stan underlying object names, instead (b)lavaan parameter names. due argument add.labels = FALSE used avoid trouble parameter names tildes equal signs . can see parameter name equates partable() function, follows example focus regressions factors Now, can calculate pd, hypothesis() function brms. can ask specific questions posterior distributions, example want know proportion regression dem65~ind60 higher 0. function requires 2 arguments, posterior draws (mc_out) hypothesis (bet_sign[2] > 0). also adding ``alpha``` argument specifies size credible intervals estimate presents mean posterior distribution, respective measures variability (deviation credible interval). Post.Prob pd stated hypothesis, example can say 91% posterior distribution dem65~ind60 lower 0. equivalent one-tail test. Evid.Ratio evidence ratio hypothesis, hypothesis form >ba > b, evidence ratio ratio posterior probability >ba > b posterior probability ## 33 dem60 ~~ dem60 ## 34 dem65 ~~ dem65 ## 35 x1 ~1 Nu_free[1] ## 36 x2 ~1 Nu_free[2] ## 37 x3 ~1 Nu_free[3] ## 38 y1 ~1 Nu_free[4] ## 39 y2 ~1 Nu_free[5] ## 40 y3 ~1 Nu_free[6] ## 41 y4 ~1 Nu_free[7] ## 42 y5 ~1 Nu_free[8] ## 43 y6 ~1 Nu_free[9] ## 44 y7 ~1 Nu_free[10] ## 45 y8 ~1 Nu_free[11] ## 46 ind60 ~1 ## 47 dem60 ~1 ## 48 dem65 ~1 ## 49 .p4. == .p8. ## 50 .p5. == .p9. ## 51 .p6. == .p10. ## 52 .p7. == .p11. pt[pt$op==\"~\",] ## lhs op rhs pxnames ## 12 dem60 ~ ind60 bet_sign[1] ## 13 dem65 ~ ind60 bet_sign[2] ## 14 dem65 ~ dem60 bet_sign[3] hypothesis(mc_out, \"bet_sign[2] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob ## 1 (bet_sign[2]) > 0 0.25 0.17 -0.03 0.54 13.49 0.93 ## Star ## 1 ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities. hypothesis(mc_out, \"bet_sign[1] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob ## 1 (bet_sign[1]) > 0 0.7 0.18 0.43 1.01 Inf 1 ## Star ## 1 * ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities. hypothesis(mc_out, \"bet_sign[1] - bet_sign[2] > 0\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio ## 1 (bet_sign[1]-bet_... > 0 0.45 0.26 0.05 0.89 30.91 ## Post.Prob Star ## 1 0.97 * ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities."},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"region-of-practical-equivalence-rope","dir":"Articles","previous_headings":"","what":"Region of Practical Equivalence (ROPE)","title":"Probability of Direction","text":"Note far tested hypothesis 0, equivalent frequentist null hypothesis tests. can test . Bayesian inference based statistical significance, effects tested “zero”. Indeed, Bayesian framework offers probabilistic view parameters, allowing assessment uncertainty related . Thus, rather concluding effect present simply differs zero, conclude probability outside specific range can considered “practically effect” (.e., negligible magnitude) sufficient. range called region practical equivalence (ROPE). Indeed, statistically, probability posterior distribution different 0 make much sense (probability different single point infinite). Therefore, idea underlining ROPE let user define area around null value enclosing values equivalent null value practical purposes (Kruschke Liddell 2018) examples, change value tested, common recommendations use |0.1| minimally relevant value standardized regressions, case find 0.79 proportion posterior 0.1","code":"hypothesis(mc_out, \"bet_sign[2] > .1\", alpha = 0.05) ## New names: ## • `ly_sign[4]` -> `ly_sign[4]...4` ## • `ly_sign[5]` -> `ly_sign[5]...5` ## • `ly_sign[6]` -> `ly_sign[6]...6` ## • `ly_sign[7]` -> `ly_sign[7]...7` ## • `ly_sign[4]` -> `ly_sign[4]...8` ## • `ly_sign[5]` -> `ly_sign[5]...9` ## • `ly_sign[6]` -> `ly_sign[6]...10` ## • `ly_sign[7]` -> `ly_sign[7]...11` ## Hypothesis Tests for class : ## Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio ## 1 (bet_sign[2])-(.1) > 0 0.15 0.17 -0.13 0.44 4.34 ## Post.Prob Star ## 1 0.81 ## --- ## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses. ## '*': For one-sided hypotheses, the posterior probability exceeds 95%; ## for two-sided hypotheses, the value tested against lies outside the 95%-CI. ## Posterior probabilities of point hypotheses assume equal prior probabilities."},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"vs--95-ci","dir":"Articles","previous_headings":"","what":"89% vs. 95% CI","title":"Probability of Direction","text":"commonly frequentist tradition see use 95% Credible interval. Using 89% another popular choice, used default long time. start? Naturally, came choosing CI level report default, people started using 95%, arbitrary convention used frequentist world. However, authors suggested 95% might appropriate Bayesian posterior distributions, potentially lacking stability enough posterior samples drawn (McElreath 2020). proposition use 90% instead 95%. However, recently, McElreath (2020) suggested use arbitrary thresholds first place, use 89%? Moreover, 89 highest prime number exceed already unstable 95% threshold. anything? Nothing, reminds us total arbitrariness conventions (McElreath 2020). can use argument alpha argument hypothesis function, interpretation values Post.Prob","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/probability_direction.html","id":"caveats","dir":"Articles","previous_headings":"","what":"Caveats","title":"Probability of Direction","text":"Although allows testing hypotheses similar manner frequentist null-hypothesis testing framework, strongly argue using arbitrary cutoffs (e.g., p < .05) determine ‘existence’ effect. ROPE sensitive scale, aware value interest representative respective scale. , standardize parameters useful commonly used scale","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/articles/start.html","id":"installation","dir":"Articles","previous_headings":"","what":"Installation","title":"Getting Started with blavaan","text":"blavaan can installed CRAN usual way: situations, may wish install blavaan GitHub. GitHub version sometimes contains bug fixes yet CRAN, though can also less stable. install GitHub, use following command. command requires system can compile Stan models, guaranteed usually install blavaan CRAN. trouble, may help look RStan Getting Started page.","code":"install.packages(\"blavaan\") remotes::install_github(\"ecmerkle/blavaan\", INSTALL_opts = \"--no-multiarch\")"},{"path":"http://ecmerkle.github.io/blavaan/articles/start.html","id":"commands-and-syntax","dir":"Articles","previous_headings":"","what":"Commands and Syntax","title":"Getting Started with blavaan","text":"blavaan package depends lavaan package model specification computations. means , already know lavaan, already able many things blavaan. particular, many blavaan commands add letter “b” start lavaan command. example, sem() becomes bsem(), lavInspect() becomes blavInspect(). also sometimes possible use lavaan command blavaan object, though results may always expect. details mind, look lavaan tutorial many examples models. can translate many examples blavaan adding “b” start commands. look pages , learn additional blavaan arguments specific Bayesian methods.","code":""},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"convergence","dir":"Articles","previous_headings":"","what":"Convergence","title":"Model Summaries","text":"Following model estimation, immediately wish look “goodness” posterior samples, including convergence stationary distribution autocorrelation. Popular convergence metrics available via blavInspect() function: R-hat values near 1.00 indicate convergence, large effective sample sizes (hundreds ) preferred. details metrics, see, e.g., Posterior Analysis section Stan Reference Manual. model definitely converged (judged Rhat), blavaan issue multiple warnings. Lack convergence sometimes caused bad initial values chain strays extreme region posterior space. cases, can helpful re-estimate model second time. also helpful specify mildly-informative priors loading parameters, chains wander extreme loading values. example, expect variables positively correlated loadings fixed 1 identification, Normal(1,.5) often mildly-informative prior. Otherwise, lack convergence may imply prior distributions severely conflict data, ill-defined model. sometimes helpful try fit model lavaan, observe whether errors occur .","code":"blavInspect(fit, 'rhat') blavInspect(fit, 'neff')"},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"model-fit-comparison","dir":"Articles","previous_headings":"","what":"Model Fit & Comparison","title":"Model Summaries","text":"Next, may wish examine model fit metrics. many metrics available summary() output, available fitMeasures() function: judging absolute fit, blavaan supplies posterior predictive p-value based likelihood ratio statistic. Good-fitting models values near 0.5 metric. examining models’ relative fits, blavaan supplies DIC, WAIC, LOOIC. latter two metrics computed help loo package (Vehtari et al. 2020). Comparison multiple models criteria facilitated via blavCompare(), provides standard errors difference two criteria. notable functions include blavFitIndices() alternative measures absolute fit ppmc() general posterior predictive checks.","code":"summary(fit) fitMeasures(fit)"},{"path":"http://ecmerkle.github.io/blavaan/articles/summaries.html","id":"latent-variables-standardization","dir":"Articles","previous_headings":"","what":"Latent Variables & Standardization","title":"Model Summaries","text":"often-discussed advantage Bayesian models abilities describe uncertainty “random” parameters, including random effects latent variables. access functionality blavaan, users must set save.lvs = TRUE model estimation, done top page. model estimation, uses can access information via blavInspect() blavPredict(). Relevant arguments blavInspect() include lvmeans lvs. former returns posterior means latent variables, similar predictions supplied frequentist models. latter returns posterior samples latent variables, users summarize uncertainties functions latent variables. posterior samples returned list length n.chains, list entry row per posterior sample (number columns total number latent variables model): related, different, information can obtained blavPredict(). function also return posterior samples latent variables, matrix instead list: blavPredict() function also return predictions observed variables conditioned sampled latent variables. type = \"yhat\" argument returns expected values observed variables conditioned latent variable samples; type = \"ypred\" argument returns posterior predictions observed variables including residual noise (essentially yhat + error); type = \"ymis\" argument returns posterior predictions missing variables conditioned observed. expected values predictions returned list format; matrix, see last line code . Finally, fully related latent variables: standardizedPosterior() function return standardized posterior draws. calls lavaan function standardizedSolution() background function’s flexibility.","code":"postmns <- blavInspect(fit, what = \"lvmeans\") postsamps <- blavInspect(fit, what = \"lvs\") postsamps <- blavPredict(fit, type = \"lv\") evpreds <- blavPredict(fit, type = \"yhat\") postpreds <- blavPredict(fit, type = \"ypred\") mispreds <- blavPredict(fit, type = \"ymis\") ## convert to matrix from list: evpreds <- do.call(\"rbind\", evpreds)"},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Edgar Merkle. Author, maintainer. Yves Rosseel. Author. Ben Goodrich. Author. Mauricio Garnier-Villarreal. Contributor. R/blav_compare.RR/ctr_bayes_fit.Rvignettes Terrence D. Jorgensen. Contributor. R/ctr_bayes_fit.RR/ctr_ppmc.RR/blav_predict.R Huub Hoofs. Contributor. R/ctr_bayes_fit.R Rens van de Schoot. Contributor. R/ctr_bayes_fit.R Andrew Johnson. Contributor. Makevars Matthew Emery. Contributor. loo moment_match","code":""},{"path":"http://ecmerkle.github.io/blavaan/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Merkle EC, Fitzsimmons E, Uanhoro J, Goodrich B (2021). “Efficient Bayesian Structural Equation Modeling Stan.” Journal Statistical Software, 100(6), 1–22. doi:10.18637/jss.v100.i06. Merkle EC, Rosseel Y (2018). “blavaan: Bayesian Structural Equation Models via Parameter Expansion.” Journal Statistical Software, 85(4), 1–30. doi:10.18637/jss.v085.i04.","code":"@Article{, title = {Efficient {Bayesian} Structural Equation Modeling in {Stan}}, author = {Edgar C. Merkle and Ellen Fitzsimmons and James Uanhoro and Ben Goodrich}, journal = {Journal of Statistical Software}, year = {2021}, volume = {100}, number = {6}, pages = {1--22}, doi = {10.18637/jss.v100.i06}, } @Article{, title = {{blavaan: Bayesian} Structural Equation Models via Parameter Expansion}, author = {Edgar C. Merkle and Yves Rosseel}, journal = {Journal of Statistical Software}, year = {2018}, volume = {85}, number = {4}, pages = {1--30}, doi = {10.18637/jss.v085.i04}, }"},{"path":"http://ecmerkle.github.io/blavaan/index.html","id":"blavaan","dir":"","previous_headings":"","what":"Bayesian Latent Variable Analysis","title":"Bayesian Latent Variable Analysis","text":"blavaan free, open source R package Bayesian latent variable analysis. relies JAGS Stan estimate models via MCMC. blavaan functions syntax similar lavaan. example, consider Political Democracy example Bollen (1989): development version blavaan (containing updates yet CRAN) can installed via command . Compilation required; may problem users currently rely binary version blavaan CRAN. information, see: Merkle, E. C., Fitzsimmons, E., Uanhoro, J., & Goodrich, B. (2021). Efficient Bayesian structural equation modeling Stan. Journal Statistical Software, 100(6), 1–22. Merkle, E. C., & Rosseel, Y. (2018). blavaan: Bayesian structural equation models via parameter expansion. Journal Statistical Software, 85(4), 1–30. blavaan supported Institute Education Sciences, U.S. Department Education, Grant R305D210044, well NSF grants SES-1061334 1460719.","code":"library(lavaan) # for the PoliticalDemocracy data library(blavaan) model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + y2 + y3 + y4 dem65 =~ y5 + y6 + y7 + y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual covariances y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data = PoliticalDemocracy) summary(fit) remotes::install_github(\"ecmerkle/blavaan\", INSTALL_opts = \"--no-multiarch\")"},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Confirmatory Factor Analysis Models — bcfa","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"Fit Confirmatory Factor Analysis (CFA) model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"","code":"bcfa(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"bcfa function wrapper general blavaan function, using following default lavaan arguments: int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"object inherits class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bcfa.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Confirmatory Factor Analysis Models — bcfa","text":"","code":"data(HolzingerSwineford1939, package = \"lavaan\") # The Holzinger and Swineford (1939) example HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' if (FALSE) { # \\dontrun{ fit <- bcfa(HS.model, data = HolzingerSwineford1939) summary(fit) } # } # A short run for rough results fit <- bcfa(HS.model, data = HolzingerSwineford1939, burnin = 100, sample = 100, n.chains = 2) #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: #> Chain 1: Gradient evaluation took 0.00034 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.4 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: #> Chain 1: WARNING: There aren't enough warmup iterations to fit the #> Chain 1: three stages of adaptation as currently configured. #> Chain 1: Reducing each adaptation stage to 15%/75%/10% of #> Chain 1: the given number of warmup iterations: #> Chain 1: init_buffer = 15 #> Chain 1: adapt_window = 75 #> Chain 1: term_buffer = 10 #> Chain 1: #> Chain 1: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 1: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 1: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 1: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 1: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 1: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 1: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 1: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 1: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 1: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: #> Chain 1: Elapsed Time: 0.432 seconds (Warm-up) #> Chain 1: 0.45 seconds (Sampling) #> Chain 1: 0.882 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: #> Chain 2: Gradient evaluation took 0.000254 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.54 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: #> Chain 2: WARNING: There aren't enough warmup iterations to fit the #> Chain 2: three stages of adaptation as currently configured. #> Chain 2: Reducing each adaptation stage to 15%/75%/10% of #> Chain 2: the given number of warmup iterations: #> Chain 2: init_buffer = 15 #> Chain 2: adapt_window = 75 #> Chain 2: term_buffer = 10 #> Chain 2: #> Chain 2: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 2: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 2: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 2: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 2: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 2: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 2: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 2: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 2: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 2: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: #> Chain 2: Elapsed Time: 0.741 seconds (Warm-up) #> Chain 2: 0.416 seconds (Sampling) #> Chain 2: 1.157 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is NA, indicating chains have not mixed. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#r-hat #> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#bulk-ess #> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#tail-ess #> Computing post-estimation metrics (including lvs if requested)... summary(fit) #> blavaan 0.5.6.1311 ended normally after 100 iterations #> #> Estimator BAYES #> Optimization method MCMC #> Number of model parameters 21 #> #> Number of observations 301 #> #> Statistic MargLogLik PPP #> Value -3806.252 0.000 #> #> Parameter Estimates: #> #> #> Latent Variables: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> visual =~ #> x1 1.000 #> x2 0.572 0.121 0.359 0.805 1.003 normal(0,10) #> x3 0.739 0.131 0.498 1.045 1.014 normal(0,10) #> textual =~ #> x4 1.000 #> x5 1.116 0.060 0.995 1.231 1.000 normal(0,10) #> x6 0.933 0.055 0.831 1.027 0.992 normal(0,10) #> speed =~ #> x7 1.000 #> x8 1.267 0.178 0.905 1.615 1.005 normal(0,10) #> x9 1.219 0.289 0.769 2.041 1.015 normal(0,10) #> #> Covariances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> visual ~~ #> textual 0.386 0.079 0.225 0.556 0.996 lkj_corr(1) #> speed 0.240 0.052 0.158 0.350 1.005 lkj_corr(1) #> textual ~~ #> speed 0.159 0.051 0.065 0.266 0.995 lkj_corr(1) #> #> Variances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .x1 0.569 0.143 0.242 0.820 1.020 gamma(1,.5)[sd] #> .x2 1.149 0.093 0.957 1.327 0.998 gamma(1,.5)[sd] #> .x3 0.855 0.105 0.656 1.078 1.009 gamma(1,.5)[sd] #> .x4 0.380 0.047 0.294 0.475 0.994 gamma(1,.5)[sd] #> .x5 0.450 0.053 0.355 0.566 0.993 gamma(1,.5)[sd] #> .x6 0.361 0.049 0.276 0.469 1.007 gamma(1,.5)[sd] #> .x7 0.839 0.092 0.670 1.022 1.004 gamma(1,.5)[sd] #> .x8 0.505 0.098 0.327 0.726 1.006 gamma(1,.5)[sd] #> .x9 0.549 0.101 0.328 0.736 1.012 gamma(1,.5)[sd] #> visual 0.796 0.164 0.533 1.171 1.009 gamma(1,.5)[sd] #> textual 0.981 0.104 0.789 1.182 1.000 gamma(1,.5)[sd] #> speed 0.342 0.097 0.154 0.525 1.038 gamma(1,.5)[sd] #>"},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Growth Curve Models — bgrowth","title":"Fit Growth Curve Models — bgrowth","text":"Fit Growth Curve model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Growth Curve Models — bgrowth","text":"","code":"bgrowth(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Growth Curve Models — bgrowth","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Growth Curve Models — bgrowth","text":"bgrowth function wrapper general blavaan function, using following default lavaan arguments: meanstructure = TRUE, int.ov.free = FALSE, int.lv.free = TRUE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Growth Curve Models — bgrowth","text":"object class blavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Growth Curve Models — bgrowth","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bgrowth.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Growth Curve Models — bgrowth","text":"","code":"if (FALSE) { # \\dontrun{ ## linear growth model with a time-varying covariate data(Demo.growth, package = \"lavaan\") model.syntax <- ' # intercept and slope with fixed coefficients i =~ 1*t1 + 1*t2 + 1*t3 + 1*t4 s =~ 0*t1 + 1*t2 + 2*t3 + 3*t4 # regressions i ~ x1 + x2 s ~ x1 + x2 # time-varying covariates t1 ~ c1 t2 ~ c2 t3 ~ c3 t4 ~ c4 ' fit <- bgrowth(model.syntax, data = Demo.growth) summary(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":null,"dir":"Reference","previous_headings":"","what":"Bayesian model comparisons — blavCompare","title":"Bayesian model comparisons — blavCompare","text":"Bayesian model comparisons, including WAIC, LOO, Bayes factor approximation.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Bayesian model comparisons — blavCompare","text":"","code":"blavCompare(object1, object2, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Bayesian model comparisons — blavCompare","text":"object1 object class blavaan. object2 second object class blavaan. ... arguments loo().","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Bayesian model comparisons — blavCompare","text":"function computes Bayesian model comparison metrics, including Bayes factor approximation, WAIC, LOOIC. log-Bayes factor two models based Laplace approximation model's marginal log-likelihood. WAIC LOOIC metrics come loo package. ELPD difference SE specifically come loo::loo_compare().","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Bayesian model comparisons — blavCompare","text":"list containing separate results log-Bayes factor, WAIC, LOOIC, differences WAIC LOOIC.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Bayesian model comparisons — blavCompare","text":"Raftery, . E. (1993). Bayesian model selection structural equation models. K. . Bollen & J. S. Long (Eds.), Testing structural equation models (pp. 163-180). Beverly Hills, CA: Sage. Vehtari ., Gelman ., Gabry J. (2017). Practical Bayesian model evaluation using leave-one-cross-validation WAIC. Statistics Computing, 27, 1413-1432.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavCompare.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Bayesian model comparisons — blavCompare","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") hsm1 <- ' visual =~ x1 + x2 + x3 + x4 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit1 <- bcfa(hsm1, data = HolzingerSwineford1939) hsm2 <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 + x7 speed =~ x7 + x8 + x9 ' fit2 <- bcfa(hsm2, data = HolzingerSwineford1939) blavCompare(fit1, fit2) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":null,"dir":"Reference","previous_headings":"","what":"SEM Fit Indices for Bayesian SEM — blavFitIndices","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"function provides posterior distribution \\(\\chi^2\\)-based fit indices assess global fit latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"","code":"blavFitIndices(object, thin = 1L, pD = c(\"loo\",\"waic\",\"dic\"), rescale = c(\"devM\",\"ppmc\",\"mcmc\"), fit.measures = \"all\", baseline.model = NULL) ## S4 method for signature 'blavFitIndices' # S4 method for class 'blavFitIndices' summary(object, ...) # S3 method for class 'bfi' summary(object, central.tendency = c(\"mean\",\"median\",\"mode\"), hpd = TRUE, prob = .90)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"object object class blavaan. thin Optional integer indicating much thin chain. Default 1L, indicating thin chains. pD character indicating information criterion returned fitMeasures(object) use estimated number parameters. default leave-one-information criterion (LOO-IC), highly recommended Vehtari et al. (2017). rescale character indicating method used calculate fit indices. rescale = \"devM\" (default), Bayesian analog \\(\\chi^2\\) statistic (deviance evaluated posterior mean model parameters) approximated rescaling deviance iteration subtracting estimated number parameters. rescale = \"PPMC\", deviance iteration rescaled subtracting deviance data simulated posterior predictive distribution (posterior predictive model checking; see Hoofs et al., 2017). rescale = \"MCMC\", fit measures simply calculated using fitMeasures iteration Markov chain(s), based model-implied moments iteration (advised model includes informative priors, case model's estimated pD deviate number parameters used calculate df fitMeasures). fit.measures \"\", fit measures available returned. single fit measures specified name, computed returned. rescale = \"devM\" \"PPMC\", currently available indices \"BRMSEA\", \"BGammaHat\", \"adjBGammaHat\", \"BMc\", \"BCFI\", \"BTLI\", \"BNFI\". rescale = \"MCMC\", user may request indices returned fitMeasures objects class lavaan. baseline.model NULL, object class blavaan, representing user-specified baseline model. baseline.model provided, incremental fit indices (BCFI, BTLI, BNFI) can requested fit.measures. Ignored rescale = \"MCMC\". ... Additional arguments summary method: central.tendency Takes values \"mean\", \"median\", \"mode\", indicating statistics used characterize location posterior distribution. default, 3 statistics returned. posterior mean labeled EAP expected posteriori estimate, mode labeled MAP modal posteriori estimate. hpd logical indicating whether calculate highest posterior density (HPD) credible interval fit index (defaults TRUE). prob \"confidence\" level credible interval(s) (defaults 0.9).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"S4 object class blavFitIndices consisting 2 slots: @details list containing choices made user (defaults; e.g., values pD rescale set), well posterior distribution \\(\\chi^2\\) (deviance) statistic (rescaled, rescale = \"devM\" \"PPMC\"). @indices list containing posterior distribution requested fit.measure. summary() method returns data.frame containing one row requested fit.measure, columns containing specified measure(s) central.tendency, posterior SD, (requested) HPD credible-interval limits.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"Mauricio Garnier-Villareal (Vrije Universiteit Amsterdam; mgv@pm.) Terrence D. Jorgensen (University Amsterdam; TJorgensen314@gmail.com)","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"rescale = \"PPMC\" based : Hoofs, H., van de Schoot, R., Jansen, N. W., & Kant, . (2017). Evaluating model fit Bayesian confirmatory factor analysis large samples: Simulation study introducing BRMSEA. Educational Psychological Measurement. doi:10.1177/0013164417709314 rescale = \"devM\" based : Garnier-Villarreal, M., & Jorgensen, T. D. (2020). Adapting Fit Indices Bayesian Structural Equation Modeling: Comparison Maximum Likelihood. Psychological Methods, 25(1), 46–70. https://doi.org/dx.doi.org/10.1037/met0000224 (See also https://osf.io/afkcw/) references: Vehtari, ., Gelman, ., & Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-cross-validation WAIC. Statistics Computing, 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavFitIndices.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"SEM Fit Indices for Bayesian SEM — blavFitIndices","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' ## fit target model fit1 <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 1000) ## fit null model to calculate CFI, TLI, and NFI null.model <- c(paste0(\"x\", 1:9, \" ~~ x\", 1:9), paste0(\"x\", 1:9, \" ~ 1\")) fit0 <- bcfa(null.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 1000) ## calculate posterior distributions of fit indices ## The default method mimics fit indices derived from ML estimation ML <- blavFitIndices(fit1, baseline.model = fit0) ML summary(ML) ## other options: ## - use Hoofs et al.'s (2017) PPMC-based method ## - use the estimated number of parameters from WAIC instead of LOO-IC PPMC <- blavFitIndices(fit1, baseline.model = fit0, pD = \"waic\", rescale = \"PPMC\") ## issues a warning about using rescale=\"PPMC\" with N < 1000 (see Hoofs et al.) ## - specify only the desired measures of central tendency ## - specify a different \"confidence\" level for the credible intervals summary(PPMC, central.tendency = c(\"mean\",\"mode\"), prob = .95) ## Access the posterior distributions for further investigation head(distML <- data.frame(ML@indices)) ## For example, diagnostic plots using the bayesplot package: ## distinguish chains nChains <- blavInspect(fit1, \"n.chains\") distML$Chain <- rep(1:nChains, each = nrow(distML) / nChains) library(bayesplot) mcmc_pairs(distML, pars = c(\"BRMSEA\",\"BMc\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"hist\") ## Indices are highly correlated across iterations in both chains ## Compare to PPMC method distPPMC <- data.frame(PPMC@indices) distPPMC$Chain <- rep(1:nChains, each = nrow(distPPMC) / nChains) mcmc_pairs(distPPMC, pars = c(\"BRMSEA\",\"BMc\",\"BGammaHat\",\"BCFI\",\"BTLI\"), diag_fun = \"dens\") ## nonlinear relation between BRMSEA, related to the floor effect of BRMSEA ## that Hoofs et al. found for larger (12-indicator) models } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":null,"dir":"Reference","previous_headings":"","what":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"blavInspect() blavTech() functions can used inspect/extract information stored inside (can computed ) fitted blavaan object. similar lavaan's lavInspect() function.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"","code":"blavInspect(blavobject, what, ...) blavTech(blavobject, what, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"blavobject object class blavaan. Character. needs inspected/extracted? See Details Bayes-specific options, see lavaan's lavInspect() additional options. Note: argument case-sensitive (everything converted lower case.) ... lavaan arguments supplied lavInspect(); see lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"list Bayesian-specific values argument; additional values can found lavInspect() documentation. \"start\": list starting values chain, unless inits=\"jags\" used model estimation. Aliases: \"starting.values\", \"inits\". \"rhat\": parameter's potential scale reduction factor convergence assessment. Can also use \"psrf\" instead \"rhat\" \"ac.10\": parameter's estimated lag-10 autocorrelation. \"neff\": parameters effective sample size, taking account autocorrelation. \"mcmc\": object class mcmc containing individual parameter draws MCMC run. Aliases: \"draws\", \"samples\". \"mcobj\": underlying run.jags stan object resulted MCMC run. \"n.chains\": number chains sampled. \"cp\": approach used estimating covariance parameters (\"srs\" \"fa\"); relevant using JAGS. \"dp\": Default prior distributions used type model parameter. \"postmode\": Estimated posterior mode free parameter. \"postmean\": Estimated posterior mean free parameter. \"postmedian\": Estimated posterior median free parameter. \"lvs\": object class mcmc containing latent variable (factor score) draws. two-level models, use level = 1 level = 2 specify factor scores want. \"lvmeans\": matrix mean factor scores (rows observations, columns variables). Use additional level argument way. \"hpd\": HPD interval free parameter. case, prob argument can used specify number (0,1) reflecting desired percentage interval.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavInspect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Inspect or Extract Information from a Fitted blavaan Object — blavInspect","text":"","code":"if (FALSE) { # \\dontrun{ # The Holzinger and Swineford (1939) example data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939, bcontrol = list(method = \"rjparallel\")) # extract information blavInspect(fit, \"psrf\") blavInspect(fit, \"hpd\", prob = .9) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"purpose blavPredict() function compute various types model predictions, conditioned observed data. differs somewhat lavPredict() lavaan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"","code":"blavPredict(object, newdata = NULL, type = \"lv\", level = 1L)"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"object object class blavaan. newdata optional data.frame, containing variables data.frame used fitting model object. type character string. \"lv\", estimated values latent variables model computed. \"ov\" \"yhat\", predicted means observed variables model computed. \"ypred\" \"ydist\", predicted values observed variables (including residual noise) computed. \"ymis\" \"ovmis\", model predicted values (\"imputations\") missing data computed. See details information. level type = \"lv\", used specify whether one desires level 1 latent variables level 2 latent variables.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"predict() function calls blavPredict() function default options. , provide information type option. options work target=\"stan\", \"number samples\" defined number posterior samples across chains. type=\"lv\": posterior distribution latent variables conditioned observed variables. Returns list \"number samples\" entries, entry matrix rows observations columns latent variables. type=\"yhat\": posterior expected value observed variables conditioned sampled latent variables. Returns list \"number samples\" entries, entry matrix rows observations columns observed variables. type=\"ypred\": posterior predictive distribution observed variables conditioned sampled latent variables (including residual variability). Returns list \"number samples\" entries, entry data frame rows observations columns observed variables. type=\"ymis\": posterior predictive distribution missing values conditioned observed variables. Returns matrix \"number samples\" rows \"number missing variables\" columns.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavPredict.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict the values of latent variables, observed variables, and missing variables. — blavPredict","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") ## fit model HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939, save.lvs = TRUE) lapply(blavPredict(fit)[1:2], head) # first 6 rows of first 10 posterior samples head(blavPredict(fit, type = \"yhat\")[[1]]) # top of first posterior sample ## multigroup models return a list of factor scores (one per group) mgfit <- bcfa(HS.model, data = HolzingerSwineford1939, group = \"school\", group.equal = c(\"loadings\",\"intercepts\"), save.lvs = TRUE) lapply(blavPredict(fit)[1:2], head) head(blavPredict(fit, type = \"ypred\")[[1]]) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blav_internal.html","id":null,"dir":"Reference","previous_headings":"","what":"blavaan internal functions — blav_internal","title":"blavaan internal functions — blav_internal","text":"Internal functions related Bayesian model estimation. called user.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":null,"dir":"Reference","previous_headings":"","what":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"blavaan class contains lavaan class, representing (fitted) Bayesian latent variable model. contains description model specified user, summary data, internal matrix representation, model fitted, fitting results.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"objects-from-the-class","dir":"Reference","previous_headings":"","what":"Objects from the Class","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"Objects can created via bcfa, bsem, bgrowth blavaan functions.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"slots","dir":"Reference","previous_headings":"","what":"Slots","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"version: lavaan package version used create objects call: function call returned match.call(). timing: elapsed time (user+system) various parts program list, including total time. Options: Named list options provided user, filled-automatically. ParTable: Named list describing model parameters. Can coerced data.frame. documentation, called `parameter table'. pta: Named list containing parameter table attributes. Data: Object internal class \"Data\": information data. SampleStats: Object internal class \"SampleStats\": sample statistics Model: Object internal class \"Model\": internal (matrix) representation model Cache: List using objects try compute , reuse many times. Fit: Object internal class \"Fit\": results fitting model. longer used. boot: List. Unused Bayesian models. optim: List. Information optimization. loglik: List. Information loglikelihood model (maximum likelihood used). implied: List. Model implied statistics. vcov: List. Information variance matrix (vcov) model parameters. test: List. Different test statistics. h1: List. Information unrestricted h1 model (available). baseline: List. Information baseline model (often independence model) (available). external: List. Includes Stan JAGS objects used MCMC.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"methods","dir":"Reference","previous_headings":"","what":"Methods","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"coef signature(object = \"blavaan\", type = \"free\"): Returns estimates parameters model named numeric vector. type=\"free\", free parameters returned. type=\"user\", parameters listed parameter table returned, including constrained fixed parameters. vcov signature(object = \"lavaan\"): returns covariance matrix estimated parameters. show signature(object = \"blavaan\"): Print short summary model fit summary signature(object = \"blavaan\", header = TRUE, fit.measures = FALSE, estimates = TRUE, ci = TRUE, standardized = FALSE, rsquare = FALSE, std.nox = FALSE, psrf = TRUE, neff = FALSE, postmedian = FALSE, postmode = FALSE, priors = TRUE, bf = FALSE, nd = 3L): Print nice summary model estimates. header = TRUE, header section (including fit measures) printed. fit.measures = TRUE, additional fit measures added header section. estimates = TRUE, print parameter estimates section. ci = TRUE, add confidence intervals parameter estimates section. standardized = TRUE, standardized solution also printed. Note SEs tests still based unstandardized estimates. Use standardizedSolution obtain SEs test statistics standardized estimates. rsquare=TRUE, R-Square values dependent variables model printed. std.nox = TRUE, std.column contains std.nox column parameterEstimates() output. psrf = TRUE, potential scale reduction factors (Rhats) printed. neff = TRUE, effective sample sizes printed. postmedian postmode TRUE, posterior medians modes printed instead posterior means. priors = TRUE, parameter prior distributions printed. bf = TRUE, Savage-Dickey approximations Bayes factor printed certain parameters. Nothing returned (use lavInspect another extractor function extract information fitted model).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan-class.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Class For Representing A (Fitted) Bayesian Latent Variable Model — blavaan-class","text":"","code":"if (FALSE) { # \\dontrun{ HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data=HolzingerSwineford1939) summary(fit, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE) coef(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit a Bayesian Latent Variable Model — blavaan","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"Fit Bayesian latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"","code":"blavaan(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model data written files (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"object inherits class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/blavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit a Bayesian Latent Variable Model — blavaan","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") # The Holzinger and Swineford (1939) example HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- blavaan(HS.model, data = HolzingerSwineford1939, auto.var = TRUE, auto.fix.first = TRUE, auto.cov.lv.x = TRUE) summary(fit) coef(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit Structural Equation Models — bsem","title":"Fit Structural Equation Models — bsem","text":"Fit Structural Equation Model (SEM).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit Structural Equation Models — bsem","text":"","code":"bsem(..., cp = \"srs\", dp = NULL, n.chains = 3, burnin, sample, adapt, mcmcfile = FALSE, mcmcextra = list(), inits = \"simple\", convergence = \"manual\", target = \"stan\", save.lvs = FALSE, wiggle = NULL, wiggle.sd = 0.1, prisamp = FALSE, jags.ic = FALSE, seed = NULL, bcontrol = list())"},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit Structural Equation Models — bsem","text":"... Default lavaan arguments. See lavaan. cp Handling prior distributions covariance parameters: possible values \"srs\" (default) \"fa\". Option \"fa\" available target=\"jags\". dp Default prior distributions different types parameters, typically result call dpriors(). See dpriors() help file information. n.chains Number desired MCMC chains. burnin Number burnin/warmup iterations (including adaptive iterations, target=\"jags\"). Defaults 4000 target=\"jags\" 500 Stan targets. sample total number samples take burnin. Defaults 10000 target=\"jags\" 1000 Stan targets. adapt target=\"jags\", number adaptive iterations use start sampling. Defaults 1000. mcmcfile TRUE, JAGS/Stan model written file (lavExport directory). Can also supply character string, serves name directory files written. mcmcextra list potential names syntax (unavailable target=\"stan\"), monitor, data, llnsamp. syntax object text string containing extra code insert JAGS/Stan model syntax. data object list extra data send JAGS/Stan model. moment_match_k_threshold specified within data looic model calculated using moment matching. monitor object character vector containing extra JAGS/Stan parameters monitor. llnsamp object relevant models ordinal variables, specifies number samples drawn approximate model log-likelihood (larger numbers imply higher accuracy longer time). log-likelihood specifically used compute information criteria. inits character string, options currently \"simple\" (default), \"Mplus\", \"prior\", \"jags\". first two cases, parameter values set though estimated via ML (see lavaan). starting parameter value chain perturbed original values addition random uniform noise. \"prior\" used, starting parameter values obtained based prior distributions (also trying ensure starting values crash model estimation). \"jags\", starting values specified JAGS choose values (probably crash Stan targets). can also supply list starting values chain, list format can obtained , e.g., blavInspect(fit, \"inits\"). Finally, can specify starting values similar way lavaan, using lavaan start argument (see lavaan documentation options ). case, also set inits=\"simple\", aware starting values used chain. convergence Useful target=\"jags\". \"auto\", parameters sampled convergence achieved (via autorun.jags()). case, arguments burnin sample passed autorun.jags() startburnin startsample, respectively. Otherwise, parameters sampled specified user (run.jags defaults). target Desired MCMC sampling, \"stan\" (pre-compiled marginal approach) default. Also available \"vb\", calls rstan function vb(). options include \"jags\", \"stancond\", \"stanclassic\", sample latent variables provide greater functionality (syntax written \"fly\"). slower less efficient. save.lvs sampled latent variables (factor scores) saved? Logical; defaults FALSE wiggle Labels equality-constrained parameters \"approximately\" equal. Can also \"intercepts\", \"loadings\", \"regressions\", \"means\". wiggle.sd prior sd (normal distribution) used approximate equality constraints. Can one value, (target=\"stan\") numeric vector values length wiggle. prisamp samples drawn prior, instead posterior (target=\"stan\" )? Logical; defaults FALSE jags.ic DIC computed JAGS way, addition BUGS way? Logical; defaults FALSE seed vector length n.chains (target \"jags\") integer (target \"stan\") containing random seeds MCMC run. NULL, seeds chosen randomly. bcontrol list containing additional parameters passed run.jags (autorun.jags) stan. See manpage functions overview additional parameters can set.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Fit Structural Equation Models — bsem","text":"bsem function wrapper general blavaan function, using following default lavaan arguments: int.ov.free = TRUE, int.lv.free = FALSE, auto.fix.first = TRUE (unless std.lv = TRUE), auto.fix.single = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE, auto.th = TRUE, auto.delta = TRUE, auto.cov.y = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit Structural Equation Models — bsem","text":"object class lavaan, several methods available, including summary method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Fit Structural Equation Models — bsem","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/. Yves Rosseel (2012). lavaan: R Package Structural Equation Modeling. Journal Statistical Software, 48(2), 1-36. URL http://www.jstatsoft.org/v48/i02/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/bsem.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit Structural Equation Models — bsem","text":"","code":"# The industrialization and Political Democracy Example # Bollen (1989), page 332 data(PoliticalDemocracy, package = \"lavaan\") model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + a*y2 + b*y3 + c*y4 dem65 =~ y5 + a*y6 + b*y7 + c*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' if (FALSE) { # \\dontrun{ # mildly informative priors for mv intercepts and loadings fit <- bsem(model, data = PoliticalDemocracy, dp = dpriors(nu = \"normal(5,10)\", lambda = \"normal(1,.5)\")) summary(fit) } # } # A short run for rough results fit <- bsem(model, data = PoliticalDemocracy, burnin = 100, sample = 100, dp = dpriors(nu = \"normal(5,10)\", lambda = \"normal(1,.5)\"), n.chains = 2) #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). #> Chain 1: #> Chain 1: Gradient evaluation took 0.000313 seconds #> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 3.13 seconds. #> Chain 1: Adjust your expectations accordingly! #> Chain 1: #> Chain 1: #> Chain 1: WARNING: There aren't enough warmup iterations to fit the #> Chain 1: three stages of adaptation as currently configured. #> Chain 1: Reducing each adaptation stage to 15%/75%/10% of #> Chain 1: the given number of warmup iterations: #> Chain 1: init_buffer = 15 #> Chain 1: adapt_window = 75 #> Chain 1: term_buffer = 10 #> Chain 1: #> Chain 1: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 1: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 1: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 1: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 1: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 1: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 1: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 1: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 1: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 1: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 1: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 1: Iteration: 200 / 200 [100%] (Sampling) #> Chain 1: #> Chain 1: Elapsed Time: 0.825 seconds (Warm-up) #> Chain 1: 0.631 seconds (Sampling) #> Chain 1: 1.456 seconds (Total) #> Chain 1: #> #> SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). #> Chain 2: #> Chain 2: Gradient evaluation took 0.00028 seconds #> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.8 seconds. #> Chain 2: Adjust your expectations accordingly! #> Chain 2: #> Chain 2: #> Chain 2: WARNING: There aren't enough warmup iterations to fit the #> Chain 2: three stages of adaptation as currently configured. #> Chain 2: Reducing each adaptation stage to 15%/75%/10% of #> Chain 2: the given number of warmup iterations: #> Chain 2: init_buffer = 15 #> Chain 2: adapt_window = 75 #> Chain 2: term_buffer = 10 #> Chain 2: #> Chain 2: Iteration: 1 / 200 [ 0%] (Warmup) #> Chain 2: Iteration: 20 / 200 [ 10%] (Warmup) #> Chain 2: Iteration: 40 / 200 [ 20%] (Warmup) #> Chain 2: Iteration: 60 / 200 [ 30%] (Warmup) #> Chain 2: Iteration: 80 / 200 [ 40%] (Warmup) #> Chain 2: Iteration: 100 / 200 [ 50%] (Warmup) #> Chain 2: Iteration: 101 / 200 [ 50%] (Sampling) #> Chain 2: Iteration: 120 / 200 [ 60%] (Sampling) #> Chain 2: Iteration: 140 / 200 [ 70%] (Sampling) #> Chain 2: Iteration: 160 / 200 [ 80%] (Sampling) #> Chain 2: Iteration: 180 / 200 [ 90%] (Sampling) #> Chain 2: Iteration: 200 / 200 [100%] (Sampling) #> Chain 2: #> Chain 2: Elapsed Time: 0.709 seconds (Warm-up) #> Chain 2: 0.666 seconds (Sampling) #> Chain 2: 1.375 seconds (Total) #> Chain 2: #> Warning: The largest R-hat is 1.05, indicating chains have not mixed. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#r-hat #> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#bulk-ess #> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable. #> Running the chains for more iterations may help. See #> https://mc-stan.org/misc/warnings.html#tail-ess #> Computing post-estimation metrics (including lvs if requested)... #> Warning: blavaan WARNING: As specified, the theta covariance matrix is neither diagonal nor unrestricted, so the actual prior might differ from the stated prior. See #> https://arxiv.org/abs/2301.08667 summary(fit) #> blavaan 0.5.6.1311 ended normally after 100 iterations #> #> Estimator BAYES #> Optimization method MCMC #> Number of model parameters 31 #> Number of equality constraints 3 #> #> Number of observations 75 #> #> Statistic MargLogLik PPP #> Value NA 0.520 #> #> Parameter Estimates: #> #> #> Latent Variables: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> ind60 =~ #> x1 1.000 #> x2 2.102 0.134 1.859 2.357 0.996 normal(1,.5) #> x3 1.724 0.157 1.447 2.054 0.999 normal(1,.5) #> dem60 =~ #> y1 1.000 #> y2 (a) 1.172 0.132 0.943 1.437 1.010 normal(1,.5) #> y3 (b) 1.172 0.117 0.946 1.406 1.007 normal(1,.5) #> y4 (c) 1.250 0.119 1.011 1.512 1.037 normal(1,.5) #> dem65 =~ #> y5 1.000 #> y6 (a) 1.172 0.132 0.943 1.437 1.010 #> y7 (b) 1.172 0.117 0.946 1.406 1.007 #> y8 (c) 1.250 0.119 1.011 1.512 1.037 #> #> Regressions: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> dem60 ~ #> ind60 1.406 0.416 0.653 2.260 0.994 normal(0,10) #> dem65 ~ #> ind60 0.545 0.269 0.045 1.061 0.997 normal(0,10) #> dem60 0.874 0.081 0.739 1.042 0.993 normal(0,10) #> #> Covariances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .y1 ~~ #> .y5 0.597 0.368 -0.029 1.424 1.001 beta(1,1) #> .y2 ~~ #> .y4 1.450 0.711 0.244 3.072 1.027 beta(1,1) #> .y6 2.272 0.789 0.974 3.822 0.996 beta(1,1) #> .y3 ~~ #> .y7 0.856 0.698 -0.349 2.230 0.992 beta(1,1) #> .y4 ~~ #> .y8 0.426 0.488 -0.446 1.472 1.004 beta(1,1) #> .y6 ~~ #> .y8 1.374 0.723 0.074 3.018 0.992 beta(1,1) #> #> Variances: #> Estimate Post.SD pi.lower pi.upper Rhat Prior #> .x1 0.084 0.022 0.048 0.125 1.019 gamma(1,.5)[sd] #> .x2 0.144 0.072 0.023 0.310 1.010 gamma(1,.5)[sd] #> .x3 0.498 0.093 0.334 0.706 0.993 gamma(1,.5)[sd] #> .y1 1.992 0.515 1.240 3.288 1.011 gamma(1,.5)[sd] #> .y2 7.941 1.451 5.490 10.723 0.996 gamma(1,.5)[sd] #> .y3 5.190 1.098 3.446 7.739 1.000 gamma(1,.5)[sd] #> .y4 3.469 0.867 1.984 5.343 1.018 gamma(1,.5)[sd] #> .y5 2.419 0.573 1.578 3.662 0.993 gamma(1,.5)[sd] #> .y6 5.175 1.009 3.463 7.460 1.002 gamma(1,.5)[sd] #> .y7 3.750 0.767 2.154 5.378 1.007 gamma(1,.5)[sd] #> .y8 3.577 0.863 2.079 5.364 0.999 gamma(1,.5)[sd] #> ind60 0.490 0.100 0.326 0.702 0.996 gamma(1,.5)[sd] #> .dem60 3.971 0.919 2.452 5.931 1.001 gamma(1,.5)[sd] #> .dem65 0.255 0.228 0.008 0.827 1.013 gamma(1,.5)[sd] #>"},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":null,"dir":"Reference","previous_headings":"","what":"Specify Default Prior Distributions — dpriors","title":"Specify Default Prior Distributions — dpriors","text":"Specify \"default\" prior distributions classes model parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Specify Default Prior Distributions — dpriors","text":"","code":"dpriors(..., target = \"stan\")"},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Specify Default Prior Distributions — dpriors","text":"... Parameter names paired desired priors (see example ). target priors jags, stan (default), stanclassic?","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Specify Default Prior Distributions — dpriors","text":"prior distributions always use JAGS/Stan syntax parameterizations. example, normal distribution JAGS parameterized via precision, whereas normal distribution Stan parameterized via standard deviation. User-specified prior distributions specific parameters (using prior() operator within model syntax) always override prior distributions set using dpriors(). parameter names : nu: Observed variable intercept parameters. alpha: Latent variable intercept parameters. lambda: Loading parameters. beta: Regression parameters. itheta: Observed variable precision parameters. ipsi: Latent variable precision parameters. rho: Correlation parameters (associated covariance parameters). ibpsi: Inverse covariance matrix blocks latent variables (used target=\"jags\"). tau: Threshold parameters (ordinal data ). delta: Delta parameters (ordinal data ).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Specify Default Prior Distributions — dpriors","text":"character vector containing prior distribution type parameter.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Specify Default Prior Distributions — dpriors","text":"Edgar C. Merkle, Ellen Fitzsimmons, James Uanhoro, & Ben Goodrich (2021). Efficient Bayesian Structural Equation Modeling Stan. Journal Statistical Software, 100(6), 1-22. URL http://www.jstatsoft.org/v100/i06/. Edgar C. Merkle & Yves Rosseel (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal Statistical Software, 85(4), 1-30. URL http://www.jstatsoft.org/v85/i04/.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/dpriors.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Specify Default Prior Distributions — dpriors","text":"","code":"dpriors(nu = \"normal(0,10)\", lambda = \"normal(0,1)\", rho = \"beta(3,3)\") #> nu alpha lambda beta #> \"normal(0,10)\" \"normal(0,10)\" \"normal(0,1)\" \"normal(0,10)\" #> theta psi rho ibpsi #> \"gamma(1,.5)[sd]\" \"gamma(1,.5)[sd]\" \"beta(3,3)\" \"wishart(3,iden)\" #> tau #> \"normal(0,1.5)\""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"blavaan Diagnostic Plots — plot.blavaan","title":"blavaan Diagnostic Plots — plot.blavaan","text":"Convenience functions create plots blavaan objects, via bayesplot package.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"blavaan Diagnostic Plots — plot.blavaan","text":"","code":"# S3 method for class 'blavaan' plot(x, pars = NULL, plot.type = \"trace\", showplot = TRUE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"blavaan Diagnostic Plots — plot.blavaan","text":"x object class blavaan. pars Parameter numbers plot, numbers correspond order parameters reported coef() (also shown 'free' column parTable). numbers provided, free parameters plotted. plot.type type plot desired. name MCMC function, without mcmc_ prefix. showplot plot sent graphic device? Defaults TRUE. ... arguments sent bayesplot function.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"blavaan Diagnostic Plots — plot.blavaan","text":"previous versions blavaan, plotting functionality handled separately JAGS Stan (using plot functionality packages runjags rstan, respectively). uniformity, plotting functionality now handled bayesplot. users desire additional functionality immediately available, can extract matrix MCMC draws via .matrix(blavInspect(x, 'mcmc')).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"blavaan Diagnostic Plots — plot.blavaan","text":"invisible ggplot object , desired, can customized.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/plot.blavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"blavaan Diagnostic Plots — plot.blavaan","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939) # trace plots of free loadings plot(fit, pars = 1:6) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":null,"dir":"Reference","previous_headings":"","what":"Posterior Predictive Model Checks — ppmc","title":"Posterior Predictive Model Checks — ppmc","text":"function allows users conduct posterior predictive model check assess global local fit latent variable model using discrepancy function can applied lavaan model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Posterior Predictive Model Checks — ppmc","text":"","code":"ppmc(object, thin = 1, fit.measures = c(\"srmr\",\"chisq\"), discFUN = NULL, conditional = FALSE) # S4 method for class 'blavPPMC' summary(object, ...) # S3 method for class 'ppmc' summary(object, discFUN, dist = c(\"obs\",\"sim\"), central.tendency = c(\"mean\",\"median\",\"mode\"), hpd = TRUE, prob = .95, to.data.frame = FALSE, diag = TRUE, sort.by = NULL, decreasing = FALSE) # S3 method for class 'blavPPMC' plot(x, ..., discFUN, element, central.tendency = \"\", hpd = TRUE, prob = .95, nd = 3) # S3 method for class 'blavPPMC' hist(x, ..., discFUN, element, hpd = TRUE, prob = .95, printLegend = TRUE, legendArgs = list(x = \"topleft\"), densityArgs = list(), nd = 3) # S3 method for class 'blavPPMC' pairs(x, discFUN, horInd = 1:DIM, verInd = 1:DIM, printLegend = FALSE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Posterior Predictive Model Checks — ppmc","text":"object,x object class blavaan. thin Optional integer indicating much thin chain. Default 1L, indicating thin chains object. fit.measures character vector indicating names global discrepancy measures returned fitMeasures. Ignored unless discFUN NULL, users may include fitMeasures list discrepancy functions discFUN. ordinal models, \"logl\" \"chisq\" computations done via lavaan. discFUN function, list functions, can called object class lavaan. function must return object whose mode numeric, may vector, matrix, multidimensional array. summary plot methods, discFUN character indicating discrepancy function summarize. conditional logical indicating whether , artificial data generation, condition estimated latent variables. Requires model estimated save.lvs = TRUE. element numeric character indicating index ( dimension discFUN output, multiple) plot. horInd,verInd Similar element, numeric character vector indicating indices matrix plot scatterplot matrix. horInd==verInd, histograms plotted upper triangle. dist character indicating whether summarize distribution discFUN either observed simulated data. central.tendency character indicating statistics used characterize location posterior (predictive) distribution. default, 3 statistics returned summary method, none plot method. posterior mean labeled EAP expected posteriori estimate, mode labeled MAP modal posteriori estimate. hpd logical indicating whether calculate highest posterior density (HPD) credible interval discFUN. prob \"confidence\" level credible interval(s). nd number digits print scatterplot. .data.frame logical indicating whether summary symmetric 2-dimensional matrix returned discFUN unique elements stored rows data.frame can sorted convenience identifying large discrepancies. discFUN returns asymmetric 2-dimensional matrix, list matrices returned summary can also converted data.frame. diag Passed lower.tri .data.frame=TRUE. sort.character. summary returns data.frame, can sorted column name using order. Note discFUN returns asymmetric 2-dimensional matrix, data.frame returned list sorted independently, rows unlikely consistent across summary statistics. decreasing Passed order !.null(sort.). ... Additional graphical parameters passed plot.default. printLegend logical. TRUE (default), legend printed histogram legendArgs list arguments passed legend function. default argument list placing legend top-left figure. densityArgs list arguments passed density function, used obtain densities hist method.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Posterior Predictive Model Checks — ppmc","text":"S4 object class blavPPMC consisting 5 list slots: @discFUN user-supplied discFUN, call fitMeasures returns fit.measures. @dims dimensions object returned discFUN. @PPP posterior predictive p value discFUN element. @obsDist posterior distribution realize values discFUN applied observed data. @simDist posterior predictive distribution values discFUN applied data simulated posterior samples. summary() method returns numeric vector discFUN returns scalar, data.frame one discrepancy function per row discFUN returns numeric vector, list one summary statistic per element discFUN returns matrix multidimensional array. plot pairs methods invisibly return NULL, printing plot (scatterplot matrix) current device. hist method invisibly returns list arguments can passed function list element named. Users can edit arguments list customize histograms.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Posterior Predictive Model Checks — ppmc","text":"Terrence D. Jorgensen (University Amsterdam; TJorgensen314@gmail.com)","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Posterior Predictive Model Checks — ppmc","text":"Levy, R. (2011). Bayesian data–model fit assessment structural equation modeling. Structural Equation Modeling, 18(4), 663–685. doi:10.1080/10705511.2011.607723","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/ppmc.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Posterior Predictive Model Checks — ppmc","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' ## fit single-group model fit <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 500) ## fit multigroup model fitg <- bcfa(HS.model, data = HolzingerSwineford1939, n.chains = 2, burnin = 1000, sample = 500, group = \"school\") ## Use fit.measures as a shortcut for global fitMeasures only ## - Note that indices calculated from the \"df\" are only appropriate under ## noninformative priors, such that pD approximates the number of estimated ## parameters counted under ML estimation; incremental fit indices ## introduce further complications) AFIs <- ppmc(fit, thin = 10, fit.measures = c(\"srmr\",\"chisq\",\"rmsea\",\"cfi\")) summary(AFIs) # summarize the whole vector in a data.frame hist(AFIs, element = \"rmsea\") # only plot one discrepancy function at a time plot(AFIs, element = \"srmr\") ## define a list of custom discrepancy functions ## - (global) fit measures ## - (local) standardized residuals discFUN <- list(global = function(fit) { fitMeasures(fit, fit.measures = c(\"cfi\",\"rmsea\",\"srmr\",\"chisq\")) }, std.cov.resid = function(fit) lavResiduals(fit, zstat = FALSE, summary = FALSE)$cov, std.mean.resid = function(fit) lavResiduals(fit, zstat = FALSE, summary = FALSE)$mean) out1g <- ppmc(fit, discFUN = discFUN) ## summarize first discrepancy by default (fit indices) summary(out1g) ## some model-implied correlations look systematically over/underestimated summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\") hist(out1g, discFUN = \"std.cov.resid\", element = c(1, 7)) plot(out1g, discFUN = \"std.cov.resid\", element = c(\"x1\",\"x7\")) ## For ease of investigation, optionally export summary as a data.frame, ## sorted by size of average residual summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\", to.data.frame = TRUE, sort.by = \"EAP\") ## or sorted by size of PPP summary(out1g, discFUN = \"std.cov.resid\", central.tendency = \"EAP\", to.data.frame = TRUE, sort.by = \"PPP_sim_LessThan_obs\") ## define a list of custom discrepancy functions for multiple groups ## (return each group's numeric output using a different function) disc2g <- list(global = function(fit) { fitMeasures(fit, fit.measures = c(\"cfi\",\"rmsea\",\"mfi\",\"srmr\",\"chisq\")) }, cor.resid1 = function(fit) lavResiduals(fit, zstat = FALSE, type = \"cor.bollen\", summary = FALSE)[[1]]$cov, cor.resid2 = function(fit) lavResiduals(fit, zstat = FALSE, type = \"cor.bollen\", summary = FALSE)[[2]]$cov) out2g <- ppmc(fitg, discFUN = disc2g, thin = 2) ## some residuals look like a bigger problem in one group than another pairs(out2g, discFUN = \"cor.resid1\", horInd = 1:3, verInd = 7:9) # group 1 pairs(out2g, discFUN = \"cor.resid2\", horInd = 1:3, verInd = 7:9) # group 2 ## print all to file: must be a LARGE picture. First group 1 ... png(\"cor.resid1.png\", width = 1600, height = 1200) pairs(out2g, discFUN = \"cor.resid1\") dev.off() ## ... then group 2 png(\"cor.resid2.png\", width = 1600, height = 1200) pairs(out2g, discFUN = \"cor.resid2\") dev.off() } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample data from the posterior (or prior) distribution. — sampleData","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"purpose sampleData() function simulate new data model already estimated. can faciliate posterior predictive checks, well prior predictive checks (setting prisamp = TRUE model estimation).","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"","code":"sampleData(object, nrep = NULL, conditional = FALSE, type = \"response\", simplify = FALSE, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"object object class blavaan. nrep many datasets generate? supplied, defaults total number posterior samples. conditional Logical indicating whether sample distribution marginal latent variables (FALSE; default) distribution conditions latent variables (TRUE). TRUE, must set save.lvs = TRUE model estimation. type type data desired (relevant ordinal data). type = \"response\" option generates ordinal data. type = \"link\" option generates continuous variables underlying ordinal data (cut thresholds yield ordinal data). simplify single-group models, list structure simplified? makes dataset single list entry, instead list within list (reflects group 1 dataset 1). Defaults FALSE. ... arguments, now parallel. Parallelization via future_lapply() available setting parallel = TRUE.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"convenience function generate data posterior prior predictive checking. underlying code also used generate data posterior predictive p-value computation.","code":""},{"path":[]},{"path":"http://ecmerkle.github.io/blavaan/reference/sampleData.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Sample data from the posterior (or prior) distribution. — sampleData","text":"","code":"if (FALSE) { # \\dontrun{ data(HolzingerSwineford1939, package = \"lavaan\") ## fit model HS.model <- ' visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' fit <- bcfa(HS.model, data = HolzingerSwineford1939) ## 1 dataset generated from the posterior out <- sampleData(fit, nrep = 1) ## nested lists: 1 list entry per nrep. ## then, within a rep, 1 list entry per group ## so our dataset is here: dim(out[[1]][[1]]) ## 1 posterior dataset per posterior sample: out <- sampleData(fit) ## obtain the data on x1 across reps and summarize: x1dat <- sapply(out, function(x) x[[1]][,1]) summary( as.numeric(x1dat) ) } # }"},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":null,"dir":"Reference","previous_headings":"","what":"Standardized Posterior — standardizedPosterior","title":"Standardized Posterior — standardizedPosterior","text":"Standardized posterior distribution latent variable model.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Standardized Posterior — standardizedPosterior","text":"","code":"standardizedPosterior(object, ...)"},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Standardized Posterior — standardizedPosterior","text":"object object class blavaan. ... Additional arguments passed lavaan's standardizedSolution()","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Standardized Posterior — standardizedPosterior","text":"allowed standardizedSolution() arguments type, cov.std, remove.eq, remove.ineq, remove.def. arguments immediately suited posterior distributions.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Standardized Posterior — standardizedPosterior","text":"matrix containing standardized posterior draws, rows draws columns parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/reference/standardizedPosterior.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Standardized Posterior — standardizedPosterior","text":"","code":"if (FALSE) { # \\dontrun{ data(PoliticalDemocracy, package = \"lavaan\") model <- ' # latent variable definitions ind60 =~ x1 + x2 + x3 dem60 =~ y1 + a*y2 + b*y3 + c*y4 dem65 =~ y5 + a*y6 + b*y7 + c*y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 ' fit <- bsem(model, data = PoliticalDemocracy, dp = dpriors(nu = \"normal(5, 10)\")) standardizedPosterior(fit) } # }"},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-6","dir":"Changelog","previous_headings":"","what":"Version 0.5-6","title":"Version 0.5-6","text":"CRAN release: 2024-09-04","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-6","text":"release contains minor improvements bug fixes.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-6","text":"Models <~ operator fail target = “jags” (reported Thomas Riecke).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-5","dir":"Changelog","previous_headings":"","what":"Version 0.5-5","title":"Version 0.5-5","text":"CRAN release: 2024-06-09","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-5","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-5","text":"Minor changes ensure compatibility lavaan 0.6-18. Bugs 0.5-4 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-5","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-5","text":"systems, blavaan installation fails “parser failed badly” message rstan (reported Larry Hunsicker). blavPredict(, type=“ov”/“ypred”) can fail sample size newdata differs sample size original data (reported Niels Skovgaard-Olsen).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-4","dir":"Changelog","previous_headings":"","what":"Version 0.5-4","title":"Version 0.5-4","text":"CRAN release: 2024-04-15","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-4","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-4","text":"New function sampleData() generating data blavaan object. Functionality newdata argument blavPredict(), can generate lv () predictions new data model already estimated (continuous data , target = “stan” ). Refinements two-level models (handle missingness via listwise deletion; lvs one level; improved messaging) Bugs 0.5-3 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-4","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-4","text":"sampleData() ignores thinning determining number posterior samples (reported Luna Fazio). two-level models fail one observed variable appears level (reported Carl Falk). target = “stan”, models fail loadings equality constrained std.lv = TRUE (reported Amos Pagin).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-3","dir":"Changelog","previous_headings":"","what":"Version 0.5-3","title":"Version 0.5-3","text":"CRAN release: 2024-01-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-3","text":"Functionality find unrestricted blocks model’s psi matrix (lv covariance matrix). lkj priors assigned unrestricted blocks, improving positive definite issue described “Opaque priors” paper. Improved functionality obtaining posterior modes via, e.g., summary(., postmode = TRUE) blavCompare() messaging improved clarify ELPD differences, function returns output. Bug fix two-level models within-observed variables, messaging added unstable ppp. extracting posterior draws via blavInspect(., “mcmc”), column names now match lavaan parameter names. old behavior involving Stan parameter names, use argument add.labels = FALSE Bugs 0.5-2 fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-3","text":"models exogenous covariates, fixed.x=TRUE, missing data fail converge yield implausible parameter values (reported DeAnne Hunter).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-2","dir":"Changelog","previous_headings":"","what":"Version 0.5-2","title":"Version 0.5-2","text":"CRAN release: 2023-09-25","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-2","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-2","text":"maintenance release, primarily adding new array declaration syntax Stan models (syntax became available new version rstan).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-2","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-2","text":"blavCompare() work models meanstructure = FALSE (reported Pedro Ribeiro). target=“jags”, posterior modes obtained via postmode = TRUE (reported Giada Venaruzzo). models continuous ordinal variables fail cases ordinal variables missing (reported Sonja Winter). certain equality constraints involving named parameters fail target=“stan” (reported Niels Skovgaard-Olsen)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-05-1","dir":"Changelog","previous_headings":"","what":"Version 0.5-1","title":"Version 0.5-1","text":"CRAN release: 2023-08-29","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-5-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.5-1","text":"Two-level models now supported (complete, continuous data) via cluster argument.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-5-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.5-1","text":"two-level model specification, levels labeled “within” “”. restrictive lavaan specification. target=“jags”, latent variable extraction via blavInspect(, “lvs”) fails (reported Joseph Saraceno).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-8","dir":"Changelog","previous_headings":"","what":"Version 0.4-8","title":"Version 0.4-8","text":"CRAN release: 2023-06-12","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-8","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-8","text":"maintenance release bug fixes changes compiler settings","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-8","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-8","text":"certain models residual correlations /correlated factors, initial values target=‘stan’ lead non-positive definite matrices (reported Yuanyuan Hu). models latent variable regressed observed variable (lv ~ ov), latent variable samples account mean observed variable (centered around 0 constant).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-7","dir":"Changelog","previous_headings":"","what":"Version 0.4-7","title":"Version 0.4-7","text":"CRAN release: 2023-03-01","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-7","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-7","text":"primarily update address C++14 vs C++17 compilation issue identified CRAN bugs 0.4-6 also fixed","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-7","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-7","text":"Sampling priors (prisamp = TRUE) fails models meanstructure = FALSE; posterior still estimated (reported Armel Brizuela Rodríguez). target = “jags”, models single-indicator latent variable, latent variable regressed variables, return incorrect parameter estimates (reported Brad Cosentino).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-6","dir":"Changelog","previous_headings":"","what":"Version 0.4-6","title":"Version 0.4-6","text":"CRAN release: 2023-02-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-6","text":"target = “stan”, meanstructure=FALSE allowed, along use sample.cov sample.nobs instead raw data Users warned priors covariance matrices neither diagonal unrestricted models observed variable intercepts appear latent intercept vector (alpha), default priors come observed intercept vector nu (user expect) inits = “simple” now default (instead “prior”), address convergence problems stan targets, “:=” can now used identity function target = “stan”, fix missing data issue 0.4-3 (complete data one group ) Column names added blavPredict(, type=“lv”)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-6","text":"blavFitIndices() save.lvs = TRUE work correctly models without meanstructure. Workaround use meanstructure = TRUE model estimation command (reported Charles Hofacker). lavaan summary() method sometimes called instead blavaan summary() method (reported multiple users, Shu Fai Cheung providing helpful examples).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-3","dir":"Changelog","previous_headings":"","what":"Version 0.4-3","title":"Version 0.4-3","text":"CRAN release: 2022-05-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-3","text":"target = “stan”, models run faster earlier versions (use sufficient statistics) Posterior summaries faster ordinal models (using mnormt::sadmvn() default) Variational Bayes option added: target=“vb”, uses rstan::vb() cmdstanr functionality added: target=“cmdstanr”, uses model target=“stan” Fix blavInspect(., “lvs”/“lvmeans”) multiple groups + missing data Fixes ppmc() ordinal models; blavFitIndices() turned ordinal models (research needed) loo() moment matching available passing mcmcextra = list(data = list(moment_match_k_threshold))","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-3","text":"target = “stan” fails complete data one group missing data another group (reported Ronja Runge). blavPredict(, type=“ymis”) still available models ordinal variables","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-04-1","dir":"Changelog","previous_headings":"","what":"Version 0.4-1","title":"Version 0.4-1","text":"CRAN release: 2022-01-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-4-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.4-1","text":"Functionality ordinal observed variables now available. models missing data, posterior summaries sped (log-likelihood computations now done Stan).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-4-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.4-1","text":"blavPredict(, type=“ymis”) working models ordinal variables blavInspect(, ‘lvs’) (, ‘lvmeans’) can fail models combination multiple groups, missing values, excluded cases blavFitIndices() ppmc() working models ordinal variables, may indicate excessively bad fit blavFitIndices(, rescale=“mcmc”) fails","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-18","dir":"Changelog","previous_headings":"","what":"Version 0.3-18","title":"Version 0.3-18","text":"CRAN release: 2021-11-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-18","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-18","text":"version adds reference new JSS paper, including DOI, corrects inconsistent version dependency. changes compared 0.3-17.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-17","dir":"Changelog","previous_headings":"","what":"Version 0.3-17","title":"Version 0.3-17","text":"CRAN release: 2021-07-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-17","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-17","text":"maintenance release correct major bugs previous version.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-16","dir":"Changelog","previous_headings":"","what":"Version 0.3-16","title":"Version 0.3-16","text":"CRAN release: 2021-07-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-16","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-16","text":"blavPredict() function added predicting latent variables missing data. posterior summaries sped . (fitMeasures available test=“none”) bug fixes previous version.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-16","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-16","text":"certain models missing data, ppp-values incorrect (sometimes equaling 1.0). target=“stan”, multiple group models fail cases missing observed variables (reported DeAnne Hunter).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-15","dir":"Changelog","previous_headings":"","what":"Version 0.3-15","title":"Version 0.3-15","text":"CRAN release: 2021-02-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-15","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-15","text":"Added S3 summary() method ppmc Posterior intervals summary() bug fixed","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-15","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-15","text":"summary() method ppmc() fitIndices() always work correctly. Jacobian incorrect target=“stan”, (non-default) priors placed precisions variances instead standard deviations. impact estimates posterior variability (reported Roy Levy).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-14","dir":"Changelog","previous_headings":"","what":"Version 0.3-14","title":"Version 0.3-14","text":"CRAN release: 2021-01-20 (version 0.3-13 violated CRAN policy)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-14","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-14","text":"maintenance release response change package Matrix.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-14","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-14","text":"Posterior intervals NA summary(). Workarounds use parameterEstimates() (intervals assuming posterior normality) compute using posterior samples (`blavInspect(fit, “mcmc”)’)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-12","dir":"Changelog","previous_headings":"","what":"Version 0.3-12","title":"Version 0.3-12","text":"CRAN release: 2020-11-12 (version 0.3-11 failed Windows CRAN checks)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-12","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-12","text":"vector values wiggle.sd allowed different priors approximate equality constraints logical argument “prisamp” added, sampling model’s prior target=“stan”, lkj prior used unrestricted lv correlation matrices default priors conditional approaches (targets jags stanclassic) revert placed precisions (opposed SDs), improvement sampling efficiency","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-10","dir":"Changelog","previous_headings":"","what":"Version 0.3-10","title":"Version 0.3-10","text":"CRAN release: 2020-08-03","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-10","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-10","text":"save.lvs=TRUE works missing data target=“stan” new arguments “wiggle” “wiggle.sd” approximate equality constraints target=“stan”","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-10","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-10","text":"plot labels target=“stan” sometimes incorrect (displaying parameter different panel label). complex equality constraints sometimes ignored (target=“jags” “stanclassic”) equality constraints std.lv=TRUE sometimes fail (target=“stan”) placing priors variances precisions yields incorrect results (target=“stan”; reported Roy Levy)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-9","dir":"Changelog","previous_headings":"","what":"Version 0.3-9","title":"Version 0.3-9","text":"CRAN release: 2020-03-09","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-9","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-9","text":"improvements save.lvs=TRUE target=“stan”. target=“stancond” added, experimental, noncentered Stan approach. bug fixes prior settings std.lv target=“stan”, defined parameters.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-9","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-9","text":"target=“stan”, problems sampling lvs multiple groups missing data. Errors blavCompare() blavFitIndices() due version updates packages. target=“stan”, models std.lv=TRUE converge.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-8","dir":"Changelog","previous_headings":"","what":"Version 0.3-8","title":"Version 0.3-8","text":"CRAN release: 2019-11-19","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-8","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-8","text":"post-estimation, posterior predictive computations sped considerably. 0.3-7 bugs fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-8","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-8","text":"target=“stan” std.lv=TRUE, estimation fails certain (growth) models (reported Mauricio Garnier-Villareal). defined variables fail target=“jags” “stanclassic” (reported Mariëlle Zondervan-Zwijnenburg). User-specified priors sometimes placed wrong parameter, related 0.3-7 bug (reported Mauricio Garnier-Villareal). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-7","dir":"Changelog","previous_headings":"","what":"Version 0.3-7","title":"Version 0.3-7","text":"CRAN release: 2019-09-27","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-7","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-7","text":"target=“stan”, gamma priors can now placed user’s choice variances, standard deviations, precisions. plot() now works uniformly across Stan JAGS, relying bayesplot. post-MCMC parallelization now handled via future.apply package (requires extra “plan” command user, works windows). 0.3-6 bugs fixed.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-7","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-7","text":"blavInspect(, ‘lvmeans’) returns rows wrong order target=“stan” (reported Mehdi Momen). User-specified priors sometimes placed wrong parameter, target=“stan” (reported Enrico Toffalini). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-6","dir":"Changelog","previous_headings":"","what":"Version 0.3-6","title":"Version 0.3-6","text":"CRAN release: 2019-08-08","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-6","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-6","text":"fixes stan plot bug 0.3-5.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-6","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-6","text":"user-specified priors correlation parameters silently ignored target=“stan” (reported James Uanhoro). save.lvs=TRUE work target=“stan” (reported Mauricio Garnier-Villareal). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-5","dir":"Changelog","previous_headings":"","what":"Version 0.3-5","title":"Version 0.3-5","text":"CRAN release: 2019-08-03","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-5","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-5","text":"target=“stan” now default, using pre-compiled Stan model instead “fly” code. ppmc() function added Terrence Jorgensen, facilitating posterior predictive checks. default priors changed gamma precisions gamma standard deviations.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-5","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-5","text":"Stan plot method silently fails (reported Matt Yalch). dpriors() issue 0.3-3 remains.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-4","dir":"Changelog","previous_headings":"","what":"Version 0.3-4","title":"Version 0.3-4","text":"CRAN release: 2019-01-11","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-4","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-4","text":"Add function standardizedPosterior() standardizing posterior draws. Turn posterior modes target=“jags”, due conflict current versions runjags modeest. Rearrange posterior predictive internals.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-4","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-4","text":"dpriors() issue 0.3-3 remains. target=“jags”, lv means obtained blavInspect() (via argument ‘lvmeans’) incorrect. (reported Mauricio Garnier-Villareal) Use plot() target=“stan” causes problems future blavInspect() calls.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-3","dir":"Changelog","previous_headings":"","what":"Version 0.3-3","title":"Version 0.3-3","text":"CRAN release: 2018-10-31","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-3","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-3","text":"convergence=“auto”, max time previously 5 min (undocumented). now Inf. Axis labels (parameter names) now sensible convergence plots. Relative effective sample size now used compute loo/waic SEs, SEs now returned via fitMeasures(). Added unit testing via package testthat. Fixed bugs 0.3-2 (exception identity assignments using ‘:=’)","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-3","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-3","text":"Use ‘dpriors()’: observed variable precisions assigned latent precision (ipsi) prior; latent means assigned observed mean (nu) prior.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-2","dir":"Changelog","previous_headings":"","what":"Version 0.3-2","title":"Version 0.3-2","text":"CRAN release: 2018-06-10","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-2","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-2","text":"Conditional (latent variables) information criteria available save.lvs = TRUE. Experimental function ‘blavFitIndices()’ added Bayesian versions SEM metrics, contributed Terrence Jorgensen. blavaan “intelligently” chooses target, either runjags rstan () installed. Fixed bugs 0.3-1, especially related missing data Stan.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-2","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-2","text":"Errors Stan models std.lv=TRUE, observed variable regressed latent variable (reported Bo Zhang). Error identity assignments using ‘:=’ (reported Marco Tullio Liuzza). Explicitly adding argument ‘.fit=TRUE’ fails (reported Esteban Montenegro).","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"version-03-1","dir":"Changelog","previous_headings":"","what":"Version 0.3-1","title":"Version 0.3-1","text":"CRAN release: 2018-01-12","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"new-features-0-3-1","dir":"Changelog","previous_headings":"","what":"New features","title":"Version 0.3-1","text":"Stan export now supported; use target=“stan”. Improved handling complex models, including growth/change models. Sampling factor scores (lvs) available via ‘save.lvs=TRUE’. Samples/means can obtained supplying arguments ‘lvs’ ‘lvmeans’ ‘blavInspect()’. Fixed bugs 0.2-4.","code":""},{"path":"http://ecmerkle.github.io/blavaan/news/index.html","id":"bugsglitches-discovered-after-the-release-0-3-1","dir":"Changelog","previous_headings":"","what":"Bugs/glitches discovered after the release:","title":"Version 0.3-1","text":"Errors Stan models missing data, exogenous (“x”) variables. Errors multi-group Stan models std.lv=TRUE.","code":""}]