plot.pcoxsurvfit: Plot survival and cumulative hazard curves

View source: R/pcoxtimeplots.R

plot.pcoxsurvfitR Documentation

Plot survival and cumulative hazard curves

Description

Plot estimated survival and cumulative hazard curves for pcoxtime model.

Usage

## S3 method for class 'pcoxsurvfit'
plot(
  x,
  ...,
  type = c("surv", "cumhaz"),
  lsize = 0.3,
  lcol = "black",
  compare = FALSE
)

Arguments

x

a pcoxsurvfit.pcoxtime or pcoxbasehaz.pcoxtime object.

...

for future implementations

type

type of curve to generate. Either type = "surv" for survival curves or type = "cumhaz" for cumulative hazard curve.

lsize

line size for the curves.

lcol

colour for the curves.

compare

logical. Whether to return plot with labels to add additional geom object for comparison. Default is FALSE.

Details

Depending on the specification in pcoxsurvfit.pcoxtime, this function plots either average or individual survival or cumulative hazard curves. The plot is a ggplot object, hence can be be customized further, see example below.

Value

a ggplot object.

Examples


library(ggplot2)
data(heart, package="survival")
lam <- 0.02
alp <- 1
pfit <- pcoxtime(Surv(start, stop, event) ~ age + year + surgery + transplant
	, data = heart
	, lambda = lam
	, alpha = alp
)

# Plot survival curves
psurv <- pcoxsurvfit(pfit)
plot(psurv)

# Baseline survival curve
bsurv <- pcoxbasehaz(pfit, centered = FALSE)
plot(bsurv)

# Compare overall and baseline cumulative hazard
p1 <- plot(psurv, type = "cumhaz", compare = TRUE)
df2 <- data.frame(time = bsurv$time, cumhaz = bsurv$hazard)
p2 <- (p1
	+ geom_step(data = df2, aes(x = time, y = cumhaz, group = 1, col = "baseline"))
	+ scale_colour_manual(name = "C. hazard"
		, values = c("#E41A1C", "#000000")
		, labels = c("baseline", "overall")
	)
)
print(p2)


pcoxtime documentation built on May 13, 2022, 1:05 a.m.