Package 'iMediate'

Title: Likelihood Methods for Mediation Analysis
Description: Implements likelihood based methods for mediation analysis.
Authors: Dr. Kai Wang
Maintainer: Kai Wang <[email protected]>
License: GPL (>= 2)
Version: 0.5.5
Built: 2024-12-22 06:52:46 UTC
Source: CRAN

Help Index


Likelihood Methods for Statistical Mediation Analysis

Description

iMediate is a collection of methods developed by our group for mediation analysis. It contains methods built upon likelihoods. Use ?iMediate to see an introduction.

Details

Package: iMediate
Type: Package
Version: 0.5
Date: 2018-08-29
License: GPL (>=2)
LazyLoad: yes

Author(s)

Kai Wang <[email protected]>

References

Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.

Wang, K. (2019) Maximum likelihood analysis of mediation models with treatment-mediator interaction. Revision submitted.

Wang, K. (2019) Likelihood-based analysis of the statistical effects of a treatment on an outcome. To be submitted.

Berger, R.L. (1997) Likelihood ratio tests and intersection-union tests. Advances in statistical decision theory and applications. Birkh\"auser Boston, 225-237.

Examples

data("jobs", package = "mediation")

fit.M <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
fit.Y <- lm(depress2 ~ treat * job_seek + econ_hard + sex + age, data=jobs)
mdn(fit.M, fit.Y, "treat")

Contour Plot of Joint Probabilities related to Mediated Effect

Description

Contour plot of joint probability of mediated effect and total effect in the absence of direct effect and joint probability of mediated effect and direct effect assuming ab=cab=c'

Usage

figure.joint.prob(prob = "mediated.main", n = 100, sig.level = 0.05,
  grid.size = 0.01)

Arguments

prob

a character string specifying the probability to be plotted. One of "mediated.main" (default) and "mediated.direct". "mediated.main" requests the probability of the mediated effect and the main effect assuming there is no direct effect (c=0c'=0). "mediated.direct" requests the probability of the mediated effect and the direct effect assuming ab=cab=c'

n

sample size

sig.level

significance level used for the test of the mediated effect

grid.size

grid size for a2a^2 and b2b^2

Details

Basic three-factor mediation model is assumed. Coefficients are standardized such that the variances of treatment, mediator, and outcome are equal to 1. Note that the y-axis is a2a^2 and the x-axis is b2b^2. The default axes labels from R function plot_ly are switched in order to make them correct.

Value

A plot generated using package plotly

Author(s)

Kai Wang <[email protected]>

References

Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.

Examples

## figure.joint.prob()                                # Figure 4 of Wang (2018)
## figure.joint.prob(prob="mediated.direct")          # Figure 5 of Wang (2018)

Contour Plot of Relative Power: Mediated Effect versus Total Effect, Mediated Effect versus Direct Effect

Description

Contour plot of relative power of mediated effect versus total effect in the absence of direct effect and relative power of mediated effect versus direct effect when ab=cab=c'.

Usage

figure.relative.power(comparison = "mediated2main", n = 100,
  sig.level = 0.05, grid.size = 0.01)

Arguments

comparison

a character string specifying the relative power to be plotted. One of "mediated2main" (default) and "mediated2direct". "mediated2main" requests the log of power ratio for the mediated effect versus the main effect assuming there is no direct effect (c=0c'=0). "mediated2direct" requests the log of power ratio for the mediated effect versus the direct effect assuming ab=cab=c'

n

sample size

sig.level

significance level used for the test of the mediated effect

grid.size

grid size for a2a^2 and b2b^2

Details

Basic three-factor mediation model is assumed. Coefficients are standardized such that the variances of treatment, mediator, and outcome are equal to 1. Note that the y-axis is a2a^2 and the x-axis is b2b^2. The default axes labels from R function plot_ly are switched in order to make them correct.

Value

A plot generated using package plotly

Author(s)

Kai Wang <[email protected]>

References

Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.

Examples

## figure.relative.power()                                # Figure 2 of Wang (2018)
## figure.relative.power(comparison="mediated2direct")    # Figure 3 of Wang (2018)

Full Information Maximum Likelihood Estimates in Linear M-model and Linear Y-model

Description

Parameter estimates in system of correlated linear M-model and linear Y-model with treatment-mediator interaction using the full information maximum likelihood method.

Usage

fimle.lnl(fit.M, fit.Y, treatment, rho = 0, t0 = 0, t1 = 1, m = 1)

Arguments

fit.M

a fitted model object for mediator. It must be an object generated by function “lm

fit.Y

a fitted model object for outcome. It must be an object generated by function “lm”. It can contain treatment-mediator interaction

treatment

a character string of the name of the treatment variable. This variable takes numerical values

rho

a numerical variable specifying the correlation coefficient between the residual of the M-model and the residual of the Y-model. Its range is between -1 and 1

t0

a reference value for the treatment

t1

another value for the treatment

m

a value specifying the level of the mediator. Used for CDE computation between the residual of the M-model and the residual of the Y-model. Its range is between -1 and 1

Details

P-values are computed from normal distribution.

Value

A list containing the following components:

M.model

a data frame containing the results for the M-model

Y.model

a data frame containing the results for the Y-model

Effects

a data frame containing estimated ACME, ADE, Total Effect, and CDE for treatment values t1 and t0

Variance

a matrix of variances and covariances of the parameters estimates

Author(s)

Kai Wang <[email protected]>

References

Wang, K. (2019) Maximum likelihood analysis of mediation models with treatment-mediator interaction. Revision submitted.

Examples

data("jobs", package = "mediation")

fit.M <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
fit.Y <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data=jobs)
fimle.lnl(fit.M, fit.Y, "treat", rho=0.2)

fit.M <- lm(job_seek ~ treat + econ_hard + sex + age , data=jobs)
fit.Y <- lm(depress2 ~ treat*job_seek+ econ_hard + sex + age , data=jobs)
fimle.lnl(fit.M, fit.Y, "treat", rho=0.5)

Mediation Analysis via Likelihood

Description

mdn conducts mediation analysis in terms of likelihood.

Usage

mdn(fit.M, fit.Y, X, sig.level = 0.05, B = 0)

Arguments

fit.M

a fitted model object for mediator. It is an object from which the function logLik can extract the log-likelihood. Examples include those from “lm”, “glm”, etc.

fit.Y

a fitted model object for outcome. It can be of a class different from the model for the mediator

X

a character string of the name of the treatment variable.

sig.level

a numerical variable specifying the significance level for the test of the mediated effect.

B

an integer specifying the number of replicates used in the bootstrapping method for the confidence interval. Default value is 0 and bootstrapping is not conducted

Details

Necessary log-likelihoods are extracted from the two fitted models. Various effects are then calculated. Significance of the mediated effect is known up to whether it is larger or smaller than sig.level. If it is larger, a 1 is reported; otherwise a 0 is reported. There is no p-value.

Value

A list with class “mdn” containing the following components:

result

a data frame containing the results of the mediation analysis. The are five variables. They include estimates of various effects and lower and upper bounds of the boostrap confidence interval at level (1-sig.level) followed by test statistics and their respective p-values.

test

a character string specifying the test statistic used for the mediated effect

Test

a numerical value of 0 or 1. If the specified test statistic is significant, its value is 1; otherwise its value is 0

sig.level

a numerical variable specifying the significance level for the test of the mediated effect.

Sample.size

number of subjects in the data

B

an integer specifying the number of replicates used for the bootstrapping

Author(s)

Kai Wang <[email protected]>

References

Berger, R.L. (1997) Likelihood ratio tests and intersection-union tests. Advances in statistical decision theory and applications. Birkh\"auser Boston, 225-237.

Wang, K. (2019) Likelihood-based analysis of the statistical effects of a treatment on an outcome. Submitted.

Examples

data("jobs", package = "mediation")

fit.M <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
fit.Y <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data=jobs)
mdn(fit.M, fit.Y, "treat")
mdn(fit.M, fit.Y, "treat", B=100)

