Search code examples
rtrace

Mediation R package p-values: workaround to get more significant digits?


I am running multiple mediation analyses and need to correct for multiple comparisons. However, the p-values provided by the mediation package appear to be stored already rounded, as observed in the very helpful answer by @Roland on this question:

R mediation package : digit behind comma

Has anyone found a workaround to actually pull out more significant digits for the pvalues?


Solution

  • Those are being printed with 2 digits, because that's all the method computes. It's a randomized analysis, so the p-value is just the fraction out of 50 (in the referenced answer) of the simulations that met some condition. If you want more digits, you'll need to run with sims set to a much larger value than 50. After you do that, you can probably change the digits setting using the same technique as in that post, or more simply as follows:

    1. Execute this:

      print.summary.mediate <- mediation:::print.summary.mediate

    2. Use fix(print.summary.mediate) to edit the source, and change the line

      printCoefmat(smat, digits = 3)

    to whatever desired number of digits you want. I chose 6.

    Then run the code:

    data(jobs)
    b <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
    c <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data=jobs)
     
    contcont <- mediate(b, c, sims=1000, treat="treat", mediator="job_seek")
    summary(contcont)
    

    I got this output:

    Causal Mediation Analysis 
    
    Quasi-Bayesian Confidence Intervals
    
                     Estimate 95% CI Lower 95% CI Upper p-value
    ACME           -0.0166933   -0.0404983      0.00735   0.168
    ADE            -0.0412011   -0.1278011      0.04465   0.348
    Total Effect   -0.0578944   -0.1449898      0.02716   0.196
    Prop. Mediated  0.2313315   -1.7557486      1.89099   0.288
    
    Sample Size Used: 899 
    
    
    Simulations: 1000 
    

    You only see 3 digits on the p-values, because that's all you get with 1000 simulations: n/1000 always has 3 digits. If you choose sims to be something that's not a round number, you'll see more digits: but the later ones will be worthless, they don't really signify anything other than the fact that a fraction like 123/456 doesn't have a nice decimal expansion.

    Yours will be different, because it's a randomized analysis.