How to mediation effect calculation in the 'blavaan'?

393 views
Skip to first unread message

Seongho Bae

unread,
Apr 20, 2016, 7:56:26 AM4/20/16
to lavaan
Hi all,

Can I know how to mediation effect calculation in the 'blavaan' library?

Best Wishes,
Seongho

Terrence Jorgensen

unread,
Apr 21, 2016, 4:32:08 AM4/21/16
to lavaan
Can I know how to mediation effect calculation in the 'blavaan' library?

The same way you would in lavaan.  blavaan translates lavaan model syntax into a jags syntax file, then runs it.  Adapting the example from the lavaan tutorial page: http://lavaan.ugent.be/tutorial/mediation.html

set.seed(1234)
X <- rnorm(100)
M <- 0.5*X + rnorm(100)
Y <- 0.7*M + rnorm(100)
Data <- data.frame(X = X, Y = Y, M = M)
model <- ' # direct effect
             Y ~ c*X
           # mediator
             M ~ a*X
             Y ~ b*M
           # indirect effect (a*b)
             ab := a*b
           # total effect
             total := c + (a*b)
         '

fit <- bsem(model, data = Data, # jagcontrol=list(method="rjparallel"),
            n.chains = 3, burnin = 1000, sample = 1000,
            jagfile = "path/to/directory")

Notice in the summary() output that there is no prior or PSRF for the defined parameters because they are just calculated from other model parameters.  Instead of using the delta method to calculate normal-theory-based SEs, you just use the M and SD (or credible interval) of the posterior distribution to make an inference (like you would if you bootstrapped SEs or CIs).

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

Danilo Assis Pereira

unread,
Apr 22, 2016, 4:14:31 PM4/22/16
to lavaan
Found more than one class "Model" in cache; using the first, from namespace 'lavaan'
Warning messages:
1: In blavaan(model, data = Data, n.chains = 3, burnin = 1000, sample = 1000,  :
  blavaan WARNING: small sample drawn, proceed with caution.

2: In blavaan(model, data = Data, n.chains = 3, burnin = 1000, sample = 1000,  :
  blavaan WARNING: blavaan does not currently handle defined parameters.
try modifying the exported JAGS code.

Mauricio Garnier-Villarreal

unread,
Apr 22, 2016, 8:14:46 PM4/22/16
to lavaan

aparently blavaan doesnt translate the define parameters into JAGS yet. it is hard to have comprehensive translator to JAGS syntax.
Luckly blavaan export the JAGS the into a folder lavExpert in your workspace, you would have to add to the code the define parameters, this would require some knowledge of JAGS syntax and R2jags to run it through R

Terrence Jorgensen

unread,
Apr 23, 2016, 6:36:30 AM4/23/16
to lavaan
aparently blavaan doesnt translate the define parameters into JAGS yet. 

I noticed that it wasn't in the JAGS syntax, too.  But the user-defined parameter still shows up in the summary() output (at least using the latest version of blavaan), so it must calculate them after importing the JAGS results.

Seongho Bae

unread,
Apr 24, 2016, 3:37:04 AM4/24/16
to lavaan
Hi Terry,

Can you explain easier? Your codes doesn't works well.

Seongho

2016년 4월 23일 토요일 오후 7시 36분 30초 UTC+9, Terrence Jorgensen 님의 말:

Ed Merkle

unread,
Apr 24, 2016, 3:43:50 PM4/24/16
to lavaan
All,

Sorry to be late to the party... there is also a "blavaan" google group that this thread could go to (though it is natural to expect overlap with the lavaan group...)

Terry is correct that the defined parameters should still show up in summary() despite the warning message. The issue is that blavaan does not directly obtain the defined parameters via the MCMC draws. Instead, it calculates the defined parameter mean/sd based on the original parameters' posterior means and sds. I will eventually allow for direct sampling (along with arbitrary equality constraints), but it is going to take some internal rearrangement of code first.

Ed

Terrence Jorgensen

unread,
Apr 25, 2016, 9:53:42 AM4/25/16
to lavaan
Can you explain easier? Your codes doesn't works well.

Could you be more specific?  Try setting "jagfile = FALSE" if you don't understand what that argument does.

Danilo Assis Pereira

unread,
Apr 25, 2016, 10:13:51 AM4/25/16
to lav...@googlegroups.com
I think ´blavaan' is a very very brilhant idea! I love JAGS and Stan, and it is much easier to do Bayesian analysis using 'lavaan' syntaxes. Great job! I will follow 'blavaan' group too.

Bests,



Danilo Assis Pereira, Ph.D.
Psychometrician and Neuropsychologist
IBNeuro - Brazilian Institute of Neuropsychology and Cognitive Sciences

2016-04-25 10:53 GMT-03:00 Terrence Jorgensen <tjorge...@gmail.com>:
Can you explain easier? Your codes doesn't works well.

Could you be more specific?  Try setting "jagfile = FALSE" if you don't understand what that argument does.

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Ws6h7rR4Zh8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages