Title: | Dynamic Path Analysis of Survival Data via Aalen's Additive Hazards Model |
---|---|
Description: | Dynamic path analysis with estimation of the corresponding direct, indirect, and total effects, based on Fosen et al., (2006) <doi:10.1007/s10985-006-9004-2>. The main outcome of interest is a counting process from survival analysis (or recurrent events) data. At each time of event, ordinary linear regression is used to estimate the relation between the covariates, while Aalen's additive hazard model is used for the regression of the counting process on the covariates. |
Authors: | Novartis Pharma AG [cph], Matthias Kormaksson [aut, cre], Susanne Strohmaier [aut], Markus Lange [aut], David Demanse [aut] |
Maintainer: | Matthias Kormaksson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-03 05:59:10 UTC |
Source: | https://github.com/cran/dpasurv |
Calculate bootstrap confidence bands for effect of interest
add.ci(object, alpha)
add.ci(object, alpha)
object |
object of class "effect" |
alpha |
the confidence level |
object of class "effect" with updated confidence interval corresponding to alpha
library(dpasurv) data(simdata) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) # Calculate cumulative direct effect (which calculates a CI with alpha = 0.05 by default): direct <- effect(x ~ outcome, s) # update confidence interval for a new alpha (this overwrites the 0.05 CI already calculated above) direct <- add.ci(direct, alpha=0.10)
library(dpasurv) data(simdata) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) # Calculate cumulative direct effect (which calculates a CI with alpha = 0.05 by default): direct <- effect(x ~ outcome, s) # update confidence interval for a new alpha (this overwrites the 0.05 CI already calculated above) direct <- add.ci(direct, alpha=0.10)
Dynamic Path Analysis
dpa( out.formula, mediator.formulas, id, data, boot.n = 200, method = "timereg", progress_bar = FALSE, ... )
dpa( out.formula, mediator.formulas, id, data, boot.n = 200, method = "timereg", progress_bar = FALSE, ... )
out.formula |
Survival formula for Aalen's additive hazards model. |
mediator.formulas |
Mediator regression formula (in case of a single mediator), or a list of regression formulas (in case of multiple mediators). The formulas must be ordered according to Directed Acyclic Graph Structure (see Details). |
id |
character string indicating which column of 'data' corresponds to the subject ID. Bootstrapping will be performed on this id. |
data |
Data set in counting process format. In particular the data should contain a "start", "stop" and "event" column along with any mediators and baseline covariates. |
boot.n |
Number of bootstrap samples. |
method |
The underlying implementation of Aalen's additive regression model. Defaults to "timereg", which relies on the timereg::aalen() implementation, while method = "aareg" uses the survival::aareg() implementation. |
progress_bar |
Boolean. If TRUE, show progress bar. Defaults to FALSE. |
... |
other parameters passed to the Aalen's additive hazards model implementation. If method = "timereg", then ... will be passed to timereg::aalen(), while if method = "aareg", then ... will be passed to survival::aareg(). If ... contains parameters that don't belong to the formalArgs of the corresponding implementation then those parameters will be ignored. |
dpa
performs Dynamic Path Analysis of a Directed Acyclic Graph (DAG). The out.formula
can have as covariates all mediators listed in mediator.formulas. The mediator.formulas must obey the
following DAG structure rule: The response of the k-th formula cannot appear as covariate in any of the formulas
k+1, ..., length(mediator.formulas).
Object of class 'dpa' with following fields:
list of estimated coefficients from each of the regressions listed in out.formula and mediator.formulas.
list of bootstrap estimates corresponding to coefs. This stores all the bootstrap estimates to facilitate calculation of direct, indirect and total effects along with bootstrap confidence intervals.
a list keeping track of responses and covariates of each of the out.formula and mediator.formulas. Also keeps track of all variable types and level names in case of factors.
Object storing information pertaining to the Aalen's additive model fit. Object is of class "aalen" if method="timereg", and of class "aareg" if method="aareg".
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) # Calculate cumulative direct, indirect, and total effects: direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) # Plot the effects using basic graphics: layout1x3 <- par(mfrow=c(1,3)) plot(direct); abline(h=0, lty=2, col=2) plot(indirect); abline(h=0, lty=2, col=2) plot(total); abline(h=0, lty=2, col=2) # restore user's graphical parameters: par(layout1x3) # Plot the effects using ggplot2 graphics: ggplot.effect(list(direct, indirect, total))
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) # Calculate cumulative direct, indirect, and total effects: direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) # Plot the effects using basic graphics: layout1x3 <- par(mfrow=c(1,3)) plot(direct); abline(h=0, lty=2, col=2) plot(indirect); abline(h=0, lty=2, col=2) plot(total); abline(h=0, lty=2, col=2) # restore user's graphical parameters: par(layout1x3) # Plot the effects using ggplot2 graphics: ggplot.effect(list(direct, indirect, total))
effect estimation method for class "dpa"
effect(formula, object, alpha = 0.05)
effect(formula, object, alpha = 0.05)
formula |
the formula for the direct or indirect effect to be estimated. Should be of the form: covariate ~ outcome for direct effect of covariate on outcome, while it should be of the form: covariate ~ mediator ~ outcome for indirect effect of covariate on outcome mediated through mediator. Note that the word "outcome" is reserved for the survival outcome process, but the word "covariate" and "mediator" should match a corresponding variable name in the data input. Alternatively the form can be: covariate ~ mediator for direct effects of covariate on mediator, or: covariate ~ mediator1 ~ mediator2 for indirect effects of covariate on mediator2 mediated through mediator1. |
object |
object of class "dpa" (as obtained by calling the function |
alpha |
The confidence level of the bootstrap intervals |
object of class "effect" with following fields:
data.frame containing the unique event times along with the calculated effect coefficients. For effects corresponding to a continuous variable this results in a single effect column. For factors with n.levels categories the data.frame contains n.levels-1 effect columns each representing the effect coefficient of a particular factor level (as compared to reference level).
data.frame of same dimension as coefs containing the lower confidence bands of the effects stored in coefs
data.frame of same dimension as coefs containing the upper confidence bands of the effects stored in coefs
data.frame with three columns: one column of bootstrap sample ID, a second column of unique event times (per bootstrap sample), and a third column of the estimated effect coefficients (per bootstrap sample). The storing of the effects per bootstrap sample facilitates calculation of bootstrap confidence intervals for sums of indirect and direct effects.
effect label with path specification: "direct" for direct effect and "indirect" for indirect effect mediated through a path of mediator(s)
scale of effect coefficients in coefs, lower, upper: "cumulative" (for effects on outcome) or "identity" (for effects on mediators)
confidence level of the bootstrap intervals
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect)
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect)
plotting method for class "effect"
ggplot.effect( object, relative = FALSE, titles = NULL, x_label = "Time", y_label = NULL )
ggplot.effect( object, relative = FALSE, titles = NULL, x_label = "Time", y_label = NULL )
object |
object of class "effect", or list of objects of class "effect" |
relative |
should the effect be plotted on a relative survival scale (i.e. 'y=exp(-effect)')?. Defaults to FALSE. |
titles |
If NULL, function will automatically generate. Otherwise character vector of length equal to number of elements in object list |
x_label |
Label for x-axis. Defaults to "Time" |
y_label |
Label for y-axis. Default when object scale is "cumulative" will be "Cumulative Effect" (relative=FALSE) and "Relative survival" (relative=TRUE). If object scale is "identity" then the default y_label will be "Effect". |
ggplot object
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) ggplot.effect(direct) ggplot.effect(list(direct, indirect, total))
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) ggplot.effect(direct) ggplot.effect(list(direct, indirect, total))
plotting method for class "effect"
## S3 method for class 'effect' plot(x, relative = FALSE, ...)
## S3 method for class 'effect' plot(x, relative = FALSE, ...)
x |
object of class "effect" |
relative |
should the effect be plotted on a relative survival scale (i.e. 'y=exp(-effect)')?. Defaults to FALSE. |
... |
other graphical parameters passed to the graphics::plot function. |
this function does not return anything, but simply plots the associated effect encoded in the object x
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) par(mfrow=c(1,3)) layout1x3 <- par(mfrow=c(1,3)) plot(direct); abline(h=0, lty=2, col=2) plot(indirect); abline(h=0, lty=2, col=2) plot(total); abline(h=0, lty=2, col=2) # restore user's graphical parameters: par(layout1x3)
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect) par(mfrow=c(1,3)) layout1x3 <- par(mfrow=c(1,3)) plot(direct); abline(h=0, lty=2, col=2) plot(indirect); abline(h=0, lty=2, col=2) plot(total); abline(h=0, lty=2, col=2) # restore user's graphical parameters: par(layout1x3)
This is a simulated data set in the (start,stop] format. The subject column refers to subject ID and note that there are multiple rows per subject. The columns x and dose correspond to a treatment and dose variable respectively, while M refers to the longitudinal mediator values. The triplet (start, stop, event) corresponds to the time-to-event data in the required (start,stop] format.
A data frame with the following variables: subject
(fct), x
(dbl),
dose
(fct), M
(dbl), start
(dbl), stop
(dbl), event
(dbl).
a sum method for class "effect"
## S3 method for class 'effect' sum(effect1, effect2, ...)
## S3 method for class 'effect' sum(effect1, effect2, ...)
effect1 |
an object of class "effect" obtained from a call to the function effect() |
effect2 |
a second object of class "effect" obtained from a call to the function effect() |
... |
additional objects of class "effect" (any number of effects allowed) |
an object of class "effect" containing the sum of effect1, effect2, ...
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect)
library(dpasurv) data(simdata) set.seed(1) # Perform dynamic path analysis: # We set boot.n=30 for the example to run fast, should be set large enough # so that results don't change meaningfully for different seeds. s <- dpa(Surv(start,stop,event)~M+x, list(M~x), id="subject", data=simdata, boot.n=30) direct <- effect(x ~ outcome, s) indirect <- effect(x ~ M ~ outcome, s) total <- sum(direct, indirect)