Rstudio covariance structure analysis error persists (lavaan function)

Asked 2 years ago, Updated 2 years ago, 288 views

What I'm trying to do
I would like to analyze the covariance structure using Rstudio's lavaan package (cross-delay effect model)
The data I'm using is panel data from two points in time

Current Code

model2009<-'

# Two potential variables, internal, installation, predict five observational variables: INFLU, COMPLEX, PARTY, ELECTION, CONGRESS (one or two after the variable name represent which of the two data points).
## Constraints coefficients to identify models
internal1=~1*INFLU1+a*COMPLEX1
installation1 = ~1 * PARTY1 + b * ELECTION1 + c * CONGRESS1
internal2=~1*INFLU2+a*COMPLEX2
installation2=~1*PARTY2+b*ELECTION2+c*CONGRESS2

# This is the error part of the measurement variable.
INFLU1~INFLU1; COMPLEX1~ COMPLEX1; PARTY1~ PARTY1~ PARTY1; ELECTION1~ELECTION1; CONGRESS1~CONGRESS1;
INFLU2~INFLU2; COMPLEX2~ COMPLEX2; PARTY2~ PARTY2~ PARTY2; ELECTION2~ELECTION2; CONGRESS2~CONGRESS2;

# This is the structural equation.
internal2 through internal1 + installation1;
installation2 through internal1 + installation1;

# This is the error part of the latent variable.
internal1~~installation1; internal2~~installation2; internal1~~internal1; installation1~~installation1; internal2~internal2~internal2~installation2~installation2
'

# We predict these models using the lavaan() function.
result2009<-lavaan(model2009, panel.2009, ordered=c("PARTY1", "ELECTION1", "CONGRESS1", "INFLU1", "COMPLEX1", "PARTY2", "ELECTION2", "CONGRESS2", "INFLU2", "COMPLEX2"),
                     WLS.V = TRUE, sample.nobs = 1107)

Problems you are facing
When I try to function with the above model, R generates the following error

Error in Gamma.g*tcrossprod(a1): Incorrect array 

I tried searching, but I'm not sure what this error is.

Notes
I tried going back with the taraceback() function, but I didn't really understand the content

traceback()
4:lav_test_satorra_ventler_trace_ABA(Gamma=Gamma, Delta=Delta, 
       WLS.V = WLS.V, E.inv = E.inv, ngroups = ngroups, nobs = lavsamplestats@nobs, 
       total=lavsamplestats@ntotal, return.ugamma=return.ugamma, 
       Satterthwaite= Satterthwaite)
3:lav_test_satorra_ventler(lavobject=NULL,lavsamplestats=lavsamplestats, 
       lavmodel=lavmodel, lavimplied=lavimplied, lavdata=lavdata, 
       lavoptions=lavoptions, TEST.unscaled=TEST[[1]], E.inv=attr(VCOV, 
           "E.inv"), Delta=attr(VCOV, "Delta"), WLS.V=attr(VCOV, 
           "WLS.V"), Gamma=attr(VCOV, "Gamma"), test=this.test, 
       mimic=lavoptions$mimic, method="ABA", return.ugamma=FALSE)
2:lav_model_test(lavmodel=lavmodel,lavpartable=lavpartable, 
       lavpta=lavpta, lavsamplestats=lavsamplestats, lavimplied=lavimplied, 
       lavh1 = lavh1, lavoptions = lavoptions, x = x, VCOV = VCOV, 
       lavdata=lavdata, lavcache=lavcache, lavloglik=lavloglik)
1:lavaan(model2009, panel.2009, ordered=c("PARTY1", "ELECTION1", 
       "CONGRESS1", "INFLU1", "COMPLEX1", "PARTY2", "ELECTION2", 
       "CONGRESS2", "INFLU2", "COMPLEX2"), WLS.V = TRUE, sample.nobs = 1107)

r

2022-09-30 21:50

1 Answers

The cause was due to arguments in the lavaan function.

Details

  • The reason for the resolution is that you removed the WLS.V argument in the lavaan function (this time it is sem).
  • WLS.V should be TRUE if it is a correlation matrix instead of raw data, but at the time of the first question, it was TRUE even though it was using raw data, so a warning message or error occurred.

Resolved Code

model_cross2009<-'
# Since we use sem() instead of lavaan(), we do not need to write the error variance of measurement variables and potential variables.
internal1 = through 1*INFLU1 + COMPLEX1;
installation1 = ~ PARTY1 + ELECTION1 + CONGRESS1;
internal2=~1*INFLU2+COMPLEX2;
installation2 = ~ PARTY2 + ELECTION2 + CONGRESS2;

internal2 through internal1 + installation1;
installation2 through internal1 + installation1
'

result_cross2009<-sem(model_cross2009, 
                        panel.2009, ordered=c("Party 1", "ELECTION 1", 
                                               "CONGRESS 1", "INFLU1", 
                                               "COMPLEX 1", 
                                               "PARTY 2", "ELECTION 2", 
                                               "CONGRESS 2", "INFLU2", 
                                               "COMPLEX 2"


2022-09-30 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.