makeContWeights: Continuous time weight estimation based on 'aalen.predict'

Description Usage Arguments Value Author(s) References Examples

View source: R/makeContWeights.R

Description

Refines data longitudinally in order to do estimate parameters(e.g. Nelson-Aalen or Kaplan-Meier) using continuous time weights. The weights can be assessed using the plot option.

Usage

1
2
3
function (faFit, cfaFit, dataFr, atRiskState, eventState, stopTimeName, 
    startStatusName, endStatusName, idName, b, weightRange = c(0, 10),
    willPlotWeights = T) 

Arguments

faFit

The aalen fit for the factual hazard,

cfaFit

The aalen fit for the hypothetical hazard,

dataFr

data.frame or data.table on long format,

atRiskState

At risk state for the event of interest,

eventState

State for the event of interest,

stopTimeName

Name of column with stop time of the at risk period,

startStatusName

Name of the column that contains the starting state for each interval,

endStatusName

Name of the column that contains the end state for each interval,

idName

Name of column in dataFr that identifies individuals,

b

Smoothing bandwidth parameter,

weightRange

Truncates weights outside this interval,

willPlotWeights

Plot indicator,

Value

Longitudinally refined data.table of the initial dataFr with weights column added.

Author(s)

Pål Christie Ryalen <p.c.ryalen@medisin.uio.no>

References

https://arxiv.org/abs/1802.01946

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
data(fr1)
data(Tmat)

# fr1 is a longitudinal data set with subjects that are diagnosed at time 0, and may
# be treated as time evolves. Subjects can die before receiving treatment:
head(fr1)

# The method assumes there are no tied event times in the observed data. Although there are no
# tied event times in fr1, we use the function addNoiseAtEventTimes() for illustration here
fr1 <- as.data.table(fr1)
fr1 <- addNoiseAtEventTimes(fr1)

# Time to treatment and death are confounded by the baseline variable L. We want to
# mimic a scenario where time to treatment is randomized (and does not depend on L):
fFit <- aalen(Surv(from,to,to.state =="treat")~1 + L,data=fr1[fr1$from.state == "diag",])
cfFit <- aalen(Surv(from,to,to.state =="treat")~1,data=fr1[fr1$from.state == "diag",])

# We calculate and plot the weights
frame1 <- makeContWeights(fFit, cfFit, fr1, "diag", "treat", "from", "to",
                         "from.state", "to.state", "id", b = 0.4,
                         weightRange = c(0,5)) 

# We fit a weighted model for the outcome. A is a treatment indicator (A=1 means treated).
a1 <- aalen(Surv(from,to,to.state =="death") ~ 1 + A,data=frame1,weights = frame1$weights)

# We plot the A coefficient from the weighted regression,
# and compare with the true hypothetical coefficient
plot(a1$cum[,c(1,3)],type="s",ylim=c(-1.2,0.5),xlim=c(0,5),
main="Weighted additive hazard treatment coefficient")
lines(Tmat,col=2)
legend("bottomleft",c("weighted estimate","hypothetical treatment coef")
,lty=1,col=c(1,2),bty="n")



data(fFrame)

# Next we consider an example with dependent censoring.
# Subjects are censored depending on a baseline variable u. We wish to mimic the
# cumulative hazard for death we would have seen if the censoring were independent.

faFit <- aalen(Surv(from,to,to.state=="Censored") ~ 1 + u, data = fFrame)
cfaFit <- aalen(Surv(from,to,to.state=="Censored") ~ 1, data = fFrame)

frame <- makeContWeights(faFit,cfaFit,fFrame,"Alive","Censored","from","to","from.state",
"to.state","id",100)

fMod <- aalen(Surv(from,to,to.state=="Dead")~1,data=fFrame)
wMod <- aalen(Surv(from,to,to.state=="Dead")~1,data=frame,weights = frame$weights)

plot(fMod$cum,type="s",main="Nelson-Aalen for death",ylab="")
lines(wMod$cum,type="s",col="red")
legend("topleft",c("factual","weighted factual"),lty=1,col=c(1,"red"),bty="n")

palryalen/ahw documentation built on Sept. 29, 2021, 6:20 p.m.