You are here

mediation in OSMASEM

6 posts / 0 new
Last post
pascofearon's picture
Offline
Joined: 05/07/2013 - 10:57
mediation in OSMASEM

I was wondering whether you could point me to information about how to pass algebraic statements to OpenMx via the osmasem function so that I can test indirect effects – in tssem2 this is done easily, but it’s not so obvious with osmasem. The documentation for osmasem doesn't seem to go into detail about this. I suspect it could be done with the mxModel.args option, but as I don’t know my way around OpenMx all that well I had trouble figuring out how…

Thanks!
Pasco

Mike Cheung's picture
Offline
Joined: 10/08/2009 - 22:37
Dear Pasco,

Dear Pasco,

Yes, you may prepare a list in 'mxModel.Args' to pass them to ‘mxModel’. If you have sample data and R code, I may be able to help.

Best,
Mike

pascofearon's picture
Offline
Joined: 05/07/2013 - 10:57
mediation in OSMASEM

Hi Mike,
Great, thanks! The basic r code is just:

specify model

dat2<-Cor2DataFrame(cordat, data$'Sample Size', acov='weighted')
model1<- "out ~ par + risk
par ~ risk
risk ~~ 1*risk"

RAM1 <- lavaan2RAM(model1, obs.variables=c("risk", "par", "out"))
M0 <- create.vechsR(A0=RAM1$A, S0=RAM1$S)
T0 <- create.Tau2(RAM=RAM1, RE.type="Diag")

fit onestage metaSEM

fit0 <- osmasem(model.name="test", Mmatrix=M0, Tmatrix=T0, data=dat2, mxModel.args = list(indirectEffect = mxAlgebra(parONrisk*outONrisk, name="indirectEffect")), suppressWarnings=FALSE)

summary(fit0)

This runs fine (doesn't produce any errors), so that's promising, but the output from summary(fit0) doesn't list the indirect effect. I've attached the 'cordat' and data files file as .csvs

Thanks a lot!

Best wishes,

Pasco

File attachments: 
pascofearon's picture
Offline
Joined: 05/07/2013 - 10:57
mediation in OSMASEM

Hi Mike,
Just a quick follow-up: I noticed I had written mxModel.args, instead of mxModel.Args. Fixing that then gets the algebra list to the mxModel, but when I call that up it reads like this:

attr(,"class")
[1] "osmasem"
> fit0$mxModel.Args
$indirectEffect
mxAlgebra 'indirect'
$formula: parONrisk * outONrisk
$result: (not yet computed) <0 x 0 matrix>
dimnames: NULL

pascofearon's picture
Offline
Joined: 05/07/2013 - 10:57
mediation in OSMASEM

Hi Mike,
I figured it out from another example on the forum. I made an error in the syntax. Running it like this worked perfectly:

Define indirect effect

ind <- mxAlgebra(parONrisk*outONrisk, name="ind")

fit onestage metaSEM

fit0 <- osmasem(model.name="test", Mmatrix=M0, Tmatrix=T0, data=dat2, intervals.type = "LB", mxModel.Args = list(ind, mxCI(c("ind"))), suppressWarnings=FALSE)

summary(fit0)

Thanks!

Best wishes,

Pasco

Mike Cheung's picture
Offline
Joined: 10/08/2009 - 22:37
Perfect!

Perfect!