Description Usage Arguments Details Value References See Also Examples
Plot method for objects returned by the fitSmoothHazard
function. Current plot types are hazard function and hazard ratio. The
visreg
package must be installed for type="hazard"
. This
function accounts for the possible timevarying exposure effects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  plotHazardRatio(x, newdata, newdata2, ci, ci.lvl, ci.col, rug, xvar, ...)
## S3 method for class 'singleEventCB'
plot(
x,
...,
type = c("hazard", "hr"),
hazard.params = list(),
newdata,
exposed,
increment = 1,
var,
xvar = NULL,
ci = FALSE,
ci.lvl = 0.95,
rug = !ci,
ci.col = "grey"
)
incrVar(var, increment = 1)

x 
Fitted object of class 
newdata 
Required for 
newdata2 

ci 
Logical; if TRUE confidence bands are calculated. Only available
for 
ci.lvl 
Confidence level. Must be in (0,1), Default: 0.95. Only used
for 
ci.col 
Confidence band color. Only used if argument 
rug 
Logical. Adds a rug representation (1d plot) of the event times
(only for 
xvar 
Variable to be used on xaxis for hazard ratio plots. If NULL,
the function defaults to using the time variable used in the call to

... 
further arguments passed to 
type 
plot type. Choose one of either 
hazard.params 
Named list of arguments which will override the defaults
passed to 
exposed 
function that takes 
increment 
Numeric value indicating how much to increment (if positive)
or decrement (if negative) the 
var 
specify the variable name for the exposed/unexposed (name is given
as a character variable). If this argument is missing, then the

This function has only been thoroughly tested for family="glm"
. If
the user wants more customized plot aesthetics, we recommend saving the
results to a data.frame
and using the graphical package of their choice.
a plot of the hazard function or hazard ratio. For type="hazard"
, a
data.frame
(returned invisibly) of the original data used in the fitting
along with the data used to create the plots including predictedhazard
which is the predicted hazard for a given covariate pattern and time.
predictedloghazard
is the predicted hazard on the log scale. lowerbound
and upperbound
are the lower and upper confidence interval bounds on the
hazard scale (i.e. used to plot the confidence bands). standarderror
is
the standard error of the log hazard or log hazard ratio (only if
family="glm"
or family="gam"
). For type="hr"
, log_hazard_ratio
and
hazard_ratio
is returned, and if ci=TRUE
, standarderror
(on the log
scale) and lowerbound
and upperbound
of the hazard_ratio
are
returned.
Mark Clements and XingRong Liu (2019). rstpm2: Smooth Survival Models, Including Generalized Survival Models. R package version 1.5.1. https://CRAN.Rproject.org/package=rstpm2
Breheny P and Burchett W (2017). Visualization of Regression Models Using visreg. The R Journal, 9: 5671.
modifyList
, fitSmoothHazard()
,
graphics::par()
, visreg::visreg()
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 52 53 54 55 56 57 58 59 60  if (requireNamespace("splines", quietly = TRUE)) {
data("simdat") # from casebase package
library(splines)
simdat < transform(simdat[sample(1:nrow(simdat), size = 200),],
treat = factor(trt, levels = 0:1,
labels = c("control","treatment")))
fit_numeric_exposure < fitSmoothHazard(status ~ trt*bs(eventtime),
data = simdat,
ratio = 1,
time = "eventtime")
fit_factor_exposure < fitSmoothHazard(status ~ treat*bs(eventtime),
data = simdat,
ratio = 1,
time = "eventtime")
newtime < quantile(fit_factor_exposure[["data"]][[fit_factor_exposure[["timeVar"]]]],
probs = seq(0.05, 0.95, 0.01))
par(mfrow = c(1,3))
plot(fit_numeric_exposure,
type = "hr",
newdata = data.frame(trt = 0, eventtime = newtime),
exposed = function(data) transform(data, trt = 1),
xvar = "eventtime",
ci = TRUE)
#by default this will increment `var` by 1 for exposed category
plot(fit_factor_exposure,
type = "hr",
newdata = data.frame(treat = factor("control",
levels = c("control","treatment")), eventtime = newtime),
var = "treat",
increment = 1,
xvar = "eventtime",
ci = TRUE,
ci.col = "lightblue",
xlab = "Time",
main = "Hazard Ratio for Treatment",
ylab = "Hazard Ratio",
lty = 5,
lwd = 7,
rug = TRUE)
# we can also decrement `var` by 1 to give hazard ratio for control/treatment
result < plot(fit_factor_exposure,
type = "hr",
newdata = data.frame(treat = factor("treatment",
levels = c("control","treatment")),
eventtime = newtime),
var = "treat",
increment = 1,
xvar = "eventtime",
ci = TRUE)
# see data used to create plot
head(result)
}

See example usage at http://sahirbhatnagar.com/casebase/
treat eventtime log_hazard_ratio standarderror hazard_ratio lowerbound
5% treatment 0.3825026 0.6626061 0.8043167 1.939841 0.4009873
6% treatment 0.4727133 0.7433444 0.7072016 2.102957 0.5258468
7% treatment 0.5045757 0.7698346 0.6776235 2.159409 0.5721907
8% treatment 0.5443924 0.8014859 0.6441048 2.228850 0.6306928
9% treatment 0.5930949 0.8380467 0.6082374 2.311847 0.7018212
10% treatment 0.6096525 0.8499452 0.5973059 2.339519 0.7256026
upperbound
5% 9.384297
6% 8.410106
7% 8.149464
8% 7.876692
9% 7.615381
10% 7.543175
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.