ggtvc: Create a plot of simulated time-varying hazard ratios or...

Description Usage Arguments Details Value References See Also Examples

Description

ggtvc uses ggplot2 to plot the simulated hazard ratios from a simtvc class object using ggplot2. Note: A dotted line is created at y = 1 (0 for first difference), i.e. no effect, for time-varying hazard ratio graphs.

Usage

1
2
3
4
5
6
  ggtvc(obj, qi = "Relative Hazard", strata = FALSE,
    from = NULL, to = NULL, xlab = NULL, ylab = NULL,
    title = NULL, xbreaks = NULL, xlabels = NULL,
    smoother = "auto", colour = "#A6CEE3",
    spalette = "Set1", leg.name = "", lsize = 2, psize = 1,
    palpha = 0.1, ...)

Arguments

obj

a simtvc class object

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'.

strata

logical whether or not you would like to plot the hazard rate for the separate strata

from

numeric time to start the plot from.

to

numeric time to plot to.

xlab

a label for the plot's x-axis.

ylab

a label of the plot's y-axis. The default uses the value of qi.

title

the plot's main title

xbreaks

breaks for x axis tick marks. These will be on the scale you used for the transformed function of time.

xlabels

labels for the x axis tick marks. These should be on the real time scale.

smoother

what type of smoothing line to use to summarize the plotted coefficient

colour

character string colour of the simulated points for relative hazards. Default is hexadecimal colour A6CEE3. Works if strata = FALSE.

spalette

colour palette for stratified hazard rates. Only works if strata = TRUE. Default palette is "Set1". See scale_colour_brewer.

leg.name

name of the stratified hazard rates legend. Only works if strata = TRUE.

lsize

size of the smoothing line. Default is 2. See ggplot2.

psize

size of the plotted simulation points. Default is psize = 1. See ggplot2.

palpha

point alpha (e.g. transparency). Default is palpha = 0.05. See ggplot2.

...

other arguments passed to specific methods

Details

Plots either a time varying hazard ratio or the hazard rates for multiple strata. Currently the strata legend labels need to be changed manually (see revalue in the plyr package) in the simtvc object with the strata component. Also, currently the x-axis tick marks and break labels must be adjusted manually for non-linear functions of time.

Value

a ggplot2 object

References

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

See Also

coxsimtvc and ggplot2

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

# Create plots
ggtvc(Sim1, qi = "Relative Hazard")
ggtvc(Sim2, qi = "First Difference")
ggtvc(Sim3, qi = "Hazard Ratio", leg.name = "Comparision", from = 1200)

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