How to applying nonlinear structural equation modeling in the lavaan?

1,908 views
Skip to first unread message

Seongho Bae

unread,
Mar 18, 2015, 11:08:52 AM3/18/15
to lav...@googlegroups.com
Dear all,

I want to apply nonlinear relationships in the lavaan.
Because, I calculate two thetas and make scatter plot using each theta, I can find cubic relationship between x and y.

Like this:

I want to try to apply nonlinear structural equation modeling in the lavaan with WLSMV estimator. How can I do it?

--

Seongho Bae

Giuseppe C.

unread,
Mar 18, 2015, 3:59:17 PM3/18/15
to lav...@googlegroups.com
Hi,

I think this is a hot but not so easy topic. First of all you have to specify what you mean by "nonlinear"? Some people call simple quadratic effects "nonlinear" which of course is right, but in general more complicated (functional) relationships are possible (for example splines; yes estimating them for SEM is also possible, see linterature below - unfortunately there is no rpackage that is able to do this to my knowledge). The next question is for which component do you want to estimate nonlinear effects? For latent variables (this would be more complicated)? Or for continuous explanatory variables?

1) 2007: http://rd.springer.com/article/10.1007/s11336-007-9010-7 (their approach is implemented in an inofficial R-package http://dynware-hq.org/p/MCMCpack/)
2) 2010: http://www.tandfonline.com/doi/suppl/10.1198/jcgs.2010.09094#.VQnSS-FeDhU (The supplementary material contains an R-Code which might help)
3) 2013: http://rd.springer.com/article/10.1007/s11336-013-9323-7#page-1

With lavaan you can estimate the "nonlinear" effects only if you specify the nonlinear relation in advance (which might be problematic as you can only make assumptions about the nonlinear effect in advance which might not have to be correct).
For example, if you want to estimate a quadratic effect of an explanatory variable (e.g. age), you can do something like:

dat$age2 <- dat$age^2

model
<- '# latent variables
     N =~ N1+N2+N3+N4+N5+N6
     E =~ E1+E2+E3+E4+E5+E6
     # regressions
     N ~ age + age2
     E ~ age + age2'


fit
<- sem(model, data=dat)
# to plot the "quadratic" effect for dat$age, you have to compute f(dat$age) using the coefficients from, then you can plot dat$age against f(dat$age)
fit@Model@GLIST$beta

Seongho Bae

unread,
Mar 19, 2015, 6:48:11 AM3/19/15
to lav...@googlegroups.com
Dear Giuseppe,

First of all you have to specify what you mean by "nonlinear"? Some people call simple quadratic effects "nonlinear" which of course is right

I want to apply cubic (x^3), not quadratic.

The next question is for which component do you want to estimate nonlinear effects? For latent variables (this would be more complicated)? Or for continuous explanatory variables?

For latent variables with wlsmv (categorical-ordered theta parameterization) estimator.

--
Seongho

2015년 3월 19일 목요일 오전 4시 59분 17초 UTC+9, Giuseppe C. 님의 말:
2015년 3월 19일 목요일 오전 4시 59분 17초 UTC+9, Giuseppe C. 님의 말:
2015년 3월 19일 목요일 오전 4시 59분 17초 UTC+9, Giuseppe C. 님의 말:
2015년 3월 19일 목요일 오전 4시 59분 17초 UTC+9, Giuseppe C. 님의 말:
2015년 3월 19일 목요일 오전 4시 59분 17초 UTC+9, Giuseppe C. 님의 말:

yrosseel

unread,
Mar 25, 2015, 4:26:33 AM3/25/15
to lav...@googlegroups.com
On 03/19/2015 11:48 AM, Seongho Bae wrote:
> For latent variables with wlsmv (categorical-ordered theta
> parameterization) estimator.

This is not trivial at all. You may try an approach similar to the
product-indicator approach, where you add cubic terms.

These references (from the semTools::indProd package) can perhaps be a
starting point:

Marsh, H. W., Wen, Z. & Hau, K. T. (2004). Structural equation
models of latent interactions: Evaluation of alternative
estimation strategies and indicator construction. _Psychological
Methods, 9,_ 275-300.

