mtmm cfa in lavaan: Error in rhs[[3L]] : subscript out of bounds

640 views
Skip to first unread message

Rick Cruz

unread,
Feb 15, 2013, 8:04:14 PM2/15/13
to lav...@googlegroups.com
I am new to R in general, and I am also new to the lavaan package, so please excuse any naivete in my question.


I am trying to fit a Multi-trait multi-method (in this case, multi-reporter)-- MTMM- model using lavaan.

I continue to get the following error
when I attempt to fit the model.
Error in rhs[[3L]] : subscript out of bounds

here is model syntax:

mtmm.model <- 'mom =~ mqrli + mrins + mhos_drec + mwarm_dad
+   dad=~ dqrli + drins + dhos_mrec + dwarm_mom 
+  relqual =~ mqrli + mrins + mhos_drec + mwarm_dad + dqrli + drins + dhos_mrec + dwarm_mom
+  mrins~~ drins'
> fit<-cfa(model=mtmm.model)
Error in rhs[[3L]] : subscript out of bounds

I am not sure what the error means, or how to fix it. Any help you could give would be greatly appreciated.


In addition, might you also be able to help me figure out how to write syntax to constrain/freely estimate item loadings, factor variances, and constrain factor correlations to zero?


I am trying to replicate this model that runs without issue in Mplus:

mom by mwarm_d* mrins mhos_d mqrli (1);
mom@1;
dad by dwarm_m* drins dhos_m dqrli (2);
dad@1;
qual by mwarm_d mrins mhos_d mqrli dwarm_m drins dhos_m dqrli;
qual;
drins with mrins;
qual with mom @ 0;
qual with dad @ 0;
mom with dad@0;

In words:
there are two reporter factors, with each indicator constrained to be equal within reporter.
reporter factor variances are set to 1.

I am freely estimating variance of overall factor (i.e., qual).

I am constraining covariance of each reporter factor with overall factor to 0.
I also constrain covariance of reporter factors to 0, so that all covariances is explained in overall factor.

residual terms from one indicator for each reporter (rins) are estimated based on modification indices.

Sincere thanks for any help--

RC

Ulrich Schroeders

unread,
Feb 16, 2013, 10:22:56 AM2/16/13
to lav...@googlegroups.com
Hi Rick,

1) I can't see any data-argument in your model (when you call cfa() ).
2) Try removing the plus signs at the beginning of each line.
3) What is the lavaan syntax you use for the second question?

Kind regards,
Ulirch

Rick Cruz

unread,
Feb 16, 2013, 8:56:47 PM2/16/13
to lav...@googlegroups.com
Hi Ulrich,

Thanks for your help-- the model began to work when I entered the data argument... makes sense I would need that :)

Regarding 3), this syntax worked well for the MTMM model, and matched up for the most part with my mplus output.

mtmm.model <- '
              #first reporter factor
              mom =~ NA*mqrli + equal("mom=~mqrli")*mhos_drec+ equal("mom=~mqrli")*mrins + equal("mom=~mqrli")*mwarm_dad
              #second reporter factor
              dad=~ NA*dqrli + equal("dad=~dqrli")*dhos_mrec + equal("dad=~dqrli")*drins + equal("dad=~dqrli")*dwarm_mom
              #set variance of reporter factors to 1
              dad~~1*dad
              mom~~1*mom
              #overall quality/trait factor
              relqual =~ mqrli + mrins + mhos_drec + mwarm_dad + dqrli + drins + dhos_mrec + dwarm_mom
              #estimate variance of trait factor
              relqual~~relqual
              #set factor covariances to zero
              mom~~0*relqual
              dad~~0*relqual
              mom~~0*dad
              #estimate residual covariance between two reporter indicators
              mrins~~ drins
              '
fit<-cfa(model=mtmm.model, data=rick.df1)
summary(fit, fit.measures=T, standardized=T)


Now all I would like to do is find a way to include a count outcome, and regress the overall (relqual) factor on the outcome, along with other covariates. From what I have seen, it looks like there is no ability in lavaan to model count outcomes?

Rick

yrosseel

unread,
Feb 17, 2013, 5:19:21 AM2/17/13
to lav...@googlegroups.com
On 02/16/2013 04:22 PM, Ulrich Schroeders wrote:
> Hi Rick,
>
> 1) I can't see any data-argument in your model (when you call cfa() ).

True, but that is not causing the error. You can omit the data argument.
This is sometimes useful if you want to provide starting values, and see
what the model-implied covariance matrix looks like.

> 2) Try removing the plus signs at the beginning of each line.

THIS is the source of the error.

Yves.

yrosseel

unread,
Feb 17, 2013, 5:23:06 AM2/17/13
to lav...@googlegroups.com
On 02/17/2013 02:56 AM, Rick Cruz wrote:
> Hi Ulrich,
>
> Thanks for your help-- the model began to work when I entered the data
> argument... makes sense I would need that :)
>
> Regarding 3), this syntax worked well for the MTMM model, and matched up
> for the most part with my mplus output.

For the most part? Which part did not match? The results should be
identical.

> Now all I would like to do is find a way to include a count outcome, and
> regress the overall (relqual) factor on the outcome, along with other
> covariates. From what I have seen, it looks like there is no ability in
> lavaan to model count outcomes?

True. lavaan only supports continuous, binary and ordinal variables for now.

Yves.

A.Bi.

unread,
Jul 21, 2015, 11:45:12 AM7/21/15
to lav...@googlegroups.com
Dear all,

I have a similar problem. I am trying to fit several cfa models and I also get the following error message:
Error in rhs[[3L]] : subscript out of bounds.

I never got this message before and all models I fitted before were quite similar. Here is the syntax:
qu1a <- ' aff =~ z2_swls1+ z2_swls2+z2_swls3+z2_swls4+ z2_swls5+ z2_soc6 + z2_soc7+z2_sub_hap1+z2_sub_hap3+z2_pmh10_9+ z2_pmh10_3+ z2_res3+ z2_res10+ z2_soc1+ z2_soc2_um+ z2_soc3_um+ z2_soc4+ z2_soc5_um+z2_pmh10_1+ z2_pmh10_2
OptPess =~ + z2_lotr3+ z2_lotr7+ z2_lotr9+ z2_pmh10_4+ z2_soc5_um
Soz =~ z2_social_sup1+ z2_social_sup2+ z2_social_sup3+z2_social_sup4+ z2_social_sup5+ z2_social_sup6+ z2_social_sup7+ z2_social_sup8+ z2_social_sup9+ z2_social_sup10+
z2_social_sup11+ z2_social_sup12+ z2_social_sup13+z2_social_sup14
Selbstk =~ z2_pmh10_7+ z2_pmh10_8+ z2_res2+ z2_res3 + z2_res7+ z2_res4 + z2_res5+ z2_res11+z2_soc1+z2_pmh10_10+z2
Ziel =~ z2_res1+ z2_res2+z2
Selbstreg =~ z2_res3+ z2_res8+ z2_res9 + z2_pmh10_5 + z2_sub_hap3'
fitqua <- cfa (qu1a, data = g2_z, estimator = "ml")

Does anyone know what`s wrong and how can I fix it!
Thank you for your help!
Kind regards, Angela

yrosseel

unread,
Jul 21, 2015, 1:38:56 PM7/21/15
to lav...@googlegroups.com
On 07/21/2015 05:45 PM, A.Bi. wrote:
> OptPess =~ + z2_lotr3

This is the problem: a '+' right after the "=~" operator. I will try to
catch this and provide a more informative error message.

Yves.

Reply all
Reply to author
Forward
0 new messages