[Mediation-information] Fwd: mediation plot.medsens

dustin tingley dtingley at gov.harvard.edu
Sat Sep 24 20:50:20 CEST 2011


Michael-

Thanks. This is because its plotting for acme(0) and acme(1) and you weren't
using par() to put them together. You also need to update your syntax, like
below, and stripping out the title prevented you from seeing this I think.

We do need to add an option to only plot one or the other for the
sensitivity in the case of binary DV. We will do that.

pdf("GroSensRsq.pdf")
 par(mfrow=c(1,2))
  plot(sens1, sens.par = "R2",
        r.type = "total",
        sign.prod = "negative")
  dev.off()


Dustin Tingley
Government Department
Harvard University
http://scholar.harvard.edu/dtingley



On Fri, Sep 23, 2011 at 9:04 PM, Michael J. Donnelly <mdonnell at princeton.edu
> wrote:

> Hi Dustin,
> I hope all is well. I ran into a bug using plot.medsens this week and
> Kosuke suggested that you might know what's causing it. I figured out
> another approach that's just as easy, but if you plan to update it any time
> soon, you might want to look at it.
>
> I'm using pdf() and the R2 option and getting a two page pdf with two
> identical graphs. If I use dev.copy(), I don't have the problem. Code below
> - run on both Linux and Mac using R-2.13.0 and 2.13.1, respectively.
>
>
> Michael
>
>
> rm(list = ls())
> # generating fake data
> obs <- 1000
> tr <- rnorm(obs)
> med <- 2*tr + rnorm(obs)
> ystar <- .5*tr - med + rnorm(obs)
>
> dat <- as.data.frame(cbind(tr, med, ystar))
> dat$y <- 1- (dat$y < 0)
>
> # fitting models
> firststage <- lm(med ~ tr, data = dat)
> secondstage <- glm(y ~ tr + med, data = dat, family = binomial(link =
> "probit"))
>
> library(mediation)
>
> # applying mediation
>   mod1 <- mediate(model.y = secondstage,
>                 model.m = firststage,
>                 boot = FALSE,
>                 treat = "tr",
>                 mediator = "med",
>                 sims = 100)
>   sens1 <- medsens(mod1, rho.by = .05, sims = 100)
>
>   pdf("GroSensRsq.pdf")
>   plot(sens1, sens.par = "R2",
>         r.type = 1,
>         sign.prod = -1,
>         levels = c(0),
>         main = "")
>   dev.off()
>



>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/mediation-information/attachments/20110924/3c363ab7/attachment.htm>


More information about the Mediation-information mailing list