Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- title: "Cross-lag demo"
- output: html_notebook
- ---
- First set it all up.
- ```{r}
- library(lavaan)
- sampsize <- 500
- lower <- '
- 1
- .7 1
- .4 .3 1
- .3 .4 .5 1 '
- longit_data <- getCov(lower, names = c("x1", "x2", "y1", "y2"))
- ```
- Fit a cross-lag model.
- ```{r}
- crosslag_model <- '
- x2 ~ x1 + y1
- y2 ~ x1 + y1
- x1 ~~ y1
- x2 ~~ y2
- '
- fit_crosslag_model <- sem(crosslag_model, sample.cov = longit_data, sample.nobs = sampsize)
- summary(fit_crosslag_model, standardized = TRUE)
- ```
- Now fit a correlated-trait model.
- ```{r}
- trait_model <- '
- X_latent =~ a*x1 + a*x2
- Y_latent =~ b*y1 + b*y2
- X_latent ~~ Y_latent
- x1 ~~ y1
- x2 ~~ y2
- '
- fit_trait_model <- sem(trait_model, sample.cov = longit_data, sample.nobs = sampsize, std.lv = TRUE)
- summary(fit_trait_model, standardized = TRUE)
- ```
Add Comment
Please, Sign In to add comment