plot.glmnetsurvfit: Plot survival and cumulative hazard curves

View source: R/postsurvplots.R

plot.glmnetsurvfitR Documentation

Plot survival and cumulative hazard curves

Description

Plot estimated survival and cumulative hazard curves for glmnet model. glmnetsurvfit.glmnetsurv

Usage

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

Arguments

x

a glmnetsurvfit.glmnetsurv or glmnetbasehaz.glmnetsurv 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. Default is 0.3.

compare

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

Details

Depending on the specification in glmnetsurvfit.glmnetsurv, 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(veteran, package="survival")

gmodel <- glmnetsurv(Surv(time, status) ~ factor(trt) + karno + diagtime + age + prior
	, data = veteran
	, lambda = 0
	, alpha = 1
)

# Survival estimate
gsurv <- glmnetsurvfit(fit = gmodel)

# Plot survival curves
plot(gsurv)

# Baseline survival estimate
gbsurv <- glmnetbasehaz(gmodel, centered = FALSE)
plot(gbsurv)

# Compare overall and baseline cumulative hazard
p1 <- plot(gsurv, type = "cumhaz", compare = TRUE)
df2 <- data.frame(time = gbsurv$time, cumhaz = gbsurv$hazard)
p2 <- (p1
	+ geom_line(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)


CYGUBICKO/glmnetpostsurv documentation built on Sept. 1, 2022, 7:26 p.m.