Description Usage Arguments Details Value References See Also Examples
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.
1 2 3 4 5 6 |
obj |
a simtvc class object |
qi |
character string indicating what quantity of
interest you would like to calculate. Can be
|
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 |
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 |
spalette |
colour palette for stratified hazard
rates. Only works if |
leg.name |
name of the stratified hazard rates
legend. Only works if |
lsize |
size of the smoothing line. Default is 2.
See |
psize |
size of the plotted simulation points.
Default is |
palpha |
point alpha (e.g. transparency). Default is
|
... |
other arguments passed to specific methods |
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.
a ggplot2 object
Licht, Amanda A. 2011. “Change Comes with Time: Substantive Interpretation of Nonproportional Hazards in Event History Analysis.” Political Analysis 19: 227–43.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.