I know that I have to take thresholds into account and not intercepts
But i don't know, if i did it in the right way??
And what does this actually mean: T2_OD1a ~*~ T2_OD1a??
T2_OD1a ~*~ c(1, NA, NA)*T2_OD1a
T2_OD1a ~~ c(1, NA, NA)*T2_OD1a
Hello all,
I was hoping someone might be able to help me with the following error. I’m trying to fit a second-order latent growth model using ordinal factors.
I’ve already established longitudinal invariance (i.e. unique factor invariance) and am now fitting the structural part of the model. Although this has worked for a complete case analysis and pairwise deletion, I’m getting funny errors when using lavaan.mi on a list of 20 imputed datasets (imputed via mice package).
# CONVERT MIDS OBJECT TO LIST OF IMPUTED DATAFRAMES
imputed_list <- list()
for(i in 1:20){
imputed_list[[i]] <- complete(imputed,action=i,include=FALSE)
}
# SPECIFY ORDINAL FACTORS
ordered_cat <- c("destruct_7", "fight_7", "disobedient_7",
"destruct_11", "fight_11", "disobedient_11",
"destruct_16", "fight_16", "disobedient_16")
as.character(ordered_cat)
# SPECIFY MODEL1
model1 <- '
# # Measurement model: Unique Factor Invariance
# Loadings (NB fix first factor loading to 1 for model identification)
latent_asb7 =~ destruct_7 + FightLoading*fight_7 + DisobedientLoading*disobedient_7
latent_asb11 =~ destruct_11 + FightLoading*fight_11 + DisobedientLoading*disobedient_11
latent_asb16 =~ destruct_16 + FightLoading*fight_16 + DisobedientLoading*disobedient_16
# Latent common factor means; fix asb7 to 0 for model identification
latent_asb7 ~ 0*1
latent_asb11 ~ 1
latent_asb16 ~ 1
# Latent common factor variances
latent_asb7 ~~ latent_asb7
latent_asb11 ~~ latent_asb11
latent_asb16 ~~ latent_asb16
# Constrain thresholds to be equal across measurement occasions
destruct_7 | destructt1*t1 + destructt2*t2
destruct_11 | destructt1*t1 + destructt2*t2
destruct_16 | destructt1*t1 + destructt2*t2
fight_7 | fightt1*t1 + fightt2*t2
fight_11 | fightt1*t1 + fightt2*t2
fight_16 | fightt1*t1 + fightt2*t2
disobedient_7 | disobedientt1*t1 + disobedientt2*t2
disobedient_11 | disobedientt1*t1 + disobedientt2*t2
disobedient_16 | disobedientt1*t1 + disobedientt2*t2
# Unique variances constrained to 1.00
destruct_7 ~~ 1*destruct_7
fight_7 ~~ 1*fight_7
disobedient_7 ~~ 1*disobedient_7
destruct_11 ~~ 1*destruct_11
fight_11 ~~ 1*fight_11
disobedient_11 ~~ 1*disobedient_11
destruct_16 ~~ 1*destruct_16
fight_16 ~~ 1*fight_16
disobedient_16 ~~ 1*disobedient_16
# Lagged unique factor covariances
destruct_7 ~~ destruct_11 + destruct_16
destruct_11 ~~ destruct_16
fight_7 ~~ fight_11 + fight_16
fight_11 ~~ fight_16
disobedient_7 ~~ disobedient_11 + disobedient_16
disobedient_11 ~~ disobedient_16
# # Structural model: Conditional Latent Growth Curve Model
# Loadings
i =~ 1*latent_asb7 + 1*latent_asb11 + 1*latent_asb16
s =~ 0*latent_asb7 + 4*latent_asb11 + 9*latent_asb16
# fixed effects
i ~ 0*1
s ~ 1
# random effects
i ~~ i
s ~~ s
i ~~ s
# regression
i + s ~ neglect6
'
# FIT MODEL1
fit. model1 <- lavaan.mi(model1, data = imputed_list,
ordered= ordered_cat,
parameterization = "theta",
estimator = "wlsmv",
auto.fix.first=TRUE)
1. When I first ran the above I got the following error, presumably because neglect6 is is a binary variable:
Error in lav_data_full(data = data, group = group, cluster = cluster, :
lavaan ERROR: unordered factor(s) detected; make them numeric or ordered: neglect6
2. I then changed ‘neglect6’ to an ordered factor using the below loop and got the following error
for(i in 1:20){
imputed_list[[i]]$neglect6 <- factor(imputed_list[[i]]$neglect6, ordered=TRUE, levels=c(0,1))
}
Error in DX1[th.idx > 0L, ] <- TAU :
number of items to replace is not a multiple of replacement length
In addition: Warning messages:
1: In th[th.idx > 0L] <- TAU[, 1L] :
number of items to replace is not a multiple of replacement length
2: In WLS.obs - WLS.est :
longer object length is not a multiple of shorter object length
3: In diff * diff * WLS.VD :
longer object length is not a multiple of shorter object length
4: In th[th.idx > 0L] <- TAU[, 1L] :
number of items to replace is not a multiple of replacement length
3. Finally I tried changing ‘neglect6’ to numeric and this gave me the below error:
Error in nlminb(start = start.x, objective = objective_function, gradient = GRADIENT, :
NA/NaN gradient evaluation
In addition: Warning message:
In muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types, :
lavaan WARNING: trouble constructing W matrix; used generalized inverse for A11 submatrix
If I remove regression ‘i + s ~ neglect6’ the model works but if I replace the regression with another binary endogenous variable (i.e. sex) I get the same errors. I’ve checked the 20 imputed dataframes and they seem to be all correct and consistent. I have a large sample size (n=8088).
If anyone could shed light on the above I would be very grateful as I’m running out of ideas!
Many thanks,
Michelle
Does my syntax look like this??:
when I try to compare two models by using "anova" i get the following error:What does it mean?Error in MASS::ginv(Delta1) %*% Delta0 : non-conformable arguments.
2. I then changed ‘neglect6’ to an ordered factor
3. Finally I tried changing ‘neglect6’ to numeric and this gave me the below error:
table(imputed_list[[1]]$neglect6, useNA = "ifany")
If I remove regression ‘i + s ~ neglect6’ the model works but if I replace the regression with another binary endogenous variable (i.e. sex) I get the same errors.
for (i in 1:20) {
fit.model1 <- try(cfa(model1, data = imputed_list[[i]], ordered= ordered_cat,
parameterization = "theta", estimator = "wlsmv"),
silent = TRUE)
if (inherits(fit.model1, "try-error") {
cat('imputation', i, 'failed \n')
} else cat('imputation', i, 'succeeded\n')
}