Logistic Regression in SEM framework

6,072 views
Skip to first unread message

Dr. Hans Hansen

unread,
Oct 18, 2012, 4:54:29 AM10/18/12
to lav...@googlegroups.com
Dear lavaan users,

as far as i understand regression models are a special case of the more general structural equation models. i wonder, whether it is possible to model logistic regression in lavaan? Wouldn't one just need to transform the left-hand-side of the formula with the logit? Probably it's much more complicated, isn't it?

Best, Hans

yrosseel

unread,
Oct 18, 2012, 5:13:24 AM10/18/12
to lav...@googlegroups.com
It is. Lavaan can not handle logistic regression (yet). It can handle
probit regression (using the probit link instead of the logit link) for
binary outcomes. But parameters can only be estimated by using WLS(MV),
not ML (at least not in 0.5-9), but the results are typically almost
identical. The only downside is that you can not directly interpret the
(exponentiated) regression coefficients as odds (ratios).

This would be an example (if y is binary):

model <- ' y ~ x1 + x2 + x3'
fit <- sem(model, data=myData, ordered="y")

Yves.

Dr. Hans Hansen

unread,
Oct 27, 2012, 7:44:45 AM10/27/12
to lav...@googlegroups.com

Thanks, Yves!

I thought, regression analysis in a sem framework would make a lot of sense to handle missing values when one could estimate parameters with fiml. Generally, would you agree on that and do you plan to implement that im lavaan?

Best, Hans

yrosseel

unread,
Oct 27, 2012, 8:42:44 AM10/27/12
to lav...@googlegroups.com
I do plan to implement vanilla ML estimation (with either probit or
logit link) as an alternative to WLS(MV) in the near future.

And yes, fiml is technically perfectly possible. However, you should
make a distinction between the dependent variable(s), and the
(exogenous) independent variables. If we consider all variables as
random (and assume multivariate normality) we can use fiml (this
corresponds with fixed.x=FALSE). But if we treat the independent
variables as fixed (fixed.x=TRUE), which is the classic regression
approach, all observations with missing values on those exogenous
variables should be deleted first.

lavaan currently (0.5) does NOT make this distinction. It happily
ignores the fixed.x=TRUE flag when missing="ml" is requested. This is
not bad per se, unless you have dummy/binary predictors. Still, in 0.6,
lavaan _will_ respect the fixed.x flag when using the fiml estimator
(and hence, by default, delete all cases with missing values on those
'fixed x' predictors, unless the user explicitly specifies fixed.x=FALSE)

Yves.

Dr. Hans Hansen

unread,
Nov 1, 2012, 6:35:24 AM11/1/12
to lav...@googlegroups.com
Thanks, yves!

Felix Schönbrodt

unread,
Nov 14, 2012, 6:49:26 AM11/14/12
to lav...@googlegroups.com
Dear Yves,


This would be an example (if y is binary):

model <- ' y ~ x1 + x2 + x3'
fit <- sem(model, data=myData, ordered="y")



I tried to run a path model with a binary DV - but this minimal example fails (on 0.5-9, -10, and -11) with following error message:
Error in pairwiseTables(data = X[[g]], no.x = ncol(X[[g]])) :
  there are less than 2 variables

library
(lavaan)
x
<- rnorm(100)
y
<- rnorm(100)
z
<- factor(sample(0:1, 100, replace=TRUE), ordered=TRUE)
df
<- data.frame(x, y, z)
s1
<- sem("z ~ x+y", data=df, ordered="z")
summary
(s1)



Is something wrong in my specification?

Thanks, Felix

Ruben Arslan

unread,
Nov 14, 2012, 7:02:33 AM11/14/12
to lav...@googlegroups.com
Hey Felix,

your minimal example works for me in -10, with the sample result,
whether I class z as a factor (which gave me trouble some 
time earlier) or eliminate the factor() call and use it as a dummy.

Are you in a clean session?

Best wishes

Ruben

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C/en_US.UTF-8/C/C/C/C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lavaan_0.5-10  quadprog_1.5-4 mnormt_1.4-5   boot_1.3-7     MASS_7.3-22   

loaded via a namespace (and not attached):
[1] stats4_2.15.2 tools_2.15.2 
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan?hl=en.
 
 

yrosseel

unread,
Nov 14, 2012, 8:13:31 AM11/14/12
to lav...@googlegroups.com
On 11/14/2012 01:02 PM, Ruben Arslan wrote:
> Hey Felix,
>
> your minimal example works for me in -10, with the sample result,
> whether I class z as a factor (which gave me trouble some
> time earlier) or eliminate the factor() call and use it as a dummy.

It currently does not work with the dev version. The reason is we use a
new function (pairwiseTables) that currently fails if there is only a
_single_ categorical variable. Will be fixed soon.

Yves.

Felix Schönbrodt

unread,
Nov 14, 2012, 9:06:16 AM11/14/12
to lav...@googlegroups.com
>> your minimal example works for me in -10, with the sample result,
>> whether I class z as a factor (which gave me trouble some
>> time earlier) or eliminate the factor() call and use it as a dummy.

That's true - it works in 0.5-10. Indeed only a new R start was needed …

