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. |
Authors: | Donna Coffman [aut, cre] |
Maintainer: | Donna Coffman <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2025-02-04 04:04:25 UTC |
Source: | https://github.com/dcoffman/tvmediation |
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.
bootci_coeff_2trt(trt, t.seq, M, Y, t.est, deltat, replicates)
bootci_coeff_2trt(trt, t.seq, M, Y, t.est, deltat, replicates)
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 |
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 |
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.
bootci_coeff_3trt( T1, T2, t.seq, mediator, outcome, t.est, original.coeff, boot.sample = 1000 )
bootci_coeff_3trt( T1, T2, t.seq, mediator, outcome, t.est, original.coeff, boot.sample = 1000 )
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. |
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 |
Internal function for estimating bootstrapped confidence intervals for the coefficients of the mediation model for a binary outcome.
bootci_coeff_binary( treatment, t.seq, m, outcome, span = 0.75, replicates = 1000 )
bootci_coeff_binary( treatment, t.seq, m, outcome, span = 0.75, replicates = 1000 )
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. |
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 |
Internal function for estimating bootstrapped confidence intervals for the mediation
effect of continuous outcome and three treatment groups when user argument
CI="boot"
.
bootci_tvm_3trt(boot.sample, orig.data, t.est)
bootci_tvm_3trt(boot.sample, orig.data, t.est)
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. |
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 |
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"
.
bootci_tvmb( treatment, t.seq, m, outcome, coeff_data, span = 0.75, replicates = 1000 )
bootci_tvmb( treatment, t.seq, m, outcome, coeff_data, span = 0.75, replicates = 1000 )
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. |
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 |
Part of the set of internal functions called within the tvmcurve_3trt
function
to assist in the estimation of time varying mediation effect.
coeff(j, T1, T2, x, y)
coeff(j, T1, T2, x, y)
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 |
coeff.est |
estimated coefficients of the mediation model |
nomissing.index |
index of complete cases |
Part of the set of internal functions for estimating bootstrapped confidence intervals
for continuous outcome and two treatment groups when user argument CI="boot"
.
estBootCIs(trt, t.seq, M, Y, t.est, deltat, replicates)
estBootCIs(trt, t.seq, M, Y, t.est, deltat, replicates)
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. |
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
Part of the set of internal functions called within the tvma
function to assist
in the estimation of the time varying mediation effect.
estCoeff(newMO.j.est)
estCoeff(newMO.j.est)
newMO.j.est |
a list containing mean centered mediators and outcomes |
coeff.est |
estimated coefficients of the mediation model |
Transposing a dataset with repeated measurements/responses for each subject from longitudinal to wide format.
LongToWide(subject.id, time.sequence, outcome, verbose = FALSE)
LongToWide(subject.id, time.sequence, outcome, verbose = FALSE)
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) |
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.
mat.wide |
a matrix in wide format, in which each column is the outcome for each subject and each row is the time sequence |
# CREATING A TRANSPOSED MATRIX FOR MEDIATOR `WantToSmokeLst15min` data(smoker) mat.wide <- LongToWide(smoker$SubjectID, smoker$timeseq, smoker$WantToSmokeLst15min)
# CREATING A TRANSPOSED MATRIX FOR MEDIATOR `WantToSmokeLst15min` data(smoker) mat.wide <- LongToWide(smoker$SubjectID, smoker$timeseq, smoker$WantToSmokeLst15min)
Part of the set of internal functions called within the tvma
function to assist
in the estimation of time varying mediation effect.
newMediatorOutcome(trt, M, Y)
newMediatorOutcome(trt, M, Y)
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. |
newMO |
list containing new mediators, outcomes, and index of complete cases |
The dataset is simulated based on the Wisconsin Smokers' Health Study 2.
data(smoker)
data(smoker)
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)
tvmb
, tvma_3trt
tvma
, LongToWide
data(smoker)
data(smoker)
Part of the set of internal functions called within the tvma
function to assist
in the estimation of the time varying mediation effect.
smoothest(t.seq, t.coeff, t.est, deltat)
smoothest(t.seq, t.coeff, t.est, deltat)
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 |
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 |
Function to estimate the time-varying mediation effect and bootstrap standard errors for two treatment groups and a continuous outcome.
tvma( treatment, t.seq, mediator, outcome, t.est = t.seq, plot = FALSE, CI = "boot", replicates = 1000, verbose = FALSE )
tvma( treatment, t.seq, mediator, outcome, t.est = t.seq, plot = FALSE, CI = "boot", replicates = 1000, verbose = FALSE )
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) |
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 |
Alpha_CI
plot for hat.alpha with CIs over t.est
Gamma_CI
plot for hat.gamma with CIs over t.est
Beta_CI
plot for hat.beta with CIs over t.est
Tau_CI
plot for hat.tau with CIs over t.est
MedEff
plot for est.M over t.est
MedEff_CI
plot for est.M with CIs over t.est
** IMPORTANT ** An alternate way of formatting the data and calling the function is documented in detail in the tutorial for the tvmb() function.
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.
## 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)
## 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)
Function to estimate the time-varying mediation effect and bootstrap standard errors for three treatment groups and a continuous outcome.
tvma_3trt( T1, T2, t.seq, mediator, outcome, t.est = t.seq, plot = FALSE, CI = "boot", replicates = 1000, grpname = "T", verbose = FALSE )
tvma_3trt( T1, T2, t.seq, mediator, outcome, t.est = t.seq, plot = FALSE, CI = "boot", replicates = 1000, grpname = "T", verbose = FALSE )
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) |
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 |
plot1_a1
plot for hat.alpha1 with CIs over t.est
plot2_a2
plot for hat.alpha2 with CIs over t.est
plot3_g1
plot for hat.gamma1 with CIs over t.est
plot4_g2
plot for hat.gamma2 with CIs over t.est
plot5_t1
plot for hat.tau1 with CIs over t.est
plot6_t2
plot for hat.tau2 with CIs over t.est
plot7_b
plot for hat.beta with CIs over t.est
MedEff_T1
plot for hat.mediation1 over t.est
MedEff_T2
plot for hat.mediation2 over t.est
MedEff_CI_T1
plot for hat.mediation1 with CIs over t.est
MedEff_CI_T2
plot for hat.mediation2 with CIs over t.est
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.
## 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)
## 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)
Function to estimate the time-varying mediation effect and bootstrap standard errors, involving two treatment groups and binary outcome.
tvmb( treatment, t.seq, mediator, outcome, span = 0.75, plot = FALSE, CI = "boot", replicates = 1000, verbose = FALSE )
tvmb( treatment, t.seq, mediator, outcome, span = 0.75, plot = FALSE, CI = "boot", replicates = 1000, verbose = FALSE )
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) |
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 |
plot1_a
plot for alpha_hat with CIs over t.seq
plot2_g
plot for gamma_hat with CIs over t.seq
plot3_b
plot for beta_hat with CIs over t.seq
plot4_t
plot for tau_hat with CIs over t.seq
MedEff
plot for medEffect over t.seq
MedEff_CI
plot for medEffect with CIs over t.seq
bootstrap
plot for estimated medEffect from bootstrapped samples over t.seq
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.
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.
## 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)
## 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)
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.
tvmcurve_3trt(T1, T2, t.seq, x, y, t.est)
tvmcurve_3trt(T1, T2, t.seq, x, y, t.est)
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 |
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 |