Lin, G. C., Wen, Z., Marsh, H. W., & Lin, H. S. (2010). Structural
equation models of latent interactions: Clarification of
orthogonalizing and double-mean-centering strategies. _Structural
Equation Modeling, 17_, 374-391.

Little, T. D., Bovaird, J. A., & Widaman, K. F. (2006). On the
merits of orthogonalizing powered and product terms: Implications
for modeling interactions among latent variables. _Structural
Equation Modeling, 13_, 497-519.

Yves.

Diana Meter

unread,
Nov 4, 2015, 5:14:51 PM11/4/15
to lavaan
Hello everyone,
I would like to plot the quadratic effect of age from this model included below. I see Giuseppe's explanation about computing f(dat$age) and then plotting it against dat$age, but I do not follow exactly how this is executed. I would appreciate some guidance!
Thank you in advance,
Diana

modage2<-'
assert=~w1ed_oa_as1 +   w1ed_oa_as3 + w1ed_oa_as4 +   w1ed_oa_as6 + w1ed_ra_as1 +   w1ed_ra_as3 + w1ed_ra_as4 +   w1ed_ra_as6
aggressO=~w1ed_oa_oag1 +  w1ed_oa_oag3 + w1ed_ra_oag1 + w1ed_ra_oag3 
AggressR=~   w1ed_oa_rag2 +   w1ed_oa_rag4 +   w1ed_ra_rag2 +  w1ed_ra_rag4
neuAdult=~w1ed_oa_neu1 + w1ed_oa_neu3 + w1ed_ra_neu1 + w1ed_ra_neu3
neuComf=~ w1ed_oa_neu2 + w1ed_oa_neu4 + w1ed_ra_neu2 + w1ed_ra_neu4
age1=~ageC10
age2=~agesqC10

assert~age1 + boy
aggressO~ age1 + age2+ boy
AggressR~age1 + boy
neuAdult~age1 + boy
neuComf~age1 + boy
'
fitmodage2<- sem(modage2, data=data, missing='fiml', meanstructure=T, std.lv=TRUE)
summary(fitmodage2, fit.measures = TRUE, standardized=TRUE, modindices = FALSE )

Terrence Jorgensen

unread,
Nov 5, 2015, 5:23:14 AM11/5/15
to lavaan
I would like to plot the quadratic effect of age from this model included below. I see Giuseppe's explanation about computing f(dat$age) and then plotting it against dat$age, but I do not follow exactly how this is executed.

It just means you need to calculate the predicted values of the outcome (Y_hat) using the regression parameters you estimated, which is the f(x).  Assuming from your description you want to plot the effect of age on aggressO, you could do something along these lines:

## generate a sequence of values in the observed range of your x-axis predictor
ageValues <- seq(from = min(data$age), to = max(data$age), length.out = 50)
## extract relevant parameter estimates to put in regression equation
# if you don't have a mean structure, you can set b0 <- 0
b0 <- lavInspect(fitmodage2, "coef")$alpha["aggressO"]
b1 <- lavInspect(fitmodage2, "coef")$beta["aggressO", "age1"]
b2 <- lavInspect(fitmodage2, "coef")$beta["aggressO", "age2"]
b3 <- lavInspect(fitmodage2, "coef")$beta["aggressO", "boy"]
## calculate predicted values using regression equation
yHat.girl <- b0 + b1*ageValues + b2*(ageValues^2)
yHat.boy <- b0 + b1*ageValues + b2*(ageValues^2) + b3 # I assume "boy" is a dummy code
## plot one group's regression line
plot(x = ageValues, y = yHat.girl, type = "l", col = "red", lwd = 2)
## add the other group's regression line
lines(x = ageValues, y = yHat.boy, col = "blue", lwd = 2)

Terry

Diana Meter

unread,
Nov 5, 2015, 9:02:51 AM11/5/15
to lavaan
Thank you very much, Terry. I really appreciate it!
Diana
Reply all
Reply to author
Forward
0 new messages