Skip to content

R functions to generate lavaan code for testing longitudinal measurement invariance

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

milanwiedemann/minvariance

Repository files navigation

minvariance

The goal of minvariance is to aid the understanding of longitudinal measurement invariance and see which parts of this method could be automated in R. The vignettes on the website of this package aim to replicate some examples found online. If you have any questions, ideas, or comments please get in touch.

Installation

You can install the released version of minvariance from GitHub with:

# install.packages("devtools")
devtools::install_github("milanwiedemann/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(minvariance)

# Specify list of variables 
# Generate lavaan syntax
long_minvariance_syntax(var_list = list(t1 = c("i1_t1", "i2_t1", "i3_t1"), 
                                        t2 = c("i1_t2", "i1_t2", "i1_t2")), 
                        model = "configural") %>% 
  cat()
#> Configural Invariance Model (Pattern Invariance)
#> #### CONFIGURAL INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * i1_t1 + lambda1 * i1_t1 + i2_t1 + i3_t1
#> eta2 =~ NA * i1_t2 + lambda1 * i1_t2 + i1_t2 + i1_t2
#> # 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 ----
#> i1_t1 ~ tau1 * 1 
#> i2_t1 ~ 1 
#> i3_t1 ~ 1 
#> i1_t2 ~ tau1 * 1 
#> i1_t2 ~ 1 
#> i1_t2 ~ 1 
#> # Specify Unique Variances ----
#> i1_t1 ~~ i1_t1 
#> i2_t1 ~~ i2_t1 
#> i3_t1 ~~ i3_t1 
#> i1_t2 ~~ i1_t2 
#> i1_t2 ~~ i1_t2 
#> i1_t2 ~~ i1_t2 
#> # Specify Unique Covariances ----
#> i1_t1 ~~ i1_t2
#> i2_t1 ~~ i1_t2
#> i3_t1 ~~ i1_t2

Here’s another example with different variable names

# Generate lavaan syntax
long_minvariance_syntax(var_list = list(t1 = c("a1", "b1", "c1"), 
                                        t2 = c("a2", "b2", "c2")), 
                        model = "strong") %>% 
  cat()
#> Strong Invariance Model (Scalar Invariance, Intercept Invariance)
#> #### STRONG INVARIANCE MODEL ####
#> # Specify Latent Factors ----
#> eta1 =~ NA * a1 + lambda1 * a1 + lambda2 * b1 + lambda3 * c1
#> eta2 =~ NA * a2 + lambda1 * a2 + lambda2 * b2 + lambda3 * c2
#> # 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 ----
#> a1 ~ tau1 * 1 
#> b1 ~ tau2 * 1 
#> c1 ~ tau3 * 1 
#> a2 ~ tau1 * 1 
#> b2 ~ tau2 * 1 
#> c2 ~ tau3 * 1 
#> # Specify Unique Variances ----
#> a1 ~~ a1 
#> b1 ~~ b1 
#> c1 ~~ c1 
#> a2 ~~ a2 
#> b2 ~~ b2 
#> c2 ~~ c2 
#> # Specify Unique Covariances ----
#> a1 ~~ a2
#> b1 ~~ b2
#> c1 ~~ c2

Resources and related work

R functions to test for longitudinal factorial/measurement invariance

Releases

No releases published

Packages

No packages published

Languages