Type: | Package |
Date: | 2022-05-13 |
Version: | 1.1.0 |
Title: | Time Varying Mediation Analysis |
Description: | Provides functions for estimating mediation effects that vary over time as described in Cai X, Coffman DL, Piper ME, Li R. Estimation and inference for the mediation effect in a time-varying mediation model. BMC Med Res Methodol. 2022;22(1):1-12. |
RoxygenNote: | 7.1.2 |
Depends: | R (≥ 4.0.0) |
Imports: | stats (≥ 4.0.2), dplyr (≥ 1.0.2), ggplot2 (≥ 3.3.2), locpol (≥ 0.7-0) |
Suggests: | knitr, rmarkdown |
License: | GPL-3 |
URL: | https://github.com/dcoffman/tvmediation/wiki |
BugReports: | https://github.com/dcoffman/tvmediation/issues |
LazyData: | true |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2022-05-21 15:38:02 UTC; yajna |
Author: | Donna Coffman |
Maintainer: | Donna Coffman <dcoffman@temple.edu> |
Repository: | CRAN |
Date/Publication: | 2022-05-25 06:40:02 UTC |
Function to transpose the data from long to wide format
Description
Transposing a dataset with repeated measurements/responses for each subject from longitudinal to wide format.
Usage
LongToWide(subject.id, time.sequence, outcome, verbose = FALSE)
Arguments
subject.id |
a column of subject identifiers |
time.sequence |
a column of time points |
outcome |
a column to be transposed |
verbose |
TRUE or FALSE (default = FALSE) prints output to screen (OPTIONAL INPUT) |
Details
If data is not sorted by subject.id, a warning message will appear. The function will then sort the data by subject.id. It is recommended that the user sorts the data prior to using this function.
Value
mat.wide |
a matrix in wide format, in which each column is the outcome for each subject and each row is the time sequence |
Examples
# CREATING A TRANSPOSED MATRIX FOR MEDIATOR `WantToSmokeLst15min`
data(smoker)
mat.wide <- LongToWide(smoker$SubjectID,
smoker$timeseq,
smoker$WantToSmokeLst15min)
Bootstrap function for computing CIs for coefficients for a continuous outcome and two treatment groups
Description
Part of the set of internal functions for estimating bootstrapped CIs for the coefficients of the mediation model for continuous outcome and two treatment groups.
Usage
bootci_coeff_2trt(trt, t.seq, M, Y, t.est, deltat, replicates)
Arguments
trt |
a vector indicating treatment group |
t.seq |
a vector of time points for each observation |
M |
matrix of mediator values in wide format |
Y |
matrix of outcome values in wide format |
t.est |
time points at which to make the estimation. Default = t.seq |
deltat |
a small constant which controls the time-lag of the effect of the mediator on the outcome. |
replicates |
number of replicates for bootstrapping confidence intervals. Default = 1000 |
Value
CI.upper.alpha |
CI upper limit for coefficient hat.alpha |
CI.lower.alpha |
CI lower limit for coefficient hat.alpha |
CI.upper.gamma |
CI upper limit for coefficient hat.gamma |
CI.lower.gamma |
CI lower limit for coefficient hat.gamma |
CI.upper.beta |
CI upper limit for coefficient hat.beta |
CI.lower.beta |
CI lower limit for coefficient hat.beta |
CI.upper.tau |
CI upper limit for coefficient hat.tau |
CI.lower.tau |
CI lower limit for coefficient hat.tau |
Bootstrap samples to estimate confidence intervals for coefficients for a continuous outcome and three treatment groups.
Description
Part of the set of internal functions for estimating bootstrapped confidence intervals for the coefficients of the mediation model for a continuous outcome and three treatment groups.
Usage
bootci_coeff_3trt(
T1,
T2,
t.seq,
mediator,
outcome,
t.est,
original.coeff,
boot.sample = 1000
)
Arguments
T1 |
a vector indicating assignment to treatment 1 |
T2 |
a vector indicating assignment to treatment 2 |
t.seq |
a vector of time points for each observation |
mediator |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
t.est |
time points at which to make the estimation. Default = t.seq |
original.coeff |
a list of the estimated coefficients. |
boot.sample |
number of replicates for bootstrapping confidence intervals. Default = 1000. |
Value
alw1 |
CI lower limit for estimated Treatment 1 effect on mediator |
aup1 |
CI upper limit for estimated Treatment 1 effect on mediator |
alw2 |
CI lower limit for estimated Treatment 2 effect on mediator |
aup2 |
CI upper limit for estimated Treatment 2 effect on mediator |
glw1 |
CI lower limit for estimated Treatment 1 direct effect on outcome |
gup1 |
CI upper limit for estimated Treatment 1 direct effect on outcome |
glw2 |
CI lower limit for estimated Treatment 2 direct effect on outcome |
gup2 |
CI upper limit for estimated Treatment 2 direct effect on outcome |
tlw1 |
CI lower limit for estimated Treatment 1 total effect on outcome |
tup1 |
CI upper limit for estimated Treatment 1 total effect on outcome |
tlw2 |
CI lower limit for estimated Treatment 2 total effect on outcome |
tup2 |
CI upper limit for estimated Treatment 2 total effect on outcome |
blw |
CI lower limit for estimated effect of mediator on outcome |
bup |
CI upper limit for estimated effect of mediator on outcome |
Bootstrap samples to estimate confidence intervals for binary outcome coefficients.
Description
Internal function for estimating bootstrapped confidence intervals for the coefficients of the mediation model for a binary outcome.
Usage
bootci_coeff_binary(
treatment,
t.seq,
m,
outcome,
span = 0.75,
replicates = 1000
)
Arguments
treatment |
a vector indicating treatment group |
t.seq |
a vector of unique time points for each observation |
m |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
span |
Numeric value of the span to be used for LOESS regression. Default = 0.75. |
replicates |
Number of replicates for bootstrapping confidence intervals. Default = 1000. |
Value
t.seq |
time points of estimation |
CI.lower.a |
CI lower limit for alpha_hat |
CI.upper.a |
CI upper limit for alpha_hat |
CI.lower.g |
CI lower limit for gamma_hat |
CI.upper.g |
CI upper limit for gamma_hat |
CI.lower.b |
CI lower limit for beta_hat |
CI.upper.b |
CI upper limit for beta_hat |
CI.lower.t |
CI lower limit for tau_hat |
CI.upper.t |
CI upper limit for tau_hat |
Bootstrap samples to estimate confidence intervals for continuous outcome and three treatment groups.
Description
Internal function for estimating bootstrapped confidence intervals for the mediation
effect of continuous outcome and three treatment groups when user argument
CI="boot"
.
Usage
bootci_tvm_3trt(boot.sample, orig.data, t.est)
Arguments
boot.sample |
number of replicates for bootstrapping confidence intervals. Default = 1000. |
orig.data |
a list of original data |
t.est |
time points at which to make the estimation. Default = t.seq. |
Value
plw1 |
CI lower limit for estimated mediation effect of T1 |
pup1 |
CI upper limit for estimated mediation effect of T1 |
plw2 |
CI lower limit for estimated mediation effect of T2 |
pup2 |
CI upper limit for estimated mediation effect of T2 |
orig.se1.all |
estimated standard errors for the mediation effect of T1 |
orig.se2.all |
estimated standard errors for the mediation effect of T2 |
orig.mediation1 |
time varying mediation effect for T1 |
orig.mediation2 |
time varying mediation effect for T2 |
Bootstrap samples to estimate confidence intervals for the mediation effect for a binary outcome.
Description
Part of the set of internal functions for estimating bootstrapped confidence intervals
for the mediation effect for a binary outcome when user argument CI="boot"
.
Usage
bootci_tvmb(
treatment,
t.seq,
m,
outcome,
coeff_data,
span = 0.75,
replicates = 1000
)
Arguments
treatment |
a vector indicating treatment group |
t.seq |
a vector of unique time points for each observation |
m |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
coeff_data |
a merged dataset of indirect and direct effects and CIs estimated
from |
span |
Numeric value of the span to be used for LOESS regression. Default = 0.75. |
replicates |
number of replicates for bootstrapping CIs. Default = 1000. |
Value
timeseq |
time points of estimation |
alpha_hat |
time-varying treatment effect on the mediator |
CI.lower.a |
CI lower limit for estimated coefficient alpha_hat |
CI.upper.a |
CI upper limit for estimated coefficient alpha_hat |
gamma_hat |
time-varying treatment effect on the outcome (direct effect) |
CI.lower.g |
CI lower limit for estimated coefficient gamma_hat |
CI.upper.g |
CI upper limit for estimated coefficient gamma_hat |
beta_hat |
time-varying effect of the mediator on the outcome |
CI.lower.b |
CI lower limit for estimated coefficient beta_hat |
CI.upper.b |
CI upper limit for estimated coefficient beta_hat |
tau_hat |
time-varying treatment effect on outcome (total effect) |
CI.lower.t |
CI lower limit for estimated coefficient tau_hat |
CI.upper.t |
CI upper limit for estimated coefficient tau_hat |
medEffect |
time varying mediation effect |
CI.lower |
CI lower limit for medEffect |
CI.upper |
CI upper limit for medEffect |
Function to estimate coefficients at time t
Description
Part of the set of internal functions called within the tvmcurve_3trt
function
to assist in the estimation of time varying mediation effect.
Usage
coeff(j, T1, T2, x, y)
Arguments
j |
a number indicating time point of observation |
T1 |
a vector indicating assignment to treatment 1 |
T2 |
a vector indicating assignment to treatment 2 |
x |
matrix of mediator values in wide format |
y |
matrix of outcome outcomes in wide format |
Value
coeff.est |
estimated coefficients of the mediation model |
nomissing.index |
index of complete cases |
Bootstrapping samples to estimate mediation effects confidence intervals for continuous outcome and two treatment (exposure) groups.
Description
Part of the set of internal functions for estimating bootstrapped confidence intervals
for continuous outcome and two treatment groups when user argument CI="boot"
.
Usage
estBootCIs(trt, t.seq, M, Y, t.est, deltat, replicates)
Arguments
trt |
a vector indicating treatment group |
t.seq |
a vector of time points at each obs |
M |
matrix of mediator values |
Y |
matrix of outcome values |
t.est |
time points at which to make the estimation |
deltat |
a small constant which controls the time-lag of the effect of the mediator on the outcome, half the time between two time points |
replicates |
number of replicates for bootstrapping confidence intervals. |
Value
boot.sebootstrapped standard error for the estimated mediation effect
CI.upperpercentile bootstrapped CI upper limit for the estimated mediation effect
CI.lowerpercentile bootstrapped CI lower limit for the estimated mediation effect
Function to estimate coefficients at time t.
Description
Part of the set of internal functions called within the tvma
function to assist
in the estimation of the time varying mediation effect.
Usage
estCoeff(newMO.j.est)
Arguments
newMO.j.est |
a list containing mean centered mediators and outcomes |
Value
coeff.est |
estimated coefficients of the mediation model |
Function to compute new Mediator and Outcome using time t and t-1 mean centered on the individual.
Description
Part of the set of internal functions called within the tvma
function to assist
in the estimation of time varying mediation effect.
Usage
newMediatorOutcome(trt, M, Y)
Arguments
trt |
numeric binary treatment group indicator for each individual |
M |
(t.seq x N) matrix where N = number of observations. Column 1 is mediator at time t-1. Column 2 is mediator at time t. |
Y |
(Nx1) matrix were N = number of observations. Column 1 is outcome at time t-1. |
Value
newMO |
list containing new mediators, outcomes, and index of complete cases |
Wisconsin Smokers' Health Study 2
Description
The dataset is simulated based on the Wisconsin Smokers' Health Study 2.
Usage
data(smoker)
Format
A data frame with 40,130 observations on 12 variables.
-
SubjectID: Subject ID
-
treatment: Treatment group (2 = patch, 3 = varenicline, 4 = combination nicotine replacement therapy)
-
patch: Received patch (0 = No, 1 = Yes)
-
varenicline: Received varenicline (0 = No, 1 = Yes)
-
comboNRT: Received combination nicotine replacement therapy (0 = No, 1 = Yes)
-
DaysFromTQD: Number of days from quit date
-
time.of.day: Time of day (0 = am, 1 = pm)
-
timeseq: Number of days from quit date (.5 indicates pm)
-
WantToSmokeLst15min: How did you feel in the last 15 min: wanting to smoke (1 = not at all, 7 = extremely)
-
NegMoodLst15min: How did you feel in the last 15 min: Negative mood (1 = not at all, 7 = extremely)
-
cessFatig: Cessation fatigue - I am tired of trying to quit smoking (1 = strongly disagree, 7 = strongly agree)
-
CigCount: Cigarettes smoked over entire day
-
smoke_status: Did you smoke (0 = No, 1 = Yes)
See Also
tvmb
, tvma_3trt
tvma
, LongToWide
Examples
data(smoker)
Function to compute local polynomial estimation using rule of thumb for bandwidth selection
Description
Part of the set of internal functions called within the tvma
function to assist
in the estimation of the time varying mediation effect.
Usage
smoothest(t.seq, t.coeff, t.est, deltat)
Arguments
t.seq |
a vector of time points at each observation |
t.coeff |
estimated coefficients |
t.est |
time points at which to make the estimation |
deltat |
a small constant which controls the time-lag of the effect of the mediator on the outcome, half the time between two time points |
Value
bw_alpha |
a number computed via Fan and Gijbels' (1996) rule of thumb for bandwidth selector for alpha coefficient. |
bw_gamma |
a number computed via Fan and Gijbels' (1996) rule of thumb for bandwidth selector for gamma coefficient. |
bw_beta |
a number computed via Fan and Gijbels' (1996) rule of thumb for bandwidth selector for beta coefficient. |
bw_beta |
a number computed via Fan and Gijbels' (1996) rule of thumb for bandwidth selector for tau coefficient. |
hat.alpha |
estimated treatment effect on mediator |
hat.gamma |
estimated treatment effect on outcome, adjusted for mediator |
hat.beta |
estimated mediator effect on outcome |
hat.tau |
estimated treatment effect on outcome, not adjusting for mediator |
est.M |
estimated mediation effect, product of hat.alpha and hat.beta |
Time Varying Mediation Function: Continuous Outcome and Two Treatment Groups
Description
Function to estimate the time-varying mediation effect and bootstrap standard errors for two treatment groups and a continuous outcome.
Usage
tvma(
treatment,
t.seq,
mediator,
outcome,
t.est = t.seq,
plot = FALSE,
CI = "boot",
replicates = 1000,
verbose = FALSE
)
Arguments
treatment |
a vector indicating treatment group |
t.seq |
a vector of time points for each observation |
mediator |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
t.est |
a vector of time points at which to estimate. Default = t.seq (OPTIONAL ARGUMENT) |
plot |
TRUE or FALSE for producing plots. Default = "FALSE" (OPTIONAL ARGUMENT) |
CI |
"none" or "boot" method of deriving confidence intervals. Default = "boot" (OPTIONAL ARGUMENT) |
replicates |
number of replicates for bootstrapping confidence intervals. Default = 1000 (OPTIONAL ARGUMENT) |
verbose |
TRUE or FALSE for printing results to screen. Default = "FALSE" (OPTIONAL ARGUMENT) |
Value
hat.alpha |
estimated time-varying treatment effect on mediator |
CI.lower.alpha |
CI lower limit for estimated coefficient hat.alpha |
CI.upper.alpha |
CI upper limit for estimated coefficient hat.alpha |
hat.gamma |
estimated time-varying treatment effect on outcome (direct effect) |
CI.lower.gamma |
CI lower limit for estimated coefficient hat.gamma |
CI.upper.gamma |
CI upper limit for estimated coefficient hat.gamma |
hat.beta |
estimated time-varying effect of the mediator on outcome |
CI.lower.beta |
CI lower limit for estimated coefficient hat.beta |
CI.upper.beta |
CI upper limit for estimated coefficient hat.beta |
hat.tau |
estimated time-varying treatment effect on outcome (total effect) |
CI.lower.tau |
CI lower limit for estimated coefficient hat.tau |
CI.upper.tau |
CI upper limit for estimated coefficient hat.tau |
est.M |
time varying mediation effect |
boot.se.m |
estimated standard error for est.M |
CI.lower |
CI lower limit for est.M |
CI.upper |
CI upper limit for est.M |
Plot Returns
Alpha_CI
plot for hat.alpha with CIs over t.estGamma_CI
plot for hat.gamma with CIs over t.estBeta_CI
plot for hat.beta with CIs over t.estTau_CI
plot for hat.tau with CIs over t.estMedEff
plot for est.M over t.estMedEff_CI
plot for est.M with CIs over t.est
Note
** IMPORTANT ** An alternate way of formatting the data and calling the function is documented in detail in the tutorial for the tvmb() function.
References
Fan, J. and Gijbels, I. Local polynomial modelling and its applications: Monographs on statistics and applied probability 66. CRC Press; 1996.
Fan J, Zhang W. Statistical Estimation in Varying Coefficient Models. The Annals of Statistics. 1999;27(5):1491-1518.
Fan J, Zhang JT. Two-step estimation of functional linear models with applications to longitudinal data. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 2000;62(2):303-322.
Cai X, Coffman DL, Piper ME, Li R. Estimation and inference for the mediation effect in a time-varying mediation model. BMC Med Res Methodol. 2022;22(1):1-12.
Baker TB, Piper ME, Stein JH, et al. Effects of Nicotine Patch vs Varenicline vs Combination Nicotine Replacement Therapy on Smoking Cessation at 26 Weeks: A Randomized Clinical Trial. JAMA. 2016;315(4):371.
B. Efron, R. Tibshirani. Bootstrap Methods for Standard Errors, Confidence Intervals, and Other Measures of Statistical Accuracy. Statistical Science. 1986;1(1):54-75.
Examples
## Not run: data(smoker)
# REDUCE DATA SET TO ONLY 2 TREATMENT CONDITIONS (EXCLUDING COMBINATION NRT)
smoker.sub <- smoker[smoker$treatment != 4, ]
# GENERATE WIDE FORMATTED MEDIATORS
mediator <- LongToWide(smoker.sub$SubjectID,
smoker.sub$timeseq,
smoker.sub$NegMoodLst15min)
# GENERATE WIDE FORMATTED OUTCOMES
outcome <- LongToWide(smoker.sub$SubjectID,
smoker.sub$timeseq,
smoker.sub$cessFatig)
# GENERATE A BINARY TREATMENT VARIABLE
trt <- as.numeric(unique(smoker.sub[,c("SubjectID","varenicline")])[,2])-1
# GENERATE A VECTOR OF UNIQUE TIME POINTS
t.seq <- sort(unique(smoker.sub$timeseq))
# COMPUTE TIME VARYING MEDIATION ANALYSIS USING BOOTSTRAPPED CONFIDENCE INTERVALS
results <- tvma(trt, t.seq, mediator, outcome)
# COMPUTE TIME VARYING MEDIATION ANALYSIS FOR SPECIFIED POINTS IN TIME USING 250 REPLICATES
results <- tvma(trt, t.seq, mediator, outcome,
t.est = c(0.2, 0.4, 0.6, 0.8),
replicates = 250)
## End(Not run)
Time Varying Mediation Function: Continuous Outcome and Three Treatment Groups
Description
Function to estimate the time-varying mediation effect and bootstrap standard errors for three treatment groups and a continuous outcome.
Usage
tvma_3trt(
T1,
T2,
t.seq,
mediator,
outcome,
t.est = t.seq,
plot = FALSE,
CI = "boot",
replicates = 1000,
grpname = "T",
verbose = FALSE
)
Arguments
T1 |
a vector indicating assignment to treatment 1 |
T2 |
a vector indicating assignment to treatment 2 |
t.seq |
a vector of time points for each observation |
mediator |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
t.est |
a vector of time points at which to make the estimation. Default = t.seq. (OPTIONAL ARGUMENT) |
plot |
TRUE or FALSE for plotting mediation effect. Default = "FALSE". (OPTIONAL ARGUMENT) |
CI |
"none" or "boot" method of deriving confidence intervals. Default = "boot". (OPTIONAL ARGUMENT) |
replicates |
number of replicates for bootstrapping confidence intervals. Default = 1000. (OPTIONAL ARGUMENT) |
grpname |
name of the treatment arms (exposure groups) to be displayed in the results. Default = "T". (OPTIONAL ARGUMENT) |
verbose |
TRUE or FALSE for printing results to screen. Default = "FALSE". (OPTIONAL ARGUMENT) |
Value
hat.alpha1 |
estimated Treatment 1 effect on mediator |
CI.lower.alpha1 |
CI lower limit for estimated coefficient hat.alpha1 |
CI.upper.alpha1 |
CI upper limit for estimated coefficient hat.alpha1 |
hat.alpha2 |
estimated Treatment 2 effect on mediator |
CI.lower.alpha2 |
CI lower limit for estimated coefficient hat.alpha2 |
CI.upper.alpha2 |
CI upper limit for estimated coefficient hat.alpha2 |
hat.gamma1 |
estimated Treatment 1 direct effect on outcome |
CI.lower.gamma1 |
CI lower limit for estimated coefficient hat.gamma1 |
CI.upper.gamma1 |
CI upper limit for estimated coefficient hat.gamma1 |
hat.gamma2 |
estimated Treatment 2 direct effect on outcome |
CI.lower.gamma2 |
CI lower limit for estimated coefficient hat.gamma2 |
CI.upper.gamma2 |
CI upper limit for estimated coefficient hat.gamma2 |
hat.tau1 |
estimated Treatment 1 total effect on outcome |
CI.lower.tau1 |
CI lower limit for estimated coefficient hat.tau1 |
CI.upper.tau1 |
CI upper limit for estimated coefficient hat.tau1 |
hat.tau2 |
estimated Treatment 2 total effect on outcome |
CI.lower.tau2 |
CI lower limit for estimated coefficient hat.tau2 |
CI.upper.tau2 |
CI upper limit for estimated coefficient hat.tau2 |
hat.beta |
estimated mediator effect on outcome |
CI.lower.beta |
CI lower limit for estimated coefficient hat.beta |
CI.upper.beta |
CI upper limit for estimated coefficient hat.beta |
hat.mediation1 |
time varying mediation effect for Treatment 1 on outcome |
SE_MedEff1 |
estimated standard errors of hat.mediation1 |
CI.upper.T1 |
CI upper limit for hat.mediation1 |
CI.lower.T1 |
CI lower limit for hat.mediation1 |
hat.mediation2 |
time varying mediation effect for Treatment 2 on outcome |
SE_MedEff2 |
estimated standard errors of hat.mediation2 |
CI.upper.T2 |
CI upper limit for hat.mediation2 |
CI.lower.T2 |
CI lower limit for hat.mediation2 |
Plot Returns
plot1_a1
plot for hat.alpha1 with CIs over t.estplot2_a2
plot for hat.alpha2 with CIs over t.estplot3_g1
plot for hat.gamma1 with CIs over t.estplot4_g2
plot for hat.gamma2 with CIs over t.estplot5_t1
plot for hat.tau1 with CIs over t.estplot6_t2
plot for hat.tau2 with CIs over t.estplot7_b
plot for hat.beta with CIs over t.estMedEff_T1
plot for hat.mediation1 over t.estMedEff_T2
plot for hat.mediation2 over t.estMedEff_CI_T1
plot for hat.mediation1 with CIs over t.estMedEff_CI_T2
plot for hat.mediation2 with CIs over t.est
References
Fan, J. and Gijbels, I. Local polynomial modelling and its applications: Monographs on statistics and applied probability 66. CRC Press; 1996.
Fan J, Zhang W. Statistical Estimation in Varying Coefficient Models. The Annals of Statistics. 1999;27(5):1491-1518.
Fan J, Zhang JT. Two-step estimation of functional linear models with applications to longitudinal data. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 2000;62(2):303-322.
Cai X, Coffman DL, Piper ME, Li R. Estimation and inference for the mediation effect in a time-varying mediation model. BMC Med Res Methodol. 2022;22(1):1-12.
Baker TB, Piper ME, Stein JH, et al. Effects of Nicotine Patch vs Varenicline vs Combination Nicotine Replacement Therapy on Smoking Cessation at 26 Weeks: A Randomized Clinical Trial. JAMA. 2016;315(4):371.
B. Efron, R. Tibshirani. Bootstrap Methods for Standard Errors, Confidence Intervals, and Other Measures of Statistical Accuracy. Statistical Science. 1986;1(1):54-75.
Examples
## Not run: data(smoker)
# GENERATE WIDE FORMATTED MEDIATORS
mediator <- LongToWide(smoker$SubjectID,
smoker$timeseq,
smoker$NegMoodLst15min)
# GENERATE WIDE FORMATTED OUTCOMES
outcome <- LongToWide(smoker$SubjectID,
smoker$timeseq,
smoker$cessFatig)
# GENERATE TWO BINARY TREATMENT VARIABLES
NRT1 <- as.numeric(unique(smoker[,c("SubjectID","varenicline")])[,2])-1
NRT2 <- as.numeric(unique(smoker[,c("SubjectID","comboNRT")])[,2])-1
# GENERATE A VECTOR OF UNIQUE TIME POINTS
t.seq <- sort(unique(smoker$timeseq))
# COMPUTE TIME VARYING MEDIATION ANALYSIS USING BOOTSTRAPPED CONFIDENCE INTERVALS
results <- tvma_3trt(NRT1, NRT2, t.seq, mediator, outcome)
# COMPUTE TIME VARYING MEDIATION ANALYSIS FOR SPECIFIED POINTS IN TIME USING 250 REPLICATES
results <- tvma_3trt(NRT1, NRT2, t.seq, mediator, outcome,
t.est = c(0.2, 0.4, 0.6, 0.8),
replicates = 250)
## End(Not run)
Time Varying Mediation Function: Binary Outcome and Two Treatment Groups
Description
Function to estimate the time-varying mediation effect and bootstrap standard errors, involving two treatment groups and binary outcome.
Usage
tvmb(
treatment,
t.seq,
mediator,
outcome,
span = 0.75,
plot = FALSE,
CI = "boot",
replicates = 1000,
verbose = FALSE
)
Arguments
treatment |
a vector indicating treatment group |
t.seq |
a vector of unique time points for each observation |
mediator |
matrix of mediator values in wide format |
outcome |
matrix of outcome values in wide format |
span |
Numeric value of the span to be used for LOESS regression. Default = 0.75. |
plot |
TRUE or FALSE for producing plots. Default = "FALSE". (OPTIONAL ARGUMENT) |
CI |
"none" or "boot" method of deriving confidence intervals. Default = "boot". (OPTIONAL ARGUMENT) |
replicates |
Number of replicates for bootstrapping confidence intervals. Default = 1000. (OPTIONAL ARGUMENT) |
verbose |
TRUE or FALSE for printing results to screen. Default = "FALSE". (OPTIONAL ARGUMENT) |
Value
timeseq |
time points of estimation |
alpha_hat |
estimated treatment effect on mediator |
CI.lower.a |
CI lower limit for estimated coefficient alpha_hat |
CI.upper.a |
CI upper limit for estimated coefficient alpha_hat |
gamma_hat |
estimated treatment effect on outcome (direct effect) |
CI.lower.g |
CI lower limit for estimated coefficient gamma_hat |
CI.upper.g |
CI upper limit for estimated coefficient gamma_hat |
beta_hat |
estimated mediator effect on outcome |
CI.lower.b |
CI lower limit for estimated coefficient beta_hat |
CI.upper.b |
CI upper limit for estimated coefficient beta_hat |
tau_hat |
estimated treatment effect on outcome (total effect) |
CI.lower.t |
CI lower limit for estimated coefficient tau_hat |
CI.upper.t |
CI upper limit for estimated coefficient tau_hat |
medEffect |
time varying mediation effect |
CI.lower |
CI lower limit for medEffect |
CI.upper |
CI upper limit for medEffect |
Plot Returns
plot1_a
plot for alpha_hat with CIs over t.seqplot2_g
plot for gamma_hat with CIs over t.seqplot3_b
plot for beta_hat with CIs over t.seqplot4_t
plot for tau_hat with CIs over t.seqMedEff
plot for medEffect over t.seqMedEff_CI
plot for medEffect with CIs over t.seqbootstrap
plot for estimated medEffect from bootstrapped samples over t.seq
Note
Currently supports 2 treatment groups
** IMPORTANT ** An alternate way of formatting the data and calling the function is documented in detail in the tutorial for the tvmb() function.
References
Fan, J. and Gijbels, I. Local polynomial modelling and its applications: Monographs on statistics and applied probability 66. CRC Press; 1996.
Fan J, Zhang W. Statistical Estimation in Varying Coefficient Models. The Annals of Statistics. 1999;27(5):1491-1518.
Fan J, Zhang JT. Two-step estimation of functional linear models with applications to longitudinal data. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 2000;62(2):303-322.
Baker TB, Piper ME, Stein JH, et al. Effects of Nicotine Patch vs Varenicline vs Combination Nicotine Replacement Therapy on Smoking Cessation at 26 Weeks: A Randomized Clinical Trial. JAMA. 2016;315(4):371.
B. Efron, R. Tibshirani. Bootstrap Methods for Standard Errors, Confidence Intervals, and Other Measures of Statistical Accuracy. Statistical Science. 1986;1(1):54-75.
Examples
## Not run: data(smoker)
# REDUCE DATA SET TO ONLY 2 TREATMENT CONDITIONS (EXCLUDE COMBINATION NRT)
smoker.sub <- smoker[smoker$treatment != 4, ]
# GENERATE WIDE FORMATTED MEDIATORS
mediator <- LongToWide(smoker.sub$SubjectID,
smoker.sub$timeseq,
smoker.sub$NegMoodLst15min)
# GENERATE WIDE FORMATTED OUTCOMES
outcome <- LongToWide(smoker.sub$SubjectID,
smoker.sub$timeseq,
smoker.sub$smoke_status)
# GENERATE A BINARY TREATMENT VARIABLE
trt <- as.numeric(unique(smoker.sub[, c("SubjectID","varenicline")])[, 2])-1
# GENERATE A VECTOR OF UNIQUE TIME POINTS
t.seq <- sort(unique(smoker.sub$timeseq))
# COMPUTE TIME VARYING MEDIATION ANALYSIS USING BOOTSTRAPPED CONFIDENCE INTERVALS
results <- tvmb(trt, t.seq, mediator, outcome)
## End(Not run)
Main function for time varying mediation function for continuous outcome and three treatment arms (i.e., exposure groups).
Description
Part of the set of internal functions to estimate the time-varying mediation effect and bootstrap standard errors for three treatment groups and continuous outcome.
Usage
tvmcurve_3trt(T1, T2, t.seq, x, y, t.est)
Arguments
T1 |
a vector indicating assignment to treatment 1 |
T2 |
a vector indicating assignment to treatment 2 |
t.seq |
a vector of time points for each observation |
x |
matrix of mediator values in wide format |
y |
matrix of outcome values in wide format |
t.est |
time points at which to make the estimation. Default = t.seq |
Value
hat.alpha1 |
estimated Treatment 1 effect on mediator |
hat.alpha2 |
estimated Treatment 2 effect on mediator |
hat.gamma1 |
estimated Treatment 1 direct effect on outcome |
hat.gamma2 |
estimated Treatment 2 direct effect on outcome |
hat.tau1 |
estimated Treatment 1 total effect on outcome |
hat.tau2 |
estimated Treatment 2 total effect on outcome |
hat.beta |
estimated mediator effect on outcome |
hat.mediation1 |
time varying mediation effect for Treatment 1 on outcome |
hat.mediation2 |
time varying mediation effect for Treatment 2 on outcome |