plot.pcoxsurvfit: Plot survival and cumulative hazard curves

Description Usage Arguments Details Value Examples

View source: R/pcoxtimeplots.R

Description

Plot estimated survival and cumulative hazard curves for pcoxtime model.

Usage

1
2
3
4
5
6
7
8
9
## 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

 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
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 Nov. 13, 2021, 9:07 a.m.