path analysis with two indirect effects

567 views
Skip to first unread message

M.West

unread,
Mar 8, 2015, 12:59:15 PM3/8/15
to lav...@googlegroups.com
Hi All,

I am trying to run a simple SEM with no latent variables. I want to estimate both direct and indirect effects.
1) I'm having trouble getting the model to run in one version of the syntax
2) I'm curious as to how R estimates the indirect effects. Is it based on running separate regression models (which would be based on different theoretical basis than 'true' mediation models)
3) For non-normal data with small sample sizes, I'm not sure which is the best estimator to use (I'll use bootstrapping for the parameter estimates but I'm not sure which "estimator" to include in the model)


Here is my code (the data are attached along with a path model to help clarify what I am looking for. In particular, I have a connection with a double headed arrow that I am not exactly sure how to code for).

data_pa <- read.csv("path_analysis.csv", header = T, sep = ",")
names(data_pa)

M2 <- as.factor(M2) ## M2 is a categorical variable coded as 0 and 1
class(M2)

model <- ' # direct effect
Y ~ a*X + c*M1 + d*M2
# mediator
X ~ b*M1 + e*M2  ## The path between X and M2 would be a double arrow head since X does not really have a direct effect on M2 but there is a link there.
# I'm not exactly sure how to code for the double arrow head in the model.

# indirect effects (b*c) + (d*e)
bc := b*c
de := d*e

# total effect
total := a + c + d + (b*c) + (d*e) ## do I include c and d here in the direct effects too ?
'


fit <- sem(model, ordered ="M2", estimator = "MML", data = data_pa)  
fit
summary(fit, rsq = T, standardized = T, fit.measures=TRUE)

I receive this warning message:
** WARNING ** lavaan (0.5-17) model has NOT been fitted
** WARNING ** Estimates below are simply the starting values


If however, I run the model with the following syntax, it works....though, again, I'm not sure that I am including all the interactions that I'm interested in 
using this condensed version of the code and I'd like the print out for the direct and indirect effects (which in the tutorials comes with the code above)
(here, I left the data in the spreadsheet as N and Y and re-coded it into 0 and 1 in R...)

data_pa$OWSrecode[data_pa$M2=="N"] <- 0
data_pa$OWSrecode[data_pa$M2=="Y"] <- 1
data_pa$OWSrecode <- as.factor(data_pa$OWSrecode)

model1 <- 'Y ~ X + M1  + OWSrecode 
         M1 ~ X + OWSrecode
         OWSrecode ~ X'
        


modfit1<- sem(model1, estimator = "WLSMV", data = data_pa, ordered ="OWSrecode") 



Many thanks in advance.
path_analysis.csv
path_analysis_model.pdf

Terrence Jorgensen

unread,
Mar 8, 2015, 7:57:30 PM3/8/15
to lav...@googlegroups.com
If the relationship between X and M2 is a double-headed arrow, there is no effect of X on M2, so the only indirect path from X to Y is via M1 (not M2).  So according to the path diagram, M2 is an exogenous predictor, not a mediator, and calculating d*e doesn't make conceptual sense.  

The first syntax doesn't correspond to your path diagram, because X and Y are both outcomes, being predicted by M1 and M2 (which are exogenous predictors in your first syntax).  I'm not sure whether that's why you got the warning messages, but judging from the second syntax, M2 is a character vector (Y/N) instead of a numeric/integer vector (which you recode to 1/0 as the variable OWSrecode), so you should include OWSrecode in the model instead.  However, M2 is already a 0/1 dummy code in the CSV file you attached.

The second syntax also does not correspond to the path diagram because you are using M2/OWSrecode  to predict M1.  If your path diagram reflects your theory correctly, the model you want to fit is:

model <- 'Y ~ a*X + c*M1 + M2
          M1 ~ b*X
          M2~~ X
## indirect effect of X on Y
bc := b*c
## total effect of X on Y
total := bc + a
'

The operator "~~" indicates a two-headed arrow between OWSrecode and X, but you can exclude it from the syntax if you include the argument "fixed.x = FALSE" in your call to sem().  

modfit <- sem(model, data = data_pa, fixed.x = FALSE) 

I don't think you should specify WLSMV estimation because you are not fitting a latent-variable model with categorical indicators.  M2 is an exogenous dummy variable, so you can use ML, although you might want to use MLR if the continuous outcomes (M1 and Y) are non-normal -- of course, your sample size is extremely small (N = 16), so it might not be feasible.

Terry

M.West

unread,
Mar 9, 2015, 7:48:51 AM3/9/15
to lav...@googlegroups.com
Terry,

Thanks so much for clearing that up - I really appreciate it. I tried the code and it works and the 4 different assessments of model fit all look good.
I have two additional questions.

1) I'm curious as to how R estimates the indirect effects. Is it based on running separate regression models or is actually running path analysis using the same underlying theory as mediation models ?

Thanks again! 

yrosseel

unread,
Mar 13, 2015, 9:20:55 AM3/13/15
to lav...@googlegroups.com
On 03/09/2015 12:48 PM, M.West wrote:
> Terry,
>
> Thanks so much for clearing that up - I really appreciate it. I tried
> the code and it works and the 4 different assessments of model fit all
> look good.
> I have two additional questions.
>
> 1) I'm curious as to how R estimates the indirect effects.

Since the user has to specify the 'formula' him/her self, eg as in your
syntax:

bc := b*c
de := d*e

there is nothing R/lavaan has to do, except looking up the estimated
value for b,d,d and e. (and calculate a standard error).

Yves.

Reply all
Reply to author
Forward
0 new messages