50% off | Unlimited Data & AI Learning

Last chance! 50% off unlimited learning

Sale ends in


pcoxtime (version 1.0.4)

plot.pcoxsurvfit: Plot survival and cumulative hazard curves

Description

Plot estimated survival and cumulative hazard curves for pcoxtime model.

Usage

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

Arguments

...

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.

Value

a ggplot object.

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.

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab