simGG.simtvc: Plot simulated time-interactive hazard ratios or stratified...

Description Usage Arguments Details Value References Examples

View source: R/simGG.simtvc.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## S3 method for class 'simtvc'
simGG(
  obj,
  from = NULL,
  to = NULL,
  xlab = NULL,
  ylab = NULL,
  title = NULL,
  method = "auto",
  spalette = "Set1",
  legend = "legend",
  leg.name = "",
  lsize = 1,
  psize = 1,
  alpha = 0.2,
  type = "ribbons",
  ...
)

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.

method

what type of smoothing method to use to summarize the center of the simulation distribution.

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

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

numeric. Alpha (e.g. transparency) for the points, lines, or ribbons. Default is alpha = 0.2. See ggplot2. Note, if type = "lines" or type = "points" then alpah sets the maximum value per line or point at the center of the distribution. Lines or points further from the center are more transparent the further they get from the middle.

type

character string. Specifies how to plot the simulations. Can be points, lines, or ribbons. If points then each simulation value will be plotted. If lines is chosen then each simulation is plotted using a different line. Note: any simulation with a value along its length that is outside of the specified central interval will be dropped. This is to create a smooth plot. If type = "ribbons" a plot will be created with shaded areas ('ribbons') for the minimum and maximum simulation values (i.e. the middle interval set with qi in coxsimSpline) as well as the central 50 percent of this area. It also plots a line for the median value of the full area, so values in method are ignored. One of the key advantages of using ribbons rather than points is that it creates plots with smaller file sizes.

...

Additional arguments. (Currently ignored.)

Details

Plots either a time-interactive hazard ratios, first differences, and relative hazards, 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.

Value

a gg ggplot class object

References

Gandrud, Christopher. 2015. simPH: An R Package for Illustrating Estimates from Cox Proportional Hazard Models Including for Interactive and Nonlinear Effects. Journal of Statistical Software. 65(3)1-20.

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

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

# Load survival package
library(survival)

# Expand data
GolubEUPData <- SurvExpand(GolubEUPData, GroupVar = 'caseno',
                     Time = 'begin', Time2 = 'end', event = 'event')

# Create time interactions
BaseVars <- c('qmv', 'backlog', 'coop', 'codec', 'qmvpostsea', 'thatcher')
GolubEUPData <- tvc(GolubEUPData, b = BaseVars, tvar = 'end', tfun = 'log')

# Run Cox PH Model
M1 <- coxph(Surv(begin, end, event) ~ qmv + qmvpostsea + qmvpostteu +
                coop + codec + eu9 + eu10 + eu12 + eu15 + thatcher +
                agenda + backlog + qmv_log + qmvpostsea_log + coop_log +
                codec_log + thatcher_log + backlog_log,
            data = GolubEUPData, ties = "efron")

# Create simtvc object for Relative Hazard
Sim1 <- coxsimtvc(obj = M1, b = "qmv", btvc = "qmv_log",
                   tfun = "log", from = 80, to = 2000,
                   Xj = 1, by = 15, ci = 0.99, nsim = 100)

# Create plot
simGG(Sim1, legend = FALSE)

# Create simtvc object for First Difference
Sim2 <- coxsimtvc(obj = M1, b = "qmv", btvc = "qmv_log",
                 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 = "backlog_log",
                  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(Sim2, type = 'points')
simGG(Sim3, leg.name = "Comparision", from = 1200, type = 'lines')

## End(Not run)

simPH documentation built on Jan. 13, 2021, 6:52 a.m.