Mediation analysis in survival context with robust standard errors taking the weights into account via influence function computations. Mediator and exposure must be factors. This is based on numerical derivative wrt parameters for weighting. See vignette for more examples.
mediatorSurv(
survmodel,
weightmodel,
data = data,
wdata = wdata,
id = "id",
silent = TRUE,
...
)
n <- 400
dat <- kumarsimRCT(n,rho1=0.5,rho2=0.5,rct=2,censpar=c(0,0,0,0),
beta = c(-0.67, 0.59, 0.55, 0.25, 0.98, 0.18, 0.45, 0.31),
treatmodel = c(-0.18, 0.56, 0.56, 0.54),restrict=1)
dfactor(dat) <- dnr.f~dnr
dfactor(dat) <- gp.f~gp
drename(dat) <- ttt24~"ttt24*"
dat$id <- 1:n
dat$ftime <- 1
weightmodel <- fit <- glm(gp.f~dnr.f+preauto+ttt24,data=dat,family=binomial)
wdata <- medweight(fit,data=dat)
### fitting models with and without mediator
aaMss2 <- binreg(Event(time,status)~gp+dnr+preauto+ttt24+cluster(id),data=dat,time=50,cause=2)
aaMss22 <- binreg(Event(time,status)~dnr+preauto+ttt24+cluster(id),data=dat,time=50,cause=2)
### estimating direct and indirect effects (under strong strong assumptions)
aaMss <- binreg(Event(time,status)~dnr.f0+dnr.f1+preauto+ttt24+cluster(id),
data=wdata,time=50,weights=wdata$weights,cause=2)
## to compute standard errors , requires numDeriv
library(numDeriv)
ll <- mediatorSurv(aaMss,fit,data=dat,wdata=wdata)
summary(ll)
#>
#> n events
#> 800 400
#>
#> 400 clusters
#> coeffients:
#> Estimate Std.Err 2.5% 97.5% P-value
#> (Intercept) -0.141487 0.164071 -0.463060 0.180087 0.3885
#> dnr.f01 0.253519 0.238565 -0.214060 0.721099 0.2879
#> dnr.f11 0.166607 0.068447 0.032454 0.300760 0.0149
#> preauto 0.131145 0.228703 -0.317105 0.579396 0.5664
#> ttt24 0.296646 0.245869 -0.185248 0.778541 0.2276
#>
#> exp(coeffients):
#> Estimate 2.5% 97.5%
#> (Intercept) 0.86807 0.62935 1.1973
#> dnr.f01 1.28855 0.80730 2.0567
#> dnr.f11 1.18129 1.03299 1.3509
#> preauto 1.14013 0.72825 1.7850
#> ttt24 1.34534 0.83090 2.1783
#>
#>
## not run bootstrap (to save time)
## bll <- BootmediatorSurv(aaMss,fit,data=dat,k.boot=500)