simPH (version 0.8.4)

simGG.simtvc: Plot simulated time-varying hazard ratios or stratified time-varying hazard rates from Cox Proportional Hazards Models

Description

simGG.simtvc uses ggplot2 to plot the simulated hazards from a simtvc class object created by coxsimtvc using ggplot2.

Usage

## S3 method for class 'simtvc':
simGG(obj, from = NULL, to = NULL,
    xlab = NULL, ylab = NULL, title = NULL,
    smoother = "auto", spalette = "Set1",
    legend = "legend", leg.name = "", lsize = 1, psize = 1,
    alpha = 0.1, ribbons = FALSE, ...)

Arguments

obj
a simtvc class object
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.
smoother
what type of smoothing line to use to summarize the plotted coefficient.
spalette
colour palette for when there are multiple sets of comparisons to plot. Default palette is "Set1". See scale_colour_brewer.
legend
specifies what type of legend to include (if applicable). The default is legend = "legend". To hide the legend use legend = FALSE. See the discrete_scale for more deta
leg.name
name of the legend (if applicable).
lsize
size of the smoothing line. Default is 1. See ggplot2.
psize
size of the plotted simulation points. Default is psize = 1. See ggplot2.
alpha
point alpha (e.g. transparency) for the points or ribbons. Default is alpha = 0.1. See ggplot2.
ribbons
logical specifies whether or not to use summary ribbons of the simulations rather than plotting every simulation value as a point. If ribbons = TRUE a plot will be created with shaded areas ('ribbons') for the minimum and maximum simu
...
Additional arguments. (Currently ignored.)

Value

  • a gg ggplot class object

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. Note: A dotted line is created at y = 1 (0 for first difference), i.e. no effect, for time-varying hazard ratio graphs. No line is created for hazard rates.

References

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

Examples

Run this code
## dontrun
# Load Golub & Steunenberg (2007) Data
# data("GolubEUPData")

# Load survival package
# library(survival)

# Create natural log time interactions
# Golubtvc <- function(x){
# tvc(data = 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,
#                   Xj = 1, by = 15, ci = 0.99)

# Create simtvc object for First Difference
# Sim2 <- coxsimtvc(obj = M1, b = "qmv", btvc = "Lqmv",
#                 qi = "First Difference", Xj = 1,
#                 tfun = "log", from = 80, to = 2000,
#                 by = 15, ci = 0.95)

# 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 = 100, to = 2000,
#                  by = 15, ci = 0.99)

# Create plots
# simGG(Sim1, legend = FALSE)
# simGG(Sim2)
# simGG(Sim3, leg.name = "Comparision", from = 1200, ribbons = TRUE)

Run the code above in your browser using DataCamp Workspace