kmm_legend: Add legend for 'kmm'

View source: R/kmm.R

kmm_legendR Documentation

Add legend for kmm

Description

Compute metrics for two or more survfit objects, and plot results as a legend.

Usage

kmm_legend(
  list,
  times = NULL,
  metric = c("rmse", "mse", "sse", "mae", "sae"),
  plot = TRUE,
  ...
)

Arguments

list

a list of two or more survfit objects

times

a vector of times to compare curves

metric

the metric to show; default is the square root of the mean squared errors "rmse"

plot

logical; if TRUE (default), a legend is draw on the existing device; otherwise, the text is returned

...

additional arguments passed to legend or to override defaults

Examples

library('survival')
set.seed(1)
lung2 <- within(lung, {
  time <- time / 100
  
  ## generate different curves with human error
  time2 <- time + runif(nrow(lung))
  time3 <- time + runif(nrow(lung), 0, 0.25)
})

truth  <- survfit(Surv(time, status) ~ 1, lung2)
recap1 <- survfit(Surv(time2, status) ~ 1, lung2)
recap2 <- survfit(Surv(time3, status) ~ 1, lung2)

plot(truth, conf.int = FALSE)
lines(recap1, col = 2, conf.int = FALSE)
lines(recap2, col = 3, conf.int = FALSE)

l <- list(truth = truth, recap1 = recap1, recap2 = recap2)

## error using all unique times
kmm_legend(l)
## error using interpolated times 0-10 (ie, asymptotic error)
kmm_legend(l, times = seq(0, 10, length.out = 1e4), inset = c(0, 0.25))
## error of interpolated time interval 0-2
kmm_legend(l, times = seq(0, 2, length.out = 1e4), inset = c(0, 0.5))
## error of interpolated time interval 6-10
kmm_legend(l, times = seq(6, 10, length.out = 1e4), inset = c(0, 0.75))

## mean squared error
kmm_legend(l, metric = 'mse', x = 'top')
kmm_legend(l, times = seq(0, 10, length.out = 1e4),
         metric = 'mse', x = 'top', inset = c(0, 0.25))
kmm_legend(l, times = seq(0, 2, length.out = 1e4),
         metric = 'mse', x = 'top', inset = c(0, 0.5))
kmm_legend(l, times = seq(6, 10, length.out = 1e4),
         metric = 'mse', x = 'top', inset = c(0, 0.75))


raredd/kmdata documentation built on June 15, 2025, 9:33 a.m.