Predict endogenous variables in a path analysis and partial correlations

494 views
Skip to first unread message

Nick Pardikes

unread,
Nov 30, 2016, 4:00:54 PM11/30/16
to lavaan
Greetings,

I am currently working with Lavaan to generate a path analysis and wanted to get predicted values for a endogenous variable of interest. Eventually I would like to plot observed vs. predicted values for that variable. I tried using lavPredict, but the values I received from the function were identical for the variable of interest and I am not interested in predicting a latent variable. Here is some data and the type of model that I am working with. Any suggestions or help would be greatly appreciated. Is there another way to get at this, perhaps through partial correlations? Can I acquire partial correlations in levaan? Thank you. 

###Lavaan help with predict 


data <- data.frame(synchrony = rnorm(70), x1 = rnorm(70), x2 = rnorm(70), x3 = rnorm(70), x4 = rnorm(70), x5 = rnorm(70), x6 = rnorm(70), x7 = rnorm(70), x8 = rnorm(70))


model <- '

     synchrony ~ x1 + x2 + x3 + x4 + x5 + x6 + x7

     x7 ~ x1 + x2 + x6

     x4 ~ x2 + x5

     x5 ~ x1

     x8 ~ synchrony'


fit.model <- sem(model, data=data, std.ov=F, fixed.x=F)

summary(fit.model, standardized=T, rsq=T, fit.measures=T, modindices=T)


###Can I use lavPredict to get predicted values for synchrony?

predict.model <- lavPredict(fit.model, type="ov", label=T, se.fit=T)

Terrence Jorgensen

unread,
Dec 1, 2016, 6:11:48 AM12/1/16
to lavaan
Can I acquire partial correlations in lavaan?

Partial correlations for which variables?  If you want the partial correlation between A and B controlling for X, Y, and Z, simply regress A and B on those variables and estimate their residual covariance.

A + B ~ X + Y + Z
A ~~ B

The "std.all" column contains the standardized residual covariance (A ~~ B), which is their partial correlation.

There is also a package ppcor that provides part (semipartial) and partial correlations.

Can I use lavPredict to get predicted values for synchrony?


As the ?lavPredict help page says, "Note that this function can not be used to ‘predict’ values of dependent variables, given the values of independent values (in the regression sense)."  But you can easily calculate them from the regression equation:

(PT <- parTable(fit.model))
(Beta <- PT$est[PT$lhs == "synchrony" & PT$op == "~"])
(xNames <- PT$rhs[PT$lhs == "synchrony" & PT$op == "~"])
data$pred.sync <- as.matrix(data[xNames]) %*% Beta # predicted values
data$resid.sync <- data$synchrony - data$pred.sync # residuals

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

Nick Pardikes

unread,
Dec 7, 2016, 2:36:37 PM12/7/16
to lavaan
Thank you very much for the help. This seemed to work. 

Terrence Jorgensen

unread,
Dec 8, 2016, 5:36:47 AM12/8/16
to lavaan
Thank you very much for the help. This seemed to work. 

Great!  FYI, my code did not include the intercept because you did not appear to have a mean structure in your model (i.e., all variables are assumed to be mean-centered, so all intercepts == 0). If your model has a mean structure (even if saturated, yielding the same model fit), then you would need to add a column of 1s to the data and add the intercept to the vector of slopes.

Beta <- PT$est[PT$lhs == "synchrony" & PT$op == "~"]
Beta <- c(PT$est[PT$lhs == "synchrony" & PT$op == "~1"], Beta)
data$pred.sync <- cbind(1, as.matrix(data[xNames])) %*% Beta # predicted values
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages