mx_data <- df_wide %>%
select(starts_with("Suppression_")) %>%
as.data.frame()
manifest_vars <- c("Suppression_Year_3", "Suppression_Year_4",
"Suppression_Year_5", "Suppression_Year_6")
latent_vars <- c("intercept", "slope")
model <- mxModel(
"BasicLGCM",
type = "RAM",
manifestVars = manifest_vars,
latentVars = latent_vars,
mxData(observed = mx_data, type = "raw"),
mxPath(from = "intercept", to = manifest_vars,
free = FALSE, values = c(1, 1, 1, 1)),
mxPath(from = "slope", to = manifest_vars,
free = FALSE, values = c(0, 1, 2, 3)),
mxPath(from = "one", to = latent_vars,
free = TRUE, values = c(3.0, 0.1),
labels = c("mean_intercept", "mean_slope")),
mxPath(from = latent_vars, arrows = 2,
connect = "unique.pairs", free = TRUE,
values = c(0.5, -0.02, 0.05),
labels = c("var_intercept", "cov_i_s", "var_slope")),
mxPath(from = manifest_vars, arrows = 2,
free = TRUE, values = rep(0.3, 4),
labels = c("resvar_yr3", "resvar_yr4", "resvar_yr5", "resvar_yr6")),
mxPath(from = "one", to = manifest_vars,
free = FALSE, values = 0)
)
fit <- mxRun(model)
summary(fit)