coxsimtvc: Simulate time-varying hazards from coxph fitted model objects

Description Usage Arguments Details Value References See Also Examples

Description

coxsimtvc simulates time-varying hazards from coxph fitted model objects using the normal distribution.

Usage

1
2
3
  coxsimtvc(obj, b, btvc, qi = "Relative Hazard", Xj = 1,
    Xl = 0, tfun = "linear", pow = NULL, nsim = 1000, from,
    to, by, ci = "95", strata = FALSE)

Arguments

obj

a coxph fitted model object with a time interaction.

b

the non-time interacted variable's name.

btvc

the time interacted variable's name.

qi

character string indicating what quantity of interest you would like to calculate. Can be 'Relative Hazard', 'First Difference', or 'Hazard Ratio'. Default is qi = 'Relative Hazard'. If qi = 'First Difference' or qi = 'Hazard Ratio' then you can set Xj and Xl. If qi = 'First Difference' then strata must be FALSE.

Xj

numeric vector of fitted values for Xj. Must be the same length as Xl. Default is Xj = 1 Only applies if qi = 'First Difference' or qi = 'Hazard Ratio'.

Xl

numeric vector of fitted values for Xl. Must be the same length as Xj. Default is Xl = 0. Only applies if qi = 'First Difference' or qi = 'Hazard Ratio'.

nsim

the number of simulations to run per point in time. Default is nsim = 1000.

tfun

function of time that btvc was multiplied by. Default is "linear". Can also be "log" (natural log) and "power". If tfun = "power" then the pow argument needs to be specified also.

pow

if tfun = "power", then use pow to specify what power the time interaction was raised to.

from

point in time from when to begin simulating coefficient values

to

point in time to stop simulating coefficient values

by

time intervals by which to simulate coefficient values

ci

the proportion of middle simulations to keep. The default is ci = "95", i.e. keep the middle 95 percent. Other possibilities include: "90", "99", "all".

strata

logical for whether or not the coxph model used stratification and you would like to simulate the hazard rates for each strata

Details

Simulates time-varying relative hazards, first differences, and hazard ratios using parameter estimates from coxph models. Can also simulate hazard rates for multiple strata.

Relative hazards are found using:

RH = e^{β_{1} + β_{2}f(t)}

where f(t) is the function of time.

First differences are found using:

FD = (e^{(X_{j} - X_{l}) (β_{1} + β_{2}f(t))} - 1) * 100

where X_{j} and X_{l} are some values of X to contrast.

Hazard ratios are calculated using:

FD = e^{(X_{j} - X_{l}) (β_{1} + β_{2}f(t))}

When simulating non-stratifed time-varying harzards coxsimtvc uses the point estimates for a given coefficient \hat{β}_{x} and its time interaction \hat{β}_{xt} along with the variance matrix (\hat{V}(\hat{β})) estimated from a coxph model. These are used to draw values of β_{x} and β_{xt} from the multivariate normal distribution N(\hat{β},\: \hat{V}(\hat{beta})).

When simulating stratified time-varying hazard rates H for a given strata k, coxsimtvc uses:

H_{kx} = \hat{β_{k0}}\exp{\hat{β_{x}} + β_{xt}(t)}

The resulting simulation values can be plotted using ggtvc.

Value

a simtvc object

References

Licht, Amanda A. 2011. “Change Comes with Time: Substantive Interpretation of Nonproportional Hazards in Event History Analysis.” Political Analysis 19: 227–43.

King, Gary, Michael Tomz, and Jason Wittenberg. 2000. “Making the Most of Statistical Analyses: Improving Interpretation and Presentation.” American Journal of Political Science 44(2): 347–61.

See Also

ggtvc, rmultinorm, survival, strata, and coxph

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
# Load Golub & Steunenberg (2007) Data
data("GolubEUPData")

# Load survival package
library(survival)

# Create natural log time interactions
Golubtvc <- function(x){
  assign(paste0("l", x), tvc(GolubEUPData, b = x, tvar = "end", tfun = "log"))
}

GolubEUPData$Lcoop <-Golubtvc("coop")
GolubEUPData$Lqmv <- Golubtvc("qmv")
GolubEUPData$Lbacklog <- Golubtvc("backlog")
GolubEUPData$Lcodec <- Golubtvc("codec")
GolubEUPData$Lqmvpostsea <- Golubtvc("qmvpostsea")
GolubEUPData$Lthatcher <- Golubtvc("thatcher")

# Run Cox PH Model
M1 <- coxph(Surv(begin, end, event) ~
            qmv + qmvpostsea + qmvpostteu +
            coop + codec + eu9 + eu10 + eu12 +
            eu15 + thatcher + agenda + backlog +
            Lqmv + Lqmvpostsea + Lcoop + Lcodec +
            Lthatcher + Lbacklog,
         data = GolubEUPData,
         ties = "efron")

# Create simtvc object for Relative Hazard
Sim1 <- coxsimtvc(obj = M1, b = "qmv", btvc = "Lqmv",
                   tfun = "log", from = 80, to = 2000,
                   by = 15, ci = "99")

# Create simtvc object for First Difference
Sim2 <- coxsimtvc(obj = M1, b = "backlog", btvc = "Lbacklog",
                  qi = "First Difference",
                  tfun = "log", from = 80, to = 2000,
                  by = 15, ci = "99")

# Create simtvc object for Hazard Ratio
Sim3 <- coxsimtvc(obj = M1, b = "backlog", btvc = "Lbacklog",
                  qi = "Hazard Ratio", Xj = c(191, 229),
                  Xl = c(0, 0),
                  tfun = "log", from = 80, to = 2000,
                  by = 15, ci = "99")

christophergandrud/simtvc documentation built on May 13, 2019, 7:03 p.m.