From 5958e40fb82328f77cd209fe396a9efe1efe604e Mon Sep 17 00:00:00 2001 From: rempsyc <13123390+rempsyc@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:33:23 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20rempsyc/?= =?UTF-8?q?lavaanExtra@9042ff89011a1580e546cdcdc0870cda9fd4ca3c=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404.html | 2 +- CONTRIBUTING.html | 2 +- LICENSE-text.html | 2 +- LICENSE.html | 2 +- TODOS.html | 2 +- articles/example.html | 2 +- articles/fullworkflow.html | 852 ++++++++++++++--------------- articles/index.html | 2 +- articles/indirect.html | 2 +- articles/regression.html | 168 +++--- articles/write_lavaan.html | 2 +- authors.html | 2 +- index.html | 2 +- news/index.html | 12 +- pkgdown.yml | 2 +- reference/cfa_fit_plot.html | 2 +- reference/index.html | 2 +- reference/lavaanExtra-package.html | 2 +- reference/lavaan_cov.html | 2 +- reference/lavaan_defined.html | 2 +- reference/lavaan_extract.html | 2 +- reference/lavaan_reg.html | 2 +- reference/lavaan_var.html | 2 +- reference/nice_fit.html | 2 +- reference/nice_lavaanPlot.html | 2 +- reference/nice_modindices.html | 2 +- reference/nice_tidySEM.html | 2 +- reference/write_lavaan.html | 2 +- search.json | 2 +- 29 files changed, 546 insertions(+), 538 deletions(-) diff --git a/404.html b/404.html index aa9ec15..1763bee 100644 --- a/404.html +++ b/404.html @@ -37,7 +37,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/CONTRIBUTING.html b/CONTRIBUTING.html index 8c5a661..cd1e08f 100644 --- a/CONTRIBUTING.html +++ b/CONTRIBUTING.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/LICENSE-text.html b/LICENSE-text.html index fa41162..7b215eb 100644 --- a/LICENSE-text.html +++ b/LICENSE-text.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/LICENSE.html b/LICENSE.html index 88e801a..30db59a 100644 --- a/LICENSE.html +++ b/LICENSE.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/TODOS.html b/TODOS.html index fc33d1c..3a39d5c 100644 --- a/TODOS.html +++ b/TODOS.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/articles/example.html b/articles/example.html index e867f1d..79ae8a4 100644 --- a/articles/example.html +++ b/articles/example.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/articles/fullworkflow.html b/articles/fullworkflow.html index 86d3d52..e80dd13 100644 --- a/articles/fullworkflow.html +++ b/articles/fullworkflow.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 @@ -287,49 +287,49 @@ CFA example# We can get it prettier with the `rempsyc::nice_table` integration nice_fit(fit.cfa, nice_table = TRUE) - - + + -Model -χ2 -df -χ2∕df -p -CFI -TLI -RMSEA [90% CI] -SRMR -AIC -BIC +Model +χ2 +df +χ2∕df +p +CFI +TLI +RMSEA [90% CI] +SRMR +AIC +BIC -Model 1 -85.31 -24 -3.55 -< .001 -.93 -.90 -.09 [.07, .11] -.06 -7,517.49 -7,595.34 +Model 1 +85.31 +24 +3.55 +< .001 +.93 +.90 +.09 [.07, .11] +.06 +7,517.49 +7,595.34 -Common guidelinesa -— -— -< 2 or 3 -> .05 -≥ .95 -≥ .95 -< .05 [.00, .08] -≤ .08 -Smaller -Smaller +Common guidelinesa +— +— +< 2 or 3 +> .05 +≥ .95 +≥ .95 +< .05 [.00, .08] +≤ .08 +Smaller +Smaller -aBased on Schreiber (2017), Table 3. +aBased on Schreiber (2017), Table 3. @@ -459,64 +459,64 @@ CFA examplefit_table <- nice_fit(lst(fit.cfa, fit.cfa2), nice_table = TRUE) fit_table - - + + -Model -χ2 -df -χ2∕df -p -CFI -TLI -RMSEA [90% CI] -SRMR -AIC -BIC +Model +χ2 +df +χ2∕df +p +CFI +TLI +RMSEA [90% CI] +SRMR +AIC +BIC -fit.cfa -85.31 -24 -3.55 -< .001 -.93 -.90 -.09 [.07, .11] -.06 -7,517.49 -7,595.34 +fit.cfa +85.31 +24 +3.55 +< .001 +.93 +.90 +.09 [.07, .11] +.06 +7,517.49 +7,595.34 -fit.cfa2 -13.11 -6 -2.19 -.041 -.98 -.96 -.06 [.01, .11] -.03 -5,106.23 -5,161.84 +fit.cfa2 +13.11 +6 +2.19 +.041 +.98 +.96 +.06 [.01, .11] +.03 +5,106.23 +5,161.84 -Common guidelinesa -— -— -< 2 or 3 -> .05 -≥ .95 -≥ .95 -< .05 [.00, .08] -≤ .08 -Smaller -Smaller +Common guidelinesa +— +— +< 2 or 3 +> .05 +≥ .95 +≥ .95 +< .05 [.00, .08] +≤ .08 +Smaller +Smaller -aBased on Schreiber (2017), Table 3. +aBased on Schreiber (2017), Table 3. @@ -892,107 +892,107 @@ Saturated model# And make it pretty with the `rempsyc::nice_table` integration lavaan_reg(fit.saturated, nice_table = TRUE, highlight = TRUE) - - + + -Outcome -Predictor -SE -Z -p -b -95% CI (b) -b* -95% CI (b*) +Outcome +Predictor +SE +Z +p +b +95% CI (b) +b* +95% CI (b*) -speed -visual -0.05 -3.91 -< .001*** -0.20 -[0.10, 0.29] -0.21 -[0.11, 0.31] +speed +visual +0.05 +3.91 +< .001*** +0.20 +[0.10, 0.29] +0.21 +[0.11, 0.31] -textual -visual -0.06 -4.53 -< .001*** -0.29 -[0.16, 0.41] -0.24 -[0.14, 0.34] +textual +visual +0.06 +4.53 +< .001*** +0.29 +[0.16, 0.41] +0.24 +[0.14, 0.34] -visual -ageyr -0.05 --2.47 -.014* --0.13 -[-0.24, -0.03] --0.16 -[-0.29, -0.03] +visual +ageyr +0.05 +-2.47 +.014* +-0.13 +[-0.24, -0.03] +-0.16 +[-0.29, -0.03] -visual -grade -0.11 -4.31 -< .001*** -0.49 -[0.27, 0.72] -0.28 -[0.16, 0.40] +visual +grade +0.11 +4.31 +< .001*** +0.49 +[0.27, 0.72] +0.28 +[0.16, 0.40] -speed -ageyr -0.05 -0.57 -.568 -0.03 -[-0.07, 0.12] -0.04 -[-0.09, 0.16] +speed +ageyr +0.05 +0.57 +.568 +0.03 +[-0.07, 0.12] +0.04 +[-0.09, 0.16] -speed -grade -0.10 -4.90 -< .001*** -0.50 -[0.30, 0.70] -0.31 -[0.19, 0.43] +speed +grade +0.10 +4.90 +< .001*** +0.50 +[0.30, 0.70] +0.31 +[0.19, 0.43] -textual -ageyr -0.06 --6.72 -< .001*** --0.41 -[-0.52, -0.29] --0.40 -[-0.51, -0.29] +textual +ageyr +0.06 +-6.72 +< .001*** +-0.41 +[-0.52, -0.29] +-0.40 +[-0.51, -0.29] -textual -grade -0.13 -5.87 -< .001*** -0.76 -[0.51, 1.01] -0.36 -[0.24, 0.47] +textual +grade +0.13 +5.87 +< .001*** +0.76 +[0.51, 1.01] +0.36 +[0.24, 0.47] @@ -1106,96 +1106,96 @@ Path analysis model# We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.path, nice_table = TRUE, highlight = TRUE) - - + + -Outcome -Predictor -SE -Z -p -b -95% CI (b) -b* -95% CI (b*) +Outcome +Predictor +SE +Z +p +b +95% CI (b) +b* +95% CI (b*) -speed -visual -0.05 -3.86 -< .001*** -0.19 -[0.09, 0.29] -0.21 -[0.10, 0.31] +speed +visual +0.05 +3.86 +< .001*** +0.19 +[0.09, 0.29] +0.21 +[0.10, 0.31] -textual -visual -0.06 -4.52 -< .001*** -0.29 -[0.16, 0.41] -0.24 -[0.14, 0.33] +textual +visual +0.06 +4.52 +< .001*** +0.29 +[0.16, 0.41] +0.24 +[0.14, 0.33] -visual -ageyr -0.05 --2.47 -.014* --0.13 -[-0.24, -0.03] --0.16 -[-0.29, -0.03] +visual +ageyr +0.05 +-2.47 +.014* +-0.13 +[-0.24, -0.03] +-0.16 +[-0.29, -0.03] -visual -grade -0.11 -4.31 -< .001*** -0.49 -[0.27, 0.72] -0.28 -[0.16, 0.40] +visual +grade +0.11 +4.31 +< .001*** +0.49 +[0.27, 0.72] +0.28 +[0.16, 0.40] -speed -grade -0.09 -6.11 -< .001*** -0.53 -[0.36, 0.70] -0.33 -[0.23, 0.43] +speed +grade +0.09 +6.11 +< .001*** +0.53 +[0.36, 0.70] +0.33 +[0.23, 0.43] -textual -ageyr -0.06 --6.85 -< .001*** --0.41 -[-0.53, -0.29] --0.40 -[-0.51, -0.29] +textual +ageyr +0.06 +-6.85 +< .001*** +-0.41 +[-0.53, -0.29] +-0.40 +[-0.51, -0.29] -textual -grade -0.13 -5.93 -< .001*** -0.76 -[0.51, 1.02] -0.36 -[0.24, 0.47] +textual +grade +0.13 +5.93 +< .001*** +0.76 +[0.51, 1.02] +0.36 +[0.24, 0.47] @@ -1215,41 +1215,41 @@ Path analysis model# We can get it prettier with the `rempsyc::nice_table` integration lavaan_cor(fit.path, nice_table = TRUE) - - + + -Variable 1 -Variable 2 -SE -Z -p -σ -95% CI (σ) -r -95% CI (r) +Variable 1 +Variable 2 +SE +Z +p +σ +95% CI (σ) +r +95% CI (r) -speed -textual -0.04 -2.25 -.024* -0.09 -[0.01, 0.17] -.13 -[0.02, 0.24] +speed +textual +0.04 +2.25 +.024* +0.09 +[0.01, 0.17] +.13 +[0.02, 0.24] -ageyr -grade -0.03 -7.89 -< .001*** -0.27 -[0.20, 0.33] -.51 -[0.43, 0.59] +ageyr +grade +0.03 +7.89 +< .001*** +0.27 +[0.20, 0.33] +.51 +[0.43, 0.59] @@ -1258,77 +1258,77 @@ Path analysis model# Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path), nice_table = TRUE) - - + + -Model -χ2 -df -χ2∕df -p -CFI -TLI -RMSEA [90% CI] -SRMR -AIC -BIC +Model +χ2 +df +χ2∕df +p +CFI +TLI +RMSEA [90% CI] +SRMR +AIC +BIC -fit.cfa -85.31 -24 -3.55 -< .001 -.93 -.90 -.09 [.07, .11] -.06 -7,517.49 -7,595.34 +fit.cfa +85.31 +24 +3.55 +< .001 +.93 +.90 +.09 [.07, .11] +.06 +7,517.49 +7,595.34 -fit.saturated -0.00 -0 -Inf - -1.0 -1.0 -.00 [.00, .00] -.00 -3,483.46 -3,539.02 +fit.saturated +0.00 +0 +Inf + +1.0 +1.0 +.00 [.00, .00] +.00 +3,483.46 +3,539.02 -fit.path -0.33 -1 -0.33 -.568 -1.0 -1.3 -.00 [.00, .13] --.00 -3,481.79 -3,533.64 +fit.path +0.33 +1 +0.33 +.568 +1.0 +1.3 +.00 [.00, .13] +-.00 +3,481.79 +3,533.64 -Common guidelinesa -— -— -< 2 or 3 -> .05 -≥ .95 -≥ .95 -< .05 [.00, .08] -≤ .08 -Smaller -Smaller +Common guidelinesa +— +— +< 2 or 3 +> .05 +≥ .95 +≥ .95 +< .05 [.00, .08] +≤ .08 +Smaller +Smaller -aBased on Schreiber (2017), Table 3. +aBased on Schreiber (2017), Table 3. @@ -1348,41 +1348,41 @@ Path analysis model# We can get it prettier with the `rempsyc::nice_table` integration lavaan_defined(fit.path, lhs_name = "Indirect Effect", nice_table = TRUE) - - + + -Indirect Effect -Paths -SE -Z -p -b -95% CI (b) -b* -95% CI (b*) +Indirect Effect +Paths +SE +Z +p +b +95% CI (b) +b* +95% CI (b*) -age → visual → speed -ageyr_visual*visual_speed -0.01 --2.08 -.037* --0.03 -[-0.05, -0.00] --0.03 -[-0.06, -0.00] +age → visual → speed +ageyr_visual*visual_speed +0.01 +-2.08 +.037* +-0.03 +[-0.05, -0.00] +-0.03 +[-0.06, -0.00] -grade → visual → textual -grade_visual*visual_textual -0.05 -3.12 -.002** -0.14 -[0.05, 0.23] -0.07 -[0.03, 0.11] +grade → visual → textual +grade_visual*visual_textual +0.05 +3.12 +.002** +0.14 +[0.05, 0.23] +0.07 +[0.03, 0.11] @@ -1473,90 +1473,90 @@ Latent model# Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path, fit.latent), nice_table = TRUE) - - + + -Model -χ2 -df -χ2∕df -p -CFI -TLI -RMSEA [90% CI] -SRMR -AIC -BIC +Model +χ2 +df +χ2∕df +p +CFI +TLI +RMSEA [90% CI] +SRMR +AIC +BIC -fit.cfa -85.31 -24 -3.55 -< .001 -.93 -.90 -.09 [.07, .11] -.06 -7,517.49 -7,595.34 +fit.cfa +85.31 +24 +3.55 +< .001 +.93 +.90 +.09 [.07, .11] +.06 +7,517.49 +7,595.34 -fit.saturated -0.00 -0 -Inf - -1.0 -1.0 -.00 [.00, .00] -.00 -3,483.46 -3,539.02 +fit.saturated +0.00 +0 +Inf + +1.0 +1.0 +.00 [.00, .00] +.00 +3,483.46 +3,539.02 -fit.path -0.33 -1 -0.33 -.568 -1.0 -1.3 -.00 [.00, .13] --.00 -3,481.79 -3,533.64 +fit.path +0.33 +1 +0.33 +.568 +1.0 +1.3 +.00 [.00, .13] +-.00 +3,481.79 +3,533.64 -fit.latent -118.92 -37 -3.21 -< .001 -.92 -.89 -.09 [.07, .10] -.05 -8,638.79 -8,746.20 +fit.latent +118.92 +37 +3.21 +< .001 +.92 +.89 +.09 [.07, .10] +.05 +8,638.79 +8,746.20 -Common guidelinesa -— -— -< 2 or 3 -> .05 -≥ .95 -≥ .95 -< .05 [.00, .08] -≤ .08 -Smaller -Smaller +Common guidelinesa +— +— +< 2 or 3 +> .05 +≥ .95 +≥ .95 +< .05 [.00, .08] +≤ .08 +Smaller +Smaller -aBased on Schreiber (2017), Table 3. +aBased on Schreiber (2017), Table 3. diff --git a/articles/index.html b/articles/index.html index 9ac5a2f..e3cd803 100644 --- a/articles/index.html +++ b/articles/index.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/articles/indirect.html b/articles/indirect.html index 2f489f9..be38e0d 100644 --- a/articles/indirect.html +++ b/articles/indirect.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/articles/regression.html b/articles/regression.html index c59515e..e0ad840 100644 --- a/articles/regression.html +++ b/articles/regression.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 @@ -177,107 +177,107 @@ Regression example# We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.reg, nice_table = TRUE, highlight = TRUE) - - + + -Outcome -Predictor -SE -Z -p -b -95% CI (b) -b* -95% CI (b*) +Outcome +Predictor +SE +Z +p +b +95% CI (b) +b* +95% CI (b*) -mpg -cyl -0.70 --1.17 -.244 --0.81 -[-2.18, 0.55] --0.24 -[-0.65, 0.16] +mpg +cyl +0.70 +-1.17 +.244 +-0.81 +[-2.18, 0.55] +-0.24 +[-0.65, 0.16] -mpg -disp -0.01 --1.54 -.123 --0.01 -[-0.03, 0.00] --0.29 -[-0.65, 0.08] +mpg +disp +0.01 +-1.54 +.123 +-0.01 +[-0.03, 0.00] +-0.29 +[-0.65, 0.08] -mpg -hp -0.02 --1.52 -.128 --0.02 -[-0.05, 0.01] --0.26 -[-0.60, 0.07] +mpg +hp +0.02 +-1.52 +.128 +-0.02 +[-0.05, 0.01] +-0.26 +[-0.60, 0.07] -mpg -drat -1.53 -1.41 -.159 -2.15 -[-0.84, 5.15] -0.19 -[-0.07, 0.46] +mpg +drat +1.53 +1.41 +.159 +2.15 +[-0.84, 5.15] +0.19 +[-0.07, 0.46] -disp -hp -0.23 -1.35 -.177 -0.32 -[-0.14, 0.78] -0.18 -[-0.08, 0.43] +disp +hp +0.23 +1.35 +.177 +0.32 +[-0.14, 0.78] +0.18 +[-0.08, 0.43] -disp -drat -19.37 --2.12 -.034* --41.13 -[-79.09, -3.17] --0.18 -[-0.34, -0.02] +disp +drat +19.37 +-2.12 +.034* +-41.13 +[-79.09, -3.17] +-0.18 +[-0.34, -0.02] -disp -wt -14.04 -5.54 -< .001*** -77.72 -[50.20, 105.24] -0.61 -[0.41, 0.82] +disp +wt +14.04 +5.54 +< .001*** +77.72 +[50.20, 105.24] +0.61 +[0.41, 0.82] -disp -qsec -6.89 --1.87 -.061 --12.91 -[-26.42, 0.59] --0.19 -[-0.38, 0.01] +disp +qsec +6.89 +-1.87 +.061 +-12.91 +[-26.42, 0.59] +-0.19 +[-0.38, 0.01] diff --git a/articles/write_lavaan.html b/articles/write_lavaan.html index 9c7e46b..733bc30 100644 --- a/articles/write_lavaan.html +++ b/articles/write_lavaan.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/authors.html b/authors.html index f251ccf..ed67e71 100644 --- a/authors.html +++ b/authors.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/index.html b/index.html index 4f310a3..4db47ed 100644 --- a/index.html +++ b/index.html @@ -39,7 +39,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/news/index.html b/news/index.html index b112d7f..730fe47 100644 --- a/news/index.html +++ b/news/index.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 @@ -88,8 +88,16 @@ -lavaanExtra 0.2.1 +lavaanExtra 0.2.2 +Incoming ✨ + + +lavaanExtra 0.2.1.1 Incoming ✨ + + +lavaanExtra 0.2.1 +New CRAN submission lavaanExtra 0.2.0.3 Fix bug in nice_fit() that created an error with categorical variables (#37) diff --git a/pkgdown.yml b/pkgdown.yml index d3f6a78..74b8c9a 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -7,7 +7,7 @@ articles: indirect: indirect.html regression: regression.html write_lavaan: write_lavaan.html -last_built: 2024-07-01T18:54Z +last_built: 2024-07-01T19:32Z urls: reference: https://lavaanExtra.remi-theriault.com/reference article: https://lavaanExtra.remi-theriault.com/articles diff --git a/reference/cfa_fit_plot.html b/reference/cfa_fit_plot.html index e8d8b75..a94247a 100644 --- a/reference/cfa_fit_plot.html +++ b/reference/cfa_fit_plot.html @@ -18,7 +18,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/index.html b/reference/index.html index 6fcdc90..50b7018 100644 --- a/reference/index.html +++ b/reference/index.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaanExtra-package.html b/reference/lavaanExtra-package.html index 87ecc45..5c8fa88 100644 --- a/reference/lavaanExtra-package.html +++ b/reference/lavaanExtra-package.html @@ -18,7 +18,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaan_cov.html b/reference/lavaan_cov.html index 0a47897..e6a7f2b 100644 --- a/reference/lavaan_cov.html +++ b/reference/lavaan_cov.html @@ -18,7 +18,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaan_defined.html b/reference/lavaan_defined.html index 1f77eba..1675c82 100644 --- a/reference/lavaan_defined.html +++ b/reference/lavaan_defined.html @@ -20,7 +20,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaan_extract.html b/reference/lavaan_extract.html index 2ebf1d5..e34bcfd 100644 --- a/reference/lavaan_extract.html +++ b/reference/lavaan_extract.html @@ -18,7 +18,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaan_reg.html b/reference/lavaan_reg.html index eaadf61..e9d846f 100644 --- a/reference/lavaan_reg.html +++ b/reference/lavaan_reg.html @@ -18,7 +18,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/lavaan_var.html b/reference/lavaan_var.html index ad78e37..71a3a86 100644 --- a/reference/lavaan_var.html +++ b/reference/lavaan_var.html @@ -26,7 +26,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/nice_fit.html b/reference/nice_fit.html index 45c067f..8058e86 100644 --- a/reference/nice_fit.html +++ b/reference/nice_fit.html @@ -20,7 +20,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/nice_lavaanPlot.html b/reference/nice_lavaanPlot.html index b70cb9d..ea2d8cb 100644 --- a/reference/nice_lavaanPlot.html +++ b/reference/nice_lavaanPlot.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/nice_modindices.html b/reference/nice_modindices.html index c929ce2..38a68cb 100644 --- a/reference/nice_modindices.html +++ b/reference/nice_modindices.html @@ -20,7 +20,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/nice_tidySEM.html b/reference/nice_tidySEM.html index 5d64025..929b0c4 100644 --- a/reference/nice_tidySEM.html +++ b/reference/nice_tidySEM.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/reference/write_lavaan.html b/reference/write_lavaan.html index 91af309..5c6a60a 100644 --- a/reference/write_lavaan.html +++ b/reference/write_lavaan.html @@ -16,7 +16,7 @@ lavaanExtra - 0.2.0.3 + 0.2.1 diff --git a/search.json b/search.json index 3392480..4301217 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contribution Guidelines","title":"Contribution Guidelines","text":"contributions welcome. Thank contributing! several ways contribute:","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_1-open-an-issue","dir":"","previous_headings":"","what":"1. Open an Issue","title":"Contribution Guidelines","text":"Open issue report bug (typo), suggest feature request, get help (yes, need go Stack Overflow, get help author directly issue becomes tutorial others!). opening issue, try include reprex, minimally reproducible example can replicated one base datasets R, mtcars dataset. make reprex, consider using reprex package. takes bit time get used , useful!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"pro-tip-on-creating-a-reprex-fast","dir":"","previous_headings":"1. Open an Issue","what":"Pro Tip on Creating a Reprex FAST","title":"Contribution Guidelines","text":"’s quality life upgrade learned late regarding reprexes. Instead loading package library(reprex), copying code Ctrl+c typing reprex() console, faster way. install package first time, actually adds addin RStudio. Simply click Addins button Help menu, search bar type reprex select Render reprex... ’ve copied relevant code. opens reprex window can specify different options finally click blue Render button render reprex. cool also allows easily add session info reprex checking Append session info check box. wait, way make even faster! Make addin selection shortcut (example) Ctrl+r going Tools, Modify Keyboard Shortcuts..., search bar type reprex, Render reprex... row, click Shortcut column, type desired shortcut (use Ctrl+r). , copy code Ctr+c, open reprex addin window Ctrl+r, press tab 3 times press enter. BAM! reprex < 5 seconds.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_2-start-a-discussion","dir":"","previous_headings":"","what":"2. Start a Discussion","title":"Contribution Guidelines","text":"Start discussion discuss ideas, organization, meta-ideas, ask questions, create polls, anything else doesn’t fit well issue.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_3-submit-a-pull-request","dir":"","previous_headings":"","what":"3. Submit a Pull Request","title":"Contribution Guidelines","text":"Submit PR (’ve never heard term , ’s Pull Request!). essentially means make code contribution package repository. ’s complicated , don’t worry, can just copy-paste code contribution issue add . bit experienced however, suggested submit PR. recommended workflow submit PR following. Fork repository (use: usethis::create_from_github(\"rempsyc/lavaanExtra\")). Create branch (RStudio, click tiny purple flowchart Git tab, blue wheel main branch buttons), name based theme suggested changes. Commit push (Ctrl+p) changes branch RStudio. Submit PR modified branch (go branch GitHub website, automatically suggest open PR draft message ). Include one reprexes showing old new behaviour comparison. Note using usethis steps, need : installed git software (.e., R package); created github token usethis::create_github_token() (see usethis::gh_token_help() help); set credentials gitcreds::gitcreds_set().","code":""},{"path":"https://lavaanExtra.remi-theriault.com/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 lavaanExtra Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/TODOS.html","id":null,"dir":"","previous_headings":"","what":"Development objectives (to-do list)","title":"Development objectives (to-do list)","text":"cfa_fit_plot, add covariances items plot? Problem keep vertical structure look pretty putting default TRUE. Perhaps programmatic way lavaanPlot specify vertical structure times. nice_fit: automatically pick robust fit indices, available(?) Allow specifying standardized unstandardized coefficients figure, e.g., c(\"b\", \"B\"). improve algorithm odd number variables layout matrix adding two empty rows around odd levels, one empty row middle even levels? Add automatic covariances (specify levels, e.g.,: “level1 = IV”, “level2 = M”, “level3 = DV”) Get community feedback","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-1-model-syntax-1","dir":"Articles","previous_headings":"","what":"Example 1 (Model syntax 1):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/syntax1.html lavaan: lavaanExtra:","code":"myModel <- \" # regressions y1 + y2 ~ f1 + f2 + x1 + x2 f1 ~ f2 + f3 f2 ~ f3 + x1 + x2 # latent variable definitions f1 =~ y1 + y2 + y3 f2 =~ y4 + y5 + y6 f3 =~ y7 + y8 + y9 + y10 # variances and covariances y1 ~~ y1 y1 ~~ y2 f1 ~~ f2 # intercepts y1 ~ 1 f1 ~ 1 \" reg <- list( y1 = c(\"f1\", \"f2\", \"x1\", \"x2\"), y2 = c(\"f1\", \"f2\", \"x1\", \"x2\"), f1 = c(\"f2\", \"f3\"), f2 = c(\"f3\", \"x1\", \"x2\") ) lat <- list( f1 = paste0(\"y\", 1:3), f2 = paste0(\"y\", 4:6), f3 = paste0(\"y\", 7:10) ) cov <- list( y1 = \"y1\", y1 = \"y2\", f1 = \"f2\" ) int <- c(\"y1\", \"f1\") myModel <- write_lavaan( regression = reg, latent = lat, covariance = cov, intercept = int ) cat(myModel) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## f1 =~ y1 + y2 + y3 ## f2 =~ y4 + y5 + y6 ## f3 =~ y7 + y8 + y9 + y10 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y1 ~ f1 + f2 + x1 + x2 ## y2 ~ f1 + f2 + x1 + x2 ## f1 ~ f2 + f3 ## f2 ~ f3 + x1 + x2 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y1 ~~ y1 ## y1 ~~ y2 ## f1 ~~ f2 ## ## ################################################## ## # [------------------Intercepts------------------] ## ## y1 ~ 1 ## f1 ~ 1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-2-a-cfa-example","dir":"Articles","previous_headings":"","what":"Example 2 (A CFA example):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/cfa.html lavaan: lavaanExtra:","code":"HS.model <- \" visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) myModel <- write_lavaan(latent = lat) cat(myModel) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-3-a-sem-example","dir":"Articles","previous_headings":"","what":"Example 3 (A SEM example):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/sem.html lavaan: lavaanExtra:","code":"model <- \" # measurement model ind60 =~ x1 + x2 + x3 dem60 =~ y1 + y2 + y3 + y4 dem65 =~ y5 + y6 + y7 + y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 \" lat <- list( ind60 = paste0(\"x\", 1:3), dem60 = paste0(\"y\", 1:4), dem65 = paste0(\"y\", 5:8) ) reg <- list( dem60 = \"ind60\", dem65 = c(\"ind60\", \"dem60\") ) cov <- list( y1 = \"y5\", y2 = c(\"y4\", \"y6\"), y3 = \"y7\", y4 = \"y8\", y6 = \"y8\" ) model <- write_lavaan( latent = lat, regression = reg, covariance = cov ) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## ind60 =~ x1 + x2 + x3 ## dem60 =~ y1 + y2 + y3 + y4 ## dem65 =~ y5 + y6 + y7 + y8 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## dem60 ~ ind60 ## dem65 ~ ind60 + dem60 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y1 ~~ y5 ## y2 ~~ y4 + y6 ## y3 ~~ y7 ## y4 ~~ y8 ## y6 ~~ y8"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-model-syntax-2","dir":"Articles","previous_headings":"","what":"Example 4 (Model syntax 2):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/syntax2.html","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-1","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.1","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" # three-factor model visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ NA*x7 + x8 + x9 # orthogonal factors visual ~~ 0*speed textual ~~ 0*speed # fix variance of speed factor speed ~~ 1*speed \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = c(\"NA*x7\", \"x8\", \"x9\") ) cov <- list( visual = \"0*speed\", textual = \"0*speed\", speed = \"1*speed\" ) model <- write_lavaan(latent = lat, covariance = cov) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ NA*x7 + x8 + x9 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## visual ~~ 0*speed ## textual ~~ 0*speed ## speed ~~ 1*speed"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-2","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.2","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" visual =~ x1 + start(0.8)*x2 + start(1.2)*x3 textual =~ x4 + start(0.5)*x5 + start(1.0)*x6 speed =~ x7 + start(0.7)*x8 + start(1.8)*x9 \" lat <- list( visual = c(\"x1\", \"start(0.8)*x2\", \"start(1.2)*x3\"), textual = c(\"x4\", \"start(0.5)*x5\", \"start(1.0)*x6\"), speed = c(\"x7\", \"start(0.7)*x8\", \"start(1.8)*x9\") ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + start(0.8)*x2 + start(1.2)*x3 ## textual =~ x4 + start(0.5)*x5 + start(1.0)*x6 ## speed =~ x7 + start(0.7)*x8 + start(1.8)*x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-3","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.3","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" f =~ y1 + y2 + myLabel*y3 + start(0.5)*y3 + y4 \" lat <- list(f = c(\"y1\", \"y2\", \"myLabel*y3\", \"start(0.5)*y3\", \"y4\")) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## f =~ y1 + y2 + myLabel*y3 + start(0.5)*y3 + y4"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-4","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.4","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" visual =~ x1 + v2*x2 + v2*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 \" lat <- list( visual = c(\"x1\", \"v2*x2\", \"v2*x3\"), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + v2*x2 + v2*x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-5","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.5","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- ' visual =~ x1 + x2 + equal(\"visual=~x2\")*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' sem(model, data = HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## Number of equality constraints 1 ## ## Number of observations 301 ## ## Model Test User Model: ## ## Test statistic 87.971 ## Degrees of freedom 25 ## P-value (Chi-square) 0.000 lat <- list( visual = c(\"x1\", \"x2\", \"equal('visual=~x2')*x3\"), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + equal('visual=~x2')*x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 sem(model, data = HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## Number of equality constraints 1 ## ## Number of observations 301 ## ## Model Test User Model: ## ## Test statistic 87.971 ## Degrees of freedom 25 ## P-value (Chi-square) 0.000"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-6","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.6","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model.constr <- \" # model with labeled parameters y ~ b1*x1 + b2*x2 + b3*x3 # constraints b1 == (b2 + b3)^2 b1 > exp(b2 + b3) \" reg <- list(y = c(\"b1*x1\", \"b2*x2\", \"b3*x3\")) cstr1 <- list(b1 = \"(b2 + b3)^2\") cstr2 <- list(b1 = \"exp(b2 + b3)\") model <- write_lavaan( regression = reg, constraint.equal = cstr1, constraint.larger = cstr2 ) cat(model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y ~ b1*x1 + b2*x2 + b3*x3 ## ## ################################################## ## # [-----------------Constraints------------------] ## ## b1 == (b2 + b3)^2 ## b1 > exp(b2 + b3)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-5-mediation","dir":"Articles","previous_headings":"","what":"Example 5 (Mediation)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/mediation.html lavaan: lavaanExtra:","code":"model <- \" # direct effect Y ~ c*X # mediator M ~ a*X Y ~ b*M # indirect effect (a*b) ab := a*b # total effect total := c + (a*b) \" mediation <- list( Y = \"c*X\", M = \"a*X\", Y = \"b*M\" ) indirect <- list( ab = \"a*b\", total = \"c + (a*b)\" ) model <- write_lavaan(mediation = mediation, indirect = indirect) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## Y ~ c*X ## M ~ a*X ## Y ~ b*M ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ab := a*b ## total := c + (a*b)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-6-multilevel-sem","dir":"Articles","previous_headings":"","what":"Example 6 (Multilevel SEM)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/multilevel.html lavaan: lavaanExtra:","code":"model <- \" level: 1 fw =~ y1 + y2 + y3 fw ~ x1 + x2 + x3 level: 2 fb =~ y1 + y2 + y3 fb ~ w1 + w2 \" cus <- \"level: 1 fw =~ y1 + y2 + y3 fw ~ x1 + x2 + x3 level: 2 fb =~ y1 + y2 + y3 fb ~ w1 + w2 \" model <- write_lavaan(custom = cus) cat(model) ## ################################################## ## # [------------Custom Specifications-------------] ## ## level: 1 ## fw =~ y1 + y2 + y3 ## fw ~ x1 + x2 + x3 ## level: 2 ## fb =~ y1 + y2 + y3 ## fb ~ w1 + w2"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-7-total-effects","dir":"Articles","previous_headings":"","what":"Example 7 (total effects)","title":"Example lavaan models","text":"Source: https://methodenlehre.github.io/SGSCLM-R-course/cfa--sem--lavaan.html#structural-equation-modelling-sem lavaan: lavaanExtra:","code":"model_mediation <- \" # Measurement model SUP_Parents =~ sup_parents_p1 + sup_parents_p2 + sup_parents_p3 SUP_Friends =~ sup_friends_p1 + sup_friends_p2 + sup_friends_p3 SE_Academic =~ se_acad_p1 + se_acad_p2 + se_acad_p3 SE_Social =~ se_social_p1 + se_social_p2 + se_social_p3 LS =~ ls_p1 + ls_p2 + ls_p3 # Structural model # Regressions SE_Academic ~ b1*SUP_Parents + b3*SUP_Friends SE_Social ~ b2*SUP_Parents + b4*SUP_Friends LS ~ b5*SUP_Parents + b6*SUP_Friends + b7*SE_Academic + b8*SE_Social # Residual covariances SE_Academic ~~ SE_Social # Indirect effects b1b7 := b1*b7 b2b8 := b2*b8 totalind_eltern := b1*b7 + b2*b8 b3b7 := b3*b7 b4b8 := b4*b8 totalind_freunde := b3*b7 + b4*b8 # Total effects total_eltern := b1*b7 + b2*b8 + b5 total_freunde := b3*b7 + b4*b8 + b6 \" x <- c(\"sup_parents\", \"sup_friends\", \"se_acad\", \"se_social\", \"ls\") y <- lapply(x, paste0, \"_p\", 1:3) y <- setNames(y, x) lat <- list( SUP_Parents = y$sup_parents, SUP_Friends = y$sup_friends, SE_Academic = y$se_acad, SE_Social = y$se_social, LS = y$ls ) b <- paste0(\"b\", 1:8) d <- c( rep(c(\"SUP_Parents\", \"SUP_Friends\"), each = 2), \"SUP_Parents\", \"SUP_Friends\", \"SE_Academic\", \"SE_Social\" ) e <- paste0(b, \"*\", d) reg <- list( SE_Academic = e[c(1, 3)], SE_Social = e[c(2, 4)], LS = e[c(5:8)] ) cov <- list(SE_Academic = \"SE_Social\") ind <- list( b1b7 = \"b1*b7\", b2b8 = \"b2*b8\", totalind_eltern = \"b1*b7 + b2*b8\", b3b7 = \"b3*b7\", b4b8 = \"b4*b8\", totalind_freunde = \"b3*b7 + b4*b8\", total_eltern = \"b1*b7 + b2*b8 + b5\", total_freunde = \"b3*b7 + b4*b8 + b6\" ) model <- write_lavaan( regression = reg, covariance = cov, indirect = ind, latent = lat ) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## SUP_Parents =~ sup_parents_p1 + sup_parents_p2 + sup_parents_p3 ## SUP_Friends =~ sup_friends_p1 + sup_friends_p2 + sup_friends_p3 ## SE_Academic =~ se_acad_p1 + se_acad_p2 + se_acad_p3 ## SE_Social =~ se_social_p1 + se_social_p2 + se_social_p3 ## LS =~ ls_p1 + ls_p2 + ls_p3 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## SE_Academic ~ b1*SUP_Parents + b3*SUP_Friends ## SE_Social ~ b2*SUP_Parents + b4*SUP_Friends ## LS ~ b5*SUP_Parents + b6*SUP_Friends + b7*SE_Academic + b8*SE_Social ## ## ################################################## ## # [------------------Covariances-----------------] ## ## SE_Academic ~~ SE_Social ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## b1b7 := b1*b7 ## b2b8 := b2*b8 ## totalind_eltern := b1*b7 + b2*b8 ## b3b7 := b3*b7 ## b4b8 := b4*b8 ## totalind_freunde := b3*b7 + b4*b8 ## total_eltern := b1*b7 + b2*b8 + b5 ## total_freunde := b3*b7 + b4*b8 + b6"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-8-intercepts","dir":"Articles","previous_headings":"","what":"Example 8 (intercepts)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/means.html lavaan: lavaanExtra:","code":"HS.model <- \" # three-factor model visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 # intercepts with fixed values x1 + x2 + x3 + x4 ~ 0.5*1 \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) cus <- \"x1 + x2 + x3 + x4 ~ 0.5*1\" HS.model <- write_lavaan( latent = lat, custom = cus ) cat(HS.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 ## ## ################################################## ## # [------------Custom Specifications-------------] ## ## x1 + x2 + x3 + x4 ~ 0.5*1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-9-thresholds","dir":"Articles","previous_headings":"","what":"Example 9 (thresholds)","title":"Example lavaan models","text":"Source: https://tdjorgensen.github.io/TDJorgensen/CatMeasEq/Jorgensen.CatMeasEq.pdf lavaan: lavaanExtra:","code":"mod2 <- \" ## LIR means y2w1 ~ mean1*1 y2w2 ~ mean2*1 ## LIR (co)variances y2w1 ~~ var1*y2w1 + y2w2 y2w2 ~~ var2*y2w2 ## thresholds link LIRs to observed items y2w1 | thr1*t1 y2w2 | thr2*t1 \" reg <- list( y2w1 = \"mean1*1\", y2w2 = \"mean2*1\" ) cov <- list( y2w1 = c(\"var1*y2w1\", \"y2w2\"), y2w2 = \"var2*y2w2\" ) thres <- list( y2w1 = \"thr1*t1\", y2w2 = \"thr2*t1\" ) HS.model <- write_lavaan( regression = reg, covariance = cov, threshold = thres ) cat(HS.model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y2w1 ~ mean1*1 ## y2w2 ~ mean2*1 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y2w1 ~~ var1*y2w1 + y2w2 ## y2w2 ~~ var2*y2w2 ## ## ################################################## ## # [------------------Thresholds------------------] ## ## y2w1 | thr1*t1 ## y2w2 | thr2*t1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-10-longitudinal-invariance","dir":"Articles","previous_headings":"","what":"Example 10 (longitudinal invariance)","title":"Example lavaan models","text":"Source: https://thechangelab.stanford.edu/tutorials/growth-modeling/modeling-change-latent-vars-ordinal-indicators-lavaan/ lavaan: lavaanExtra:","code":"configural_invar <- \" #opening quote #factor loadings eta1 =~ 1*t1_sc + #for identification t1_intp + t1_ext eta2 =~ 1*t2_sc + #for identification t2_intp + t2_ext eta3 =~ 1*t4_sc + #for identification t4_intp + t4_ext #latent variable variances eta1~~eta1 eta2~~eta2 eta3~~eta3 #latent variable covariances eta1~~eta2 eta1~~eta3 eta2~~eta3 #latent variable means eta1~0*1 #for scaling eta2~0*1 #for scaling eta3~0*1 #for scaling #propensity variances t1_sc ~~ 1*t1_sc t1_intp~~ 1*t1_intp t1_ext ~~ 1*t1_ext t2_sc ~~ 1*t2_sc t2_intp~~ 1*t2_intp t2_ext ~~ 1*t2_ext t4_sc ~~ 1*t4_sc t4_intp~~ 1*t4_intp t4_ext ~~ 1*t4_ext #unique covariances #observed variable intercepts/thresholds (4 categories = 3 thresholds) t1_sc |t1 + t2 + t3 t1_intp |t1 + t2 + t3 t1_ext |t1 + t2 + t3 t2_sc |t1 + t2 + t3 t2_intp |t1 + t2 + t3 t2_ext |t1 + t2 + t3 t4_sc |t1 + t2 + t3 t4_intp |t1 + t2 + t3 t4_ext |t1 + t2 + t3 \" # closing quote eta <- paste0(\"eta\", 1:3) t <- paste0(\"t\", 1:4) term <- c(\"sc\", \"intp\", \"ext\") tnames <- paste0(rep(t[c(1:2, 4)], each = 3), \"_\", term) tnames2 <- paste0(\"1*\", tnames) lat <- list( eta1 = c(tnames2[1], tnames[2:3]), eta2 = c(tnames2[4], tnames[5:6]), eta3 = c(tnames2[7], tnames[8:9]) ) cov <- as.list(c(eta, eta[2:3], eta[3], tnames2)) names(cov) <- c(eta, eta[1], eta[1:2], tnames) thres <- rep(list(t[1:3]), 9) names(thres) <- tnames reg <- as.list(setNames(rep(\"0*1\", 3), eta)) HS.model <- write_lavaan( regression = reg, latent = lat, covariance = cov, threshold = thres ) cat(HS.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## eta1 =~ 1*t1_sc + t1_intp + t1_ext ## eta2 =~ 1*t2_sc + t2_intp + t2_ext ## eta3 =~ 1*t4_sc + t4_intp + t4_ext ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## eta1 ~ 0*1 ## eta2 ~ 0*1 ## eta3 ~ 0*1 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## eta1 ~~ eta1 ## eta2 ~~ eta2 ## eta3 ~~ eta3 ## eta1 ~~ eta2 ## eta1 ~~ eta3 ## eta2 ~~ eta3 ## t1_sc ~~ 1*t1_sc ## t1_intp ~~ 1*t1_intp ## t1_ext ~~ 1*t1_ext ## t2_sc ~~ 1*t2_sc ## t2_intp ~~ 1*t2_intp ## t2_ext ~~ 1*t2_ext ## t4_sc ~~ 1*t4_sc ## t4_intp ~~ 1*t4_intp ## t4_ext ~~ 1*t4_ext ## ## ################################################## ## # [------------------Thresholds------------------] ## ## t1_sc | t1 + t2 + t3 ## t1_intp | t1 + t2 + t3 ## t1_ext | t1 + t2 + t3 ## t2_sc | t1 + t2 + t3 ## t2_intp | t1 + t2 + t3 ## t2_ext | t1 + t2 + t3 ## t4_sc | t1 + t2 + t3 ## t4_intp | t1 + t2 + t3 ## t4_ext | t1 + t2 + t3"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"cfa-example","dir":"Articles","previous_headings":"","what":"CFA example","title":"Full CFA/SEM workflow","text":"Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC Model 1 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. let’s say wanted develop short-scale x items per dimension. decide remove, dimension, items lowest loadings reach desired number items per dimension (look Estimation items reliability section ). can without respecify model, items wish remove: Let’s compare fit short version: Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.cfa2 13.11 6 2.19 .041 .98 .96 .06 [.01, .11] .03 5,106.23 5,161.84 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. like table, may also wish save Word. Also easy: Note also render PDF rmarkdown document output: pdf_document, using latex_engine: xelatex necessary including Unicode symbols tables like nice_fit() function.","code":"# Load library library(lavaan) library(lavaanExtra) library(tibble) library(psych) # Define latent variables x <- paste0(\"x\", 1:9) latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] ) # Write the model, and check it cfa.model <- write_lavaan(latent = latent) cat(cfa.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (optionally as PDF) fit.cfa <- cfa_fit_plot(cfa.model, HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 35 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## ## Number of observations 301 ## ## Model Test User Model: ## Standard Scaled ## Test Statistic 85.306 87.132 ## Degrees of freedom 24 24 ## P-value (Chi-square) 0.000 0.000 ## Scaling correction factor 0.979 ## Yuan-Bentler correction (Mplus variant) ## ## Model Test Baseline Model: ## ## Test statistic 918.852 880.082 ## Degrees of freedom 36 36 ## P-value 0.000 0.000 ## Scaling correction factor 1.044 ## ## User Model versus Baseline Model: ## ## Comparative Fit Index (CFI) 0.931 0.925 ## Tucker-Lewis Index (TLI) 0.896 0.888 ## ## Robust Comparative Fit Index (CFI) 0.930 ## Robust Tucker-Lewis Index (TLI) 0.895 ## ## Loglikelihood and Information Criteria: ## ## Loglikelihood user model (H0) -3737.745 -3737.745 ## Scaling correction factor 1.133 ## for the MLR correction ## Loglikelihood unrestricted model (H1) -3695.092 -3695.092 ## Scaling correction factor 1.051 ## for the MLR correction ## ## Akaike (AIC) 7517.490 7517.490 ## Bayesian (BIC) 7595.339 7595.339 ## Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 ## ## Root Mean Square Error of Approximation: ## ## RMSEA 0.092 0.093 ## 90 Percent confidence interval - lower 0.071 0.073 ## 90 Percent confidence interval - upper 0.114 0.115 ## P-value H_0: RMSEA <= 0.050 0.001 0.001 ## P-value H_0: RMSEA >= 0.080 0.840 0.862 ## ## Robust RMSEA 0.092 ## 90 Percent confidence interval - lower 0.072 ## 90 Percent confidence interval - upper 0.114 ## P-value H_0: Robust RMSEA <= 0.050 0.001 ## P-value H_0: Robust RMSEA >= 0.080 0.849 ## ## Standardized Root Mean Square Residual: ## ## SRMR 0.065 0.065 ## ## Parameter Estimates: ## ## Standard errors Sandwich ## Information bread Observed ## Observed information based on Hessian ## ## Latent Variables: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual =~ ## x1 1.000 0.900 0.772 ## x2 0.554 0.132 4.191 0.000 0.498 0.424 ## x3 0.729 0.141 5.170 0.000 0.656 0.581 ## textual =~ ## x4 1.000 0.990 0.852 ## x5 1.113 0.066 16.946 0.000 1.102 0.855 ## x6 0.926 0.061 15.089 0.000 0.917 0.838 ## speed =~ ## x7 1.000 0.619 0.570 ## x8 1.180 0.130 9.046 0.000 0.731 0.723 ## x9 1.082 0.266 4.060 0.000 0.670 0.665 ## ## Covariances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual ~~ ## textual 0.408 0.099 4.110 0.000 0.459 0.459 ## speed 0.262 0.060 4.366 0.000 0.471 0.471 ## textual ~~ ## speed 0.173 0.056 3.081 0.002 0.283 0.283 ## ## Variances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## .x1 0.549 0.156 3.509 0.000 0.549 0.404 ## .x2 1.134 0.112 10.135 0.000 1.134 0.821 ## .x3 0.844 0.100 8.419 0.000 0.844 0.662 ## .x4 0.371 0.050 7.382 0.000 0.371 0.275 ## .x5 0.446 0.057 7.870 0.000 0.446 0.269 ## .x6 0.356 0.047 7.658 0.000 0.356 0.298 ## .x7 0.799 0.097 8.222 0.000 0.799 0.676 ## .x8 0.488 0.120 4.080 0.000 0.488 0.477 ## .x9 0.566 0.119 4.768 0.000 0.566 0.558 ## visual 0.809 0.180 4.486 0.000 1.000 1.000 ## textual 0.979 0.121 8.075 0.000 1.000 1.000 ## speed 0.384 0.107 3.596 0.000 1.000 1.000 ## ## R-Square: ## Estimate ## x1 0.596 ## x2 0.179 ## x3 0.338 ## x4 0.725 ## x5 0.731 ## x6 0.702 ## x7 0.324 ## x8 0.523 ## x9 0.442 # Get fit indices nice_fit(fit.cfa) ## Model chisq df chi2.df pvalue cfi tli rmsea rmsea.ci.lower ## 1 Model 1 85.306 24 3.554 0 0.931 0.896 0.092 0.071 ## rmsea.ci.upper srmr aic bic ## 1 0.114 0.055 7517.49 7595.339 # We can get it prettier with the `rempsyc::nice_table` integration nice_fit(fit.cfa, nice_table = TRUE) # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (as PDF) fit.cfa2 <- cfa_fit_plot(cfa.model, HolzingerSwineford1939, remove.items = x[c(2, 6:7)] ) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 15 ## ## Number of observations 301 ## ## Model Test User Model: ## Standard Scaled ## Test Statistic 13.109 13.560 ## Degrees of freedom 6 6 ## P-value (Chi-square) 0.041 0.035 ## Scaling correction factor 0.967 ## Yuan-Bentler correction (Mplus variant) ## ## Model Test Baseline Model: ## ## Test statistic 481.386 460.467 ## Degrees of freedom 15 15 ## P-value 0.000 0.000 ## Scaling correction factor 1.045 ## ## User Model versus Baseline Model: ## ## Comparative Fit Index (CFI) 0.985 0.983 ## Tucker-Lewis Index (TLI) 0.962 0.958 ## ## Robust Comparative Fit Index (CFI) 0.984 ## Robust Tucker-Lewis Index (TLI) 0.961 ## ## Loglikelihood and Information Criteria: ## ## Loglikelihood user model (H0) -2538.118 -2538.118 ## Scaling correction factor 1.076 ## for the MLR correction ## Loglikelihood unrestricted model (H1) -2531.563 -2531.563 ## Scaling correction factor 1.045 ## for the MLR correction ## ## Akaike (AIC) 5106.235 5106.235 ## Bayesian (BIC) 5161.842 5161.842 ## Sample-size adjusted Bayesian (SABIC) 5114.271 5114.271 ## ## Root Mean Square Error of Approximation: ## ## RMSEA 0.063 0.065 ## 90 Percent confidence interval - lower 0.012 0.015 ## 90 Percent confidence interval - upper 0.109 0.112 ## P-value H_0: RMSEA <= 0.050 0.276 0.255 ## P-value H_0: RMSEA >= 0.080 0.309 0.337 ## ## Robust RMSEA 0.064 ## 90 Percent confidence interval - lower 0.016 ## 90 Percent confidence interval - upper 0.109 ## P-value H_0: Robust RMSEA <= 0.050 0.262 ## P-value H_0: Robust RMSEA >= 0.080 0.314 ## ## Standardized Root Mean Square Residual: ## ## SRMR 0.036 0.036 ## ## Parameter Estimates: ## ## Standard errors Sandwich ## Information bread Observed ## Observed information based on Hessian ## ## Latent Variables: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual =~ ## x1 1.000 0.954 0.818 ## x3 0.637 0.119 5.343 0.000 0.608 0.538 ## textual =~ ## x4 1.000 1.115 0.959 ## x5 0.883 0.140 6.292 0.000 0.985 0.764 ## speed =~ ## x8 1.000 0.511 0.505 ## x9 1.754 0.398 4.405 0.000 0.896 0.889 ## ## Covariances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual ~~ ## textual 0.472 0.098 4.798 0.000 0.444 0.444 ## speed 0.274 0.073 3.732 0.000 0.562 0.562 ## textual ~~ ## speed 0.144 0.055 2.590 0.010 0.252 0.252 ## ## Variances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## .x1 0.448 0.172 2.606 0.009 0.448 0.330 ## .x3 0.905 0.085 10.670 0.000 0.905 0.710 ## .x4 0.107 0.190 0.564 0.573 0.107 0.080 ## .x5 0.690 0.160 4.311 0.000 0.690 0.416 ## .x8 0.761 0.088 8.623 0.000 0.761 0.745 ## .x9 0.213 0.165 1.294 0.196 0.213 0.210 ## visual 0.910 0.197 4.623 0.000 1.000 1.000 ## textual 1.243 0.219 5.678 0.000 1.000 1.000 ## speed 0.261 0.080 3.270 0.001 1.000 1.000 ## ## R-Square: ## Estimate ## x1 0.670 ## x3 0.290 ## x4 0.920 ## x5 0.584 ## x8 0.255 ## x9 0.790 fit_table <- nice_fit(lst(fit.cfa, fit.cfa2), nice_table = TRUE) fit_table # Save fit table to Word! flextable::save_as_docx(fit_table, path = \"fit_table.docx\")"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"estimation-of-items-reliability","dir":"Articles","previous_headings":"CFA example","what":"Estimation of items reliability","title":"Full CFA/SEM workflow","text":"Ideally, rather just looking loadings, also estimate item reliability dimensions long vs short scales help select items drop short scale. can first look alpha item dropped using psych::alpha function. Looking “Reliability item dropped” section, can see decision drop items 2, 6, 7, consistent new results except item 7. Indeed, according reliability estimation, better drop item 9 instead.","code":"visual <- HolzingerSwineford1939[x[1:3]] textual <- HolzingerSwineford1939[x[4:6]] speed <- HolzingerSwineford1939[x[7:9]] alpha(visual) ## ## Reliability analysis ## Call: alpha(x = visual) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.63 0.63 0.54 0.36 1.7 0.037 4.4 0.88 0.34 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.55 0.63 0.69 ## Duhachek 0.55 0.63 0.70 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x1 0.51 0.51 0.34 0.34 1.03 0.057 NA 0.34 ## x2 0.61 0.61 0.44 0.44 1.58 0.045 NA 0.44 ## x3 0.46 0.46 0.30 0.30 0.85 0.062 NA 0.30 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x1 301 0.77 0.77 0.58 0.45 4.9 1.2 ## x2 301 0.73 0.72 0.47 0.37 6.1 1.2 ## x3 301 0.78 0.78 0.62 0.48 2.3 1.1 alpha(textual) ## ## Reliability analysis ## Call: alpha(x = textual) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.88 0.88 0.84 0.72 7.7 0.011 3.2 1.1 0.72 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.86 0.88 0.90 ## Duhachek 0.86 0.88 0.91 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x4 0.83 0.84 0.72 0.72 5.1 0.019 NA 0.72 ## x5 0.83 0.83 0.70 0.70 4.8 0.020 NA 0.70 ## x6 0.84 0.85 0.73 0.73 5.5 0.018 NA 0.73 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x4 301 0.90 0.90 0.82 0.78 3.1 1.2 ## x5 301 0.92 0.91 0.84 0.79 4.3 1.3 ## x6 301 0.89 0.90 0.81 0.77 2.2 1.1 alpha(speed) ## ## Reliability analysis ## Call: alpha(x = speed) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.69 0.69 0.6 0.43 2.2 0.031 5 0.81 0.45 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.62 0.69 0.74 ## Duhachek 0.63 0.69 0.75 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x7 0.62 0.62 0.45 0.45 1.6 0.044 NA 0.45 ## x8 0.51 0.51 0.34 0.34 1.0 0.057 NA 0.34 ## x9 0.65 0.65 0.49 0.49 1.9 0.040 NA 0.49 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x7 301 0.79 0.78 0.59 0.49 4.2 1.1 ## x8 301 0.82 0.82 0.69 0.57 5.5 1.0 ## x9 301 0.75 0.76 0.55 0.46 5.4 1.0"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"sem-example","dir":"Articles","previous_headings":"","what":"SEM example","title":"Full CFA/SEM workflow","text":"structural equation model example. start path analysis first.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"saturated-model","dir":"Articles","previous_headings":"SEM example","what":"Saturated model","title":"Full CFA/SEM workflow","text":"One might decide look saturated lavaan model first. looks good far, might also want check indirect effects (mediations). , obtain path names setting label = TRUE. allow us define indirect effects feed back write_lavaan. , check mediation section model, see “augmented” path names. visual_speed, visual_textual, ageyr_visual, grade_visual. logic determination path names predictable: always predictor variable, left, followed predicted variable, right. test possible indirect effects, define indirect object : preferred (e.g., dealing long variable names), one can choose use letters predictor variables. Note however tends somewhat confusing ambiguous. case, path names a_speed, a_textual, a_visual, b_visual. define indirect object : also experimental feature attempts produce indirect effects automatically. feature requires specifying independent, dependent, mediator variables “IV”, “M”, “DV”, respectively, indirect object. case, already defined earlier, can just feed proper objects. now satisfied model, can finally fit ! Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) speed visual 0.05 3.91 < .001*** 0.20 [0.10, 0.29] 0.21 [0.11, 0.31] textual visual 0.06 4.53 < .001*** 0.29 [0.16, 0.41] 0.24 [0.14, 0.34] visual ageyr 0.05 -2.47 .014* -0.13 [-0.24, -0.03] -0.16 [-0.29, -0.03] visual grade 0.11 4.31 < .001*** 0.49 [0.27, 0.72] 0.28 [0.16, 0.40] speed ageyr 0.05 0.57 .568 0.03 [-0.07, 0.12] 0.04 [-0.09, 0.16] speed grade 0.10 4.90 < .001*** 0.50 [0.30, 0.70] 0.31 [0.19, 0.43] textual ageyr 0.06 -6.72 < .001*** -0.41 [-0.52, -0.29] -0.40 [-0.51, -0.29] textual grade 0.13 5.87 < .001*** 0.76 [0.51, 1.01] 0.36 [0.24, 0.47] speed predicted ageyr isn’t significant. remove path model trying make parsimonious model. Let’s make non-saturated path analysis model next.","code":"# Calculate scale averages data <- HolzingerSwineford1939 data$visual <- rowMeans(data[x[1:3]]) data$textual <- rowMeans(data[x[4:6]]) data$speed <- rowMeans(data[x[7:9]]) # Define our variables M <- \"visual\" IV <- c(\"ageyr\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) regression <- list(speed = IV, textual = IV) covariance <- list(speed = \"textual\", ageyr = \"grade\") # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual ## textual ~ visual ## visual ~ ageyr + grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # We can run the model again. # However, we set `label = TRUE` to get the path names model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # Define indirect object indirect <- list( ageyr_visual_speed = c(\"ageyr_visual\", \"visual_speed\"), ageyr_visual_textual = c(\"ageyr_visual\", \"visual_textual\"), grade_visual_speed = c(\"grade_visual\", \"visual_speed\"), grade_visual_textual = c(\"grade_visual\", \"visual_textual\") ) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## grade_visual_speed := grade_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE, use.letters = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ a_speed*visual ## textual ~ a_textual*visual ## visual ~ a_visual*ageyr + b_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # Define indirect object indirect <- list( ageyr_visual_speed = c(\"a_visual\", \"a_speed\"), ageyr_visual_textual = c(\"a_visual\", \"a_textual\"), grade_visual_speed = c(\"b_visual\", \"a_speed\"), grade_visual_textual = c(\"b_visual\", \"a_textual\") ) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE, use.letters = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ a_speed*visual ## textual ~ a_textual*visual ## visual ~ a_visual*ageyr + b_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := a_visual * a_speed ## ageyr_visual_textual := a_visual * a_textual ## grade_visual_speed := b_visual * a_speed ## grade_visual_textual := b_visual * a_textual # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## grade_visual_speed := grade_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Fit the model with `lavaan` fit.saturated <- sem(model.saturated, data = data) # Get regression parameters only # And make it pretty with the `rempsyc::nice_table` integration lavaan_reg(fit.saturated, nice_table = TRUE, highlight = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"path-analysis-model","dir":"Articles","previous_headings":"SEM example","what":"Path analysis model","title":"Full CFA/SEM workflow","text":"use lavaanExtra, don’t redefine entire model: simply want update. case, regressions indirect effects. Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) speed visual 0.05 3.86 < .001*** 0.19 [0.09, 0.29] 0.21 [0.10, 0.31] textual visual 0.06 4.52 < .001*** 0.29 [0.16, 0.41] 0.24 [0.14, 0.33] visual ageyr 0.05 -2.47 .014* -0.13 [-0.24, -0.03] -0.16 [-0.29, -0.03] visual grade 0.11 4.31 < .001*** 0.49 [0.27, 0.72] 0.28 [0.16, 0.40] speed grade 0.09 6.11 < .001*** 0.53 [0.36, 0.70] 0.33 [0.23, 0.43] textual ageyr 0.06 -6.85 < .001*** -0.41 [-0.53, -0.29] -0.40 [-0.51, -0.29] textual grade 0.13 5.93 < .001*** 0.76 [0.51, 1.02] 0.36 [0.24, 0.47] Variable 1 Variable 2 SE Z p σ 95% CI (σ) r 95% CI (r) speed textual 0.04 2.25 .024* 0.09 [0.01, 0.17] .13 [0.02, 0.24] ageyr grade 0.03 7.89 < .001*** 0.27 [0.20, 0.33] .51 [0.43, 0.59] Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.saturated 0.00 0 Inf 1.0 1.0 .00 [.00, .00] .00 3,483.46 3,539.02 fit.path 0.33 1 0.33 .568 1.0 1.3 .00 [.00, .13] -.00 3,481.79 3,533.64 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. Indirect Effect Paths SE Z p b 95% CI (b) b* 95% CI (b*) age → visual → speed ageyr_visual*visual_speed 0.01 -2.08 .037* -0.03 [-0.05, -0.00] -0.03 [-0.06, -0.00] grade → visual → textual grade_visual*visual_textual 0.05 3.12 .002** 0.14 [0.05, 0.23] 0.07 [0.03, 0.11] reference, model, visually speaking also attempt draw lavaanExtra::nice_tidySEM, convenience wrapper around amazing tidySEM package.","code":"regression <- list(speed = \"grade\", textual = IV) # We can run the model again, setting `label = TRUE` to get the path names model.path <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE ) cat(model.path) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # We check that we have removed \"ageyr\" correctly from \"speed\" in the # regression section. OK. # Define just our indirect effects of interest indirect <- list( age_visual_speed = c(\"ageyr_visual\", \"visual_speed\"), grade_visual_textual = c(\"grade_visual\", \"visual_textual\") ) # We run the model again, with the indirect effects model.path <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.path) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## age_visual_speed := ageyr_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Fit the model with `lavaan` fit.path <- sem(model.path, data = data) # Get regression parameters only lavaan_reg(fit.path) ## Outcome Predictor SE Z p b CI_lower ## 1 speed visual 0.04967204 3.861565 1.126628e-04 0.1918118 0.09445643 ## 2 textual visual 0.06336429 4.518796 6.219227e-06 0.2863303 0.16213859 ## 3 visual ageyr 0.05439452 -2.469906 1.351486e-02 -0.1343493 -0.24096064 ## 4 visual grade 0.11439571 4.306175 1.661018e-05 0.4926079 0.26839646 ## 5 speed grade 0.08716854 6.111181 9.889656e-10 0.5327027 0.36185552 ## 6 textual ageyr 0.05979047 -6.851140 7.326362e-12 -0.4096329 -0.52682005 ## 7 textual grade 0.12908567 5.925622 3.111173e-09 0.7649129 0.51190965 ## CI_upper B CI_lower_B CI_upper_B ## 1 0.28916724 0.2064640 0.1035674 0.30936052 ## 2 0.41052205 0.2351233 0.1353706 0.33487606 ## 3 -0.02773804 -0.1610061 -0.2876179 -0.03439429 ## 4 0.71681940 0.2807072 0.1566382 0.40477626 ## 5 0.70354992 0.3267428 0.2271881 0.42629750 ## 6 -0.29244571 -0.4031160 -0.5133146 -0.29291740 ## 7 1.01791619 0.3579255 0.2434470 0.47240398 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.path, nice_table = TRUE, highlight = TRUE) # We only kept significant regressions. Good (for this demo). # Get correlations lavaan_cor(fit.path) ## Variable 1 Variable 2 SE Z p sigma CI_lower ## 8 speed textual 0.04017743 2.254287 2.417812e-02 0.09057145 0.01182514 ## 9 ageyr grade 0.03401916 7.885426 3.108624e-15 0.26825556 0.20157923 ## CI_upper r CI_lower_r CI_upper_r ## 8 0.1693178 0.1312679 0.02005915 0.2424766 ## 9 0.3349319 0.5113296 0.42775726 0.5949020 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_cor(fit.path, nice_table = TRUE) # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path), nice_table = TRUE) # Let's get the indirect effects only lavaan_defined(fit.path, lhs_name = \"Indirect Effect\") ## Indirect Effect Paths SE Z ## 15 age → visual → speed ageyr_visual*visual_speed 0.01238517 -2.080697 ## 16 grade → visual → textual grade_visual*visual_textual 0.04524584 3.117383 ## p b CI_lower CI_upper B CI_lower_B ## 15 0.037461652 -0.02576979 -0.05004429 -0.001495299 -0.03324196 -0.06438407 ## 16 0.001824646 0.14104859 0.05236837 0.229728799 0.06600083 0.02535014 ## CI_upper_B ## 15 -0.002099853 ## 16 0.106651508 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_defined(fit.path, lhs_name = \"Indirect Effect\", nice_table = TRUE) # Get modification indices only modindices(fit.path, sort = TRUE, maximum.number = 5) ## lhs op rhs mi epc sepc.lv sepc.all sepc.nox ## 29 visual ~ textual 0.326 1.622 1.622 1.975 1.975 ## 35 grade ~ textual 0.326 -0.228 -0.228 -0.488 -0.488 ## 34 grade ~ speed 0.326 -0.038 -0.038 -0.062 -0.062 ## 19 speed ~~ grade 0.326 -0.021 -0.021 -0.056 -0.056 ## 25 speed ~ textual 0.326 -0.067 -0.067 -0.087 -0.087 labels <- list( ageyr = \"Age (year)\", grade = \"Grade\", visual = \"Visual\", speed = \"Speed\", textual = \"Textual\" ) layout <- list(IV = IV, M = M, DV = DV) nice_tidySEM(fit.path, layout = layout, label = labels, hide_nonsig_edges = TRUE, label_location = .60 )"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"latent-model","dir":"Articles","previous_headings":"SEM example","what":"Latent model","title":"Full CFA/SEM workflow","text":"Finally, perhaps change mind decide run full SEM instead, latent variables. Fear : don’t redo everything . can simply define latent variables proceed. example, already defined latent variable CFA earlier, don’t even need write ! Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.saturated 0.00 0 Inf 1.0 1.0 .00 [.00, .00] .00 3,483.46 3,539.02 fit.path 0.33 1 0.33 .568 1.0 1.3 .00 [.00, .13] -.00 3,481.79 3,533.64 fit.latent 118.92 37 3.21 < .001 .92 .89 .09 [.07, .10] .05 8,638.79 8,746.20 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3.","code":"model.latent <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, latent = latent, label = TRUE ) cat(model.latent) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 ## ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## age_visual_speed := ageyr_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Run model fit.latent <- sem(model.latent, data = HolzingerSwineford1939) # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path, fit.latent), nice_table = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-1-mediator-1-dv","dir":"Articles","previous_headings":"","what":"1 IV, 1 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Calculate scale averages data <- HolzingerSwineford1939 data$visual <- rowMeans(data[paste0(\"x\", 1:3)]) data$textual <- rowMeans(data[paste0(\"x\", 4:6)]) data$speed <- rowMeans(data[paste0(\"x\", 7:9)]) # Define our variables IV <- \"ageyr\" M <- \"visual\" DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## visual ~ ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-1-mediator-2-dvs","dir":"Articles","previous_headings":"","what":"1 IV, 1 mediator, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-2-mediator-1-dv","dir":"Articles","previous_headings":"","what":"1 IV, 2 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables M <- c(\"visual\", \"grade\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ ageyr_visual*ageyr ## grade ~ ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_grade_speed := ageyr_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-2-mediators-2-dvs","dir":"Articles","previous_headings":"","what":"1 IV, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ ageyr_visual*ageyr ## grade ~ ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-1-mediator-1-dv","dir":"Articles","previous_headings":"","what":"2 IVs, 1 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\") M <- \"visual\" DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV) # Define indirect object indirect <- list(M = M, DV = DV, IV = IV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-1-mediator-2-dvs","dir":"Articles","previous_headings":"","what":"2 IVs, 1 mediator, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) # Define indirect object indirect <- list(M = M, DV = DV, IV = IV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-1-dv","dir":"Articles","previous_headings":"","what":"2 IVs, 2 mediators, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables M <- c(\"visual\", \"grade\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## grade ~ sex_grade*sex + ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed ## sex_grade_speed := sex_grade * grade_speed ## ageyr_grade_speed := ageyr_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs","dir":"Articles","previous_headings":"","what":"2 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## grade ~ sex_grade*sex + ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-1-dv-1","dir":"Articles","previous_headings":"","what":"3 IVs, 2 mediators, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed ## agemo_visual_speed := agemo_visual * visual_speed ## sex_grade_speed := sex_grade * grade_speed ## ageyr_grade_speed := ageyr_grade * grade_speed ## agemo_grade_speed := agemo_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs-1","dir":"Articles","previous_headings":"","what":"3 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs-2","dir":"Articles","previous_headings":"","what":"6 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\", \"school\", \"x2\", \"x3\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school + x2_visual*x2 + x3_visual*x3 ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school + x2_grade*x2 + x3_grade*x3 ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## school_visual_speed := school_visual * visual_speed ## school_visual_textual := school_visual * visual_textual ## x2_visual_speed := x2_visual * visual_speed ## x2_visual_textual := x2_visual * visual_textual ## x3_visual_speed := x3_visual * visual_speed ## x3_visual_textual := x3_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual ## school_grade_speed := school_grade * grade_speed ## school_grade_textual := school_grade * grade_textual ## x2_grade_speed := x2_grade * grade_speed ## x2_grade_textual := x2_grade * grade_textual ## x3_grade_speed := x3_grade * grade_speed ## x3_grade_textual := x3_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-3-mediators-5-dvs","dir":"Articles","previous_headings":"","what":"6 IVs, 3 mediators, 5 DVs","title":"Automatic indirect effects","text":"Etc.","code":"# Define our variables M <- c(\"visual\", \"grade\", \"x8\") DV <- c(\"speed\", \"textual\", \"x4\", \"x5\", \"x7\") # Define our lavaan lists mediation <- list( speed = M, textual = M, x4 = M, x5 = M, x7 = M, x8 = IV, visual = IV, grade = IV ) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade + x8_speed*x8 ## textual ~ visual_textual*visual + grade_textual*grade + x8_textual*x8 ## x4 ~ visual_x4*visual + grade_x4*grade + x8_x4*x8 ## x5 ~ visual_x5*visual + grade_x5*grade + x8_x5*x8 ## x7 ~ visual_x7*visual + grade_x7*grade + x8_x7*x8 ## x8 ~ sex_x8*sex + ageyr_x8*ageyr + agemo_x8*agemo + school_x8*school + x2_x8*x2 + x3_x8*x3 ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school + x2_visual*x2 + x3_visual*x3 ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school + x2_grade*x2 + x3_grade*x3 ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## sex_visual_x4 := sex_visual * visual_x4 ## sex_visual_x5 := sex_visual * visual_x5 ## sex_visual_x7 := sex_visual * visual_x7 ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## ageyr_visual_x4 := ageyr_visual * visual_x4 ## ageyr_visual_x5 := ageyr_visual * visual_x5 ## ageyr_visual_x7 := ageyr_visual * visual_x7 ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## agemo_visual_x4 := agemo_visual * visual_x4 ## agemo_visual_x5 := agemo_visual * visual_x5 ## agemo_visual_x7 := agemo_visual * visual_x7 ## school_visual_speed := school_visual * visual_speed ## school_visual_textual := school_visual * visual_textual ## school_visual_x4 := school_visual * visual_x4 ## school_visual_x5 := school_visual * visual_x5 ## school_visual_x7 := school_visual * visual_x7 ## x2_visual_speed := x2_visual * visual_speed ## x2_visual_textual := x2_visual * visual_textual ## x2_visual_x4 := x2_visual * visual_x4 ## x2_visual_x5 := x2_visual * visual_x5 ## x2_visual_x7 := x2_visual * visual_x7 ## x3_visual_speed := x3_visual * visual_speed ## x3_visual_textual := x3_visual * visual_textual ## x3_visual_x4 := x3_visual * visual_x4 ## x3_visual_x5 := x3_visual * visual_x5 ## x3_visual_x7 := x3_visual * visual_x7 ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## sex_grade_x4 := sex_grade * grade_x4 ## sex_grade_x5 := sex_grade * grade_x5 ## sex_grade_x7 := sex_grade * grade_x7 ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## ageyr_grade_x4 := ageyr_grade * grade_x4 ## ageyr_grade_x5 := ageyr_grade * grade_x5 ## ageyr_grade_x7 := ageyr_grade * grade_x7 ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual ## agemo_grade_x4 := agemo_grade * grade_x4 ## agemo_grade_x5 := agemo_grade * grade_x5 ## agemo_grade_x7 := agemo_grade * grade_x7 ## school_grade_speed := school_grade * grade_speed ## school_grade_textual := school_grade * grade_textual ## school_grade_x4 := school_grade * grade_x4 ## school_grade_x5 := school_grade * grade_x5 ## school_grade_x7 := school_grade * grade_x7 ## x2_grade_speed := x2_grade * grade_speed ## x2_grade_textual := x2_grade * grade_textual ## x2_grade_x4 := x2_grade * grade_x4 ## x2_grade_x5 := x2_grade * grade_x5 ## x2_grade_x7 := x2_grade * grade_x7 ## x3_grade_speed := x3_grade * grade_speed ## x3_grade_textual := x3_grade * grade_textual ## x3_grade_x4 := x3_grade * grade_x4 ## x3_grade_x5 := x3_grade * grade_x5 ## x3_grade_x7 := x3_grade * grade_x7 ## sex_x8_speed := sex_x8 * x8_speed ## sex_x8_textual := sex_x8 * x8_textual ## sex_x8_x4 := sex_x8 * x8_x4 ## sex_x8_x5 := sex_x8 * x8_x5 ## sex_x8_x7 := sex_x8 * x8_x7 ## ageyr_x8_speed := ageyr_x8 * x8_speed ## ageyr_x8_textual := ageyr_x8 * x8_textual ## ageyr_x8_x4 := ageyr_x8 * x8_x4 ## ageyr_x8_x5 := ageyr_x8 * x8_x5 ## ageyr_x8_x7 := ageyr_x8 * x8_x7 ## agemo_x8_speed := agemo_x8 * x8_speed ## agemo_x8_textual := agemo_x8 * x8_textual ## agemo_x8_x4 := agemo_x8 * x8_x4 ## agemo_x8_x5 := agemo_x8 * x8_x5 ## agemo_x8_x7 := agemo_x8 * x8_x7 ## school_x8_speed := school_x8 * x8_speed ## school_x8_textual := school_x8 * x8_textual ## school_x8_x4 := school_x8 * x8_x4 ## school_x8_x5 := school_x8 * x8_x5 ## school_x8_x7 := school_x8 * x8_x7 ## x2_x8_speed := x2_x8 * x8_speed ## x2_x8_textual := x2_x8 * x8_textual ## x2_x8_x4 := x2_x8 * x8_x4 ## x2_x8_x5 := x2_x8 * x8_x5 ## x2_x8_x7 := x2_x8 * x8_x7 ## x3_x8_speed := x3_x8 * x8_speed ## x3_x8_textual := x3_x8 * x8_textual ## x3_x8_x4 := x3_x8 * x8_x4 ## x3_x8_x5 := x3_x8 * x8_x5 ## x3_x8_x7 := x3_x8 * x8_x7 # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) labels <- list( sex = \"Sex\", ageyr = \"Age (year)\", agemo = \"Age (month)\", school = \"School\", x2 = \"Item 2\", x3 = \"Item 3\", visual = \"Visual\", grade = \"Grade\", x8 = \"Item 8\", speed = \"Speed\", textual = \"Textual\", x4 = \"Item 4\", x5 = \"Item 5\", x7 = \"Item 7\" ) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE, label = labels)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"other-scenarios","dir":"Articles","previous_headings":"","what":"Other scenarios","title":"Automatic indirect effects","text":"experience issues scenarios, please open GitHub issue example, try adapt function support case. Thank !","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/regression.html","id":"regression-example","dir":"Articles","previous_headings":"","what":"Regression example","title":"Regressions","text":"Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) mpg cyl 0.70 -1.17 .244 -0.81 [-2.18, 0.55] -0.24 [-0.65, 0.16] mpg disp 0.01 -1.54 .123 -0.01 [-0.03, 0.00] -0.29 [-0.65, 0.08] mpg hp 0.02 -1.52 .128 -0.02 [-0.05, 0.01] -0.26 [-0.60, 0.07] mpg drat 1.53 1.41 .159 2.15 [-0.84, 5.15] 0.19 [-0.07, 0.46] disp hp 0.23 1.35 .177 0.32 [-0.14, 0.78] 0.18 [-0.08, 0.43] disp drat 19.37 -2.12 .034* -41.13 [-79.09, -3.17] -0.18 [-0.34, -0.02] disp wt 14.04 5.54 < .001*** 77.72 [50.20, 105.24] 0.61 [0.41, 0.82] disp qsec 6.89 -1.87 .061 -12.91 [-26.42, 0.59] -0.19 [-0.38, 0.01]","code":"# Load libraries library(lavaan) library(lavaanExtra) # Define our regression terms regression <- list( mpg = names(mtcars)[2:5], disp = names(mtcars)[4:7] ) # Write the model, and check it mtcars.model <- write_lavaan(regression = regression) cat(mtcars.model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## mpg ~ cyl + disp + hp + drat ## disp ~ hp + drat + wt + qsec # Fit the model with `lavaan` fit.reg <- sem(mtcars.model, data = mtcars) # Get regression parameters only lavaan_reg(fit.reg) ## Outcome Predictor SE Z p b ## 1 mpg cyl 0.69815671 -1.165959 2.436311e-01 -0.81402201 ## 2 mpg disp 0.00901291 -1.541816 1.231184e-01 -0.01389625 ## 3 mpg hp 0.01521110 -1.523275 1.276900e-01 -0.02317068 ## 4 mpg drat 1.52814327 1.409583 1.586627e-01 2.15404553 ## 5 disp hp 0.23487240 1.348926 1.773606e-01 0.31682557 ## 6 disp drat 19.36831070 -2.123660 3.369862e-02 -41.13169751 ## 7 disp wt 14.04152370 5.535006 3.112178e-08 77.71991684 ## 8 disp qsec 6.88881338 -1.874538 6.085630e-02 -12.91334294 ## CI_lower CI_upper B CI_lower_B CI_upper_B ## 1 -2.18238402 0.554339998 -0.2419101 -0.64651698 0.162696788 ## 2 -0.03156123 0.003768732 -0.2865893 -0.64840670 0.075228183 ## 3 -0.05298388 0.006642523 -0.2643524 -0.60156925 0.072864499 ## 4 -0.84106024 5.149151295 0.1916475 -0.07287256 0.456167633 ## 5 -0.14351587 0.777167015 0.1752679 -0.07855326 0.429088994 ## 6 -79.09288894 -3.170506091 -0.1774445 -0.33986967 -0.015019402 ## 7 50.19903609 105.240797584 0.6135746 0.40870132 0.818447825 ## 8 -26.41516906 0.588483178 -0.1861841 -0.37961141 0.007243262 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.reg, nice_table = TRUE, highlight = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"regression","dir":"Articles","previous_headings":"","what":"regression","title":"How to use `write_lavaan()`","text":"regression argument shorthand ~ operator. example usage, see Regression vignette.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"covariance","dir":"Articles","previous_headings":"","what":"covariance","title":"How to use `write_lavaan()`","text":"covariance argument shorthand ~~ operator. example usage, see Example 1.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"intercept","dir":"Articles","previous_headings":"","what":"intercept","title":"How to use `write_lavaan()`","text":"latent argument shorthand ~ 1 operator. example usage, see Example 1.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"latent","dir":"Articles","previous_headings":"","what":"latent","title":"How to use `write_lavaan()`","text":"latent argument shorthand =~ operator. example usage see Example 2.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"constraints","dir":"Articles","previous_headings":"","what":"constraints","title":"How to use `write_lavaan()`","text":"Constraints can specified constraint.equal, constraint.smaller, constraint.larger argument, showcased Example 4.6.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"mediation","dir":"Articles","previous_headings":"","what":"mediation","title":"How to use `write_lavaan()`","text":"mediation argument also shorthand ~ operator. However, difference regression argument can automatically specify path names argument label set TRUE. also possible name paths letters instead variable names setting use.letters = TRUE. example usage, see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"indirect","dir":"Articles","previous_headings":"","what":"indirect","title":"How to use `write_lavaan()`","text":"indirect argument shorthand := operator. example usage, see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"user-defined-parameters","dir":"Articles","previous_headings":"","what":"user-defined parameters","title":"How to use `write_lavaan()`","text":"user-defined parameters (e.g,. total effects), see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"custom","dir":"Articles","previous_headings":"","what":"custom","title":"How to use `write_lavaan()`","text":"Sometimes, elements specified arguments, custom argument becomes handy make tailored specifications, Multilevel SEM Example 6. custom argument can also useful specify thresholds “|” operator. example usage, see Example 10.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Rémi Thériault. Author, maintainer.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Thériault, R., (2023). lavaanExtra: Convenience Functions Package lavaan. *Journal Open Source Software*, *8*(90), 5701, https://doi.org/10.21105/joss.05701","code":"@Article{, doi = {10.21105/joss.05701}, url = {https://doi.org/10.21105/joss.05701}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {90}, pages = {5701}, author = {Rémi Thériault}, title = {lavaanExtra: Convenience functions for lavaan}, journal = {Journal of Open Source Software}, }"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"lavaanextra-convenience-functions-for-lavaan","dir":"","previous_headings":"","what":"Convenience Functions for Package lavaan","title":"Convenience Functions for Package lavaan","text":"Affords alternative, vector-based syntax lavaan, well convenience functions naming paths defining indirect links automatically. Also offers convenience formatting optimized publication script sharing workflow.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Convenience Functions for Package lavaan","text":"can install lavaanExtra package directly CRAN: development version r-universe (note 24-hour delay GitHub): GitHub, latest version: see available functions, use: Dependencies: lavaanExtra package convenience functions relying several external packages, uses (inspired easystats packages) minimalist philosophy installing packages need need rlang::check_installed(). wish specifically install suggested dependencies (can view full list clicking CRAN badge page), can run following (warned may take long time, suggested packages used vignettes examples):","code":"install.packages(\"lavaanExtra\") install.packages(\"lavaanExtra\", repos = c( rempsyc = \"https://rempsyc.r-universe.dev\", CRAN = \"https://cloud.r-project.org\")) # If not already installed, install package `remotes` with `install.packages(\"remotes\")` remotes::install_github(\"rempsyc/lavaanExtra\") help(package = \"lavaanExtra\") install.packages(\"lavaanExtra\", dependencies = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"why-use-lavaanextra","dir":"","previous_headings":"","what":"Why use lavaanExtra?","title":"Convenience Functions for Package lavaan","text":"Reusable code. Don’t repeat anymore want change things comparing fitting models. Shorter code. point 1, can shorter code, since write simply reuse . items similar patterns, can also use paste0() appropriate item numbers instead typing one every time. Less error-prone code. point 1, can less risk human errors since don’t possibly multiple different version thing (makes easier correct ). Better control code. point 1, control whole flow. change , change everywhere else script, without change manually model. readable code. point 1, people (also ) process information first time make sure ’s specified correctly, every time check new models. Prettier code. format model pretty way, every time. don’t worry manually making model good-looking readable anymore. accessible code. don’t remember exact syntax (although recommended) work. uses intuitive variable names people can understand. benefit apparent beginners, also saves precious typing time veterans.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Convenience Functions for Package lavaan","text":"CFA example SEM example Final note","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"cfa-example","dir":"","previous_headings":"","what":"CFA example","title":"Convenience Functions for Package lavaan","text":"","code":"# Load libraries library(lavaan) library(lavaanExtra) # Define latent variables latent <- list( visual = c(\"x1\", \"x2\", \"x3\"), textual = c(\"x4\", \"x5\", \"x6\"), speed = c(\"x7\", \"x8\", \"x9\") ) # If you have many items, you can also use the `paste0` function: x <- paste0(\"x\", 1:9) latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] ) # Write the model, and check it cfa.model <- write_lavaan(latent = latent) cat(cfa.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (optionally as PDF) fit.cfa <- cfa_fit_plot(cfa.model, HolzingerSwineford1939) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> Standard Scaled #> Test Statistic 85.306 87.132 #> Degrees of freedom 24 24 #> P-value (Chi-square) 0.000 0.000 #> Scaling correction factor 0.979 #> Yuan-Bentler correction (Mplus variant) #> #> Model Test Baseline Model: #> #> Test statistic 918.852 880.082 #> Degrees of freedom 36 36 #> P-value 0.000 0.000 #> Scaling correction factor 1.044 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 0.925 #> Tucker-Lewis Index (TLI) 0.896 0.888 #> #> Robust Comparative Fit Index (CFI) 0.930 #> Robust Tucker-Lewis Index (TLI) 0.895 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 -3737.745 #> Scaling correction factor 1.133 #> for the MLR correction #> Loglikelihood unrestricted model (H1) -3695.092 -3695.092 #> Scaling correction factor 1.051 #> for the MLR correction #> #> Akaike (AIC) 7517.490 7517.490 #> Bayesian (BIC) 7595.339 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 0.093 #> 90 Percent confidence interval - lower 0.071 0.073 #> 90 Percent confidence interval - upper 0.114 0.115 #> P-value H_0: RMSEA <= 0.050 0.001 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 0.862 #> #> Robust RMSEA 0.092 #> 90 Percent confidence interval - lower 0.072 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: Robust RMSEA <= 0.050 0.001 #> P-value H_0: Robust RMSEA >= 0.080 0.849 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 0.065 #> #> Parameter Estimates: #> #> Standard errors Sandwich #> Information bread Observed #> Observed information based on Hessian #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual =~ #> x1 1.000 0.900 0.772 #> x2 0.554 0.132 4.191 0.000 0.498 0.424 #> x3 0.729 0.141 5.170 0.000 0.656 0.581 #> textual =~ #> x4 1.000 0.990 0.852 #> x5 1.113 0.066 16.946 0.000 1.102 0.855 #> x6 0.926 0.061 15.089 0.000 0.917 0.838 #> speed =~ #> x7 1.000 0.619 0.570 #> x8 1.180 0.130 9.046 0.000 0.731 0.723 #> x9 1.082 0.266 4.060 0.000 0.670 0.665 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual ~~ #> textual 0.408 0.099 4.110 0.000 0.459 0.459 #> speed 0.262 0.060 4.366 0.000 0.471 0.471 #> textual ~~ #> speed 0.173 0.056 3.081 0.002 0.283 0.283 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> .x1 0.549 0.156 3.509 0.000 0.549 0.404 #> .x2 1.134 0.112 10.135 0.000 1.134 0.821 #> .x3 0.844 0.100 8.419 0.000 0.844 0.662 #> .x4 0.371 0.050 7.382 0.000 0.371 0.275 #> .x5 0.446 0.057 7.870 0.000 0.446 0.269 #> .x6 0.356 0.047 7.658 0.000 0.356 0.298 #> .x7 0.799 0.097 8.222 0.000 0.799 0.676 #> .x8 0.488 0.120 4.080 0.000 0.488 0.477 #> .x9 0.566 0.119 4.768 0.000 0.566 0.558 #> visual 0.809 0.180 4.486 0.000 1.000 1.000 #> textual 0.979 0.121 8.075 0.000 1.000 1.000 #> speed 0.384 0.107 3.596 0.000 1.000 1.000 #> #> R-Square: #> Estimate #> x1 0.596 #> x2 0.179 #> x3 0.338 #> x4 0.725 #> x5 0.731 #> x6 0.702 #> x7 0.324 #> x8 0.523 #> x9 0.442 # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(fit.cfa, nice_table = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"sem-example","dir":"","previous_headings":"","what":"SEM example","title":"Convenience Functions for Package lavaan","text":"Note latent variables defined , can reuse , without redefine .","code":"# Define our other variables M <- \"visual\" IV <- c(\"ageyr\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) regression <- list(speed = IV, textual = IV) covariance <- list(speed = \"textual\", ageyr = \"grade\") # Define indirect effects object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, latent = latent, label = TRUE ) cat(model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> speed ~ ageyr + grade #> textual ~ ageyr + grade #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual fit.sem <- sem(model, data = HolzingerSwineford1939) # Get regression parameters and make pretty with `rempsyc::nice_table` lavaan_reg(fit.sem, nice_table = TRUE, highlight = TRUE) # Get covariances/correlations and make them pretty with # the `rempsyc::nice_table` integration lavaan_cor(fit.sem, nice_table = TRUE) # Get nice fit indices with the `rempsyc::nice_table` integration fit_table <- nice_fit(list(fit.cfa, fit.sem), nice_table = TRUE) fit_table # Save fit table to Word! flextable::save_as_docx(fit_table, path = \"fit_table.docx\") # Note that it will also render to PDF in an `rmarkdown` document # with `output: pdf_document`, but using `latex_engine: xelatex` # is necessary when including Unicode symbols in tables like with # the `nice_fit()` function. # Let's get the user-defined (e.g., indirect) effects only and make it pretty # with the `rempsyc::nice_table` integration lavaan_defined(fit.sem, nice_table = TRUE) # Plot our model nice_lavaanPlot(fit.sem) # Alternative way to plot mylayout <- data.frame( IV = c(\"\", \"x1\", \"grade\", \"\", \"ageyr\", \"\", \"\"), M = c(\"\", \"x2\", \"\", \"visual\", \"\", \"\", \"\"), DV = c(\"\", \"x3\", \"textual\", \"\", \"speed\", \"\", \"\"), DV.items = c(paste0(\"x\", 4:6), \"\", paste0(\"x\", 7:9)) ) |> as.matrix() mylayout #> IV M DV DV.items #> [1,] \"\" \"\" \"\" \"x4\" #> [2,] \"x1\" \"x2\" \"x3\" \"x5\" #> [3,] \"grade\" \"\" \"textual\" \"x6\" #> [4,] \"\" \"visual\" \"\" \"\" #> [5,] \"ageyr\" \"\" \"speed\" \"x7\" #> [6,] \"\" \"\" \"\" \"x8\" #> [7,] \"\" \"\" \"\" \"x9\" nice_tidySEM(fit.sem, layout = mylayout, label_location = 0.7) ggplot2::ggsave(\"my_semPlot.pdf\", width = 6, height = 6, limitsize = FALSE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"final-note","dir":"","previous_headings":"","what":"Final note","title":"Convenience Functions for Package lavaan","text":"experimental package early stage. feedback feature request appreciated, package likely change evolve time based community feedback. Feel free open issue discussion share questions concerns. course, please look tutorials discover even cool features: https://lavaanExtra.remi-theriault.com/articles/","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"support-me-and-this-package","dir":"","previous_headings":"","what":"Support me and this package","title":"Convenience Functions for Package lavaan","text":"Thank support. can support package : https://github.com/sponsors/rempsyc","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit and plot CFA simultaneously — cfa_fit_plot","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"Prints saves CFA fit, well plots CFA factor loadings, simultaneously.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"","code":"cfa_fit_plot( model, data, covs = FALSE, estimator = \"MLR\", remove.items = \"\", print = TRUE, save.as.pdf = FALSE, file.name, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"model CFA model fit. data Data set fit CFA model. covs Logical, whether include covariances lavaan plot. estimator estimator use CFA. remove.items Optional, one wants remove items CFA model without redefine completely . print Logical, whether print model summary console. save..pdf Logical, whether save PDF high-resolution, scalable vector graphic quality plot. Defaults saving \"/model\" subfolder working directory. exist, creates . automatically open created PDF default browser. Defaults false. file.name Optional (save..pdf set TRUE), one wants something different default file name. saves pdf per default, .pdf extension specified add automatically. ... Arguments passed function lavaan::cfa.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"function returns lavaan fit object. However, also: prints summary lavaan fit object console, ; prints lavaanPlot lavaan fit object.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) #> This is lavaan 0.6-18 #> lavaan is FREE software! Please report any bugs. fit <- cfa_fit_plot(HS.model, HolzingerSwineford1939) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> Standard Scaled #> Test Statistic 85.306 87.132 #> Degrees of freedom 24 24 #> P-value (Chi-square) 0.000 0.000 #> Scaling correction factor 0.979 #> Yuan-Bentler correction (Mplus variant) #> #> Model Test Baseline Model: #> #> Test statistic 918.852 880.082 #> Degrees of freedom 36 36 #> P-value 0.000 0.000 #> Scaling correction factor 1.044 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 0.925 #> Tucker-Lewis Index (TLI) 0.896 0.888 #> #> Robust Comparative Fit Index (CFI) 0.930 #> Robust Tucker-Lewis Index (TLI) 0.895 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 -3737.745 #> Scaling correction factor 1.133 #> for the MLR correction #> Loglikelihood unrestricted model (H1) -3695.092 -3695.092 #> Scaling correction factor 1.051 #> for the MLR correction #> #> Akaike (AIC) 7517.490 7517.490 #> Bayesian (BIC) 7595.339 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 0.093 #> 90 Percent confidence interval - lower 0.071 0.073 #> 90 Percent confidence interval - upper 0.114 0.115 #> P-value H_0: RMSEA <= 0.050 0.001 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 0.862 #> #> Robust RMSEA 0.092 #> 90 Percent confidence interval - lower 0.072 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: Robust RMSEA <= 0.050 0.001 #> P-value H_0: Robust RMSEA >= 0.080 0.849 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 0.065 #> #> Parameter Estimates: #> #> Standard errors Sandwich #> Information bread Observed #> Observed information based on Hessian #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual =~ #> x1 1.000 0.900 0.772 #> x2 0.554 0.132 4.191 0.000 0.498 0.424 #> x3 0.729 0.141 5.170 0.000 0.656 0.581 #> textual =~ #> x4 1.000 0.990 0.852 #> x5 1.113 0.066 16.946 0.000 1.102 0.855 #> x6 0.926 0.061 15.089 0.000 0.917 0.838 #> speed =~ #> x7 1.000 0.619 0.570 #> x8 1.180 0.130 9.046 0.000 0.731 0.723 #> x9 1.082 0.266 4.060 0.000 0.670 0.665 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual ~~ #> textual 0.408 0.099 4.110 0.000 0.459 0.459 #> speed 0.262 0.060 4.366 0.000 0.471 0.471 #> textual ~~ #> speed 0.173 0.056 3.081 0.002 0.283 0.283 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> .x1 0.549 0.156 3.509 0.000 0.549 0.404 #> .x2 1.134 0.112 10.135 0.000 1.134 0.821 #> .x3 0.844 0.100 8.419 0.000 0.844 0.662 #> .x4 0.371 0.050 7.382 0.000 0.371 0.275 #> .x5 0.446 0.057 7.870 0.000 0.446 0.269 #> .x6 0.356 0.047 7.658 0.000 0.356 0.298 #> .x7 0.799 0.097 8.222 0.000 0.799 0.676 #> .x8 0.488 0.120 4.080 0.000 0.488 0.477 #> .x9 0.566 0.119 4.768 0.000 0.566 0.558 #> visual 0.809 0.180 4.486 0.000 1.000 1.000 #> textual 0.979 0.121 8.075 0.000 1.000 1.000 #> speed 0.384 0.107 3.596 0.000 1.000 1.000 #> #> R-Square: #> Estimate #> x1 0.596 #> x2 0.179 #> x3 0.338 #> x4 0.725 #> x5 0.731 #> x6 0.702 #> x7 0.324 #> x8 0.523 #> x9 0.442 #>"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaanExtra-package.html","id":null,"dir":"Reference","previous_headings":"","what":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","title":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","text":"Affords alternative, vector-based syntax 'lavaan', well convenience functions naming paths defining indirect links automatically, addition convenience formatting optimized publication script sharing workflow.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaanExtra-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","text":"Maintainer: Rémi Thériault remi.theriault@mail.mcgill.ca (ORCID)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"Extract relevant covariance/correlation indices lavaan lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"","code":"lavaan_cov(fit, nice_table = FALSE, ...) lavaan_cor(fit, nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"fit lavaan fit object extract covariance indices nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"dataframe covariances/correlation, including covaried variables, covariance/correlation, corresponding p-value.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"lavaan_cor(): Shortcut lavaan_cov(fit, estimate = \"r\")","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> (covariance <- list(speed = \"textual\", ageyr = \"grade\")) #> $speed #> [1] \"textual\" #> #> $ageyr #> [1] \"grade\" #> HS.model <- write_lavaan( regression = regression, covariance = covariance, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_cov(fit) #> Variable 1 Variable 2 SE Z p sigma CI_lower #> 16 textual speed 0.05102682 3.411223 6.467214e-04 0.1740639 0.07405313 #> 17 ageyr grade 0.03077116 7.488490 6.972201e-14 0.2304295 0.17011916 #> 32 visual textual 0.07430296 5.572306 2.513899e-08 0.4140388 0.26840769 #> 33 visual speed 0.05710260 4.545270 5.486495e-06 0.2595467 0.14762767 #> CI_upper r CI_lower_r CI_upper_r #> 16 0.2740746 0.2679391 0.1331814 0.4026968 #> 17 0.2907399 0.5332236 0.4471455 0.6193016 #> 32 0.5596700 0.4583362 0.3334309 0.5832415 #> 33 0.3714657 0.4384508 0.2944977 0.5824039"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"Extract relevant user-defined parameters (e.g., indirect total effects) indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"","code":"lavaan_defined( fit, underscores_to_symbol = \"→\", lhs_name = \"User-Defined Parameter\", rhs_name = \"Paths\", nice_table = FALSE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"fit lavaan fit object extract fit indices underscores_to_symbol Character convert underscores arrows first column, like indirect effects. Default right arrow symbol, can set NULL \"_\", desired symbol. also possible provide vector replacements . lhs_name Name first column, referring left-hand side expression (lhs). rhs_name Name first column, referring right-hand side expression (rhs). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"dataframe, including indirect effect (\"lhs\"), corresponding paths (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (mediation <- list( speed = \"visual\", textual = \"visual\", visual = c(\"ageyr\", \"grade\") )) #> $speed #> [1] \"visual\" #> #> $textual #> [1] \"visual\" #> #> $visual #> [1] \"ageyr\" \"grade\" #> (indirect <- list( IV = c(\"ageyr\", \"grade\"), M = \"visual\", DV = c(\"speed\", \"textual\") )) #> $IV #> [1] \"ageyr\" \"grade\" #> #> $M #> [1] \"visual\" #> #> $DV #> [1] \"speed\" \"textual\" #> HS.model <- write_lavaan(mediation, indirect = indirect, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_defined(fit, lhs_name = \"Indirect Effect\") #> Indirect Effect Paths SE Z #> 30 ageyr → visual → speed ageyr_visual*visual_speed 0.02808889 -3.198387 #> 31 ageyr → visual → textual ageyr_visual*visual_textual 0.04191650 -3.461890 #> 32 grade → visual → speed grade_visual*visual_speed 0.07291514 4.257496 #> 33 grade → visual → textual grade_visual*visual_textual 0.10134908 4.947490 #> p b CI_lower CI_upper B CI_lower_B #> 30 1.381987e-03 -0.08983914 -0.1448924 -0.03478593 -0.1508037 -0.2358595 #> 31 5.363956e-04 -0.14511033 -0.2272652 -0.06295550 -0.1534909 -0.2371048 #> 32 2.067294e-05 0.31043593 0.1675249 0.45334698 0.2477787 0.1503789 #> 33 7.517664e-07 0.50142352 0.3027830 0.70006406 0.2521937 0.1601663 #> CI_upper_B #> 30 -0.06574796 #> 31 -0.06987694 #> 32 0.34517843 #> 33 0.34422119"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"Extract relevant indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"","code":"lavaan_extract( fit, operator = NULL, lhs_name = \"Left-Hand Side\", rhs_name = \"Right-Hand Side\", underscores_to_symbol = \"→\", diag = NULL, nice_table = FALSE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"fit lavaan fit object extract fit indices operator operator subselect . lhs_name Name first column, referring left-hand side expression (lhs). rhs_name Name first column, referring right-hand side expression (rhs). underscores_to_symbol Character convert underscores arrows first column, like indirect effects. Default right arrow symbol, can set NULL \"_\", desired symbol. also possible provide vector replacements . diag extracting covariances (~~), whether include exclude diagonal values (one \"exclude\" \"include\"). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"dataframe, including indirect effect (\"lhs\"), corresponding paths (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (mediation <- list( speed = \"visual\", textual = \"visual\", visual = c(\"ageyr\", \"grade\") )) #> $speed #> [1] \"visual\" #> #> $textual #> [1] \"visual\" #> #> $visual #> [1] \"ageyr\" \"grade\" #> (indirect <- list( IV = c(\"ageyr\", \"grade\"), M = \"visual\", DV = c(\"speed\", \"textual\") )) #> $IV #> [1] \"ageyr\" \"grade\" #> #> $M #> [1] \"visual\" #> #> $DV #> [1] \"speed\" \"textual\" #> HS.model <- write_lavaan(mediation, indirect = indirect, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_extract(fit, lhs_name = \"Indirect Effect\", operator = \":=\") #> Indirect Effect Right-Hand Side SE Z #> 30 ageyr → visual → speed ageyr_visual*visual_speed 0.02808889 -3.198387 #> 31 ageyr → visual → textual ageyr_visual*visual_textual 0.04191650 -3.461890 #> 32 grade → visual → speed grade_visual*visual_speed 0.07291514 4.257496 #> 33 grade → visual → textual grade_visual*visual_textual 0.10134908 4.947490 #> p b CI_lower CI_upper B CI_lower_B #> 30 1.381987e-03 -0.08983914 -0.1448924 -0.03478593 -0.1508037 -0.2358595 #> 31 5.363956e-04 -0.14511033 -0.2272652 -0.06295550 -0.1534909 -0.2371048 #> 32 2.067294e-05 0.31043593 0.1675249 0.45334698 0.2477787 0.1503789 #> 33 7.517664e-07 0.50142352 0.3027830 0.70006406 0.2521937 0.1601663 #> CI_upper_B #> 30 -0.06574796 #> 31 -0.06987694 #> 32 0.34517843 #> 33 0.34422119"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant regression indices from lavaan model — lavaan_reg","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"Extract relevant regression indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"","code":"lavaan_reg(fit, nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"fit lavaan fit object extract fit indices nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"dataframe, including outcome (\"lhs\"), predictor (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_reg(fit) #> Outcome Predictor SE Z p b CI_lower #> 10 ageyr visual 0.10223059 -0.6515452 5.146946e-01 -0.06660785 -0.26697612 #> 11 ageyr textual 0.07452101 -4.3003671 1.705154e-05 -0.32046768 -0.46652617 #> 12 ageyr speed 0.13527746 4.2102536 2.550842e-05 0.56955240 0.30441346 #> 13 grade visual 0.04763058 0.2303820 8.177950e-01 0.01097323 -0.08238099 #> 14 grade textual 0.03444008 1.4407968 1.496421e-01 0.04962116 -0.01788016 #> 15 grade speed 0.06427861 4.6357654 3.556191e-06 0.29798057 0.17199681 #> CI_upper B CI_lower_B CI_upper_B #> 10 0.1337604 -0.05753255 -0.22998065 0.1149156 #> 11 -0.1744092 -0.30377383 -0.43682901 -0.1707186 #> 12 0.8346913 0.35378347 0.20775141 0.4998155 #> 13 0.1043274 0.01993320 -0.14957182 0.1894382 #> 14 0.1171225 0.09892078 -0.03509861 0.2329402 #> 15 0.4239643 0.38926587 0.24802239 0.5305094"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant variance indices from lavaan model — lavaan_var","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"Extract relevant variance indices lavaan model lavaan::parameterEstimates (estimate = \"sigma\", est column)) lavaan::standardizedsolution (estimate = \"r2\", est.std column). R2 values calculated 1 - est.std, new p values R2, following formula: stats::pnorm((1 - est) / se).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"","code":"lavaan_var(fit, estimate = \"r2\", nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"fit lavaan fit object extract covariance indices estimate estimate use, either standardized estimate (\"r2\", default), unstandardized estimate (\"sigma2\"). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"dataframe covariances/correlation, including covaried variables, covariance/correlation, corresponding p-value.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> (covariance <- list(speed = \"textual\", ageyr = \"grade\")) #> $speed #> [1] \"textual\" #> #> $ageyr #> [1] \"grade\" #> HS.model <- write_lavaan( regression = regression, covariance = covariance, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_var(fit) #> Variable p R2 CI_lower CI_upper #> 18 x1 0 0.605 0.436 0.773 #> 19 x2 0 0.180 0.081 0.280 #> 20 x3 0 0.333 0.208 0.458 #> 21 x4 0 0.732 0.659 0.806 #> 22 x5 0 0.736 0.663 0.809 #> 23 x6 0 0.689 0.612 0.765 #> 24 x7 0 0.359 0.241 0.476 #> 25 x8 0 0.563 0.428 0.699 #> 26 x9 0 0.390 0.270 0.511 #> 27 ageyr 0 0.161 0.068 0.255 #> 28 grade 0 0.191 0.095 0.287 #> 29 visual NaN 0.000 0.000 0.000 #> 30 textual NaN 0.000 0.000 0.000 #> 31 speed 0 0.000 0.000 0.000"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant fit indices from lavaan model — nice_fit","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Compares fit one several lavaan models. Also optionally includes references values. reference fit values based Schreiber (2017), Table 3.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"","code":"nice_fit( model, model.labels, nice_table = FALSE, guidelines = TRUE, stars = FALSE, verbose = TRUE )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"model lavaan model object(s) extract fit indices model.labels Model labels use. named list provided model, default names list. Otherwise, list unnamed, defaults generic numbering. nice_table Logical, whether print table rempsyc::nice_table. guidelines Logical, nice_table = TRUE, whether display include reference values based Schreiber (2017), Table 3, bottom table. stars Logical, nice_table = TRUE, whether display significance stars (defaults FALSE). verbose Logical, whether display messages warnings.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"dataframe, representing select fit indices (chi2, df, chi2/df, p-value chi2 test, CFI, TLI, RMSEA 90% CI, unbiased SRMR, AIC, BIC).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Note nice_fit reports unbiased SRMR lavaan::lavResiduals() standard SRMR upwardly biased (doi:10.1007/s11336-016-9552-7 ) noticeable way smaller samples (thanks James Uanhoro change). using guidelines = TRUE, please carefully consider following 2023 quote Terrence D. Jorgensen: recommend including cutoffs table, perpetuate misuse. Fit indices test statistics, suggested cutoffs critical values associated known Type error rates. Numerous simulation studies shown poorly cutoffs perform model selection (e.g., , Jorgensen et al. (2018). Instead test statistics, fit indices designed measures effect size (practical significance), complement chi-squared test statistical significance. range RMSEA interpretations reminiscent range small/medium/large effect sizes proposed Cohen use power analyses, arbitrary alpha levels, least better respect idea (mis)fit matter magnitude, nearly simple \"perfect imperfect.\"","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Schreiber, J. B. (2017). Update core reporting practices structural equation modeling. Research social administrative pharmacy, 13(3), 634-643. doi:10.1016/j.sapharm.2016.06.006","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) nice_fit(fit) #> Model chisq df chi2.df pvalue cfi tli rmsea rmsea.ci.lower #> 1 Model 1 116.263 36 3.23 0 0.926 0.887 0.086 0.069 #> rmsea.ci.upper srmr aic bic #> 1 0.104 0.052 8638.134 8749.248"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a quick lavaanPlot — nice_lavaanPlot","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"Make quick decent-looking lavaanPlot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"","code":"nice_lavaanPlot( model, node_options = list(shape = \"box\", fontname = \"Helvetica\"), edge_options = c(color = \"black\"), coefs = TRUE, stand = TRUE, covs = FALSE, stars = c(\"regress\", \"latent\", \"covs\"), sig = 0.05, graph_options = c(rankdir = \"LR\"), ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"model SEM CFA model plot. node_options Shape font name. edge_options Colour edges. coefs Logical, whether plot coefficients. Defaults TRUE. stand Logical, whether use standardized coefficients. Defaults TRUE. covs Logical, whether plot covariances. Defaults FALSE. stars links plot significance stars . One c(\"regress\", \"latent\", \"covs\"). sig significance threshold use plot coefficients (defaults .05). plot coefficients, set sig 1. graph_options Read left right, rather top bottom. ... Arguments passed function lavaanPlot::lavaanPlot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"lavaanPlot, classes c(\"grViz\", \"htmlwidget\"), representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) fit <- cfa(HS.model, HolzingerSwineford1939) nice_lavaanPlot(fit) {\"x\":{\"diagram\":\" digraph plot { \\n graph [ rankdir = LR ] \\n node [ shape = box, fontname = Helvetica ] \\n node [shape = box] \\n x1; x2; x3; x4; x5; x6; x7; x8; x9 \\n node [shape = oval] \\n visual; textual; speed \\n \\n edge [ color = black ] \\n visual->x1 [label = \\\"0.77***\\\"] visual->x2 [label = \\\"0.42***\\\"] visual->x3 [label = \\\"0.58***\\\"] textual->x4 [label = \\\"0.85***\\\"] textual->x5 [label = \\\"0.86***\\\"] textual->x6 [label = \\\"0.84***\\\"] speed->x7 [label = \\\"0.57***\\\"] speed->x8 [label = \\\"0.72***\\\"] speed->x9 [label = \\\"0.67***\\\"] \\n}\",\"config\":{\"engine\":\"dot\",\"options\":null}},\"evals\":[],\"jsHooks\":[]}"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant modification indices along item labels — nice_modindices","title":"Extract relevant modification indices along item labels — nice_modindices","text":"Extract relevant modification indices along item labels, similarity score provided help guide decision-making removing redundant items high covariance.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant modification indices along item labels — nice_modindices","text":"","code":"nice_modindices(fit, labels = NULL, method = \"lcs\", sort = TRUE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant modification indices along item labels — nice_modindices","text":"fit lavaan fit object extract modification indices labels Dataframe labels. original data frame provided, contains labelled variables, automatically attempt extract correct labels dataframe. method Method distance calculation stringdist::stringsim. Defaults \"lcs\". sort Logical. TRUE, sort output using values modification index values. Higher values appear first. Defaults TRUE. ... Arguments passed lavaan::modindices","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant modification indices along item labels — nice_modindices","text":"dataframe, including outcome (\"lhs\"), predictor (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant modification indices along item labels — nice_modindices","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) nice_modindices(fit, maximum.number = 5) #> lhs op rhs mi #> 1 visual =~ x9 35.699 #> 2 visual =~ x7 16.659 #> 3 x7 ~~ grade 16.511 #> 4 x7 ~~ ageyr 10.030 #> 5 textual =~ x3 9.833 data_labels <- data.frame( x1 = \"I have good visual perception\", x2 = \"I have good cube perception\", x3 = \"I have good at lozenge perception\", x4 = \"I have paragraph comprehension\", x5 = \"I am good at sentence completion\", x6 = \"I excel at finding the meaning of words\", x7 = \"I am quick at doing mental additions\", x8 = \"I am quick at counting dots\", x9 = \"I am quick at discriminating straight and curved capitals\" ) nice_modindices(fit, maximum.number = 10, labels = data_labels, op = \"~~\") #> lhs op rhs mi lhs.labels #> 1 x7 ~~ grade 16.511 I am quick at doing mental additions #> 2 x7 ~~ ageyr 10.030 I am quick at doing mental additions #> 3 x2 ~~ x7 9.673 I have good cube perception #> 4 x7 ~~ x8 9.479 I am quick at doing mental additions #> 5 x2 ~~ x3 8.746 I have good cube perception #> 6 x1 ~~ x9 8.408 I have good visual perception #> rhs.labels similarity similar #> 1 NA FALSE #> 2 NA FALSE #> 3 I am quick at doing mental additions 0.381 FALSE #> 4 I am quick at counting dots 0.698 TRUE #> 5 I have good at lozenge perception 0.800 TRUE #> 6 I am quick at discriminating straight and curved capitals 0.326 FALSE x <- HolzingerSwineford1939 x <- sjlabelled::set_label(x, label = c(rep(\"\", 6), data_labels)) fit <- sem(HS.model, data = x) nice_modindices(fit, maximum.number = 10, op = \"~~\") #> lhs op rhs mi #> 1 x7 ~~ grade 16.511 #> 2 x7 ~~ ageyr 10.030 #> 3 x2 ~~ x7 9.673 #> 4 x7 ~~ x8 9.479 #> 5 x2 ~~ x3 8.746 #> 6 x1 ~~ x9 8.408"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a quick tidySEM plot — nice_tidySEM","title":"Make a quick tidySEM plot — nice_tidySEM","text":"Make quick decent-looking tidySEM plot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a quick tidySEM plot — nice_tidySEM","text":"","code":"nice_tidySEM( fit, layout = NULL, hide_nonsig_edges = FALSE, hide_var = TRUE, hide_cov = FALSE, hide_mean = TRUE, est_std = TRUE, label, label_location = NULL, reduce_items = NULL, plot = TRUE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a quick tidySEM plot — nice_tidySEM","text":"fit SEM CFA model fit plot. layout matrix (data.frame) describes structure; see tidySEM::get_layout. named list provided, names \"IV\" (independent variables), \"M\" (mediator), \"DV\" (dependent variables), nice_tidySEM attempts write layout matrix automatically. hide_nonsig_edges Logical, hides non-significant edges. Defaults FALSE. hide_var Logical, hides variances. Defaults TRUE. hide_cov Logical, hides co-variances. Defaults FALSE. hide_mean Logical, hides means/node labels. Defaults TRUE. est_std Logical, whether use standardized coefficients. Defaults TRUE. label Labels used plot. elsewhere lavaanExtra, provided named list format (colname = \"label\"). label_location Location label along path, percentage (defaults middle, 0.5). reduce_items numeric vector length 1 (x) 2 (x & y) defining much space trim nodes (boxes) items defining latent variables. Can provided either reduce_items = 0.4 (affect horizontal space, x), reduce_items = c(x = 0.4, y = 0.2) (affect horizontal x vertical y). plot Logical, whether plot result (default). FALSE, returns tidy_sem object, can edited needed. ... Arguments passed tidySEM::prepare_graph.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a quick tidySEM plot — nice_tidySEM","text":"tidySEM plot, class ggplot, representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a quick tidySEM plot — nice_tidySEM","text":"","code":"# Calculate scale averages library(lavaan) data <- HolzingerSwineford1939 data$visual <- rowMeans(data[paste0(\"x\", 1:3)]) data$textual <- rowMeans(data[paste0(\"x\", 4:6)]) data$speed <- rowMeans(data[paste0(\"x\", 7:9)]) # Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\", \"school\") M <- c(\"visual\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object structure <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan(mediation, indirect = structure, label = TRUE) cat(model) #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual + grade_speed*grade #> textual ~ visual_textual*visual + grade_textual*grade #> visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school #> grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> sex_visual_speed := sex_visual * visual_speed #> sex_visual_textual := sex_visual * visual_textual #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> agemo_visual_speed := agemo_visual * visual_speed #> agemo_visual_textual := agemo_visual * visual_textual #> school_visual_speed := school_visual * visual_speed #> school_visual_textual := school_visual * visual_textual #> sex_grade_speed := sex_grade * grade_speed #> sex_grade_textual := sex_grade * grade_textual #> ageyr_grade_speed := ageyr_grade * grade_speed #> ageyr_grade_textual := ageyr_grade * grade_textual #> agemo_grade_speed := agemo_grade * grade_speed #> agemo_grade_textual := agemo_grade * grade_textual #> school_grade_speed := school_grade * grade_speed #> school_grade_textual := school_grade * grade_textual #> # Fit model fit <- sem(model, data) # Plot model # \\donttest{ nice_tidySEM(fit, layout = structure) # }"},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"Vector-based lavaan syntax interpreter — write_lavaan","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"Vector-based lavaan syntax interpreter.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"","code":"write_lavaan( mediation = NULL, regression = NULL, covariance = NULL, indirect = NULL, latent = NULL, intercept = NULL, threshold = NULL, constraint.equal = NULL, constraint.smaller = NULL, constraint.larger = NULL, custom = NULL, label = FALSE, use.letters = FALSE )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"mediation Mediation indicators (~ symbol: \"regressed \"). Differs argument regression path names can optionally specified automatically argument label. regression Regression indicators (~ symbol: \"regressed \"). covariance (Residual) (co)variance indicators (~~ symbol: \"correlated \"). indirect Indirect effect indicators (:= symbol: \"indirect effect defined \"). named list provided, names \"IV\" (independent variables), \"M\" (mediator), \"DV\" (dependent variables), write_lavaan attempts write indirect effects automatically. case, mediation argument must specified . latent Latent variable indicators (=~ symbol: \"measured \"). intercept Intercept indicators (~ 1 symbol: \"intercept\"). threshold Threshold indicators (| symbol: \"threshold\"). constraint.equal Equality indicators (== symbol). constraint.smaller Smaller indicators (< symbol). constraint.larger Greater indicators (> symbol). custom Custom specifications. Takes single string just like regular lavaan syntax . Always added end model. label Logical, whether display path names mediation argument. use.letters Logical, labels, whether use letters instead variable names.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"character string, representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) fit <- lavaan(HS.model, data = HolzingerSwineford1939, auto.var = TRUE, auto.fix.first = TRUE, auto.cov.lv.x = TRUE ) summary(fit, fit.measures = TRUE) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> #> Test statistic 85.306 #> Degrees of freedom 24 #> P-value (Chi-square) 0.000 #> #> Model Test Baseline Model: #> #> Test statistic 918.852 #> Degrees of freedom 36 #> P-value 0.000 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 #> Tucker-Lewis Index (TLI) 0.896 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 #> Loglikelihood unrestricted model (H1) -3695.092 #> #> Akaike (AIC) 7517.490 #> Bayesian (BIC) 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 #> 90 Percent confidence interval - lower 0.071 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: RMSEA <= 0.050 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 #> #> Parameter Estimates: #> #> Standard errors Standard #> Information Expected #> Information saturated (h1) model Structured #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) #> visual =~ #> x1 1.000 #> x2 0.554 0.100 5.554 0.000 #> x3 0.729 0.109 6.685 0.000 #> textual =~ #> x4 1.000 #> x5 1.113 0.065 17.014 0.000 #> x6 0.926 0.055 16.703 0.000 #> speed =~ #> x7 1.000 #> x8 1.180 0.165 7.152 0.000 #> x9 1.082 0.151 7.155 0.000 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) #> visual ~~ #> textual 0.408 0.074 5.552 0.000 #> speed 0.262 0.056 4.660 0.000 #> textual ~~ #> speed 0.173 0.049 3.518 0.000 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) #> .x1 0.549 0.114 4.833 0.000 #> .x2 1.134 0.102 11.146 0.000 #> .x3 0.844 0.091 9.317 0.000 #> .x4 0.371 0.048 7.779 0.000 #> .x5 0.446 0.058 7.642 0.000 #> .x6 0.356 0.043 8.277 0.000 #> .x7 0.799 0.081 9.823 0.000 #> .x8 0.488 0.074 6.573 0.000 #> .x9 0.566 0.071 8.003 0.000 #> visual 0.809 0.145 5.564 0.000 #> textual 0.979 0.112 8.737 0.000 #> speed 0.384 0.086 4.451 0.000 #>"},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-021","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.1","title":"lavaanExtra 0.2.1","text":"Incoming ✨","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.3","title":"lavaanExtra 0.2.1","text":"Fix bug nice_fit() created error categorical variables (#37)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.2","title":"lavaanExtra 0.2.1","text":"Fix bug lavaan_defined() / lavaan_extract() repeated first cell rows first column (#36)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.1","title":"lavaanExtra 0.2.1","text":"Now skips tests examples DiagrammeRsvg installed","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-020","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0","title":"lavaanExtra 0.2.0","text":"CRAN release: 2023-10-15 CRAN resubmission fix unicode problem","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-019","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.9","title":"lavaanExtra 0.1.9","text":"New release + CRAN New paper JOSS! Citation updated accordingly.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-9","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.8.1","title":"lavaanExtra 0.1.9","text":"?lavaanExtra now works expected. write_lavaan(): accepts new argument, threshold, represented “|” operator. lavaan_ind() renames lavaan_defined() specific indirect effects actually extracts user-defined parameters total effects moderated slopes using := operator. lavaan_reg() gets rid estimate argument, comply best practices reporting unstandardized standardized parameters respective confidence intervals. new function: lavaan_extract(), takes specific operator extracts relevant information (now used internally lavaan_reg(), lavaan_defined(), lavaan_cov())","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-018","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.8","title":"lavaanExtra 0.1.8","text":"CRAN release: 2023-08-25 CRAN resubmission New function: nice_modindices, outputs modification indices along item labels similarity score left-hand side right-hand side items. Useful assess item redundancy considering modification indices.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-017","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.7","title":"lavaanExtra 0.1.7","text":"CRAN release: 2023-06-25 CRAN resubmission: suggested dependencies now check correct version rlang::check_installed().","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-016","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.6","title":"lavaanExtra 0.1.6","text":"CRAN release: 2023-05-24 CRAN resubmission: tests now run even without suggested dependencies.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-015","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.5","title":"lavaanExtra 0.1.5","text":"CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.7","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: new argument: reduce_items, change size nodes (boxes) items defining latent variables (often require less emphasis).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.6","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: now omit leading zero using standardized coefficients (APA style). Update fit indices recommendations Schreiber et al. (2006) Schreiber (2017). benchmark changed RMSEA, moving < .05 [.00, .08] < .06-.08 [.00, .10]. Make table shorter combining RMSEA column confidence interval shortening AIC BIC interpretations.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.5","title":"lavaanExtra 0.1.5","text":"lavaan_cov: renamed r column covariance since cases standardized residual variances real correlations. New function: lavaan_cor, lavaan_cov actual correlations lavaan_reg, lavaan_ind, lavaan_cov: new argument estimate can either “B” obtain standardized estimates corresponding p values confidence interval, “b” unstandardized values. nice_lavaanPlot: stars now appear regression per default, also latent variables covariances c(\"regress\", \"latent\", \"covs\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-3","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.4","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: corrected bug whereas layout contained columns named c(“IV”, “M”, “DV”), remove extra columns (items), explicitly ignoring part layout provided. nice_lavaanPlot: now default black path lines instead gray.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-4","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.3","title":"lavaanExtra 0.1.5","text":"examples internal tests, now check package availability satisfy CRAN requirements. Remove vignettes package, satisfy CRAN package size requirements (still available website however).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-5","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.2","title":"lavaanExtra 0.1.5","text":"nice_fit: better error message providing lavaan object. tmvnsim package now required nice_tidySEM seems necessary use tidySEM’s new version.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-6","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.1","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: New argument hide covariances: hide_cov (defaults FALSE).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-014","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4","title":"lavaanExtra 0.1.4","text":"CRAN release: 2023-02-04 CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.3","title":"lavaanExtra 0.1.4","text":"remove copied/reexported save_as_docx like favour explicitly calling flextable::save_as_docx. way creating namespace conflicts functions, consistent new approach rempsyc, also gives credit flextable package, powerhouse produces tables hood. nice_fit now requires list models (single model), accept models loosely provided function different arguments. get rid dot-dot-dot ... argument favour supporting list objects. nice_fit now added footnote reference Schreiber et al. (2006) fit indices references using nice_table = TRUE.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.2","title":"lavaanExtra 0.1.4","text":"nice_fit: gains model.labels argument customize model names table.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.1","title":"lavaanExtra 0.1.4","text":"lavaan_ind gains argument, underscores_to_arrows, replace underscores arrows indirect effect column, indirect effects quickly visually interpretable. nice_tidySEM: meaningful error message providing unmatching label names. nice_fit look improved using nice_table = TRUE","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-013","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3","title":"lavaanExtra 0.1.3","text":"CRAN release: 2022-10-04 CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-012","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.2","title":"lavaanExtra 0.1.2","text":"rempsyc package dependency now CRAN, can rely normally now (yeah!). Adding test coverage (100% far!). Preparing CRAN.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-011","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.1","title":"lavaanExtra 0.1.1","text":"nice_tidySEM: Gains label_location ... arguments.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-010","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.0","title":"lavaanExtra 0.1.0","text":"nice_tidySEM: Corrected bug providing structure/matrix layout.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-009","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.9","title":"lavaanExtra 0.0.9","text":"Added new function: nice_tidySEM, quick decent-looking tidySEM plot sensical (customizable) defaults.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-008","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.8","title":"lavaanExtra 0.0.8","text":"write_lavaan: Exciting news! Automatic indirect effects now seemingly support combination IV, moderator, DV!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-007","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.7","title":"lavaanExtra 0.0.7","text":"write_lavaan: Automatic indirect effects now support another scenario: two mediators three IVs!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-006","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.6","title":"lavaanExtra 0.0.6","text":"Added new function: nice_lavaanPlot, quick decent-looking lavaanPlot sensical (customizable) defaults. write_lavaan: Automatic indirect effects now support another scenario: two mediators two IVs!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-005","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.5","title":"lavaanExtra 0.0.5","text":"write_lavaan: Fixed bug automatic indirect effects 1 mediator making forbidden paths (two mediators tested successfully)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-004","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.4","title":"lavaanExtra 0.0.4","text":"Adds ellipsis pass desired argument lavaan::cfa, thus removes default missing = \"fiml\" causing bug estimator = DWLS. Changes default saving PDF opening RStudio Viewer, adds additional save..pdf argument save PDF. Now imports flextable::save_as_docx (save_as_html, save_as_image, save_as_pptx…) support saving nice_fit tables Word without explicitly load flextable rempsyc. Added package logo!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-003","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.3","title":"lavaanExtra 0.0.3","text":"Added new function: cfa_fit_plot simultaneously print, save, plot CFA results.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-002","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.2","title":"lavaanExtra 0.0.2","text":"Added new arguments/symbols: constraint.equal (==), constraint.smaller (<), constraint.larger (>), custom (accepts single, lavaan-like string)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-0-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.1.0","title":"lavaanExtra 0.0.2","text":"Added automatic indirect effects","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-0-2-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.0.9","title":"lavaanExtra 0.0.2","text":"First package version","code":""}] +[{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contribution Guidelines","title":"Contribution Guidelines","text":"contributions welcome. Thank contributing! several ways contribute:","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_1-open-an-issue","dir":"","previous_headings":"","what":"1. Open an Issue","title":"Contribution Guidelines","text":"Open issue report bug (typo), suggest feature request, get help (yes, need go Stack Overflow, get help author directly issue becomes tutorial others!). opening issue, try include reprex, minimally reproducible example can replicated one base datasets R, mtcars dataset. make reprex, consider using reprex package. takes bit time get used , useful!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"pro-tip-on-creating-a-reprex-fast","dir":"","previous_headings":"1. Open an Issue","what":"Pro Tip on Creating a Reprex FAST","title":"Contribution Guidelines","text":"’s quality life upgrade learned late regarding reprexes. Instead loading package library(reprex), copying code Ctrl+c typing reprex() console, faster way. install package first time, actually adds addin RStudio. Simply click Addins button Help menu, search bar type reprex select Render reprex... ’ve copied relevant code. opens reprex window can specify different options finally click blue Render button render reprex. cool also allows easily add session info reprex checking Append session info check box. wait, way make even faster! Make addin selection shortcut (example) Ctrl+r going Tools, Modify Keyboard Shortcuts..., search bar type reprex, Render reprex... row, click Shortcut column, type desired shortcut (use Ctrl+r). , copy code Ctr+c, open reprex addin window Ctrl+r, press tab 3 times press enter. BAM! reprex < 5 seconds.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_2-start-a-discussion","dir":"","previous_headings":"","what":"2. Start a Discussion","title":"Contribution Guidelines","text":"Start discussion discuss ideas, organization, meta-ideas, ask questions, create polls, anything else doesn’t fit well issue.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/CONTRIBUTING.html","id":"id_3-submit-a-pull-request","dir":"","previous_headings":"","what":"3. Submit a Pull Request","title":"Contribution Guidelines","text":"Submit PR (’ve never heard term , ’s Pull Request!). essentially means make code contribution package repository. ’s complicated , don’t worry, can just copy-paste code contribution issue add . bit experienced however, suggested submit PR. recommended workflow submit PR following. Fork repository (use: usethis::create_from_github(\"rempsyc/lavaanExtra\")). Create branch (RStudio, click tiny purple flowchart Git tab, blue wheel main branch buttons), name based theme suggested changes. Commit push (Ctrl+p) changes branch RStudio. Submit PR modified branch (go branch GitHub website, automatically suggest open PR draft message ). Include one reprexes showing old new behaviour comparison. Note using usethis steps, need : installed git software (.e., R package); created github token usethis::create_github_token() (see usethis::gh_token_help() help); set credentials gitcreds::gitcreds_set().","code":""},{"path":"https://lavaanExtra.remi-theriault.com/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2022 lavaanExtra Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/TODOS.html","id":null,"dir":"","previous_headings":"","what":"Development objectives (to-do list)","title":"Development objectives (to-do list)","text":"cfa_fit_plot, add covariances items plot? Problem keep vertical structure look pretty putting default TRUE. Perhaps programmatic way lavaanPlot specify vertical structure times. nice_fit: automatically pick robust fit indices, available(?) Allow specifying standardized unstandardized coefficients figure, e.g., c(\"b\", \"B\"). improve algorithm odd number variables layout matrix adding two empty rows around odd levels, one empty row middle even levels? Add automatic covariances (specify levels, e.g.,: “level1 = IV”, “level2 = M”, “level3 = DV”) Get community feedback","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-1-model-syntax-1","dir":"Articles","previous_headings":"","what":"Example 1 (Model syntax 1):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/syntax1.html lavaan: lavaanExtra:","code":"myModel <- \" # regressions y1 + y2 ~ f1 + f2 + x1 + x2 f1 ~ f2 + f3 f2 ~ f3 + x1 + x2 # latent variable definitions f1 =~ y1 + y2 + y3 f2 =~ y4 + y5 + y6 f3 =~ y7 + y8 + y9 + y10 # variances and covariances y1 ~~ y1 y1 ~~ y2 f1 ~~ f2 # intercepts y1 ~ 1 f1 ~ 1 \" reg <- list( y1 = c(\"f1\", \"f2\", \"x1\", \"x2\"), y2 = c(\"f1\", \"f2\", \"x1\", \"x2\"), f1 = c(\"f2\", \"f3\"), f2 = c(\"f3\", \"x1\", \"x2\") ) lat <- list( f1 = paste0(\"y\", 1:3), f2 = paste0(\"y\", 4:6), f3 = paste0(\"y\", 7:10) ) cov <- list( y1 = \"y1\", y1 = \"y2\", f1 = \"f2\" ) int <- c(\"y1\", \"f1\") myModel <- write_lavaan( regression = reg, latent = lat, covariance = cov, intercept = int ) cat(myModel) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## f1 =~ y1 + y2 + y3 ## f2 =~ y4 + y5 + y6 ## f3 =~ y7 + y8 + y9 + y10 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y1 ~ f1 + f2 + x1 + x2 ## y2 ~ f1 + f2 + x1 + x2 ## f1 ~ f2 + f3 ## f2 ~ f3 + x1 + x2 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y1 ~~ y1 ## y1 ~~ y2 ## f1 ~~ f2 ## ## ################################################## ## # [------------------Intercepts------------------] ## ## y1 ~ 1 ## f1 ~ 1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-2-a-cfa-example","dir":"Articles","previous_headings":"","what":"Example 2 (A CFA example):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/cfa.html lavaan: lavaanExtra:","code":"HS.model <- \" visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) myModel <- write_lavaan(latent = lat) cat(myModel) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-3-a-sem-example","dir":"Articles","previous_headings":"","what":"Example 3 (A SEM example):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/sem.html lavaan: lavaanExtra:","code":"model <- \" # measurement model ind60 =~ x1 + x2 + x3 dem60 =~ y1 + y2 + y3 + y4 dem65 =~ y5 + y6 + y7 + y8 # regressions dem60 ~ ind60 dem65 ~ ind60 + dem60 # residual correlations y1 ~~ y5 y2 ~~ y4 + y6 y3 ~~ y7 y4 ~~ y8 y6 ~~ y8 \" lat <- list( ind60 = paste0(\"x\", 1:3), dem60 = paste0(\"y\", 1:4), dem65 = paste0(\"y\", 5:8) ) reg <- list( dem60 = \"ind60\", dem65 = c(\"ind60\", \"dem60\") ) cov <- list( y1 = \"y5\", y2 = c(\"y4\", \"y6\"), y3 = \"y7\", y4 = \"y8\", y6 = \"y8\" ) model <- write_lavaan( latent = lat, regression = reg, covariance = cov ) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## ind60 =~ x1 + x2 + x3 ## dem60 =~ y1 + y2 + y3 + y4 ## dem65 =~ y5 + y6 + y7 + y8 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## dem60 ~ ind60 ## dem65 ~ ind60 + dem60 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y1 ~~ y5 ## y2 ~~ y4 + y6 ## y3 ~~ y7 ## y4 ~~ y8 ## y6 ~~ y8"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-model-syntax-2","dir":"Articles","previous_headings":"","what":"Example 4 (Model syntax 2):","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/syntax2.html","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-1","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.1","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" # three-factor model visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ NA*x7 + x8 + x9 # orthogonal factors visual ~~ 0*speed textual ~~ 0*speed # fix variance of speed factor speed ~~ 1*speed \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = c(\"NA*x7\", \"x8\", \"x9\") ) cov <- list( visual = \"0*speed\", textual = \"0*speed\", speed = \"1*speed\" ) model <- write_lavaan(latent = lat, covariance = cov) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ NA*x7 + x8 + x9 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## visual ~~ 0*speed ## textual ~~ 0*speed ## speed ~~ 1*speed"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-2","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.2","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" visual =~ x1 + start(0.8)*x2 + start(1.2)*x3 textual =~ x4 + start(0.5)*x5 + start(1.0)*x6 speed =~ x7 + start(0.7)*x8 + start(1.8)*x9 \" lat <- list( visual = c(\"x1\", \"start(0.8)*x2\", \"start(1.2)*x3\"), textual = c(\"x4\", \"start(0.5)*x5\", \"start(1.0)*x6\"), speed = c(\"x7\", \"start(0.7)*x8\", \"start(1.8)*x9\") ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + start(0.8)*x2 + start(1.2)*x3 ## textual =~ x4 + start(0.5)*x5 + start(1.0)*x6 ## speed =~ x7 + start(0.7)*x8 + start(1.8)*x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-3","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.3","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" f =~ y1 + y2 + myLabel*y3 + start(0.5)*y3 + y4 \" lat <- list(f = c(\"y1\", \"y2\", \"myLabel*y3\", \"start(0.5)*y3\", \"y4\")) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## f =~ y1 + y2 + myLabel*y3 + start(0.5)*y3 + y4"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-4","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.4","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- \" visual =~ x1 + v2*x2 + v2*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 \" lat <- list( visual = c(\"x1\", \"v2*x2\", \"v2*x3\"), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + v2*x2 + v2*x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-5","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.5","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model <- ' visual =~ x1 + x2 + equal(\"visual=~x2\")*x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 ' sem(model, data = HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## Number of equality constraints 1 ## ## Number of observations 301 ## ## Model Test User Model: ## ## Test statistic 87.971 ## Degrees of freedom 25 ## P-value (Chi-square) 0.000 lat <- list( visual = c(\"x1\", \"x2\", \"equal('visual=~x2')*x3\"), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) model <- write_lavaan(latent = lat) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + equal('visual=~x2')*x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 sem(model, data = HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## Number of equality constraints 1 ## ## Number of observations 301 ## ## Model Test User Model: ## ## Test statistic 87.971 ## Degrees of freedom 25 ## P-value (Chi-square) 0.000"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-4-6","dir":"Articles","previous_headings":"Example 4 (Model syntax 2):","what":"Example 4.6","title":"Example lavaan models","text":"lavaan: lavaanExtra:","code":"model.constr <- \" # model with labeled parameters y ~ b1*x1 + b2*x2 + b3*x3 # constraints b1 == (b2 + b3)^2 b1 > exp(b2 + b3) \" reg <- list(y = c(\"b1*x1\", \"b2*x2\", \"b3*x3\")) cstr1 <- list(b1 = \"(b2 + b3)^2\") cstr2 <- list(b1 = \"exp(b2 + b3)\") model <- write_lavaan( regression = reg, constraint.equal = cstr1, constraint.larger = cstr2 ) cat(model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y ~ b1*x1 + b2*x2 + b3*x3 ## ## ################################################## ## # [-----------------Constraints------------------] ## ## b1 == (b2 + b3)^2 ## b1 > exp(b2 + b3)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-5-mediation","dir":"Articles","previous_headings":"","what":"Example 5 (Mediation)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/mediation.html lavaan: lavaanExtra:","code":"model <- \" # direct effect Y ~ c*X # mediator M ~ a*X Y ~ b*M # indirect effect (a*b) ab := a*b # total effect total := c + (a*b) \" mediation <- list( Y = \"c*X\", M = \"a*X\", Y = \"b*M\" ) indirect <- list( ab = \"a*b\", total = \"c + (a*b)\" ) model <- write_lavaan(mediation = mediation, indirect = indirect) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## Y ~ c*X ## M ~ a*X ## Y ~ b*M ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ab := a*b ## total := c + (a*b)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-6-multilevel-sem","dir":"Articles","previous_headings":"","what":"Example 6 (Multilevel SEM)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/multilevel.html lavaan: lavaanExtra:","code":"model <- \" level: 1 fw =~ y1 + y2 + y3 fw ~ x1 + x2 + x3 level: 2 fb =~ y1 + y2 + y3 fb ~ w1 + w2 \" cus <- \"level: 1 fw =~ y1 + y2 + y3 fw ~ x1 + x2 + x3 level: 2 fb =~ y1 + y2 + y3 fb ~ w1 + w2 \" model <- write_lavaan(custom = cus) cat(model) ## ################################################## ## # [------------Custom Specifications-------------] ## ## level: 1 ## fw =~ y1 + y2 + y3 ## fw ~ x1 + x2 + x3 ## level: 2 ## fb =~ y1 + y2 + y3 ## fb ~ w1 + w2"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-7-total-effects","dir":"Articles","previous_headings":"","what":"Example 7 (total effects)","title":"Example lavaan models","text":"Source: https://methodenlehre.github.io/SGSCLM-R-course/cfa--sem--lavaan.html#structural-equation-modelling-sem lavaan: lavaanExtra:","code":"model_mediation <- \" # Measurement model SUP_Parents =~ sup_parents_p1 + sup_parents_p2 + sup_parents_p3 SUP_Friends =~ sup_friends_p1 + sup_friends_p2 + sup_friends_p3 SE_Academic =~ se_acad_p1 + se_acad_p2 + se_acad_p3 SE_Social =~ se_social_p1 + se_social_p2 + se_social_p3 LS =~ ls_p1 + ls_p2 + ls_p3 # Structural model # Regressions SE_Academic ~ b1*SUP_Parents + b3*SUP_Friends SE_Social ~ b2*SUP_Parents + b4*SUP_Friends LS ~ b5*SUP_Parents + b6*SUP_Friends + b7*SE_Academic + b8*SE_Social # Residual covariances SE_Academic ~~ SE_Social # Indirect effects b1b7 := b1*b7 b2b8 := b2*b8 totalind_eltern := b1*b7 + b2*b8 b3b7 := b3*b7 b4b8 := b4*b8 totalind_freunde := b3*b7 + b4*b8 # Total effects total_eltern := b1*b7 + b2*b8 + b5 total_freunde := b3*b7 + b4*b8 + b6 \" x <- c(\"sup_parents\", \"sup_friends\", \"se_acad\", \"se_social\", \"ls\") y <- lapply(x, paste0, \"_p\", 1:3) y <- setNames(y, x) lat <- list( SUP_Parents = y$sup_parents, SUP_Friends = y$sup_friends, SE_Academic = y$se_acad, SE_Social = y$se_social, LS = y$ls ) b <- paste0(\"b\", 1:8) d <- c( rep(c(\"SUP_Parents\", \"SUP_Friends\"), each = 2), \"SUP_Parents\", \"SUP_Friends\", \"SE_Academic\", \"SE_Social\" ) e <- paste0(b, \"*\", d) reg <- list( SE_Academic = e[c(1, 3)], SE_Social = e[c(2, 4)], LS = e[c(5:8)] ) cov <- list(SE_Academic = \"SE_Social\") ind <- list( b1b7 = \"b1*b7\", b2b8 = \"b2*b8\", totalind_eltern = \"b1*b7 + b2*b8\", b3b7 = \"b3*b7\", b4b8 = \"b4*b8\", totalind_freunde = \"b3*b7 + b4*b8\", total_eltern = \"b1*b7 + b2*b8 + b5\", total_freunde = \"b3*b7 + b4*b8 + b6\" ) model <- write_lavaan( regression = reg, covariance = cov, indirect = ind, latent = lat ) cat(model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## SUP_Parents =~ sup_parents_p1 + sup_parents_p2 + sup_parents_p3 ## SUP_Friends =~ sup_friends_p1 + sup_friends_p2 + sup_friends_p3 ## SE_Academic =~ se_acad_p1 + se_acad_p2 + se_acad_p3 ## SE_Social =~ se_social_p1 + se_social_p2 + se_social_p3 ## LS =~ ls_p1 + ls_p2 + ls_p3 ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## SE_Academic ~ b1*SUP_Parents + b3*SUP_Friends ## SE_Social ~ b2*SUP_Parents + b4*SUP_Friends ## LS ~ b5*SUP_Parents + b6*SUP_Friends + b7*SE_Academic + b8*SE_Social ## ## ################################################## ## # [------------------Covariances-----------------] ## ## SE_Academic ~~ SE_Social ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## b1b7 := b1*b7 ## b2b8 := b2*b8 ## totalind_eltern := b1*b7 + b2*b8 ## b3b7 := b3*b7 ## b4b8 := b4*b8 ## totalind_freunde := b3*b7 + b4*b8 ## total_eltern := b1*b7 + b2*b8 + b5 ## total_freunde := b3*b7 + b4*b8 + b6"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-8-intercepts","dir":"Articles","previous_headings":"","what":"Example 8 (intercepts)","title":"Example lavaan models","text":"Source: https://lavaan.ugent./tutorial/means.html lavaan: lavaanExtra:","code":"HS.model <- \" # three-factor model visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 # intercepts with fixed values x1 + x2 + x3 + x4 ~ 0.5*1 \" lat <- list( visual = paste0(\"x\", 1:3), textual = paste0(\"x\", 4:6), speed = paste0(\"x\", 7:9) ) cus <- \"x1 + x2 + x3 + x4 ~ 0.5*1\" HS.model <- write_lavaan( latent = lat, custom = cus ) cat(HS.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 ## ## ################################################## ## # [------------Custom Specifications-------------] ## ## x1 + x2 + x3 + x4 ~ 0.5*1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-9-thresholds","dir":"Articles","previous_headings":"","what":"Example 9 (thresholds)","title":"Example lavaan models","text":"Source: https://tdjorgensen.github.io/TDJorgensen/CatMeasEq/Jorgensen.CatMeasEq.pdf lavaan: lavaanExtra:","code":"mod2 <- \" ## LIR means y2w1 ~ mean1*1 y2w2 ~ mean2*1 ## LIR (co)variances y2w1 ~~ var1*y2w1 + y2w2 y2w2 ~~ var2*y2w2 ## thresholds link LIRs to observed items y2w1 | thr1*t1 y2w2 | thr2*t1 \" reg <- list( y2w1 = \"mean1*1\", y2w2 = \"mean2*1\" ) cov <- list( y2w1 = c(\"var1*y2w1\", \"y2w2\"), y2w2 = \"var2*y2w2\" ) thres <- list( y2w1 = \"thr1*t1\", y2w2 = \"thr2*t1\" ) HS.model <- write_lavaan( regression = reg, covariance = cov, threshold = thres ) cat(HS.model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## y2w1 ~ mean1*1 ## y2w2 ~ mean2*1 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## y2w1 ~~ var1*y2w1 + y2w2 ## y2w2 ~~ var2*y2w2 ## ## ################################################## ## # [------------------Thresholds------------------] ## ## y2w1 | thr1*t1 ## y2w2 | thr2*t1"},{"path":"https://lavaanExtra.remi-theriault.com/articles/example.html","id":"example-10-longitudinal-invariance","dir":"Articles","previous_headings":"","what":"Example 10 (longitudinal invariance)","title":"Example lavaan models","text":"Source: https://thechangelab.stanford.edu/tutorials/growth-modeling/modeling-change-latent-vars-ordinal-indicators-lavaan/ lavaan: lavaanExtra:","code":"configural_invar <- \" #opening quote #factor loadings eta1 =~ 1*t1_sc + #for identification t1_intp + t1_ext eta2 =~ 1*t2_sc + #for identification t2_intp + t2_ext eta3 =~ 1*t4_sc + #for identification t4_intp + t4_ext #latent variable variances eta1~~eta1 eta2~~eta2 eta3~~eta3 #latent variable covariances eta1~~eta2 eta1~~eta3 eta2~~eta3 #latent variable means eta1~0*1 #for scaling eta2~0*1 #for scaling eta3~0*1 #for scaling #propensity variances t1_sc ~~ 1*t1_sc t1_intp~~ 1*t1_intp t1_ext ~~ 1*t1_ext t2_sc ~~ 1*t2_sc t2_intp~~ 1*t2_intp t2_ext ~~ 1*t2_ext t4_sc ~~ 1*t4_sc t4_intp~~ 1*t4_intp t4_ext ~~ 1*t4_ext #unique covariances #observed variable intercepts/thresholds (4 categories = 3 thresholds) t1_sc |t1 + t2 + t3 t1_intp |t1 + t2 + t3 t1_ext |t1 + t2 + t3 t2_sc |t1 + t2 + t3 t2_intp |t1 + t2 + t3 t2_ext |t1 + t2 + t3 t4_sc |t1 + t2 + t3 t4_intp |t1 + t2 + t3 t4_ext |t1 + t2 + t3 \" # closing quote eta <- paste0(\"eta\", 1:3) t <- paste0(\"t\", 1:4) term <- c(\"sc\", \"intp\", \"ext\") tnames <- paste0(rep(t[c(1:2, 4)], each = 3), \"_\", term) tnames2 <- paste0(\"1*\", tnames) lat <- list( eta1 = c(tnames2[1], tnames[2:3]), eta2 = c(tnames2[4], tnames[5:6]), eta3 = c(tnames2[7], tnames[8:9]) ) cov <- as.list(c(eta, eta[2:3], eta[3], tnames2)) names(cov) <- c(eta, eta[1], eta[1:2], tnames) thres <- rep(list(t[1:3]), 9) names(thres) <- tnames reg <- as.list(setNames(rep(\"0*1\", 3), eta)) HS.model <- write_lavaan( regression = reg, latent = lat, covariance = cov, threshold = thres ) cat(HS.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## eta1 =~ 1*t1_sc + t1_intp + t1_ext ## eta2 =~ 1*t2_sc + t2_intp + t2_ext ## eta3 =~ 1*t4_sc + t4_intp + t4_ext ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## eta1 ~ 0*1 ## eta2 ~ 0*1 ## eta3 ~ 0*1 ## ## ################################################## ## # [------------------Covariances-----------------] ## ## eta1 ~~ eta1 ## eta2 ~~ eta2 ## eta3 ~~ eta3 ## eta1 ~~ eta2 ## eta1 ~~ eta3 ## eta2 ~~ eta3 ## t1_sc ~~ 1*t1_sc ## t1_intp ~~ 1*t1_intp ## t1_ext ~~ 1*t1_ext ## t2_sc ~~ 1*t2_sc ## t2_intp ~~ 1*t2_intp ## t2_ext ~~ 1*t2_ext ## t4_sc ~~ 1*t4_sc ## t4_intp ~~ 1*t4_intp ## t4_ext ~~ 1*t4_ext ## ## ################################################## ## # [------------------Thresholds------------------] ## ## t1_sc | t1 + t2 + t3 ## t1_intp | t1 + t2 + t3 ## t1_ext | t1 + t2 + t3 ## t2_sc | t1 + t2 + t3 ## t2_intp | t1 + t2 + t3 ## t2_ext | t1 + t2 + t3 ## t4_sc | t1 + t2 + t3 ## t4_intp | t1 + t2 + t3 ## t4_ext | t1 + t2 + t3"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"cfa-example","dir":"Articles","previous_headings":"","what":"CFA example","title":"Full CFA/SEM workflow","text":"Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC Model 1 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. let’s say wanted develop short-scale x items per dimension. decide remove, dimension, items lowest loadings reach desired number items per dimension (look Estimation items reliability section ). can without respecify model, items wish remove: Let’s compare fit short version: Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.cfa2 13.11 6 2.19 .041 .98 .96 .06 [.01, .11] .03 5,106.23 5,161.84 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. like table, may also wish save Word. Also easy: Note also render PDF rmarkdown document output: pdf_document, using latex_engine: xelatex necessary including Unicode symbols tables like nice_fit() function.","code":"# Load library library(lavaan) library(lavaanExtra) library(tibble) library(psych) # Define latent variables x <- paste0(\"x\", 1:9) latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] ) # Write the model, and check it cfa.model <- write_lavaan(latent = latent) cat(cfa.model) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (optionally as PDF) fit.cfa <- cfa_fit_plot(cfa.model, HolzingerSwineford1939) ## lavaan 0.6-18 ended normally after 35 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 21 ## ## Number of observations 301 ## ## Model Test User Model: ## Standard Scaled ## Test Statistic 85.306 87.132 ## Degrees of freedom 24 24 ## P-value (Chi-square) 0.000 0.000 ## Scaling correction factor 0.979 ## Yuan-Bentler correction (Mplus variant) ## ## Model Test Baseline Model: ## ## Test statistic 918.852 880.082 ## Degrees of freedom 36 36 ## P-value 0.000 0.000 ## Scaling correction factor 1.044 ## ## User Model versus Baseline Model: ## ## Comparative Fit Index (CFI) 0.931 0.925 ## Tucker-Lewis Index (TLI) 0.896 0.888 ## ## Robust Comparative Fit Index (CFI) 0.930 ## Robust Tucker-Lewis Index (TLI) 0.895 ## ## Loglikelihood and Information Criteria: ## ## Loglikelihood user model (H0) -3737.745 -3737.745 ## Scaling correction factor 1.133 ## for the MLR correction ## Loglikelihood unrestricted model (H1) -3695.092 -3695.092 ## Scaling correction factor 1.051 ## for the MLR correction ## ## Akaike (AIC) 7517.490 7517.490 ## Bayesian (BIC) 7595.339 7595.339 ## Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 ## ## Root Mean Square Error of Approximation: ## ## RMSEA 0.092 0.093 ## 90 Percent confidence interval - lower 0.071 0.073 ## 90 Percent confidence interval - upper 0.114 0.115 ## P-value H_0: RMSEA <= 0.050 0.001 0.001 ## P-value H_0: RMSEA >= 0.080 0.840 0.862 ## ## Robust RMSEA 0.092 ## 90 Percent confidence interval - lower 0.072 ## 90 Percent confidence interval - upper 0.114 ## P-value H_0: Robust RMSEA <= 0.050 0.001 ## P-value H_0: Robust RMSEA >= 0.080 0.849 ## ## Standardized Root Mean Square Residual: ## ## SRMR 0.065 0.065 ## ## Parameter Estimates: ## ## Standard errors Sandwich ## Information bread Observed ## Observed information based on Hessian ## ## Latent Variables: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual =~ ## x1 1.000 0.900 0.772 ## x2 0.554 0.132 4.191 0.000 0.498 0.424 ## x3 0.729 0.141 5.170 0.000 0.656 0.581 ## textual =~ ## x4 1.000 0.990 0.852 ## x5 1.113 0.066 16.946 0.000 1.102 0.855 ## x6 0.926 0.061 15.089 0.000 0.917 0.838 ## speed =~ ## x7 1.000 0.619 0.570 ## x8 1.180 0.130 9.046 0.000 0.731 0.723 ## x9 1.082 0.266 4.060 0.000 0.670 0.665 ## ## Covariances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual ~~ ## textual 0.408 0.099 4.110 0.000 0.459 0.459 ## speed 0.262 0.060 4.366 0.000 0.471 0.471 ## textual ~~ ## speed 0.173 0.056 3.081 0.002 0.283 0.283 ## ## Variances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## .x1 0.549 0.156 3.509 0.000 0.549 0.404 ## .x2 1.134 0.112 10.135 0.000 1.134 0.821 ## .x3 0.844 0.100 8.419 0.000 0.844 0.662 ## .x4 0.371 0.050 7.382 0.000 0.371 0.275 ## .x5 0.446 0.057 7.870 0.000 0.446 0.269 ## .x6 0.356 0.047 7.658 0.000 0.356 0.298 ## .x7 0.799 0.097 8.222 0.000 0.799 0.676 ## .x8 0.488 0.120 4.080 0.000 0.488 0.477 ## .x9 0.566 0.119 4.768 0.000 0.566 0.558 ## visual 0.809 0.180 4.486 0.000 1.000 1.000 ## textual 0.979 0.121 8.075 0.000 1.000 1.000 ## speed 0.384 0.107 3.596 0.000 1.000 1.000 ## ## R-Square: ## Estimate ## x1 0.596 ## x2 0.179 ## x3 0.338 ## x4 0.725 ## x5 0.731 ## x6 0.702 ## x7 0.324 ## x8 0.523 ## x9 0.442 # Get fit indices nice_fit(fit.cfa) ## Model chisq df chi2.df pvalue cfi tli rmsea rmsea.ci.lower ## 1 Model 1 85.306 24 3.554 0 0.931 0.896 0.092 0.071 ## rmsea.ci.upper srmr aic bic ## 1 0.114 0.055 7517.49 7595.339 # We can get it prettier with the `rempsyc::nice_table` integration nice_fit(fit.cfa, nice_table = TRUE) # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (as PDF) fit.cfa2 <- cfa_fit_plot(cfa.model, HolzingerSwineford1939, remove.items = x[c(2, 6:7)] ) ## lavaan 0.6-18 ended normally after 36 iterations ## ## Estimator ML ## Optimization method NLMINB ## Number of model parameters 15 ## ## Number of observations 301 ## ## Model Test User Model: ## Standard Scaled ## Test Statistic 13.109 13.560 ## Degrees of freedom 6 6 ## P-value (Chi-square) 0.041 0.035 ## Scaling correction factor 0.967 ## Yuan-Bentler correction (Mplus variant) ## ## Model Test Baseline Model: ## ## Test statistic 481.386 460.467 ## Degrees of freedom 15 15 ## P-value 0.000 0.000 ## Scaling correction factor 1.045 ## ## User Model versus Baseline Model: ## ## Comparative Fit Index (CFI) 0.985 0.983 ## Tucker-Lewis Index (TLI) 0.962 0.958 ## ## Robust Comparative Fit Index (CFI) 0.984 ## Robust Tucker-Lewis Index (TLI) 0.961 ## ## Loglikelihood and Information Criteria: ## ## Loglikelihood user model (H0) -2538.118 -2538.118 ## Scaling correction factor 1.076 ## for the MLR correction ## Loglikelihood unrestricted model (H1) -2531.563 -2531.563 ## Scaling correction factor 1.045 ## for the MLR correction ## ## Akaike (AIC) 5106.235 5106.235 ## Bayesian (BIC) 5161.842 5161.842 ## Sample-size adjusted Bayesian (SABIC) 5114.271 5114.271 ## ## Root Mean Square Error of Approximation: ## ## RMSEA 0.063 0.065 ## 90 Percent confidence interval - lower 0.012 0.015 ## 90 Percent confidence interval - upper 0.109 0.112 ## P-value H_0: RMSEA <= 0.050 0.276 0.255 ## P-value H_0: RMSEA >= 0.080 0.309 0.337 ## ## Robust RMSEA 0.064 ## 90 Percent confidence interval - lower 0.016 ## 90 Percent confidence interval - upper 0.109 ## P-value H_0: Robust RMSEA <= 0.050 0.262 ## P-value H_0: Robust RMSEA >= 0.080 0.314 ## ## Standardized Root Mean Square Residual: ## ## SRMR 0.036 0.036 ## ## Parameter Estimates: ## ## Standard errors Sandwich ## Information bread Observed ## Observed information based on Hessian ## ## Latent Variables: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual =~ ## x1 1.000 0.954 0.818 ## x3 0.637 0.119 5.343 0.000 0.608 0.538 ## textual =~ ## x4 1.000 1.115 0.959 ## x5 0.883 0.140 6.292 0.000 0.985 0.764 ## speed =~ ## x8 1.000 0.511 0.505 ## x9 1.754 0.398 4.405 0.000 0.896 0.889 ## ## Covariances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## visual ~~ ## textual 0.472 0.098 4.798 0.000 0.444 0.444 ## speed 0.274 0.073 3.732 0.000 0.562 0.562 ## textual ~~ ## speed 0.144 0.055 2.590 0.010 0.252 0.252 ## ## Variances: ## Estimate Std.Err z-value P(>|z|) Std.lv Std.all ## .x1 0.448 0.172 2.606 0.009 0.448 0.330 ## .x3 0.905 0.085 10.670 0.000 0.905 0.710 ## .x4 0.107 0.190 0.564 0.573 0.107 0.080 ## .x5 0.690 0.160 4.311 0.000 0.690 0.416 ## .x8 0.761 0.088 8.623 0.000 0.761 0.745 ## .x9 0.213 0.165 1.294 0.196 0.213 0.210 ## visual 0.910 0.197 4.623 0.000 1.000 1.000 ## textual 1.243 0.219 5.678 0.000 1.000 1.000 ## speed 0.261 0.080 3.270 0.001 1.000 1.000 ## ## R-Square: ## Estimate ## x1 0.670 ## x3 0.290 ## x4 0.920 ## x5 0.584 ## x8 0.255 ## x9 0.790 fit_table <- nice_fit(lst(fit.cfa, fit.cfa2), nice_table = TRUE) fit_table # Save fit table to Word! flextable::save_as_docx(fit_table, path = \"fit_table.docx\")"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"estimation-of-items-reliability","dir":"Articles","previous_headings":"CFA example","what":"Estimation of items reliability","title":"Full CFA/SEM workflow","text":"Ideally, rather just looking loadings, also estimate item reliability dimensions long vs short scales help select items drop short scale. can first look alpha item dropped using psych::alpha function. Looking “Reliability item dropped” section, can see decision drop items 2, 6, 7, consistent new results except item 7. Indeed, according reliability estimation, better drop item 9 instead.","code":"visual <- HolzingerSwineford1939[x[1:3]] textual <- HolzingerSwineford1939[x[4:6]] speed <- HolzingerSwineford1939[x[7:9]] alpha(visual) ## ## Reliability analysis ## Call: alpha(x = visual) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.63 0.63 0.54 0.36 1.7 0.037 4.4 0.88 0.34 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.55 0.63 0.69 ## Duhachek 0.55 0.63 0.70 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x1 0.51 0.51 0.34 0.34 1.03 0.057 NA 0.34 ## x2 0.61 0.61 0.44 0.44 1.58 0.045 NA 0.44 ## x3 0.46 0.46 0.30 0.30 0.85 0.062 NA 0.30 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x1 301 0.77 0.77 0.58 0.45 4.9 1.2 ## x2 301 0.73 0.72 0.47 0.37 6.1 1.2 ## x3 301 0.78 0.78 0.62 0.48 2.3 1.1 alpha(textual) ## ## Reliability analysis ## Call: alpha(x = textual) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.88 0.88 0.84 0.72 7.7 0.011 3.2 1.1 0.72 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.86 0.88 0.90 ## Duhachek 0.86 0.88 0.91 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x4 0.83 0.84 0.72 0.72 5.1 0.019 NA 0.72 ## x5 0.83 0.83 0.70 0.70 4.8 0.020 NA 0.70 ## x6 0.84 0.85 0.73 0.73 5.5 0.018 NA 0.73 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x4 301 0.90 0.90 0.82 0.78 3.1 1.2 ## x5 301 0.92 0.91 0.84 0.79 4.3 1.3 ## x6 301 0.89 0.90 0.81 0.77 2.2 1.1 alpha(speed) ## ## Reliability analysis ## Call: alpha(x = speed) ## ## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r ## 0.69 0.69 0.6 0.43 2.2 0.031 5 0.81 0.45 ## ## 95% confidence boundaries ## lower alpha upper ## Feldt 0.62 0.69 0.74 ## Duhachek 0.63 0.69 0.75 ## ## Reliability if an item is dropped: ## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r ## x7 0.62 0.62 0.45 0.45 1.6 0.044 NA 0.45 ## x8 0.51 0.51 0.34 0.34 1.0 0.057 NA 0.34 ## x9 0.65 0.65 0.49 0.49 1.9 0.040 NA 0.49 ## ## Item statistics ## n raw.r std.r r.cor r.drop mean sd ## x7 301 0.79 0.78 0.59 0.49 4.2 1.1 ## x8 301 0.82 0.82 0.69 0.57 5.5 1.0 ## x9 301 0.75 0.76 0.55 0.46 5.4 1.0"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"sem-example","dir":"Articles","previous_headings":"","what":"SEM example","title":"Full CFA/SEM workflow","text":"structural equation model example. start path analysis first.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"saturated-model","dir":"Articles","previous_headings":"SEM example","what":"Saturated model","title":"Full CFA/SEM workflow","text":"One might decide look saturated lavaan model first. looks good far, might also want check indirect effects (mediations). , obtain path names setting label = TRUE. allow us define indirect effects feed back write_lavaan. , check mediation section model, see “augmented” path names. visual_speed, visual_textual, ageyr_visual, grade_visual. logic determination path names predictable: always predictor variable, left, followed predicted variable, right. test possible indirect effects, define indirect object : preferred (e.g., dealing long variable names), one can choose use letters predictor variables. Note however tends somewhat confusing ambiguous. case, path names a_speed, a_textual, a_visual, b_visual. define indirect object : also experimental feature attempts produce indirect effects automatically. feature requires specifying independent, dependent, mediator variables “IV”, “M”, “DV”, respectively, indirect object. case, already defined earlier, can just feed proper objects. now satisfied model, can finally fit ! Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) speed visual 0.05 3.91 < .001*** 0.20 [0.10, 0.29] 0.21 [0.11, 0.31] textual visual 0.06 4.53 < .001*** 0.29 [0.16, 0.41] 0.24 [0.14, 0.34] visual ageyr 0.05 -2.47 .014* -0.13 [-0.24, -0.03] -0.16 [-0.29, -0.03] visual grade 0.11 4.31 < .001*** 0.49 [0.27, 0.72] 0.28 [0.16, 0.40] speed ageyr 0.05 0.57 .568 0.03 [-0.07, 0.12] 0.04 [-0.09, 0.16] speed grade 0.10 4.90 < .001*** 0.50 [0.30, 0.70] 0.31 [0.19, 0.43] textual ageyr 0.06 -6.72 < .001*** -0.41 [-0.52, -0.29] -0.40 [-0.51, -0.29] textual grade 0.13 5.87 < .001*** 0.76 [0.51, 1.01] 0.36 [0.24, 0.47] speed predicted ageyr isn’t significant. remove path model trying make parsimonious model. Let’s make non-saturated path analysis model next.","code":"# Calculate scale averages data <- HolzingerSwineford1939 data$visual <- rowMeans(data[x[1:3]]) data$textual <- rowMeans(data[x[4:6]]) data$speed <- rowMeans(data[x[7:9]]) # Define our variables M <- \"visual\" IV <- c(\"ageyr\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) regression <- list(speed = IV, textual = IV) covariance <- list(speed = \"textual\", ageyr = \"grade\") # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual ## textual ~ visual ## visual ~ ageyr + grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # We can run the model again. # However, we set `label = TRUE` to get the path names model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # Define indirect object indirect <- list( ageyr_visual_speed = c(\"ageyr_visual\", \"visual_speed\"), ageyr_visual_textual = c(\"ageyr_visual\", \"visual_textual\"), grade_visual_speed = c(\"grade_visual\", \"visual_speed\"), grade_visual_textual = c(\"grade_visual\", \"visual_textual\") ) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## grade_visual_speed := grade_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE, use.letters = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ a_speed*visual ## textual ~ a_textual*visual ## visual ~ a_visual*ageyr + b_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # Define indirect object indirect <- list( ageyr_visual_speed = c(\"a_visual\", \"a_speed\"), ageyr_visual_textual = c(\"a_visual\", \"a_textual\"), grade_visual_speed = c(\"b_visual\", \"a_speed\"), grade_visual_textual = c(\"b_visual\", \"a_textual\") ) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE, use.letters = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ a_speed*visual ## textual ~ a_textual*visual ## visual ~ a_visual*ageyr + b_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := a_visual * a_speed ## ageyr_visual_textual := a_visual * a_textual ## grade_visual_speed := b_visual * a_speed ## grade_visual_textual := b_visual * a_textual # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model.saturated <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.saturated) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ ageyr + grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## grade_visual_speed := grade_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Fit the model with `lavaan` fit.saturated <- sem(model.saturated, data = data) # Get regression parameters only # And make it pretty with the `rempsyc::nice_table` integration lavaan_reg(fit.saturated, nice_table = TRUE, highlight = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"path-analysis-model","dir":"Articles","previous_headings":"SEM example","what":"Path analysis model","title":"Full CFA/SEM workflow","text":"use lavaanExtra, don’t redefine entire model: simply want update. case, regressions indirect effects. Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) speed visual 0.05 3.86 < .001*** 0.19 [0.09, 0.29] 0.21 [0.10, 0.31] textual visual 0.06 4.52 < .001*** 0.29 [0.16, 0.41] 0.24 [0.14, 0.33] visual ageyr 0.05 -2.47 .014* -0.13 [-0.24, -0.03] -0.16 [-0.29, -0.03] visual grade 0.11 4.31 < .001*** 0.49 [0.27, 0.72] 0.28 [0.16, 0.40] speed grade 0.09 6.11 < .001*** 0.53 [0.36, 0.70] 0.33 [0.23, 0.43] textual ageyr 0.06 -6.85 < .001*** -0.41 [-0.53, -0.29] -0.40 [-0.51, -0.29] textual grade 0.13 5.93 < .001*** 0.76 [0.51, 1.02] 0.36 [0.24, 0.47] Variable 1 Variable 2 SE Z p σ 95% CI (σ) r 95% CI (r) speed textual 0.04 2.25 .024* 0.09 [0.01, 0.17] .13 [0.02, 0.24] ageyr grade 0.03 7.89 < .001*** 0.27 [0.20, 0.33] .51 [0.43, 0.59] Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.saturated 0.00 0 Inf 1.0 1.0 .00 [.00, .00] .00 3,483.46 3,539.02 fit.path 0.33 1 0.33 .568 1.0 1.3 .00 [.00, .13] -.00 3,481.79 3,533.64 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3. Indirect Effect Paths SE Z p b 95% CI (b) b* 95% CI (b*) age → visual → speed ageyr_visual*visual_speed 0.01 -2.08 .037* -0.03 [-0.05, -0.00] -0.03 [-0.06, -0.00] grade → visual → textual grade_visual*visual_textual 0.05 3.12 .002** 0.14 [0.05, 0.23] 0.07 [0.03, 0.11] reference, model, visually speaking also attempt draw lavaanExtra::nice_tidySEM, convenience wrapper around amazing tidySEM package.","code":"regression <- list(speed = \"grade\", textual = IV) # We can run the model again, setting `label = TRUE` to get the path names model.path <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, label = TRUE ) cat(model.path) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade # We check that we have removed \"ageyr\" correctly from \"speed\" in the # regression section. OK. # Define just our indirect effects of interest indirect <- list( age_visual_speed = c(\"ageyr_visual\", \"visual_speed\"), grade_visual_textual = c(\"grade_visual\", \"visual_textual\") ) # We run the model again, with the indirect effects model.path <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, label = TRUE ) cat(model.path) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## age_visual_speed := ageyr_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Fit the model with `lavaan` fit.path <- sem(model.path, data = data) # Get regression parameters only lavaan_reg(fit.path) ## Outcome Predictor SE Z p b CI_lower ## 1 speed visual 0.04967204 3.861565 1.126628e-04 0.1918118 0.09445643 ## 2 textual visual 0.06336429 4.518796 6.219227e-06 0.2863303 0.16213859 ## 3 visual ageyr 0.05439452 -2.469906 1.351486e-02 -0.1343493 -0.24096064 ## 4 visual grade 0.11439571 4.306175 1.661018e-05 0.4926079 0.26839646 ## 5 speed grade 0.08716854 6.111181 9.889656e-10 0.5327027 0.36185552 ## 6 textual ageyr 0.05979047 -6.851140 7.326362e-12 -0.4096329 -0.52682005 ## 7 textual grade 0.12908567 5.925622 3.111173e-09 0.7649129 0.51190965 ## CI_upper B CI_lower_B CI_upper_B ## 1 0.28916724 0.2064640 0.1035674 0.30936052 ## 2 0.41052205 0.2351233 0.1353706 0.33487606 ## 3 -0.02773804 -0.1610061 -0.2876179 -0.03439429 ## 4 0.71681940 0.2807072 0.1566382 0.40477626 ## 5 0.70354992 0.3267428 0.2271881 0.42629750 ## 6 -0.29244571 -0.4031160 -0.5133146 -0.29291740 ## 7 1.01791619 0.3579255 0.2434470 0.47240398 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.path, nice_table = TRUE, highlight = TRUE) # We only kept significant regressions. Good (for this demo). # Get correlations lavaan_cor(fit.path) ## Variable 1 Variable 2 SE Z p sigma CI_lower ## 8 speed textual 0.04017743 2.254287 2.417812e-02 0.09057145 0.01182514 ## 9 ageyr grade 0.03401916 7.885426 3.108624e-15 0.26825556 0.20157923 ## CI_upper r CI_lower_r CI_upper_r ## 8 0.1693178 0.1312679 0.02005915 0.2424766 ## 9 0.3349319 0.5113296 0.42775726 0.5949020 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_cor(fit.path, nice_table = TRUE) # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path), nice_table = TRUE) # Let's get the indirect effects only lavaan_defined(fit.path, lhs_name = \"Indirect Effect\") ## Indirect Effect Paths SE Z ## 15 age → visual → speed ageyr_visual*visual_speed 0.01238517 -2.080697 ## 16 grade → visual → textual grade_visual*visual_textual 0.04524584 3.117383 ## p b CI_lower CI_upper B CI_lower_B ## 15 0.037461652 -0.02576979 -0.05004429 -0.001495299 -0.03324196 -0.06438407 ## 16 0.001824646 0.14104859 0.05236837 0.229728799 0.06600083 0.02535014 ## CI_upper_B ## 15 -0.002099853 ## 16 0.106651508 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_defined(fit.path, lhs_name = \"Indirect Effect\", nice_table = TRUE) # Get modification indices only modindices(fit.path, sort = TRUE, maximum.number = 5) ## lhs op rhs mi epc sepc.lv sepc.all sepc.nox ## 29 visual ~ textual 0.326 1.622 1.622 1.975 1.975 ## 35 grade ~ textual 0.326 -0.228 -0.228 -0.488 -0.488 ## 34 grade ~ speed 0.326 -0.038 -0.038 -0.062 -0.062 ## 19 speed ~~ grade 0.326 -0.021 -0.021 -0.056 -0.056 ## 25 speed ~ textual 0.326 -0.067 -0.067 -0.087 -0.087 labels <- list( ageyr = \"Age (year)\", grade = \"Grade\", visual = \"Visual\", speed = \"Speed\", textual = \"Textual\" ) layout <- list(IV = IV, M = M, DV = DV) nice_tidySEM(fit.path, layout = layout, label = labels, hide_nonsig_edges = TRUE, label_location = .60 )"},{"path":"https://lavaanExtra.remi-theriault.com/articles/fullworkflow.html","id":"latent-model","dir":"Articles","previous_headings":"SEM example","what":"Latent model","title":"Full CFA/SEM workflow","text":"Finally, perhaps change mind decide run full SEM instead, latent variables. Fear : don’t redo everything . can simply define latent variables proceed. example, already defined latent variable CFA earlier, don’t even need write ! Model χ2 df χ2∕df p CFI TLI RMSEA [90% CI] SRMR AIC BIC fit.cfa 85.31 24 3.55 < .001 .93 .90 .09 [.07, .11] .06 7,517.49 7,595.34 fit.saturated 0.00 0 Inf 1.0 1.0 .00 [.00, .00] .00 3,483.46 3,539.02 fit.path 0.33 1 0.33 .568 1.0 1.3 .00 [.00, .13] -.00 3,481.79 3,533.64 fit.latent 118.92 37 3.21 < .001 .92 .89 .09 [.07, .10] .05 8,638.79 8,746.20 Common guidelinesa — — < 2 3 > .05 ≥ .95 ≥ .95 < .05 [.00, .08] ≤ .08 Smaller Smaller aBased Schreiber (2017), Table 3.","code":"model.latent <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, latent = latent, label = TRUE ) cat(model.latent) ## ################################################## ## # [-----Latent variables (measurement model)-----] ## ## visual =~ x1 + x2 + x3 ## textual =~ x4 + x5 + x6 ## speed =~ x7 + x8 + x9 ## ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr + grade_visual*grade ## ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## speed ~ grade ## textual ~ ageyr + grade ## ## ################################################## ## # [------------------Covariances-----------------] ## ## speed ~~ textual ## ageyr ~~ grade ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## age_visual_speed := ageyr_visual * visual_speed ## grade_visual_textual := grade_visual * visual_textual # Run model fit.latent <- sem(model.latent, data = HolzingerSwineford1939) # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(lst(fit.cfa, fit.saturated, fit.path, fit.latent), nice_table = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-1-mediator-1-dv","dir":"Articles","previous_headings":"","what":"1 IV, 1 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Calculate scale averages data <- HolzingerSwineford1939 data$visual <- rowMeans(data[paste0(\"x\", 1:3)]) data$textual <- rowMeans(data[paste0(\"x\", 4:6)]) data$speed <- rowMeans(data[paste0(\"x\", 7:9)]) # Define our variables IV <- \"ageyr\" M <- \"visual\" DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## visual ~ ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-1-mediator-2-dvs","dir":"Articles","previous_headings":"","what":"1 IV, 1 mediator, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-2-mediator-1-dv","dir":"Articles","previous_headings":"","what":"1 IV, 2 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables M <- c(\"visual\", \"grade\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ ageyr_visual*ageyr ## grade ~ ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_grade_speed := ageyr_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"iv-2-mediators-2-dvs","dir":"Articles","previous_headings":"","what":"1 IV, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ ageyr_visual*ageyr ## grade ~ ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-1-mediator-1-dv","dir":"Articles","previous_headings":"","what":"2 IVs, 1 mediator, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\") M <- \"visual\" DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV) # Define indirect object indirect <- list(M = M, DV = DV, IV = IV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-1-mediator-2-dvs","dir":"Articles","previous_headings":"","what":"2 IVs, 1 mediator, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) # Define indirect object indirect <- list(M = M, DV = DV, IV = IV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual ## textual ~ visual_textual*visual ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-1-dv","dir":"Articles","previous_headings":"","what":"2 IVs, 2 mediators, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables M <- c(\"visual\", \"grade\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## grade ~ sex_grade*sex + ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed ## sex_grade_speed := sex_grade * grade_speed ## ageyr_grade_speed := ageyr_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs","dir":"Articles","previous_headings":"","what":"2 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr ## grade ~ sex_grade*sex + ageyr_grade*ageyr ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-1-dv-1","dir":"Articles","previous_headings":"","what":"3 IVs, 2 mediators, 1 DV","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\") DV <- \"speed\" # Define our lavaan lists mediation <- list(speed = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## ageyr_visual_speed := ageyr_visual * visual_speed ## agemo_visual_speed := agemo_visual * visual_speed ## sex_grade_speed := sex_grade * grade_speed ## ageyr_grade_speed := ageyr_grade * grade_speed ## agemo_grade_speed := agemo_grade * grade_speed # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs-1","dir":"Articles","previous_headings":"","what":"3 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-2-mediators-2-dvs-2","dir":"Articles","previous_headings":"","what":"6 IVs, 2 mediators, 2 DVs","title":"Automatic indirect effects","text":"","code":"# Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\", \"school\", \"x2\", \"x3\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade ## textual ~ visual_textual*visual + grade_textual*grade ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school + x2_visual*x2 + x3_visual*x3 ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school + x2_grade*x2 + x3_grade*x3 ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## school_visual_speed := school_visual * visual_speed ## school_visual_textual := school_visual * visual_textual ## x2_visual_speed := x2_visual * visual_speed ## x2_visual_textual := x2_visual * visual_textual ## x3_visual_speed := x3_visual * visual_speed ## x3_visual_textual := x3_visual * visual_textual ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual ## school_grade_speed := school_grade * grade_speed ## school_grade_textual := school_grade * grade_textual ## x2_grade_speed := x2_grade * grade_speed ## x2_grade_textual := x2_grade * grade_textual ## x3_grade_speed := x3_grade * grade_speed ## x3_grade_textual := x3_grade * grade_textual # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"ivs-3-mediators-5-dvs","dir":"Articles","previous_headings":"","what":"6 IVs, 3 mediators, 5 DVs","title":"Automatic indirect effects","text":"Etc.","code":"# Define our variables M <- c(\"visual\", \"grade\", \"x8\") DV <- c(\"speed\", \"textual\", \"x4\", \"x5\", \"x7\") # Define our lavaan lists mediation <- list( speed = M, textual = M, x4 = M, x5 = M, x7 = M, x8 = IV, visual = IV, grade = IV ) # Define indirect object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, indirect = indirect, label = TRUE ) cat(model) ## ################################################## ## # [-----------Mediations (named paths)-----------] ## ## speed ~ visual_speed*visual + grade_speed*grade + x8_speed*x8 ## textual ~ visual_textual*visual + grade_textual*grade + x8_textual*x8 ## x4 ~ visual_x4*visual + grade_x4*grade + x8_x4*x8 ## x5 ~ visual_x5*visual + grade_x5*grade + x8_x5*x8 ## x7 ~ visual_x7*visual + grade_x7*grade + x8_x7*x8 ## x8 ~ sex_x8*sex + ageyr_x8*ageyr + agemo_x8*agemo + school_x8*school + x2_x8*x2 + x3_x8*x3 ## visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school + x2_visual*x2 + x3_visual*x3 ## grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school + x2_grade*x2 + x3_grade*x3 ## ## ################################################## ## # [--------Mediations (indirect effects)---------] ## ## sex_visual_speed := sex_visual * visual_speed ## sex_visual_textual := sex_visual * visual_textual ## sex_visual_x4 := sex_visual * visual_x4 ## sex_visual_x5 := sex_visual * visual_x5 ## sex_visual_x7 := sex_visual * visual_x7 ## ageyr_visual_speed := ageyr_visual * visual_speed ## ageyr_visual_textual := ageyr_visual * visual_textual ## ageyr_visual_x4 := ageyr_visual * visual_x4 ## ageyr_visual_x5 := ageyr_visual * visual_x5 ## ageyr_visual_x7 := ageyr_visual * visual_x7 ## agemo_visual_speed := agemo_visual * visual_speed ## agemo_visual_textual := agemo_visual * visual_textual ## agemo_visual_x4 := agemo_visual * visual_x4 ## agemo_visual_x5 := agemo_visual * visual_x5 ## agemo_visual_x7 := agemo_visual * visual_x7 ## school_visual_speed := school_visual * visual_speed ## school_visual_textual := school_visual * visual_textual ## school_visual_x4 := school_visual * visual_x4 ## school_visual_x5 := school_visual * visual_x5 ## school_visual_x7 := school_visual * visual_x7 ## x2_visual_speed := x2_visual * visual_speed ## x2_visual_textual := x2_visual * visual_textual ## x2_visual_x4 := x2_visual * visual_x4 ## x2_visual_x5 := x2_visual * visual_x5 ## x2_visual_x7 := x2_visual * visual_x7 ## x3_visual_speed := x3_visual * visual_speed ## x3_visual_textual := x3_visual * visual_textual ## x3_visual_x4 := x3_visual * visual_x4 ## x3_visual_x5 := x3_visual * visual_x5 ## x3_visual_x7 := x3_visual * visual_x7 ## sex_grade_speed := sex_grade * grade_speed ## sex_grade_textual := sex_grade * grade_textual ## sex_grade_x4 := sex_grade * grade_x4 ## sex_grade_x5 := sex_grade * grade_x5 ## sex_grade_x7 := sex_grade * grade_x7 ## ageyr_grade_speed := ageyr_grade * grade_speed ## ageyr_grade_textual := ageyr_grade * grade_textual ## ageyr_grade_x4 := ageyr_grade * grade_x4 ## ageyr_grade_x5 := ageyr_grade * grade_x5 ## ageyr_grade_x7 := ageyr_grade * grade_x7 ## agemo_grade_speed := agemo_grade * grade_speed ## agemo_grade_textual := agemo_grade * grade_textual ## agemo_grade_x4 := agemo_grade * grade_x4 ## agemo_grade_x5 := agemo_grade * grade_x5 ## agemo_grade_x7 := agemo_grade * grade_x7 ## school_grade_speed := school_grade * grade_speed ## school_grade_textual := school_grade * grade_textual ## school_grade_x4 := school_grade * grade_x4 ## school_grade_x5 := school_grade * grade_x5 ## school_grade_x7 := school_grade * grade_x7 ## x2_grade_speed := x2_grade * grade_speed ## x2_grade_textual := x2_grade * grade_textual ## x2_grade_x4 := x2_grade * grade_x4 ## x2_grade_x5 := x2_grade * grade_x5 ## x2_grade_x7 := x2_grade * grade_x7 ## x3_grade_speed := x3_grade * grade_speed ## x3_grade_textual := x3_grade * grade_textual ## x3_grade_x4 := x3_grade * grade_x4 ## x3_grade_x5 := x3_grade * grade_x5 ## x3_grade_x7 := x3_grade * grade_x7 ## sex_x8_speed := sex_x8 * x8_speed ## sex_x8_textual := sex_x8 * x8_textual ## sex_x8_x4 := sex_x8 * x8_x4 ## sex_x8_x5 := sex_x8 * x8_x5 ## sex_x8_x7 := sex_x8 * x8_x7 ## ageyr_x8_speed := ageyr_x8 * x8_speed ## ageyr_x8_textual := ageyr_x8 * x8_textual ## ageyr_x8_x4 := ageyr_x8 * x8_x4 ## ageyr_x8_x5 := ageyr_x8 * x8_x5 ## ageyr_x8_x7 := ageyr_x8 * x8_x7 ## agemo_x8_speed := agemo_x8 * x8_speed ## agemo_x8_textual := agemo_x8 * x8_textual ## agemo_x8_x4 := agemo_x8 * x8_x4 ## agemo_x8_x5 := agemo_x8 * x8_x5 ## agemo_x8_x7 := agemo_x8 * x8_x7 ## school_x8_speed := school_x8 * x8_speed ## school_x8_textual := school_x8 * x8_textual ## school_x8_x4 := school_x8 * x8_x4 ## school_x8_x5 := school_x8 * x8_x5 ## school_x8_x7 := school_x8 * x8_x7 ## x2_x8_speed := x2_x8 * x8_speed ## x2_x8_textual := x2_x8 * x8_textual ## x2_x8_x4 := x2_x8 * x8_x4 ## x2_x8_x5 := x2_x8 * x8_x5 ## x2_x8_x7 := x2_x8 * x8_x7 ## x3_x8_speed := x3_x8 * x8_speed ## x3_x8_textual := x3_x8 * x8_textual ## x3_x8_x4 := x3_x8 * x8_x4 ## x3_x8_x5 := x3_x8 * x8_x5 ## x3_x8_x7 := x3_x8 * x8_x7 # Fit and plot fit <- sem(model, data = data) nice_lavaanPlot(fit) labels <- list( sex = \"Sex\", ageyr = \"Age (year)\", agemo = \"Age (month)\", school = \"School\", x2 = \"Item 2\", x3 = \"Item 3\", visual = \"Visual\", grade = \"Grade\", x8 = \"Item 8\", speed = \"Speed\", textual = \"Textual\", x4 = \"Item 4\", x5 = \"Item 5\", x7 = \"Item 7\" ) nice_tidySEM(fit, layout = indirect, hide_nonsig_edges = TRUE, label = labels)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/indirect.html","id":"other-scenarios","dir":"Articles","previous_headings":"","what":"Other scenarios","title":"Automatic indirect effects","text":"experience issues scenarios, please open GitHub issue example, try adapt function support case. Thank !","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/regression.html","id":"regression-example","dir":"Articles","previous_headings":"","what":"Regression example","title":"Regressions","text":"Outcome Predictor SE Z p b 95% CI (b) b* 95% CI (b*) mpg cyl 0.70 -1.17 .244 -0.81 [-2.18, 0.55] -0.24 [-0.65, 0.16] mpg disp 0.01 -1.54 .123 -0.01 [-0.03, 0.00] -0.29 [-0.65, 0.08] mpg hp 0.02 -1.52 .128 -0.02 [-0.05, 0.01] -0.26 [-0.60, 0.07] mpg drat 1.53 1.41 .159 2.15 [-0.84, 5.15] 0.19 [-0.07, 0.46] disp hp 0.23 1.35 .177 0.32 [-0.14, 0.78] 0.18 [-0.08, 0.43] disp drat 19.37 -2.12 .034* -41.13 [-79.09, -3.17] -0.18 [-0.34, -0.02] disp wt 14.04 5.54 < .001*** 77.72 [50.20, 105.24] 0.61 [0.41, 0.82] disp qsec 6.89 -1.87 .061 -12.91 [-26.42, 0.59] -0.19 [-0.38, 0.01]","code":"# Load libraries library(lavaan) library(lavaanExtra) # Define our regression terms regression <- list( mpg = names(mtcars)[2:5], disp = names(mtcars)[4:7] ) # Write the model, and check it mtcars.model <- write_lavaan(regression = regression) cat(mtcars.model) ## ################################################## ## # [---------Regressions (Direct effects)---------] ## ## mpg ~ cyl + disp + hp + drat ## disp ~ hp + drat + wt + qsec # Fit the model with `lavaan` fit.reg <- sem(mtcars.model, data = mtcars) # Get regression parameters only lavaan_reg(fit.reg) ## Outcome Predictor SE Z p b ## 1 mpg cyl 0.69815671 -1.165959 2.436311e-01 -0.81402201 ## 2 mpg disp 0.00901291 -1.541816 1.231184e-01 -0.01389625 ## 3 mpg hp 0.01521110 -1.523275 1.276900e-01 -0.02317068 ## 4 mpg drat 1.52814327 1.409583 1.586627e-01 2.15404553 ## 5 disp hp 0.23487240 1.348926 1.773606e-01 0.31682557 ## 6 disp drat 19.36831070 -2.123660 3.369862e-02 -41.13169751 ## 7 disp wt 14.04152370 5.535006 3.112178e-08 77.71991684 ## 8 disp qsec 6.88881338 -1.874538 6.085630e-02 -12.91334294 ## CI_lower CI_upper B CI_lower_B CI_upper_B ## 1 -2.18238402 0.554339998 -0.2419101 -0.64651698 0.162696788 ## 2 -0.03156123 0.003768732 -0.2865893 -0.64840670 0.075228183 ## 3 -0.05298388 0.006642523 -0.2643524 -0.60156925 0.072864499 ## 4 -0.84106024 5.149151295 0.1916475 -0.07287256 0.456167633 ## 5 -0.14351587 0.777167015 0.1752679 -0.07855326 0.429088994 ## 6 -79.09288894 -3.170506091 -0.1774445 -0.33986967 -0.015019402 ## 7 50.19903609 105.240797584 0.6135746 0.40870132 0.818447825 ## 8 -26.41516906 0.588483178 -0.1861841 -0.37961141 0.007243262 # We can get it prettier with the `rempsyc::nice_table` integration lavaan_reg(fit.reg, nice_table = TRUE, highlight = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"regression","dir":"Articles","previous_headings":"","what":"regression","title":"How to use `write_lavaan()`","text":"regression argument shorthand ~ operator. example usage, see Regression vignette.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"covariance","dir":"Articles","previous_headings":"","what":"covariance","title":"How to use `write_lavaan()`","text":"covariance argument shorthand ~~ operator. example usage, see Example 1.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"intercept","dir":"Articles","previous_headings":"","what":"intercept","title":"How to use `write_lavaan()`","text":"latent argument shorthand ~ 1 operator. example usage, see Example 1.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"latent","dir":"Articles","previous_headings":"","what":"latent","title":"How to use `write_lavaan()`","text":"latent argument shorthand =~ operator. example usage see Example 2.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"constraints","dir":"Articles","previous_headings":"","what":"constraints","title":"How to use `write_lavaan()`","text":"Constraints can specified constraint.equal, constraint.smaller, constraint.larger argument, showcased Example 4.6.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"mediation","dir":"Articles","previous_headings":"","what":"mediation","title":"How to use `write_lavaan()`","text":"mediation argument also shorthand ~ operator. However, difference regression argument can automatically specify path names argument label set TRUE. also possible name paths letters instead variable names setting use.letters = TRUE. example usage, see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"indirect","dir":"Articles","previous_headings":"","what":"indirect","title":"How to use `write_lavaan()`","text":"indirect argument shorthand := operator. example usage, see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"user-defined-parameters","dir":"Articles","previous_headings":"","what":"user-defined parameters","title":"How to use `write_lavaan()`","text":"user-defined parameters (e.g,. total effects), see Example 5.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/articles/write_lavaan.html","id":"custom","dir":"Articles","previous_headings":"","what":"custom","title":"How to use `write_lavaan()`","text":"Sometimes, elements specified arguments, custom argument becomes handy make tailored specifications, Multilevel SEM Example 6. custom argument can also useful specify thresholds “|” operator. example usage, see Example 10.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Rémi Thériault. Author, maintainer.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Thériault, R., (2023). lavaanExtra: Convenience Functions Package lavaan. *Journal Open Source Software*, *8*(90), 5701, https://doi.org/10.21105/joss.05701","code":"@Article{, doi = {10.21105/joss.05701}, url = {https://doi.org/10.21105/joss.05701}, year = {2023}, publisher = {The Open Journal}, volume = {8}, number = {90}, pages = {5701}, author = {Rémi Thériault}, title = {lavaanExtra: Convenience functions for lavaan}, journal = {Journal of Open Source Software}, }"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"lavaanextra-convenience-functions-for-lavaan","dir":"","previous_headings":"","what":"Convenience Functions for Package lavaan","title":"Convenience Functions for Package lavaan","text":"Affords alternative, vector-based syntax lavaan, well convenience functions naming paths defining indirect links automatically. Also offers convenience formatting optimized publication script sharing workflow.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Convenience Functions for Package lavaan","text":"can install lavaanExtra package directly CRAN: development version r-universe (note 24-hour delay GitHub): GitHub, latest version: see available functions, use: Dependencies: lavaanExtra package convenience functions relying several external packages, uses (inspired easystats packages) minimalist philosophy installing packages need need rlang::check_installed(). wish specifically install suggested dependencies (can view full list clicking CRAN badge page), can run following (warned may take long time, suggested packages used vignettes examples):","code":"install.packages(\"lavaanExtra\") install.packages(\"lavaanExtra\", repos = c( rempsyc = \"https://rempsyc.r-universe.dev\", CRAN = \"https://cloud.r-project.org\")) # If not already installed, install package `remotes` with `install.packages(\"remotes\")` remotes::install_github(\"rempsyc/lavaanExtra\") help(package = \"lavaanExtra\") install.packages(\"lavaanExtra\", dependencies = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"why-use-lavaanextra","dir":"","previous_headings":"","what":"Why use lavaanExtra?","title":"Convenience Functions for Package lavaan","text":"Reusable code. Don’t repeat anymore want change things comparing fitting models. Shorter code. point 1, can shorter code, since write simply reuse . items similar patterns, can also use paste0() appropriate item numbers instead typing one every time. Less error-prone code. point 1, can less risk human errors since don’t possibly multiple different version thing (makes easier correct ). Better control code. point 1, control whole flow. change , change everywhere else script, without change manually model. readable code. point 1, people (also ) process information first time make sure ’s specified correctly, every time check new models. Prettier code. format model pretty way, every time. don’t worry manually making model good-looking readable anymore. accessible code. don’t remember exact syntax (although recommended) work. uses intuitive variable names people can understand. benefit apparent beginners, also saves precious typing time veterans.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Convenience Functions for Package lavaan","text":"CFA example SEM example Final note","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"cfa-example","dir":"","previous_headings":"","what":"CFA example","title":"Convenience Functions for Package lavaan","text":"","code":"# Load libraries library(lavaan) library(lavaanExtra) # Define latent variables latent <- list( visual = c(\"x1\", \"x2\", \"x3\"), textual = c(\"x4\", \"x5\", \"x6\"), speed = c(\"x7\", \"x8\", \"x9\") ) # If you have many items, you can also use the `paste0` function: x <- paste0(\"x\", 1:9) latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] ) # Write the model, and check it cfa.model <- write_lavaan(latent = latent) cat(cfa.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 # Fit the model fit and plot with `lavaanExtra::cfa_fit_plot` # to get the factor loadings visually (optionally as PDF) fit.cfa <- cfa_fit_plot(cfa.model, HolzingerSwineford1939) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> Standard Scaled #> Test Statistic 85.306 87.132 #> Degrees of freedom 24 24 #> P-value (Chi-square) 0.000 0.000 #> Scaling correction factor 0.979 #> Yuan-Bentler correction (Mplus variant) #> #> Model Test Baseline Model: #> #> Test statistic 918.852 880.082 #> Degrees of freedom 36 36 #> P-value 0.000 0.000 #> Scaling correction factor 1.044 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 0.925 #> Tucker-Lewis Index (TLI) 0.896 0.888 #> #> Robust Comparative Fit Index (CFI) 0.930 #> Robust Tucker-Lewis Index (TLI) 0.895 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 -3737.745 #> Scaling correction factor 1.133 #> for the MLR correction #> Loglikelihood unrestricted model (H1) -3695.092 -3695.092 #> Scaling correction factor 1.051 #> for the MLR correction #> #> Akaike (AIC) 7517.490 7517.490 #> Bayesian (BIC) 7595.339 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 0.093 #> 90 Percent confidence interval - lower 0.071 0.073 #> 90 Percent confidence interval - upper 0.114 0.115 #> P-value H_0: RMSEA <= 0.050 0.001 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 0.862 #> #> Robust RMSEA 0.092 #> 90 Percent confidence interval - lower 0.072 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: Robust RMSEA <= 0.050 0.001 #> P-value H_0: Robust RMSEA >= 0.080 0.849 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 0.065 #> #> Parameter Estimates: #> #> Standard errors Sandwich #> Information bread Observed #> Observed information based on Hessian #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual =~ #> x1 1.000 0.900 0.772 #> x2 0.554 0.132 4.191 0.000 0.498 0.424 #> x3 0.729 0.141 5.170 0.000 0.656 0.581 #> textual =~ #> x4 1.000 0.990 0.852 #> x5 1.113 0.066 16.946 0.000 1.102 0.855 #> x6 0.926 0.061 15.089 0.000 0.917 0.838 #> speed =~ #> x7 1.000 0.619 0.570 #> x8 1.180 0.130 9.046 0.000 0.731 0.723 #> x9 1.082 0.266 4.060 0.000 0.670 0.665 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual ~~ #> textual 0.408 0.099 4.110 0.000 0.459 0.459 #> speed 0.262 0.060 4.366 0.000 0.471 0.471 #> textual ~~ #> speed 0.173 0.056 3.081 0.002 0.283 0.283 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> .x1 0.549 0.156 3.509 0.000 0.549 0.404 #> .x2 1.134 0.112 10.135 0.000 1.134 0.821 #> .x3 0.844 0.100 8.419 0.000 0.844 0.662 #> .x4 0.371 0.050 7.382 0.000 0.371 0.275 #> .x5 0.446 0.057 7.870 0.000 0.446 0.269 #> .x6 0.356 0.047 7.658 0.000 0.356 0.298 #> .x7 0.799 0.097 8.222 0.000 0.799 0.676 #> .x8 0.488 0.120 4.080 0.000 0.488 0.477 #> .x9 0.566 0.119 4.768 0.000 0.566 0.558 #> visual 0.809 0.180 4.486 0.000 1.000 1.000 #> textual 0.979 0.121 8.075 0.000 1.000 1.000 #> speed 0.384 0.107 3.596 0.000 1.000 1.000 #> #> R-Square: #> Estimate #> x1 0.596 #> x2 0.179 #> x3 0.338 #> x4 0.725 #> x5 0.731 #> x6 0.702 #> x7 0.324 #> x8 0.523 #> x9 0.442 # Get nice fit indices with the `rempsyc::nice_table` integration nice_fit(fit.cfa, nice_table = TRUE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"sem-example","dir":"","previous_headings":"","what":"SEM example","title":"Convenience Functions for Package lavaan","text":"Note latent variables defined , can reuse , without redefine .","code":"# Define our other variables M <- \"visual\" IV <- c(\"ageyr\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV) regression <- list(speed = IV, textual = IV) covariance <- list(speed = \"textual\", ageyr = \"grade\") # Define indirect effects object indirect <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan( mediation = mediation, regression = regression, covariance = covariance, indirect = indirect, latent = latent, label = TRUE ) cat(model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> speed ~ ageyr + grade #> textual ~ ageyr + grade #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual fit.sem <- sem(model, data = HolzingerSwineford1939) # Get regression parameters and make pretty with `rempsyc::nice_table` lavaan_reg(fit.sem, nice_table = TRUE, highlight = TRUE) # Get covariances/correlations and make them pretty with # the `rempsyc::nice_table` integration lavaan_cor(fit.sem, nice_table = TRUE) # Get nice fit indices with the `rempsyc::nice_table` integration fit_table <- nice_fit(list(fit.cfa, fit.sem), nice_table = TRUE) fit_table # Save fit table to Word! flextable::save_as_docx(fit_table, path = \"fit_table.docx\") # Note that it will also render to PDF in an `rmarkdown` document # with `output: pdf_document`, but using `latex_engine: xelatex` # is necessary when including Unicode symbols in tables like with # the `nice_fit()` function. # Let's get the user-defined (e.g., indirect) effects only and make it pretty # with the `rempsyc::nice_table` integration lavaan_defined(fit.sem, nice_table = TRUE) # Plot our model nice_lavaanPlot(fit.sem) # Alternative way to plot mylayout <- data.frame( IV = c(\"\", \"x1\", \"grade\", \"\", \"ageyr\", \"\", \"\"), M = c(\"\", \"x2\", \"\", \"visual\", \"\", \"\", \"\"), DV = c(\"\", \"x3\", \"textual\", \"\", \"speed\", \"\", \"\"), DV.items = c(paste0(\"x\", 4:6), \"\", paste0(\"x\", 7:9)) ) |> as.matrix() mylayout #> IV M DV DV.items #> [1,] \"\" \"\" \"\" \"x4\" #> [2,] \"x1\" \"x2\" \"x3\" \"x5\" #> [3,] \"grade\" \"\" \"textual\" \"x6\" #> [4,] \"\" \"visual\" \"\" \"\" #> [5,] \"ageyr\" \"\" \"speed\" \"x7\" #> [6,] \"\" \"\" \"\" \"x8\" #> [7,] \"\" \"\" \"\" \"x9\" nice_tidySEM(fit.sem, layout = mylayout, label_location = 0.7) ggplot2::ggsave(\"my_semPlot.pdf\", width = 6, height = 6, limitsize = FALSE)"},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"final-note","dir":"","previous_headings":"","what":"Final note","title":"Convenience Functions for Package lavaan","text":"experimental package early stage. feedback feature request appreciated, package likely change evolve time based community feedback. Feel free open issue discussion share questions concerns. course, please look tutorials discover even cool features: https://lavaanExtra.remi-theriault.com/articles/","code":""},{"path":"https://lavaanExtra.remi-theriault.com/index.html","id":"support-me-and-this-package","dir":"","previous_headings":"","what":"Support me and this package","title":"Convenience Functions for Package lavaan","text":"Thank support. can support package : https://github.com/sponsors/rempsyc","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":null,"dir":"Reference","previous_headings":"","what":"Fit and plot CFA simultaneously — cfa_fit_plot","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"Prints saves CFA fit, well plots CFA factor loadings, simultaneously.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"","code":"cfa_fit_plot( model, data, covs = FALSE, estimator = \"MLR\", remove.items = \"\", print = TRUE, save.as.pdf = FALSE, file.name, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"model CFA model fit. data Data set fit CFA model. covs Logical, whether include covariances lavaan plot. estimator estimator use CFA. remove.items Optional, one wants remove items CFA model without redefine completely . print Logical, whether print model summary console. save..pdf Logical, whether save PDF high-resolution, scalable vector graphic quality plot. Defaults saving \"/model\" subfolder working directory. exist, creates . automatically open created PDF default browser. Defaults false. file.name Optional (save..pdf set TRUE), one wants something different default file name. saves pdf per default, .pdf extension specified add automatically. ... Arguments passed function lavaan::cfa.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"function returns lavaan fit object. However, also: prints summary lavaan fit object console, ; prints lavaanPlot lavaan fit object.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/cfa_fit_plot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fit and plot CFA simultaneously — cfa_fit_plot","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) #> This is lavaan 0.6-18 #> lavaan is FREE software! Please report any bugs. fit <- cfa_fit_plot(HS.model, HolzingerSwineford1939) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> Standard Scaled #> Test Statistic 85.306 87.132 #> Degrees of freedom 24 24 #> P-value (Chi-square) 0.000 0.000 #> Scaling correction factor 0.979 #> Yuan-Bentler correction (Mplus variant) #> #> Model Test Baseline Model: #> #> Test statistic 918.852 880.082 #> Degrees of freedom 36 36 #> P-value 0.000 0.000 #> Scaling correction factor 1.044 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 0.925 #> Tucker-Lewis Index (TLI) 0.896 0.888 #> #> Robust Comparative Fit Index (CFI) 0.930 #> Robust Tucker-Lewis Index (TLI) 0.895 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 -3737.745 #> Scaling correction factor 1.133 #> for the MLR correction #> Loglikelihood unrestricted model (H1) -3695.092 -3695.092 #> Scaling correction factor 1.051 #> for the MLR correction #> #> Akaike (AIC) 7517.490 7517.490 #> Bayesian (BIC) 7595.339 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 0.093 #> 90 Percent confidence interval - lower 0.071 0.073 #> 90 Percent confidence interval - upper 0.114 0.115 #> P-value H_0: RMSEA <= 0.050 0.001 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 0.862 #> #> Robust RMSEA 0.092 #> 90 Percent confidence interval - lower 0.072 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: Robust RMSEA <= 0.050 0.001 #> P-value H_0: Robust RMSEA >= 0.080 0.849 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 0.065 #> #> Parameter Estimates: #> #> Standard errors Sandwich #> Information bread Observed #> Observed information based on Hessian #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual =~ #> x1 1.000 0.900 0.772 #> x2 0.554 0.132 4.191 0.000 0.498 0.424 #> x3 0.729 0.141 5.170 0.000 0.656 0.581 #> textual =~ #> x4 1.000 0.990 0.852 #> x5 1.113 0.066 16.946 0.000 1.102 0.855 #> x6 0.926 0.061 15.089 0.000 0.917 0.838 #> speed =~ #> x7 1.000 0.619 0.570 #> x8 1.180 0.130 9.046 0.000 0.731 0.723 #> x9 1.082 0.266 4.060 0.000 0.670 0.665 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> visual ~~ #> textual 0.408 0.099 4.110 0.000 0.459 0.459 #> speed 0.262 0.060 4.366 0.000 0.471 0.471 #> textual ~~ #> speed 0.173 0.056 3.081 0.002 0.283 0.283 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) Std.lv Std.all #> .x1 0.549 0.156 3.509 0.000 0.549 0.404 #> .x2 1.134 0.112 10.135 0.000 1.134 0.821 #> .x3 0.844 0.100 8.419 0.000 0.844 0.662 #> .x4 0.371 0.050 7.382 0.000 0.371 0.275 #> .x5 0.446 0.057 7.870 0.000 0.446 0.269 #> .x6 0.356 0.047 7.658 0.000 0.356 0.298 #> .x7 0.799 0.097 8.222 0.000 0.799 0.676 #> .x8 0.488 0.120 4.080 0.000 0.488 0.477 #> .x9 0.566 0.119 4.768 0.000 0.566 0.558 #> visual 0.809 0.180 4.486 0.000 1.000 1.000 #> textual 0.979 0.121 8.075 0.000 1.000 1.000 #> speed 0.384 0.107 3.596 0.000 1.000 1.000 #> #> R-Square: #> Estimate #> x1 0.596 #> x2 0.179 #> x3 0.338 #> x4 0.725 #> x5 0.731 #> x6 0.702 #> x7 0.324 #> x8 0.523 #> x9 0.442 #>"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaanExtra-package.html","id":null,"dir":"Reference","previous_headings":"","what":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","title":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","text":"Affords alternative, vector-based syntax 'lavaan', well convenience functions naming paths defining indirect links automatically, addition convenience formatting optimized publication script sharing workflow.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaanExtra-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"lavaanExtra: Convenience Functions for Package 'lavaan' — lavaanExtra-package","text":"Maintainer: Rémi Thériault remi.theriault@mail.mcgill.ca (ORCID)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"Extract relevant covariance/correlation indices lavaan lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"","code":"lavaan_cov(fit, nice_table = FALSE, ...) lavaan_cor(fit, nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"fit lavaan fit object extract covariance indices nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"dataframe covariances/correlation, including covaried variables, covariance/correlation, corresponding p-value.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"lavaan_cor(): Shortcut lavaan_cov(fit, estimate = \"r\")","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_cov.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant covariance/correlation indices from lavaan model — lavaan_cov","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> (covariance <- list(speed = \"textual\", ageyr = \"grade\")) #> $speed #> [1] \"textual\" #> #> $ageyr #> [1] \"grade\" #> HS.model <- write_lavaan( regression = regression, covariance = covariance, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_cov(fit) #> Variable 1 Variable 2 SE Z p sigma CI_lower #> 16 textual speed 0.05102682 3.411223 6.467214e-04 0.1740639 0.07405313 #> 17 ageyr grade 0.03077116 7.488490 6.972201e-14 0.2304295 0.17011916 #> 32 visual textual 0.07430296 5.572306 2.513899e-08 0.4140388 0.26840769 #> 33 visual speed 0.05710260 4.545270 5.486495e-06 0.2595467 0.14762767 #> CI_upper r CI_lower_r CI_upper_r #> 16 0.2740746 0.2679391 0.1331814 0.4026968 #> 17 0.2907399 0.5332236 0.4471455 0.6193016 #> 32 0.5596700 0.4583362 0.3334309 0.5832415 #> 33 0.3714657 0.4384508 0.2944977 0.5824039"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"Extract relevant user-defined parameters (e.g., indirect total effects) indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"","code":"lavaan_defined( fit, underscores_to_symbol = \"→\", lhs_name = \"User-Defined Parameter\", rhs_name = \"Paths\", nice_table = FALSE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"fit lavaan fit object extract fit indices underscores_to_symbol Character convert underscores arrows first column, like indirect effects. Default right arrow symbol, can set NULL \"_\", desired symbol. also possible provide vector replacements . lhs_name Name first column, referring left-hand side expression (lhs). rhs_name Name first column, referring right-hand side expression (rhs). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"dataframe, including indirect effect (\"lhs\"), corresponding paths (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_defined.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant user-defined parameter (e.g., indirect or total effects) indices from lavaan model — lavaan_defined","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (mediation <- list( speed = \"visual\", textual = \"visual\", visual = c(\"ageyr\", \"grade\") )) #> $speed #> [1] \"visual\" #> #> $textual #> [1] \"visual\" #> #> $visual #> [1] \"ageyr\" \"grade\" #> (indirect <- list( IV = c(\"ageyr\", \"grade\"), M = \"visual\", DV = c(\"speed\", \"textual\") )) #> $IV #> [1] \"ageyr\" \"grade\" #> #> $M #> [1] \"visual\" #> #> $DV #> [1] \"speed\" \"textual\" #> HS.model <- write_lavaan(mediation, indirect = indirect, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_defined(fit, lhs_name = \"Indirect Effect\") #> Indirect Effect Paths SE Z #> 30 ageyr → visual → speed ageyr_visual*visual_speed 0.02808889 -3.198387 #> 31 ageyr → visual → textual ageyr_visual*visual_textual 0.04191650 -3.461890 #> 32 grade → visual → speed grade_visual*visual_speed 0.07291514 4.257496 #> 33 grade → visual → textual grade_visual*visual_textual 0.10134908 4.947490 #> p b CI_lower CI_upper B CI_lower_B #> 30 1.381987e-03 -0.08983914 -0.1448924 -0.03478593 -0.1508037 -0.2358595 #> 31 5.363956e-04 -0.14511033 -0.2272652 -0.06295550 -0.1534909 -0.2371048 #> 32 2.067294e-05 0.31043593 0.1675249 0.45334698 0.2477787 0.1503789 #> 33 7.517664e-07 0.50142352 0.3027830 0.70006406 0.2521937 0.1601663 #> CI_upper_B #> 30 -0.06574796 #> 31 -0.06987694 #> 32 0.34517843 #> 33 0.34422119"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"Extract relevant indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"","code":"lavaan_extract( fit, operator = NULL, lhs_name = \"Left-Hand Side\", rhs_name = \"Right-Hand Side\", underscores_to_symbol = \"→\", diag = NULL, nice_table = FALSE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"fit lavaan fit object extract fit indices operator operator subselect . lhs_name Name first column, referring left-hand side expression (lhs). rhs_name Name first column, referring right-hand side expression (rhs). underscores_to_symbol Character convert underscores arrows first column, like indirect effects. Default right arrow symbol, can set NULL \"_\", desired symbol. also possible provide vector replacements . diag extracting covariances (~~), whether include exclude diagonal values (one \"exclude\" \"include\"). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"dataframe, including indirect effect (\"lhs\"), corresponding paths (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_extract.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant indices from lavaan model based on specified operator — lavaan_extract","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (mediation <- list( speed = \"visual\", textual = \"visual\", visual = c(\"ageyr\", \"grade\") )) #> $speed #> [1] \"visual\" #> #> $textual #> [1] \"visual\" #> #> $visual #> [1] \"ageyr\" \"grade\" #> (indirect <- list( IV = c(\"ageyr\", \"grade\"), M = \"visual\", DV = c(\"speed\", \"textual\") )) #> $IV #> [1] \"ageyr\" \"grade\" #> #> $M #> [1] \"visual\" #> #> $DV #> [1] \"speed\" \"textual\" #> HS.model <- write_lavaan(mediation, indirect = indirect, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual #> textual ~ visual_textual*visual #> visual ~ ageyr_visual*ageyr + grade_visual*grade #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> grade_visual_speed := grade_visual * visual_speed #> grade_visual_textual := grade_visual * visual_textual #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_extract(fit, lhs_name = \"Indirect Effect\", operator = \":=\") #> Indirect Effect Right-Hand Side SE Z #> 30 ageyr → visual → speed ageyr_visual*visual_speed 0.02808889 -3.198387 #> 31 ageyr → visual → textual ageyr_visual*visual_textual 0.04191650 -3.461890 #> 32 grade → visual → speed grade_visual*visual_speed 0.07291514 4.257496 #> 33 grade → visual → textual grade_visual*visual_textual 0.10134908 4.947490 #> p b CI_lower CI_upper B CI_lower_B #> 30 1.381987e-03 -0.08983914 -0.1448924 -0.03478593 -0.1508037 -0.2358595 #> 31 5.363956e-04 -0.14511033 -0.2272652 -0.06295550 -0.1534909 -0.2371048 #> 32 2.067294e-05 0.31043593 0.1675249 0.45334698 0.2477787 0.1503789 #> 33 7.517664e-07 0.50142352 0.3027830 0.70006406 0.2521937 0.1601663 #> CI_upper_B #> 30 -0.06574796 #> 31 -0.06987694 #> 32 0.34517843 #> 33 0.34422119"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant regression indices from lavaan model — lavaan_reg","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"Extract relevant regression indices lavaan model lavaan::parameterEstimates lavaan::standardizedsolution.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"","code":"lavaan_reg(fit, nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"fit lavaan fit object extract fit indices nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"dataframe, including outcome (\"lhs\"), predictor (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_reg.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant regression indices from lavaan model — lavaan_reg","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_reg(fit) #> Outcome Predictor SE Z p b CI_lower #> 10 ageyr visual 0.10223059 -0.6515452 5.146946e-01 -0.06660785 -0.26697612 #> 11 ageyr textual 0.07452101 -4.3003671 1.705154e-05 -0.32046768 -0.46652617 #> 12 ageyr speed 0.13527746 4.2102536 2.550842e-05 0.56955240 0.30441346 #> 13 grade visual 0.04763058 0.2303820 8.177950e-01 0.01097323 -0.08238099 #> 14 grade textual 0.03444008 1.4407968 1.496421e-01 0.04962116 -0.01788016 #> 15 grade speed 0.06427861 4.6357654 3.556191e-06 0.29798057 0.17199681 #> CI_upper B CI_lower_B CI_upper_B #> 10 0.1337604 -0.05753255 -0.22998065 0.1149156 #> 11 -0.1744092 -0.30377383 -0.43682901 -0.1707186 #> 12 0.8346913 0.35378347 0.20775141 0.4998155 #> 13 0.1043274 0.01993320 -0.14957182 0.1894382 #> 14 0.1171225 0.09892078 -0.03509861 0.2329402 #> 15 0.4239643 0.38926587 0.24802239 0.5305094"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant variance indices from lavaan model — lavaan_var","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"Extract relevant variance indices lavaan model lavaan::parameterEstimates (estimate = \"sigma\", est column)) lavaan::standardizedsolution (estimate = \"r2\", est.std column). R2 values calculated 1 - est.std, new p values R2, following formula: stats::pnorm((1 - est) / se).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"","code":"lavaan_var(fit, estimate = \"r2\", nice_table = FALSE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"fit lavaan fit object extract covariance indices estimate estimate use, either standardized estimate (\"r2\", default), unstandardized estimate (\"sigma2\"). nice_table Logical, whether print table rempsyc::nice_table well print reference values bottom table. ... Arguments passed rempsyc::nice_table","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"dataframe covariances/correlation, including covaried variables, covariance/correlation, corresponding p-value.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/lavaan_var.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant variance indices from lavaan model — lavaan_var","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> (covariance <- list(speed = \"textual\", ageyr = \"grade\")) #> $speed #> [1] \"textual\" #> #> $ageyr #> [1] \"grade\" #> HS.model <- write_lavaan( regression = regression, covariance = covariance, latent = latent, label = TRUE ) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> #> ################################################## #> # [------------------Covariances-----------------] #> #> speed ~~ textual #> ageyr ~~ grade #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) lavaan_var(fit) #> Variable p R2 CI_lower CI_upper #> 18 x1 0 0.605 0.436 0.773 #> 19 x2 0 0.180 0.081 0.280 #> 20 x3 0 0.333 0.208 0.458 #> 21 x4 0 0.732 0.659 0.806 #> 22 x5 0 0.736 0.663 0.809 #> 23 x6 0 0.689 0.612 0.765 #> 24 x7 0 0.359 0.241 0.476 #> 25 x8 0 0.563 0.428 0.699 #> 26 x9 0 0.390 0.270 0.511 #> 27 ageyr 0 0.161 0.068 0.255 #> 28 grade 0 0.191 0.095 0.287 #> 29 visual NaN 0.000 0.000 0.000 #> 30 textual NaN 0.000 0.000 0.000 #> 31 speed 0 0.000 0.000 0.000"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant fit indices from lavaan model — nice_fit","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Compares fit one several lavaan models. Also optionally includes references values. reference fit values based Schreiber (2017), Table 3.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"","code":"nice_fit( model, model.labels, nice_table = FALSE, guidelines = TRUE, stars = FALSE, verbose = TRUE )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"model lavaan model object(s) extract fit indices model.labels Model labels use. named list provided model, default names list. Otherwise, list unnamed, defaults generic numbering. nice_table Logical, whether print table rempsyc::nice_table. guidelines Logical, nice_table = TRUE, whether display include reference values based Schreiber (2017), Table 3, bottom table. stars Logical, nice_table = TRUE, whether display significance stars (defaults FALSE). verbose Logical, whether display messages warnings.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"dataframe, representing select fit indices (chi2, df, chi2/df, p-value chi2 test, CFI, TLI, RMSEA 90% CI, unbiased SRMR, AIC, BIC).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Note nice_fit reports unbiased SRMR lavaan::lavResiduals() standard SRMR upwardly biased (doi:10.1007/s11336-016-9552-7 ) noticeable way smaller samples (thanks James Uanhoro change). using guidelines = TRUE, please carefully consider following 2023 quote Terrence D. Jorgensen: recommend including cutoffs table, perpetuate misuse. Fit indices test statistics, suggested cutoffs critical values associated known Type error rates. Numerous simulation studies shown poorly cutoffs perform model selection (e.g., , Jorgensen et al. (2018). Instead test statistics, fit indices designed measures effect size (practical significance), complement chi-squared test statistical significance. range RMSEA interpretations reminiscent range small/medium/large effect sizes proposed Cohen use power analyses, arbitrary alpha levels, least better respect idea (mis)fit matter magnitude, nearly simple \"perfect imperfect.\"","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"Schreiber, J. B. (2017). Update core reporting practices structural equation modeling. Research social administrative pharmacy, 13(3), 634-643. doi:10.1016/j.sapharm.2016.06.006","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_fit.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant fit indices from lavaan model — nice_fit","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) nice_fit(fit) #> Model chisq df chi2.df pvalue cfi tli rmsea rmsea.ci.lower #> 1 Model 1 116.263 36 3.23 0 0.926 0.887 0.086 0.069 #> rmsea.ci.upper srmr aic bic #> 1 0.104 0.052 8638.134 8749.248"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a quick lavaanPlot — nice_lavaanPlot","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"Make quick decent-looking lavaanPlot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"","code":"nice_lavaanPlot( model, node_options = list(shape = \"box\", fontname = \"Helvetica\"), edge_options = c(color = \"black\"), coefs = TRUE, stand = TRUE, covs = FALSE, stars = c(\"regress\", \"latent\", \"covs\"), sig = 0.05, graph_options = c(rankdir = \"LR\"), ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"model SEM CFA model plot. node_options Shape font name. edge_options Colour edges. coefs Logical, whether plot coefficients. Defaults TRUE. stand Logical, whether use standardized coefficients. Defaults TRUE. covs Logical, whether plot covariances. Defaults FALSE. stars links plot significance stars . One c(\"regress\", \"latent\", \"covs\"). sig significance threshold use plot coefficients (defaults .05). plot coefficients, set sig 1. graph_options Read left right, rather top bottom. ... Arguments passed function lavaanPlot::lavaanPlot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"lavaanPlot, classes c(\"grViz\", \"htmlwidget\"), representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_lavaanPlot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a quick lavaanPlot — nice_lavaanPlot","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) fit <- cfa(HS.model, HolzingerSwineford1939) nice_lavaanPlot(fit) {\"x\":{\"diagram\":\" digraph plot { \\n graph [ rankdir = LR ] \\n node [ shape = box, fontname = Helvetica ] \\n node [shape = box] \\n x1; x2; x3; x4; x5; x6; x7; x8; x9 \\n node [shape = oval] \\n visual; textual; speed \\n \\n edge [ color = black ] \\n visual->x1 [label = \\\"0.77***\\\"] visual->x2 [label = \\\"0.42***\\\"] visual->x3 [label = \\\"0.58***\\\"] textual->x4 [label = \\\"0.85***\\\"] textual->x5 [label = \\\"0.86***\\\"] textual->x6 [label = \\\"0.84***\\\"] speed->x7 [label = \\\"0.57***\\\"] speed->x8 [label = \\\"0.72***\\\"] speed->x9 [label = \\\"0.67***\\\"] \\n}\",\"config\":{\"engine\":\"dot\",\"options\":null}},\"evals\":[],\"jsHooks\":[]}"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract relevant modification indices along item labels — nice_modindices","title":"Extract relevant modification indices along item labels — nice_modindices","text":"Extract relevant modification indices along item labels, similarity score provided help guide decision-making removing redundant items high covariance.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract relevant modification indices along item labels — nice_modindices","text":"","code":"nice_modindices(fit, labels = NULL, method = \"lcs\", sort = TRUE, ...)"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract relevant modification indices along item labels — nice_modindices","text":"fit lavaan fit object extract modification indices labels Dataframe labels. original data frame provided, contains labelled variables, automatically attempt extract correct labels dataframe. method Method distance calculation stringdist::stringsim. Defaults \"lcs\". sort Logical. TRUE, sort output using values modification index values. Higher values appear first. Defaults TRUE. ... Arguments passed lavaan::modindices","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract relevant modification indices along item labels — nice_modindices","text":"dataframe, including outcome (\"lhs\"), predictor (\"rhs\"), standardized regression coefficient (\"std.\"), corresponding p-value, well unstandardized regression coefficient (\"est\") confidence interval (\"ci.lower\", \"ci.upper\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_modindices.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract relevant modification indices along item labels — nice_modindices","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> (regression <- list( ageyr = c(\"visual\", \"textual\", \"speed\"), grade = c(\"visual\", \"textual\", \"speed\") )) #> $ageyr #> [1] \"visual\" \"textual\" \"speed\" #> #> $grade #> [1] \"visual\" \"textual\" \"speed\" #> HS.model <- write_lavaan(latent = latent, regression = regression) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> #> ################################################## #> # [---------Regressions (Direct effects)---------] #> #> ageyr ~ visual + textual + speed #> grade ~ visual + textual + speed #> library(lavaan) fit <- sem(HS.model, data = HolzingerSwineford1939) nice_modindices(fit, maximum.number = 5) #> lhs op rhs mi #> 1 visual =~ x9 35.699 #> 2 visual =~ x7 16.659 #> 3 x7 ~~ grade 16.511 #> 4 x7 ~~ ageyr 10.030 #> 5 textual =~ x3 9.833 data_labels <- data.frame( x1 = \"I have good visual perception\", x2 = \"I have good cube perception\", x3 = \"I have good at lozenge perception\", x4 = \"I have paragraph comprehension\", x5 = \"I am good at sentence completion\", x6 = \"I excel at finding the meaning of words\", x7 = \"I am quick at doing mental additions\", x8 = \"I am quick at counting dots\", x9 = \"I am quick at discriminating straight and curved capitals\" ) nice_modindices(fit, maximum.number = 10, labels = data_labels, op = \"~~\") #> lhs op rhs mi lhs.labels #> 1 x7 ~~ grade 16.511 I am quick at doing mental additions #> 2 x7 ~~ ageyr 10.030 I am quick at doing mental additions #> 3 x2 ~~ x7 9.673 I have good cube perception #> 4 x7 ~~ x8 9.479 I am quick at doing mental additions #> 5 x2 ~~ x3 8.746 I have good cube perception #> 6 x1 ~~ x9 8.408 I have good visual perception #> rhs.labels similarity similar #> 1 NA FALSE #> 2 NA FALSE #> 3 I am quick at doing mental additions 0.381 FALSE #> 4 I am quick at counting dots 0.698 TRUE #> 5 I have good at lozenge perception 0.800 TRUE #> 6 I am quick at discriminating straight and curved capitals 0.326 FALSE x <- HolzingerSwineford1939 x <- sjlabelled::set_label(x, label = c(rep(\"\", 6), data_labels)) fit <- sem(HS.model, data = x) nice_modindices(fit, maximum.number = 10, op = \"~~\") #> lhs op rhs mi #> 1 x7 ~~ grade 16.511 #> 2 x7 ~~ ageyr 10.030 #> 3 x2 ~~ x7 9.673 #> 4 x7 ~~ x8 9.479 #> 5 x2 ~~ x3 8.746 #> 6 x1 ~~ x9 8.408"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":null,"dir":"Reference","previous_headings":"","what":"Make a quick tidySEM plot — nice_tidySEM","title":"Make a quick tidySEM plot — nice_tidySEM","text":"Make quick decent-looking tidySEM plot.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Make a quick tidySEM plot — nice_tidySEM","text":"","code":"nice_tidySEM( fit, layout = NULL, hide_nonsig_edges = FALSE, hide_var = TRUE, hide_cov = FALSE, hide_mean = TRUE, est_std = TRUE, label, label_location = NULL, reduce_items = NULL, plot = TRUE, ... )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Make a quick tidySEM plot — nice_tidySEM","text":"fit SEM CFA model fit plot. layout matrix (data.frame) describes structure; see tidySEM::get_layout. named list provided, names \"IV\" (independent variables), \"M\" (mediator), \"DV\" (dependent variables), nice_tidySEM attempts write layout matrix automatically. hide_nonsig_edges Logical, hides non-significant edges. Defaults FALSE. hide_var Logical, hides variances. Defaults TRUE. hide_cov Logical, hides co-variances. Defaults FALSE. hide_mean Logical, hides means/node labels. Defaults TRUE. est_std Logical, whether use standardized coefficients. Defaults TRUE. label Labels used plot. elsewhere lavaanExtra, provided named list format (colname = \"label\"). label_location Location label along path, percentage (defaults middle, 0.5). reduce_items numeric vector length 1 (x) 2 (x & y) defining much space trim nodes (boxes) items defining latent variables. Can provided either reduce_items = 0.4 (affect horizontal space, x), reduce_items = c(x = 0.4, y = 0.2) (affect horizontal x vertical y). plot Logical, whether plot result (default). FALSE, returns tidy_sem object, can edited needed. ... Arguments passed tidySEM::prepare_graph.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Make a quick tidySEM plot — nice_tidySEM","text":"tidySEM plot, class ggplot, representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/nice_tidySEM.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Make a quick tidySEM plot — nice_tidySEM","text":"","code":"# Calculate scale averages library(lavaan) data <- HolzingerSwineford1939 data$visual <- rowMeans(data[paste0(\"x\", 1:3)]) data$textual <- rowMeans(data[paste0(\"x\", 4:6)]) data$speed <- rowMeans(data[paste0(\"x\", 7:9)]) # Define our variables IV <- c(\"sex\", \"ageyr\", \"agemo\", \"school\") M <- c(\"visual\", \"grade\") DV <- c(\"speed\", \"textual\") # Define our lavaan lists mediation <- list(speed = M, textual = M, visual = IV, grade = IV) # Define indirect object structure <- list(IV = IV, M = M, DV = DV) # Write the model, and check it model <- write_lavaan(mediation, indirect = structure, label = TRUE) cat(model) #> ################################################## #> # [-----------Mediations (named paths)-----------] #> #> speed ~ visual_speed*visual + grade_speed*grade #> textual ~ visual_textual*visual + grade_textual*grade #> visual ~ sex_visual*sex + ageyr_visual*ageyr + agemo_visual*agemo + school_visual*school #> grade ~ sex_grade*sex + ageyr_grade*ageyr + agemo_grade*agemo + school_grade*school #> #> ################################################## #> # [--------Mediations (indirect effects)---------] #> #> sex_visual_speed := sex_visual * visual_speed #> sex_visual_textual := sex_visual * visual_textual #> ageyr_visual_speed := ageyr_visual * visual_speed #> ageyr_visual_textual := ageyr_visual * visual_textual #> agemo_visual_speed := agemo_visual * visual_speed #> agemo_visual_textual := agemo_visual * visual_textual #> school_visual_speed := school_visual * visual_speed #> school_visual_textual := school_visual * visual_textual #> sex_grade_speed := sex_grade * grade_speed #> sex_grade_textual := sex_grade * grade_textual #> ageyr_grade_speed := ageyr_grade * grade_speed #> ageyr_grade_textual := ageyr_grade * grade_textual #> agemo_grade_speed := agemo_grade * grade_speed #> agemo_grade_textual := agemo_grade * grade_textual #> school_grade_speed := school_grade * grade_speed #> school_grade_textual := school_grade * grade_textual #> # Fit model fit <- sem(model, data) # Plot model # \\donttest{ nice_tidySEM(fit, layout = structure) # }"},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":null,"dir":"Reference","previous_headings":"","what":"Vector-based lavaan syntax interpreter — write_lavaan","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"Vector-based lavaan syntax interpreter.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"","code":"write_lavaan( mediation = NULL, regression = NULL, covariance = NULL, indirect = NULL, latent = NULL, intercept = NULL, threshold = NULL, constraint.equal = NULL, constraint.smaller = NULL, constraint.larger = NULL, custom = NULL, label = FALSE, use.letters = FALSE )"},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"mediation Mediation indicators (~ symbol: \"regressed \"). Differs argument regression path names can optionally specified automatically argument label. regression Regression indicators (~ symbol: \"regressed \"). covariance (Residual) (co)variance indicators (~~ symbol: \"correlated \"). indirect Indirect effect indicators (:= symbol: \"indirect effect defined \"). named list provided, names \"IV\" (independent variables), \"M\" (mediator), \"DV\" (dependent variables), write_lavaan attempts write indirect effects automatically. case, mediation argument must specified . latent Latent variable indicators (=~ symbol: \"measured \"). intercept Intercept indicators (~ 1 symbol: \"intercept\"). threshold Threshold indicators (| symbol: \"threshold\"). constraint.equal Equality indicators (== symbol). constraint.smaller Smaller indicators (< symbol). constraint.larger Greater indicators (> symbol). custom Custom specifications. Takes single string just like regular lavaan syntax . Always added end model. label Logical, whether display path names mediation argument. use.letters Logical, labels, whether use letters instead variable names.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"character string, representing specified lavaan model.","code":""},{"path":[]},{"path":"https://lavaanExtra.remi-theriault.com/reference/write_lavaan.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Vector-based lavaan syntax interpreter — write_lavaan","text":"","code":"x <- paste0(\"x\", 1:9) (latent <- list( visual = x[1:3], textual = x[4:6], speed = x[7:9] )) #> $visual #> [1] \"x1\" \"x2\" \"x3\" #> #> $textual #> [1] \"x4\" \"x5\" \"x6\" #> #> $speed #> [1] \"x7\" \"x8\" \"x9\" #> HS.model <- write_lavaan(latent = latent) cat(HS.model) #> ################################################## #> # [-----Latent variables (measurement model)-----] #> #> visual =~ x1 + x2 + x3 #> textual =~ x4 + x5 + x6 #> speed =~ x7 + x8 + x9 #> library(lavaan) fit <- lavaan(HS.model, data = HolzingerSwineford1939, auto.var = TRUE, auto.fix.first = TRUE, auto.cov.lv.x = TRUE ) summary(fit, fit.measures = TRUE) #> lavaan 0.6-18 ended normally after 35 iterations #> #> Estimator ML #> Optimization method NLMINB #> Number of model parameters 21 #> #> Number of observations 301 #> #> Model Test User Model: #> #> Test statistic 85.306 #> Degrees of freedom 24 #> P-value (Chi-square) 0.000 #> #> Model Test Baseline Model: #> #> Test statistic 918.852 #> Degrees of freedom 36 #> P-value 0.000 #> #> User Model versus Baseline Model: #> #> Comparative Fit Index (CFI) 0.931 #> Tucker-Lewis Index (TLI) 0.896 #> #> Loglikelihood and Information Criteria: #> #> Loglikelihood user model (H0) -3737.745 #> Loglikelihood unrestricted model (H1) -3695.092 #> #> Akaike (AIC) 7517.490 #> Bayesian (BIC) 7595.339 #> Sample-size adjusted Bayesian (SABIC) 7528.739 #> #> Root Mean Square Error of Approximation: #> #> RMSEA 0.092 #> 90 Percent confidence interval - lower 0.071 #> 90 Percent confidence interval - upper 0.114 #> P-value H_0: RMSEA <= 0.050 0.001 #> P-value H_0: RMSEA >= 0.080 0.840 #> #> Standardized Root Mean Square Residual: #> #> SRMR 0.065 #> #> Parameter Estimates: #> #> Standard errors Standard #> Information Expected #> Information saturated (h1) model Structured #> #> Latent Variables: #> Estimate Std.Err z-value P(>|z|) #> visual =~ #> x1 1.000 #> x2 0.554 0.100 5.554 0.000 #> x3 0.729 0.109 6.685 0.000 #> textual =~ #> x4 1.000 #> x5 1.113 0.065 17.014 0.000 #> x6 0.926 0.055 16.703 0.000 #> speed =~ #> x7 1.000 #> x8 1.180 0.165 7.152 0.000 #> x9 1.082 0.151 7.155 0.000 #> #> Covariances: #> Estimate Std.Err z-value P(>|z|) #> visual ~~ #> textual 0.408 0.074 5.552 0.000 #> speed 0.262 0.056 4.660 0.000 #> textual ~~ #> speed 0.173 0.049 3.518 0.000 #> #> Variances: #> Estimate Std.Err z-value P(>|z|) #> .x1 0.549 0.114 4.833 0.000 #> .x2 1.134 0.102 11.146 0.000 #> .x3 0.844 0.091 9.317 0.000 #> .x4 0.371 0.048 7.779 0.000 #> .x5 0.446 0.058 7.642 0.000 #> .x6 0.356 0.043 8.277 0.000 #> .x7 0.799 0.081 9.823 0.000 #> .x8 0.488 0.074 6.573 0.000 #> .x9 0.566 0.071 8.003 0.000 #> visual 0.809 0.145 5.564 0.000 #> textual 0.979 0.112 8.737 0.000 #> speed 0.384 0.086 4.451 0.000 #>"},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-022","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.2","title":"lavaanExtra 0.2.2","text":"Incoming ✨","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0211","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.1.1","title":"lavaanExtra 0.2.1.1","text":"Incoming ✨","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-021","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.1","title":"lavaanExtra 0.2.1","text":"New CRAN submission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.3","title":"lavaanExtra 0.2.1","text":"Fix bug nice_fit() created error categorical variables (#37)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.2","title":"lavaanExtra 0.2.1","text":"Fix bug lavaan_defined() / lavaan_extract() repeated first cell rows first column (#36)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-2-1-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0.1","title":"lavaanExtra 0.2.1","text":"Now skips tests examples DiagrammeRsvg installed","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-020","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.2.0","title":"lavaanExtra 0.2.0","text":"CRAN release: 2023-10-15 CRAN resubmission fix unicode problem","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-019","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.9","title":"lavaanExtra 0.1.9","text":"New release + CRAN New paper JOSS! Citation updated accordingly.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-9","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.8.1","title":"lavaanExtra 0.1.9","text":"?lavaanExtra now works expected. write_lavaan(): accepts new argument, threshold, represented “|” operator. lavaan_ind() renames lavaan_defined() specific indirect effects actually extracts user-defined parameters total effects moderated slopes using := operator. lavaan_reg() gets rid estimate argument, comply best practices reporting unstandardized standardized parameters respective confidence intervals. new function: lavaan_extract(), takes specific operator extracts relevant information (now used internally lavaan_reg(), lavaan_defined(), lavaan_cov())","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-018","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.8","title":"lavaanExtra 0.1.8","text":"CRAN release: 2023-08-25 CRAN resubmission New function: nice_modindices, outputs modification indices along item labels similarity score left-hand side right-hand side items. Useful assess item redundancy considering modification indices.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-017","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.7","title":"lavaanExtra 0.1.7","text":"CRAN release: 2023-06-25 CRAN resubmission: suggested dependencies now check correct version rlang::check_installed().","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-016","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.6","title":"lavaanExtra 0.1.6","text":"CRAN release: 2023-05-24 CRAN resubmission: tests now run even without suggested dependencies.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-015","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.5","title":"lavaanExtra 0.1.5","text":"CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.7","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: new argument: reduce_items, change size nodes (boxes) items defining latent variables (often require less emphasis).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.6","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: now omit leading zero using standardized coefficients (APA style). Update fit indices recommendations Schreiber et al. (2006) Schreiber (2017). benchmark changed RMSEA, moving < .05 [.00, .08] < .06-.08 [.00, .10]. Make table shorter combining RMSEA column confidence interval shortening AIC BIC interpretations.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.5","title":"lavaanExtra 0.1.5","text":"lavaan_cov: renamed r column covariance since cases standardized residual variances real correlations. New function: lavaan_cor, lavaan_cov actual correlations lavaan_reg, lavaan_ind, lavaan_cov: new argument estimate can either “B” obtain standardized estimates corresponding p values confidence interval, “b” unstandardized values. nice_lavaanPlot: stars now appear regression per default, also latent variables covariances c(\"regress\", \"latent\", \"covs\").","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-3","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.4","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: corrected bug whereas layout contained columns named c(“IV”, “M”, “DV”), remove extra columns (items), explicitly ignoring part layout provided. nice_lavaanPlot: now default black path lines instead gray.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-4","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.3","title":"lavaanExtra 0.1.5","text":"examples internal tests, now check package availability satisfy CRAN requirements. Remove vignettes package, satisfy CRAN package size requirements (still available website however).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-5","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.2","title":"lavaanExtra 0.1.5","text":"nice_fit: better error message providing lavaan object. tmvnsim package now required nice_tidySEM seems necessary use tidySEM’s new version.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-5-6","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4.1","title":"lavaanExtra 0.1.5","text":"nice_tidySEM: New argument hide covariances: hide_cov (defaults FALSE).","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-014","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.4","title":"lavaanExtra 0.1.4","text":"CRAN release: 2023-02-04 CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.3","title":"lavaanExtra 0.1.4","text":"remove copied/reexported save_as_docx like favour explicitly calling flextable::save_as_docx. way creating namespace conflicts functions, consistent new approach rempsyc, also gives credit flextable package, powerhouse produces tables hood. nice_fit now requires list models (single model), accept models loosely provided function different arguments. get rid dot-dot-dot ... argument favour supporting list objects. nice_fit now added footnote reference Schreiber et al. (2006) fit indices references using nice_table = TRUE.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.2","title":"lavaanExtra 0.1.4","text":"nice_fit: gains model.labels argument customize model names table.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-1-4-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3.1","title":"lavaanExtra 0.1.4","text":"lavaan_ind gains argument, underscores_to_arrows, replace underscores arrows indirect effect column, indirect effects quickly visually interpretable. nice_tidySEM: meaningful error message providing unmatching label names. nice_fit look improved using nice_table = TRUE","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-013","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.3","title":"lavaanExtra 0.1.3","text":"CRAN release: 2022-10-04 CRAN resubmission","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-012","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.2","title":"lavaanExtra 0.1.2","text":"rempsyc package dependency now CRAN, can rely normally now (yeah!). Adding test coverage (100% far!). Preparing CRAN.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-011","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.1","title":"lavaanExtra 0.1.1","text":"nice_tidySEM: Gains label_location ... arguments.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-010","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.1.0","title":"lavaanExtra 0.1.0","text":"nice_tidySEM: Corrected bug providing structure/matrix layout.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-009","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.9","title":"lavaanExtra 0.0.9","text":"Added new function: nice_tidySEM, quick decent-looking tidySEM plot sensical (customizable) defaults.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-008","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.8","title":"lavaanExtra 0.0.8","text":"write_lavaan: Exciting news! Automatic indirect effects now seemingly support combination IV, moderator, DV!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-007","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.7","title":"lavaanExtra 0.0.7","text":"write_lavaan: Automatic indirect effects now support another scenario: two mediators three IVs!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-006","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.6","title":"lavaanExtra 0.0.6","text":"Added new function: nice_lavaanPlot, quick decent-looking lavaanPlot sensical (customizable) defaults. write_lavaan: Automatic indirect effects now support another scenario: two mediators two IVs!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-005","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.5","title":"lavaanExtra 0.0.5","text":"write_lavaan: Fixed bug automatic indirect effects 1 mediator making forbidden paths (two mediators tested successfully)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-004","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.4","title":"lavaanExtra 0.0.4","text":"Adds ellipsis pass desired argument lavaan::cfa, thus removes default missing = \"fiml\" causing bug estimator = DWLS. Changes default saving PDF opening RStudio Viewer, adds additional save..pdf argument save PDF. Now imports flextable::save_as_docx (save_as_html, save_as_image, save_as_pptx…) support saving nice_fit tables Word without explicitly load flextable rempsyc. Added package logo!","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-003","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.3","title":"lavaanExtra 0.0.3","text":"Added new function: cfa_fit_plot simultaneously print, save, plot CFA results.","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-002","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.2","title":"lavaanExtra 0.0.2","text":"Added new arguments/symbols: constraint.equal (==), constraint.smaller (<), constraint.larger (>), custom (accepts single, lavaan-like string)","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-0-2","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.1.0","title":"lavaanExtra 0.0.2","text":"Added automatic indirect effects","code":""},{"path":"https://lavaanExtra.remi-theriault.com/news/index.html","id":"lavaanextra-0-0-2-1","dir":"Changelog","previous_headings":"","what":"lavaanExtra 0.0.0.9","title":"lavaanExtra 0.0.2","text":"First package version","code":""}]
Model
χ2
df
χ2∕df
p
CFI
TLI
RMSEA [90% CI]
SRMR
AIC
BIC
Model 1
85.31
24
3.55
< .001
.93
.90
.09 [.07, .11]
.06
7,517.49
7,595.34
Common guidelinesa
—
< 2 or 3
> .05
≥ .95
< .05 [.00, .08]
≤ .08
Smaller
aBased on Schreiber (2017), Table 3.
fit.cfa
fit.cfa2
13.11
6
2.19
.041
.98
.96
.06 [.01, .11]
.03
5,106.23
5,161.84
Outcome
Predictor
SE
Z
b
95% CI (b)
b*
95% CI (b*)
speed
visual
0.05
3.91
< .001***
0.20
[0.10, 0.29]
0.21
[0.11, 0.31]
textual
0.06
4.53
0.29
[0.16, 0.41]
0.24
[0.14, 0.34]
ageyr
-2.47
.014*
-0.13
[-0.24, -0.03]
-0.16
[-0.29, -0.03]
grade
0.11
4.31
0.49
[0.27, 0.72]
0.28
[0.16, 0.40]
0.57
.568
0.03
[-0.07, 0.12]
0.04
[-0.09, 0.16]
0.10
4.90
0.50
[0.30, 0.70]
0.31
[0.19, 0.43]
-6.72
-0.41
[-0.52, -0.29]
-0.40
[-0.51, -0.29]
0.13
5.87
0.76
[0.51, 1.01]
0.36
[0.24, 0.47]
3.86
0.19
[0.09, 0.29]
[0.10, 0.31]
4.52
[0.14, 0.33]
0.09
6.11
0.53
[0.36, 0.70]
0.33
[0.23, 0.43]
-6.85
[-0.53, -0.29]
5.93
[0.51, 1.02]
Variable 1
Variable 2
σ
95% CI (σ)
r
95% CI (r)
2.25
.024*
[0.01, 0.17]
.13
[0.02, 0.24]
7.89
0.27
[0.20, 0.33]
.51
[0.43, 0.59]
fit.saturated
0.00
0
Inf
1.0
.00 [.00, .00]
.00
3,483.46
3,539.02
fit.path
1
1.3
.00 [.00, .13]
-.00
3,481.79
3,533.64
Indirect Effect
Paths
age → visual → speed
ageyr_visual*visual_speed
0.01
-2.08
.037*
-0.03
[-0.05, -0.00]
[-0.06, -0.00]
grade → visual → textual
grade_visual*visual_textual
3.12
.002**
0.14
[0.05, 0.23]
0.07
[0.03, 0.11]
fit.latent
118.92
37
3.21
.92
.89
.09 [.07, .10]
.05
8,638.79
8,746.20
mpg
cyl
0.70
-1.17
.244
-0.81
[-2.18, 0.55]
-0.24
[-0.65, 0.16]
disp
-1.54
.123
-0.01
[-0.03, 0.00]
-0.29
[-0.65, 0.08]
hp
0.02
-1.52
.128
-0.02
[-0.05, 0.01]
-0.26
[-0.60, 0.07]
drat
1.53
1.41
.159
2.15
[-0.84, 5.15]
[-0.07, 0.46]
0.23
1.35
.177
0.32
[-0.14, 0.78]
0.18
[-0.08, 0.43]
19.37
-2.12
.034*
-41.13
[-79.09, -3.17]
-0.18
[-0.34, -0.02]
wt
14.04
5.54
77.72
[50.20, 105.24]
0.61
[0.41, 0.82]
qsec
6.89
-1.87
.061
-12.91
[-26.42, 0.59]
-0.19
[-0.38, 0.01]
nice_fit()