Defined parameters don't appear using "blavInspect(fitted.model, what="mcobj")"

115 views
Skip to first unread message

Diana Alvarez

unread,
Apr 17, 2021, 10:13:42 PM4/17/21
to blavaan
Hello!
I am running a causal mediation analysis in blavaan. I specified four defined parameters.
I got the summary of the model (including the defined parameters) with the following instruction: summary(fitted.model). 
Nevertheless, when specify "blavInspect(fitted.model, what="mcobj")", the defined parameters don't appear. I want that information to draw a graph of their posterior distributions. Do you know I can get that information?

Thanks

bsem.model.expressions <- '
           # a path
             M ~ a*X
             
           # b path
             Y ~ b*M
             
           # cp path
             Y ~ cp*X
             
           # h path
             Y ~ h*X:M
             
           # intercepts
             M~i2*1
             Y~i3*1
             
             # Error variance for dependent variable
             M~~M
             Y~~Y
             
           # Pure Natural Direct Effect (cp + h*i2)
             PNDE := cp + h*i2
           
           # Total Natural Direct Effect (cp + h*i2 + ah)
             TNDE := cp + h*i2 + a*h
             
           # Pure Natural Indirect Effect (a*b)
             PNIE := a*b
             
           # Total Natural Indirect Effect (a*b + ah)
             TNIE := a*b + (a*h)'

summary(fitted.model)
blavaan (0.3-14) results of 5000 samples after 1000 adapt/burnin iterations

  Number of observations                            44

  Number of missing patterns                         1

  Statistic                               
  Value                                   

Regressions:
                   Estimate  Post.SD pi.lower pi.upper     Rhat    Prior        
  M ~                                                                           
    X          (a)    3.565    0.688       NA       NA    1.000     normal(0,30)
  Y ~                                                                           
    M          (b)    0.515    0.239       NA       NA    1.000     normal(0,30)
    X         (cp)   -5.605    5.247       NA       NA    1.000     normal(0,30)
    X:M        (h)    0.779    0.670       NA       NA    1.000     normal(0,30)

Intercepts:
                   Estimate  Post.SD pi.lower pi.upper     Rhat    Prior        
   .M         (i2)    4.540    0.468       NA       NA    1.000     normal(0,30)
   .Y         (i3)    9.728    1.281       NA       NA    1.000     normal(0,30)

Variances:
                   Estimate  Post.SD pi.lower pi.upper     Rhat    Prior        
   .M                 5.230    1.173       NA       NA    1.000 gamma(1,1)[prec]
   .Y                11.023    2.556       NA       NA    1.000 gamma(1,1)[prec]

Defined Parameters:
                   Estimate  Post.SD pi.lower pi.upper     Rhat    Prior        
    PNDE             -2.069    2.461   -6.892    2.755       NA                 
    TNDE              0.708    1.408   -2.052    3.468       NA                 
    PNIE              1.836    0.935    0.003    3.669       NA                 
    TNIE              4.613    2.441   -0.171    9.397       NA       
      
varnames(draws.to.analyze) 
[1] "beta.1"           "beta.2"           "beta.3"           "beta.4"           "sigma.squared.e1" 
[6] "sigma.squared.e2" "beta.0.1"         "beta.0.2"         "lp__" >

    

Ed Merkle

unread,
Apr 18, 2021, 2:26:51 PM4/18/21
to Diana Alvarez, blavaan
Diana,

You are correct that those defined parameters are not in the Stan object, because they are not official model parameters. For now, you have to compute the defined parameters yourself, using the samples of the "official" parameters. This can be done via something like:

samps <- do.call("rbind", blavInspect(fitted.model, "mcmc"))

## correspondence between parameters and the column names of samps:
with(parTable(fitted.model), cbind(lhs, op, rhs, label, pxnames))

And then, once you see which columns you want, you can multiply and add those columns to get the posterior samples of the defined parameters. For example, say that "beta[1]" and "beta[2]" are two columns in samps, then you could multiply them by

dp1 <- samps[,"beta[1]"] * samps[,"beta[2]"]

Ed
--
You received this message because you are subscribed to the Google Groups "blavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blavaan+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blavaan/785cb1ae-6c26-47a6-b5a8-9944d5e5c36dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages