Description Usage Arguments Details Value References See Also Examples
View source: R/simGG.siminteract.R
simGG.siminteract
uses ggplot2 to plot the quantities of
interest from siminteract
objects, including marginal effects, first
differences, hazard ratios, and hazard rates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## S3 method for class 'siminteract'
simGG(
obj,
from = NULL,
rug = TRUE,
rug_position = "identity",
to = NULL,
xlab = NULL,
ylab = NULL,
title = NULL,
method = "auto",
spalette = "Set1",
legend = "legend",
leg.name = "",
lcolour = "#2B8CBE",
lsize = 1,
pcolour = "#A6CEE3",
psize = 1,
alpha = 0.2,
type = "ribbons",
...
)
|
obj |
a |
from |
numeric time to start the plot from. Only relevant if
|
rug |
logical indicating whether or not to include a rug plot showing
the distribution of values in the sample used to estimate the |
rug_position |
character string. The position adjustment to use for
overlapping points in the rug plot. Use |
to |
numeric time to plot to. Only relevant if
|
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. |
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. Not relevant for |
legend |
specifies what type of legend to include (if applicable). The
default is |
leg.name |
name of the legend (if applicable). |
lcolour |
character string colour of the smoothing line. The default is
hexadecimal colour |
lsize |
size of the smoothing line. Default is 1. See
|
pcolour |
character string colour of the simulated points or ribbons
(when there are not multiple sets of simulations). Default is hexadecimal
colour |
psize |
size of the plotted simulation points. Default is
|
alpha |
numeric. Alpha (e.g. transparency) for the points, lines, or
ribbons. Default is |
type |
character string. Specifies how to plot the simulations. Can be
|
... |
Additional arguments. (Currently ignored.) |
Uses ggplot2 to plot the quantities of interest from
siminteract
objects, including marginal effects, first differences,
hazard ratios, and hazard rates. If there are multiple strata, the quantities
of interest will be plotted in a grid by strata.
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.
Note: if qi = "Hazard Ratio"
or qi = "First Difference"
then
you need to have choosen more than one fitted value for X1
in
coxsimInteract
.
a gg
ggplot
class object
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.
Brambor, Thomas, William Roberts Clark, and Matt Golder. 2006. ”Understanding Interaction Models: Improving Empirical Analyses.” Political Analysis 14(1): 63-82.
Keele, Luke. 2010. ”Proportionally Difficult: Testing for Nonproportional Hazards in Cox Models.” Political Analysis 18(2): 189-205.
Carpenter, Daniel P. 2002. ”Groups, the Media, Agency Waiting Costs, and FDA Drug Approval.” American Journal of Political Science 46(3): 490-505.
coxsimInteract
, simGG.simlinear
,
and ggplot2
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 | # Load Carpenter (2002) data
data("CarpenterFdaData")
# Load survival package
library(survival)
# Run basic model
M1 <- coxph(Surv(acttime, censor) ~ lethal*prevgenx,
data = CarpenterFdaData)
# Simulate Marginal Effect of lethal for multiple values of prevgenx
Sim1 <- coxsimInteract(M1, b1 = "lethal", b2 = "prevgenx",
X2 = seq(2, 115, by = 2), nsim = 100)
# Plot quantities of interest
simGG(Sim1)
simGG(Sim1, rug_position = 'jitter')
## Not run:
# Change the order of the covariates to make a more easily
# interpretable hazard ratio graph.
M2 <- coxph(Surv(acttime, censor) ~ prevgenx*lethal,
data = CarpenterFdaData)
# Simulate Hazard Ratio of lethal for multiple values of prevgenx
Sim2 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "Hazard Ratio", ci = 0.9)
# Simulate First Difference
Sim3 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "First Difference", spin = TRUE)
# Simulate Hazard Rate
Sim4 <- coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = 100, X2 = 1, qi = "Hazard Rate")
# Plot quantities of interest
simGG(Sim1, xlab = "\nprevgenx",
ylab = "Marginal Effect of lethal\n")
simGG(Sim2, type = 'ribbons', rug_position = 'jitter')
simGG(Sim3)
simGG(Sim4, to = 150, type = 'lines', legend = FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.