Sampling Weight_lavaan.survey?

388 views
Skip to first unread message

k.jaha...@gmail.com

unread,
Dec 19, 2012, 2:35:18 PM12/19/12
to lav...@googlegroups.com
Hello All;

I have fitted an SEM model with latent variable and also endogenous categorical variable as shown below:

model <-      'LU =~ AreaType+PopDen_Sc
               LU ~ Male+1adult+FT+manual+Prof+skilledmanual+50kandover+lessthan25k
               NoCar ~ LU+Male+1adult+FT+manual+Prof+skilledmanual+50kandover+lessthan25k
               TTT_HBW ~ LU+Male+1adult+FT+manual+Prof+skilledmanual+50kandover+lessthan25k+NoCar
               TTT_Sh ~ LU+Male+1adult+FT+manual+Prof+skilledmanual+50kandover+lessthan25k+NoCar
               TTT_Sh ~ TTT_HBW'

My Question:

    How can I weight my sample. My dataset has a weight variable (W) which should be applied to have weighted regressions in order to correct the under-representation for some of the records (ie. individuals) in my dataset.
    I did try survey design as below but it produce an error message.

    modelFit <- sem(model = model, ordered=c("AreaType","NoCar"), std.lv = TRUE, data = WorkData, estimator="WLSMV") - This converged normally
    surveydesign <- svydesign(ids=~0,probs=~W, data = WorkData)
    lavaan.survey (modelFit, surveydesign)

This produce the following error message:
    Error in t(x) - xbar : non-numeric argument to binary operator

I am wondering if there is a better/correct way to specify weights (W is a variable in my model (i.e. a column in data frame)) like weights ="W" in MPLUS.

Many Thanks
Kaveh Jahanshahi

PhD Student
Department of Urban Planning
University of Cambridge
1-5 Scroope Terrace
Cambridge
CB2 1PX

yrosseel

unread,
Dec 19, 2012, 3:29:58 PM12/19/12
to lav...@googlegroups.com

> How can I weight my sample. My dataset has a weight variable (W)
> which should be applied to have weighted regressions in order to correct
> the under-representation for some of the records (ie. individuals) in my
> dataset.
> I did try survey design as below but it produce an error message.

I'm afraid lavaan itself can not handle weights yet. It is on my TODO
list for 0.5-12. The lavaan.survey package handles weights very well,
but is limited to numeric/continuous data.

Yves.

k.jaha...@gmail.com

unread,
Dec 19, 2012, 3:44:18 PM12/19/12
to lav...@googlegroups.com
Many thanks Yves for your hard work. Do you have any timing plan in mind for the time when  version 0.5-12 is released? 

I compared my model in MPLUS (using MLM estimator) with laavan (using WLSMV estimator) and the directional effect and significant level of variablea are the same. Only small differences in magnitude of coefficients (partly due to weights I guess). I did try my model in MPLUS by using Least Square estimator (WLSMV) and, when converged after 20,000 iterations, it produces quite different output in some aspects. I prefer Least square estimator as it is faster and I can also get indirect effects easier. 

Many Thanks again.
Kaveh 

yrosseel

unread,
Dec 19, 2012, 4:19:13 PM12/19/12
to lav...@googlegroups.com
On 12/19/2012 09:44 PM, k.jaha...@gmail.com wrote:
> Many thanks Yves for your hard work. Do you have any timing plan in mind
> for the time when version 0.5-12 is released?

I learned the hard way to avoid any timing plans whatsoever...

Yves.

Emil Ole William Kirkegaard

unread,
Aug 17, 2015, 7:05:38 PM8/17/15
to lavaan
Here 2.5 years later I ran into the same problem, namely, trying to use factors (categorical data) with weighted lavaan. This gives the aforementioned indecipherable error. If the factor only has 2 levels, one can use use as.numeric() to get around the problem. If it has more, one will have to create multiple numeric dummy variables.

At the least, it would be very nice if a more sensible error message could be returned.

A.Bi.

unread,
Aug 26, 2015, 10:35:47 AM8/26/15
to lavaan
Dear all,

I am also a little bit confused using lavaan.survey.
The model converges without applying lavaan.survey:
efa1a <- '
socialsupport =~ 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
pmh=~ z2_pmh10_1+ z2_pmh10_2+ z2_pmh10_3+ z2_pmh10_4+ z2_pmh10_5+ z2_pmh10_7+ z2_pmh10_8+ z2_pmh10_9+ z2_pmh10_10+z2_sub_hap1+z2_sub_hap3
pos=~ z2_soc1+ z2_soc2_um+ z2_soc3_um+ z2_soc5_um+ z2_soc6+ z2_soc7+ z2_soc9+ z2_sub_hap1+z2_sub_hap3           
resilience =~ z2_res1+ z2_res2+ z2_res3+ z2_res4+ z2_res5+ z2_res6+ z2_res7+ z2_res8+ z2_res9+ z2_res10+z2_res11
swls =~  z2_swls1+ z2_swls2+z2_swls3+z2_swls4+ z2_swls5
pessimism =~ z2_lotr3+ z2_lotr7+ z2_lotr9
'
fitefa1a <- cfa (efa1a, data = g2_z, estimator = "ml")
summary (fitefa1a, fit.measures = TRUE, standardized = TRUE)

But when I fit it for lavaan.survey it does not converge anymore. Do I have an error in the syntax? I just included a weighting variable.
efa1a <- '
socialsupport =~ 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
pmh=~ z2_pmh10_1+ z2_pmh10_2+ z2_pmh10_3+ z2_pmh10_4+ z2_pmh10_5+ z2_pmh10_7+ z2_pmh10_8+ z2_pmh10_9+ z2_pmh10_10+z2_sub_hap1+z2_sub_hap3
pos=~ z2_soc1+ z2_soc2_um+ z2_soc3_um+ z2_soc5_um+ z2_soc6+ z2_soc7+ z2_soc9+ z2_sub_hap1+z2_sub_hap3           
resilience =~ z2_res1+ z2_res2+ z2_res3+ z2_res4+ z2_res5+ z2_res6+ z2_res7+ z2_res8+ z2_res9+ z2_res10+z2_res11
swls =~  z2_swls1+ z2_swls2+z2_swls3+z2_swls4+ z2_swls5
pessimism =~ z2_lotr3+ z2_lotr7+ z2_lotr9
'
survey.design<-svydesign(ids=~0, data=g2_z, weights=~weight_1)
fitefa1a.survey <- lavaan.survey(lavaan.fit=fitefa1a, survey.design=survey.design)
summary(fitefa1a.survey, standardized=TRUE, fit.measures=TRUE).

I would be grateful for your help!
Kind regards, Angela Bieda

A.Bi.

unread,
Aug 26, 2015, 10:37:03 AM8/26/15
to lavaan


Please find below the error message I got using lavaan.survey:
Error in lav_model_estimate(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  : 
  lavaan ERROR: initial model-implied matrix (Sigma) is not positive definite;
  check your model and/or starting parameters.
In addition: Warning message:
In lav_samplestats_from_moments(sample.cov = sample.cov, sample.mean = sample.mean,  :
  lavaan WARNING: sample covariance can not be inverted

Reply all
Reply to author
Forward
0 new messages