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 |
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.
Package: | iMediate |
Type: | Package |
Version: | 0.5 |
Date: | 2018-08-29 |
License: | GPL (>=2) |
LazyLoad: | yes |
Kai Wang <[email protected]>
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.
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")
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 probability of mediated effect and total effect in the
absence of direct effect and joint probability of mediated effect and direct
effect assuming
figure.joint.prob(prob = "mediated.main", n = 100, sig.level = 0.05, grid.size = 0.01)
figure.joint.prob(prob = "mediated.main", n = 100, sig.level = 0.05, grid.size = 0.01)
prob |
a character string specifying the probability to be plotted. One
of |
n |
sample size |
sig.level |
significance level used for the test of the mediated effect |
grid.size |
grid size for |
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 and the x-axis is
. The default axes
labels from R function
plot_ly
are switched in order to make them
correct.
A plot generated using package plotly
Kai Wang <[email protected]>
Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.
## figure.joint.prob() # Figure 4 of Wang (2018) ## figure.joint.prob(prob="mediated.direct") # Figure 5 of Wang (2018)
## figure.joint.prob() # Figure 4 of Wang (2018) ## figure.joint.prob(prob="mediated.direct") # Figure 5 of Wang (2018)
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 .
figure.relative.power(comparison = "mediated2main", n = 100, sig.level = 0.05, grid.size = 0.01)
figure.relative.power(comparison = "mediated2main", n = 100, sig.level = 0.05, grid.size = 0.01)
comparison |
a character string specifying the relative power to be
plotted. One of |
n |
sample size |
sig.level |
significance level used for the test of the mediated effect |
grid.size |
grid size for |
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 and the x-axis is
. The default axes
labels from R function
plot_ly
are switched in order to make them
correct.
A plot generated using package plotly
Kai Wang <[email protected]>
Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.
## figure.relative.power() # Figure 2 of Wang (2018) ## figure.relative.power(comparison="mediated2direct") # Figure 3 of Wang (2018)
## figure.relative.power() # Figure 2 of Wang (2018) ## figure.relative.power(comparison="mediated2direct") # Figure 3 of Wang (2018)
Parameter estimates in system of correlated linear M-model and linear Y-model with treatment-mediator interaction using the full information maximum likelihood method.
fimle.lnl(fit.M, fit.Y, treatment, rho = 0, t0 = 0, t1 = 1, m = 1)
fimle.lnl(fit.M, fit.Y, treatment, rho = 0, t0 = 0, t1 = 1, m = 1)
fit.M |
a fitted model object for mediator. It must be an object
generated by function “ |
fit.Y |
a fitted model object for outcome. It must be an object
generated by function “ |
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 |
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 |
P-values are computed from normal distribution.
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 |
Variance |
a matrix of variances and covariances of the parameters estimates |
Kai Wang <[email protected]>
Wang, K. (2019) Maximum likelihood analysis of mediation models with treatment-mediator interaction. Revision submitted.
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)
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)
mdn
conducts mediation analysis in terms of likelihood.
mdn(fit.M, fit.Y, X, sig.level = 0.05, B = 0)
mdn(fit.M, fit.Y, X, sig.level = 0.05, B = 0)
fit.M |
a fitted model object for mediator. It is an object from which
the function |
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 |
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.
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- |
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 |
Kai Wang <[email protected]>
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.
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)
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.mdn
is the print utility for the output from function
mdn
## S3 method for class 'mdn' print(x, ...)
## S3 method for class 'mdn' print(x, ...)
x |
an output from function |
... |
not used. |
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.
Kai Wang <[email protected]>
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")
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")
pwr.mdn
Compute power of tests related to mediation analysis or sample size to achieve desired power.
pwr.mdn(a, b, c.p, tau1, tau2, n = NULL, power = NULL, alpha = 0.05)
pwr.mdn(a, b, c.p, tau1, tau2, n = NULL, power = NULL, alpha = 0.05)
a |
specified value for coefficient |
b |
specified value for coefficient |
c.p |
specified value for coefficient |
tau1 |
specified value of the ratio of residual variance of mediator |
tau2 |
specified value of the ratio of residual variance of outcome |
n |
the sample size available. Either |
power |
a value specifying the desired power. Either |
alpha |
specified significance level |
This model is for the basic three-factor model. If coefficients are standardized, then and
.
A matrix
Kai Wang <[email protected]>
Wang, K. (2018) Understanding power anomalies in mediation analysis. Psychometrika 83 (2), 387-406.
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)
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
conducts the S test proposed in Berger (1996)
S.test(u1, u2, alpha)
S.test(u1, u2, alpha)
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. |
If (u1, u2) falls in the rejection region of the S test, a 1 is returned; otherwise a 0 is returned.
Kai Wang <[email protected]>
Berger, R.L. (1997) Likelihood ratio tests and intersection-union tests. Advances in statistical decision theory and applications. Birkh\"auser Boston, 225-237.
S.test(0.1, 0.4, 0.05)
S.test(0.1, 0.4, 0.05)