[simsem] two group latent change score model power analysis

52 views
Skip to first unread message

lw

unread,
Feb 28, 2020, 8:35:52 AM2/28/20
to lavaan
Dear lavaan and simsem developers/maintainers,

first of all, I want to thank you for the brilliant packages!

I know lavaan quite well but I'm only starting to work with simsem. I want to use the latter to determine the necessary sample size for a forthcoming study where I will estimate latent change score models in a control group and an experimental group. My approach follows ex24 from the simsem wiki.
I define a nested model where the intercept of the change factor is zero and a parent model where that intercept is freely estimated at a certain value. I want to identify which combinations of effect size and sample size will allow me to detect significant differences between the models.

My code (with strict measurement invariance across time points) produces the following error message:
Error in lambda %*% totalFactorCov : non-conformable arguments

Can anyone please give me a hint where the error in my code is?

Thank you very much in advance!

Best
Luc

library(simsem)

### NESTED MODEL

# factor loadings
loading
<- matrix(0, 6, 2)
loading
[1, 1] <- "l1"
loading
[2:3, 1] <- c("l2", "l3")
loading
[4, 2] <- "l1"
loading
[5:6, 2] <- c("l2", "l3")
LY
<- bind(loading, "runif(1, 0.5, 0.8)")
LY

# factor variances
VE
<- bind(c(1, 0, 1))
VE

# factor correlations
facCor
<- matrix(NA, 3, 3)
diag
(facCor) <- 1
facCorVal
<- diag(3)
facCorVal
[1, 2] <- facCorVal[2, 1] <- "runif(1, 0.7, 0.95)" # pre~post
facCorVal
[2, 3] <- facCorVal[3, 2] <- "runif(1, 0.4, 0.7)" # lc~post
facCorVal
[1, 3] <- facCorVal[3, 1] <- "runif(1, -0.2, 0.2)" # LC~~Pre
RPS
<- binds(facCor, facCorVal)
RPS

# mean structure
ALnested <- bind(c(0, 0, 0))
ALnested

# equal intercepts
inter
<- rep(NA, 6)
inter
[1] <- inter[4] <- "int1"
inter
[2] <- inter[5] <- "int2"
inter
[3] <- inter[6] <- "int3"
TY
<- bind(inter, 1)
TY

# residual variances across time
resvar
<- rep(NA, 6)
resvar
[1] <- resvar[4] <- "res1"
resvar
[2] <- resvar[5] <- "res2"
resvar
[3] <- resvar[6] <- "res3"
VTE
<- bind(resvar, "runif(1, 0.4, 0.6)")
VTE

# residual covariances across time
error
<- diag(6)
error
[1, 4] <- error[4, 1] <- "res1"
error
[2, 5] <- error[5, 2] <- "res2"
error
[3, 6] <- error[6, 3] <- "res3"
errorVal
<- diag(6)
errorVal
[1, 4] <- errorVal[4, 1] <- "runif(1, 0.4, 0.6)"
errorVal
[2, 5] <- errorVal[5, 2] <- "runif(1, 0.4, 0.6)"
errorVal
[3, 6] <- errorVal[6, 3] <- "runif(1, 0.4, 0.6)"
RTE
<- binds(error, errorVal)
RTE


# generate nested model
lcsmNested
<- model(LY = LY,
                    RPS
= RPS,
                    VE
= VE,
                    AL
= ALnested,
                    TY
= TY,  
                    VTE
= VTE,
                    RTE
= RTE,
                    modelType
= "CFA")


### PARENT MODEL

# mean structure
ALparent <- bind(c(0, 0, "runif(1, 0.8, 1.2)"))
ALparent

# generate parent model
lcsmParent
<- model(LY = LY,
                    RPS
= RPS,
                    VE
= VE,
                    AL
= ALparent,
                    TY
= TY,
                    VTE
= VTE,
                    RTE
= RTE,
                    modelType
= "CFA")


# fit nested and parent model on data from nested model
outDatNestedModNested
<- sim(1000, n = 200, lcsmNested, generate = lcsmNested)
outDatNestedModParent
<- sim(1000, n = 200, lcsmParent, generate = lcsmNested)

anova
(outDatNestedModNested, outDatNestedModParent)






Terrence Jorgensen

unread,
Mar 21, 2020, 10:01:04 AM3/21/20
to lavaan
My code (with strict measurement invariance across time points) produces the following error message:
Error in lambda %*% totalFactorCov : non-conformable arguments

Can anyone please give me a hint where the error in my code is?

You are defining Psi and Alpha to have 3 latent variables, but Lambda only has 2 columns (implying 2 latent variables).

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

lw

unread,
Apr 14, 2020, 10:09:51 AM4/14/20
to lavaan
Thank you so much! That's where the error was.
Reply all
Reply to author
Forward
0 new messages