Print Method for Class “mdn”

Description

print.mdn is the print utility for the output from function mdn

Usage

## S3 method for class 'mdn'
print(x, ...)

Arguments

x

an output from function mdn

...

not used.

Details

The p-value for the mediated effect is displayed as greater or smaller than sig.level. For instance, if it is not significant at level 0.05, then “> 0.05” is displayed.

Author(s)

Kai Wang <[email protected]>

Examples

data("jobs", package = "mediation")

fit.M <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
fit.Y <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data=jobs)
mdn(fit.M, fit.Y, "treat")

Power and Sample Size for Mediation Analysis

Description

pwr.mdn Compute power of tests related to mediation analysis or sample size to achieve desired power.

Usage

pwr.mdn(a, b, c.p, tau1, tau2, n = NULL, power = NULL, alpha = 0.05)

Arguments

a

specified value for coefficient aa

b

specified value for coefficient bb

c.p

specified value for coefficient cc'

tau1

specified value of the ratio of residual variance of mediator MM to the variance of the treatment XX

tau2

specified value of the ratio of residual variance of outcome YY to the variance of the treatment XX

n

the sample size available. Either "n" or "power" must be provided

power

a value specifying the desired power. Either "n" or "power" must be provided

alpha

specified significance level

Details

This model is for the basic three-factor model. If coefficients are standardized, then τ1=1a2\tau_1=1-a^2 and τ2=1(c)2b22abc\tau_2=1-(c')^2-b^2-2abc'.

Value

A 2×52\times 5 matrix

Author(s)

Kai Wang <[email protected]>

References

Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.

Examples

n = 100
X = rnorm(n)
s2X = mean((X-mean(X))^2)
a=0.3
b=0.3
c.p = a*b

pwr.mdn(a, b, c.p, 1/s2X, 1/s2X, alpha=0.05, power=0.8)   
pwr.mdn(a, b, c.p, 1/s2X, 1/s2X, alpha=0.05, n=200)

## Using standardized coefficients
pwr.mdn(a, b, c.p, 1-a^2, 1-c.p^2-b^2-2*a*b*c.p, alpha=0.05, power=0.8)
pwr.mdn(a, b, c.p, 1-a^2, 1-c.p^2-b^2-2*a*b*c.p, alpha=0.05, n=200)

S test of Berger (1996)

Description

S.test conducts the S test proposed in Berger (1996)

Usage

S.test(u1, u2, alpha)

Arguments

u1

a numerical value between 0 and 1.

u2

a numerical value between 0 and 1.

alpha

a numerical variable specifying the significance level for the test.

Value

If (u1, u2) falls in the rejection region of the S test, a 1 is returned; otherwise a 0 is returned.

Author(s)

Kai Wang <[email protected]>

References

Berger, R.L. (1997) Likelihood ratio tests and intersection-union tests. Advances in statistical decision theory and applications. Birkh\"auser Boston, 225-237.

Examples

S.test(0.1, 0.4, 0.05)