library(minvariance)
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
#> ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
#> ✓ tibble 3.1.0 ✓ dplyr 1.0.5
#> ✓ tidyr 1.1.3 ✓ stringr 1.4.0
#> ✓ readr 1.4.0 ✓ forcats 0.5.1
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag() masks stats::lag()
library(lavaan)
#> This is lavaan 0.6-8
#> lavaan is FREE software! Please report any bugs.
library(semPlot)
Load data
filepath <- "https://quantdev.ssri.psu.edu/sites/qdev/files/WISC_MIexample.csv"
df <- read_csv(file = url(filepath))
#>
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#> id = col_double(),
#> info1 = col_double(),
#> comp1 = col_double(),
#> simi1 = col_double(),
#> voca1 = col_double(),
#> info6 = col_double(),
#> comp6 = col_double(),
#> simi6 = col_double(),
#> voca6 = col_double()
#> )
Fit statistics
minvariance(data = df,
var_list = list(t1 = c("info1", "comp1", "simi1", "voca1"),
t6 = c("info6", "comp6", "simi6", "voca6")),
remove = list(unique_covar = T),
return = "fit_statistics") %>%
knitr::kable(digits = 3)
configural |
25.968 |
25 |
11252.23 |
11335.18 |
0.991 |
0.042 |
0.031 |
0.987 |
TRUE |
weak |
41.897 |
22 |
11262.16 |
11335.16 |
0.976 |
0.067 |
0.076 |
0.969 |
TRUE |
strong |
53.723 |
19 |
11267.98 |
11331.03 |
0.965 |
0.075 |
0.087 |
0.961 |
TRUE |
strict |
134.559 |
15 |
11340.82 |
11390.59 |
0.871 |
0.134 |
0.169 |
0.876 |
TRUE |
Model tests
minvariance(data = df,
var_list = list(t1 = c("info1", "comp1", "simi1", "voca1"),
t6 = c("info6", "comp6", "simi6", "voca6")),
remove = list(unique_covar = T),
return = "model_tests") %>%
knitr::kable(digits = 3)
configural |
19 |
11252.23 |
11335.18 |
25.968 |
NA |
NA |
NA |
weak |
22 |
11262.16 |
11335.16 |
41.897 |
15.929 |
3 |
0.001 |
strong |
25 |
11267.98 |
11331.03 |
53.723 |
11.826 |
3 |
0.008 |
strict |
29 |
11340.82 |
11390.59 |
134.559 |
80.836 |
4 |
0.000 |
lavaan syntax
lminvar_syntax <- minvariance(data = df,
var_list = list(t1 = c("info1", "comp1", "simi1", "voca1"),
t6 = c("info6", "comp6", "simi6", "voca6")),
remove = list(unique_covar = T),
return = "lavaan_syntax")
Configural
lminvar_syntax$configural %>%
cat()
#> #### CONFIGURAL INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * info1 + lambda1 * info1 + comp1 + simi1 + voca1
#> eta2 =~ NA * info6 + lambda1 * info6 + comp6 + simi6 + voca6
#> # Specify Latent Variable Means ----
#> eta1 ~ 0 * 1
#> eta2 ~ 1
#> # Specify Latent Variable Variances ----
#> eta1 ~~ 1 * eta1
#> eta2 ~~ eta2
#> # Specify Latent Variable Covariances ----
#> eta1 ~~ eta2
#> # Specify Observed Variable Intercepts ----
#> info1 ~ tau1 * 1
#> comp1 ~ 1
#> simi1 ~ 1
#> voca1 ~ 1
#> info6 ~ tau1 * 1
#> comp6 ~ 1
#> simi6 ~ 1
#> voca6 ~ 1
#> # Specify Unique Variances ----
#> info1 ~~ info1
#> comp1 ~~ comp1
#> simi1 ~~ simi1
#> voca1 ~~ voca1
#> info6 ~~ info6
#> comp6 ~~ comp6
#> simi6 ~~ simi6
#> voca6 ~~ voca6
#> # Specify Unique Covariances ----
#> # REMOVED
Weak
lminvar_syntax$weak %>%
cat()
#> #### WEAK INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * info1 + lambda1 * info1 + lambda2 * comp1 + lambda3 * simi1 + lambda4 * voca1
#> eta2 =~ NA * info6 + lambda1 * info6 + lambda2 * comp6 + lambda3 * simi6 + lambda4 * voca6
#> # Specify Latent Variable Means ----
#> eta1 ~ 0 * 1
#> eta2 ~ 1
#> # Specify Latent Variable Variances ----
#> eta1 ~~ 1 * eta1
#> eta2 ~~ eta2
#> # Specify Latent Variable Covariances ----
#> eta1 ~~ eta2
#> # Specify Observed Variable Intercepts ----
#> info1 ~ tau1 * 1
#> comp1 ~ 1
#> simi1 ~ 1
#> voca1 ~ 1
#> info6 ~ tau1 * 1
#> comp6 ~ 1
#> simi6 ~ 1
#> voca6 ~ 1
#> # Specify Unique Variances ----
#> info1 ~~ info1
#> comp1 ~~ comp1
#> simi1 ~~ simi1
#> voca1 ~~ voca1
#> info6 ~~ info6
#> comp6 ~~ comp6
#> simi6 ~~ simi6
#> voca6 ~~ voca6
#> # Specify Unique Covariances ----
#> # REMOVED
Strong
lminvar_syntax$strong %>%
cat()
#> #### STRONG INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * info1 + lambda1 * info1 + lambda2 * comp1 + lambda3 * simi1 + lambda4 * voca1
#> eta2 =~ NA * info6 + lambda1 * info6 + lambda2 * comp6 + lambda3 * simi6 + lambda4 * voca6
#> # Specify Latent Variable Means ----
#> eta1 ~ 0 * 1
#> eta2 ~ 1
#> # Specify Latent Variable Variances ----
#> eta1 ~~ 1 * eta1
#> eta2 ~~ eta2
#> # Specify Latent Variable Covariances ----
#> eta1 ~~ eta2
#> # Specify Observed Variable Intercepts ----
#> info1 ~ tau1 * 1
#> comp1 ~ tau2 * 1
#> simi1 ~ tau3 * 1
#> voca1 ~ tau4 * 1
#> info6 ~ tau1 * 1
#> comp6 ~ tau2 * 1
#> simi6 ~ tau3 * 1
#> voca6 ~ tau4 * 1
#> # Specify Unique Variances ----
#> info1 ~~ info1
#> comp1 ~~ comp1
#> simi1 ~~ simi1
#> voca1 ~~ voca1
#> info6 ~~ info6
#> comp6 ~~ comp6
#> simi6 ~~ simi6
#> voca6 ~~ voca6
#> # Specify Unique Covariances ----
#> # REMOVED
Strict
lminvar_syntax$strict %>%
cat()
#> #### STRICT INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * info1 + lambda1 * info1 + lambda2 * comp1 + lambda3 * simi1 + lambda4 * voca1
#> eta2 =~ NA * info6 + lambda1 * info6 + lambda2 * comp6 + lambda3 * simi6 + lambda4 * voca6
#> # Specify Latent Variable Means ----
#> eta1 ~ 0 * 1
#> eta2 ~ 1
#> # Specify Latent Variable Variances ----
#> eta1 ~~ 1 * eta1
#> eta2 ~~ eta2
#> # Specify Latent Variable Covariances ----
#> eta1 ~~ eta2
#> # Specify Observed Variable Intercepts ----
#> info1 ~ tau1 * 1
#> comp1 ~ tau2 * 1
#> simi1 ~ tau3 * 1
#> voca1 ~ tau4 * 1
#> info6 ~ tau1 * 1
#> comp6 ~ tau2 * 1
#> simi6 ~ tau3 * 1
#> voca6 ~ tau4 * 1
#> # Specify Unique Variances ----
#> info1 ~~ theta1 * info1
#> comp1 ~~ theta2 * comp1
#> simi1 ~~ theta3 * simi1
#> voca1 ~~ theta4 * voca1
#> info6 ~~ theta1 * info6
#> comp6 ~~ theta2 * comp6
#> simi6 ~~ theta3 * simi6
#> voca6 ~~ theta4 * voca6
#> # Specify Unique Covariances ----
#> # REMOVED