Problem: Extracting Residual Correlation Matrix

49 views
Skip to first unread message

Isa

unread,
Dec 11, 2018, 7:26:40 AM12/11/18
to lavaan
Dear lavaan Google Group

I have a question regarding the resid() function and its output. I am testing a mediation model where my mediator is a latent factor, all other viariables are observed.
When I run first just the latent factor mediator and try to extract the residual correlation matrix, everything works fine:

cfa_se2 <- "
SE =~ t4_belief_qualities_trait + t4_belief_useless_trait + t4_belief_useful_trait + t4_belief_positive_trait
t4_belief_useless_trait ~~ t4_belief_qualities_trait
"
cfa_fit_se2 <- cfa(cfa_se2,  estimator = "WLSMV", data = data_imputed, mimic="Mplus")
summary(cfa_fit_se2, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
residuals(cfa_fit_se2, type = "cor")$cov

                          t4_blf_q_ t4_blf_sl_ t4_blf_sf_ t4_blf_p_
t4_belief_qualities_trait  0.000                                   
t4_belief_useless_trait    0.000     0.000                         
t4_belief_useful_trait     0.020    -0.049      0.000              
t4_belief_positive_trait  -0.032     0.041      0.000      0.000  



But, when I then run the whole mediation model and try to extract its residual correlation matrix, I get an error message:

sem_med_se <- "
# Latent constructs
SE =~ t4_belief_qualities_trait + t4_belief_useless_trait + t4_belief_useful_trait + t4_belief_positive_trait
t4_belief_useless_trait ~~ t4_belief_qualities_trait

# Regression
# Direct effect
t4_scim_location ~ t4_decubitus + t4_urin_infection  + t4_pulmonary + t4_cardiac_function + t4_bowel_care + t4_pain + t4_partet + t4_compl + age_sci_group + sex

# Mediation
SE ~ t4_decubitus + t4_urin_infection  + t4_pulmonary + t4_cardiac_function + t4_bowel_care + t4_pain + t4_partet + t4_compl

t4_scim_location ~ SE
"
sem_fit_med_se <- sem(sem_med_se,  estimator = "WLSMV", data = data_imputed, mimic = 'Mplus')
summary(sem_fit_med_se, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
resid(sem_fit_med_se, type = "cor")$cov

Error in x$cov * scale.cov : non-conformable Arrays


Does anybody know what is the problem?
 
Thanks for any help and best regards,
Isabel



Terrence Jorgensen

unread,
Dec 13, 2018, 8:21:05 AM12/13/18
to lavaan
resid(sem_fit_med_se, type = "cor")$cov

Error in x$cov * scale.cov : non-conformable Arrays

Does anybody know what is the problem?

No, but it only happens when conditional.x = TRUE (the default).  Try setting conditional.x = FALSE

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages