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

Description Usage Arguments Value Author(s) Examples

View source: R/weightPredict.R

Description

Extracts cumulative hazard estimates for each individual. Each individual receives a weight process evaluated at pre-specified time points. The weight process is estimated as a cumulative product involving estimated cumulative hazard increments, and a hazard ratio estimated using a smoothing parameter b.

Usage

1
weightPredict(fPred, cfPred, wtFrame, ids, eventTimes, eventIds, b)

Arguments

fPred, cfPred, wtFrame, ids, eventTimes, eventIds, b)

fPred

predict.aalen object of the factual fit

cfPred

predict.aalen object of the counterfactual fit

wtFrame

data.frame or data.table for the at risk individuals

ids

All individuals in the data set

eventTimes

Observed event times

eventIds

Individuals that experience the event

b

Smoothing parameter

Value

data.table

Author(s)

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

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (dataFr, atRiskState, eventTimes) 
{
    sortedEventTimes <- sort(eventTimes)
    baseTable <- as.data.table(dataFr)
    baseTable$rowNumber <- 1:nrow(baseTable)
    baseTable[, `:=`(isAtRisk, 1 * (from.state %in% atRiskState))]
    baseTable[, `:=`(numRep, 0)]
    baseTable[isAtRisk == 1, `:=`(numRep, as.numeric(sum(from <= 
        eventTimes & to > eventTimes))), by = rowNumber]
    baseTable[, `:=`(numRep, numRep + 1)]
    baseTable[, `:=`(to.state, as.character(to.state))]
    Table <- baseTable[rep(1:nrow(baseTable), times = baseTable[, 
        numRep]), ]
    Table[, `:=`(putEventTimes, 0)]
    Table[numRep > 1, `:=`(putEventTimes, c(sortedEventTimes[sortedEventTimes >= 
        from[1] & sortedEventTimes < to[1]], to[1])), by = id]
    Table[numRep == 1, `:=`(putEventTimes, to)]
    Table[, `:=`(to, putEventTimes)]
    Table[, `:=`(from, c(from[1], to[-length(to)])), by = id]
    Table[, `:=`(to.state, c(rep(0, length(to) - 1), baseTable$to.state[rowNumber[1]])), 
        by = rowNumber]
    return(Table)
  }

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