Thanks,
Felix

Tobias Ludwig

unread,
Oct 20, 2014, 11:26:30 AM10/20/14
to lav...@googlegroups.com
Yves, 

are there any news regarding logistic regression in lavaan? I do want to calculate a regression from a endogenous latent variable (already explained by 2 exogenous LVs) to a nominal DV. Is that already possible in lavaan? When I specify my model like, lavaan is calculating the regressions. But how can this output be interpreted? Is this is just a "normal" regression? Does anybody know if Mplus is able to calculate logistic regressions?

Thanks, Tobias

PS: I don´t want to switch to WLSMV for certain reasons. 

yrosseel

unread,
Oct 21, 2014, 2:26:53 AM10/21/14
to lav...@googlegroups.com
On 10/20/2014 05:26 PM, Tobias Ludwig wrote:
> Yves,
>
> are there any news regarding logistic regression in lavaan? I do want to
> calculate a regression from a endogenous latent variable (already
> explained by 2 exogenous LVs) to a nominal DV.

With 'nominal', do you mean an unordered categorical outcome with more
than 2 levels? In that case, the answer is 'no'.

For binary outcomes, you can try estimator = "MML" (which is very, very
slow), with link = "probit" ("logit" is not ready yet).

Yves.

Tobias Ludwig

unread,
Oct 22, 2014, 4:30:05 AM10/22/14
to lav...@googlegroups.com
Yes, I mean a binary outcome. I tried MML, but it takes literally hours. Does´t work here.
 
Is there any "trick" to do my logistic regressions "outside" the SE model in a clever way? What I´m currently doing is to calculate logistic regressions based on the manifest indicator variables with the glm() function in base R. But this means to leave the model-based approach including all the advantages behind. I´m thinking of somehow predicting latent means of my endogenous LV in the first step and then doing logistic regressions. Would this be appropriate? 
Thank you, 
Tobias

yrosseel

unread,
Oct 23, 2014, 1:13:07 PM10/23/14
to lav...@googlegroups.com
On 10/22/2014 10:30 AM, Tobias Ludwig wrote:
> Yes, I mean a binary outcome. I tried MML, but it takes literally hours.

You mentioned you did not want to use WLSMV. Why? What about estimator =
"PML" (pairwise ML). Only if you have categorical indicators only (for now).

> Is there any "trick" to do my logistic regressions "outside" the SE
> model in a clever way?

Perhaps. How does your model look like? What do you want to achieve? It
might be possible to compute so-called 'factor scores' for the latent
variables (using either the Bartlett or the regression method, see
Skrondal & Laake, 2001). Next, you can use glm(), and if done right, you
might get unbiased (unstandardized) regression coefficients.

Yves.

Tobias Ludwig

unread,
Oct 24, 2014, 10:36:40 AM10/24/14
to lav...@googlegroups.com


Am Donnerstag, 23. Oktober 2014 19:13:07 UTC+2 schrieb yrosseel:


You mentioned you did not want to use WLSMV. Why? What about estimator =
"PML" (pairwise ML). Only if you have categorical indicators only (for now).


During the last two years research I always struggled with WLSMV, mostly due to missing values in the data. If I use missing="listwise", my dataset gets too small to compute gamma, although I do have 835 cases in total (2 groups analysis). missing="pairwise" seems to work only sometimes in certain models. Sometimes I get large SDs and further not plausible results (CFI > 1). MLR uses FIML and is more easy to handle. I can´t get my model to work right now, using WLSMV.

I can´t use PML because I have exogenous covariates.
 
> Is there any "trick" to do my logistic regressions "outside" the SE
> model in a clever way?

Perhaps. How does your model look like?

Basically, it consists of two groups, four predictors (one of those predictors is a single-indicator variable, see my "How to integrate Rasch measures into SEM"), four outcomes, the four outcomes are predictors for two binary outcomes in the next step.

 
What do you want to achieve?

Right now, I´m using only manifest indicator values in terms of a manifest mean to regress the binary outcomes in the second step. But that means, that I´m leaving SEM and go back into CTT.
 
It
might be possible to compute so-called 'factor scores' for the latent
variables (using either the Bartlett or the regression method, see
Skrondal & Laake, 2001). Next, you can use glm(), and if done right, you
might get unbiased (unstandardized) regression coefficients.


Didn´t look into the paper yet, but does this work with predict()?

Thank you a lot, 
Tobias



 
Yves.

Tobias Ludwig

unread,
Jan 29, 2015, 10:18:39 AM1/29/15
to lav...@googlegroups.com
Any help on this issue is still greatly appreciated. :-)

yrosseel

unread,
Feb 3, 2015, 1:11:06 PM2/3/15
to lav...@googlegroups.com
On 01/29/2015 04:18 PM, Tobias Ludwig wrote:
> Any help on this issue is still greatly appreciated. :-)

What about multiple imputation? The semTools package has some nice tools
for this.

Yves.

Tobias Ludwig

unread,
Mar 29, 2016, 9:13:56 AM3/29/16
to lavaan
I wanted to ask if the logit link is planned for the near future?
Reply all
Reply to author
Forward
0 new messages