Skip to contents

Overview

The jsurvival package provides functions to help researchers carry out survival analyses and produce publication ready tables and plots. It supports several workflows ranging from simple survival summaries to multi‑arm comparisons.

This vignette gives a brief tour of the main functions with example code using the built in histopathology data set.

Example data

The package ships with a small demonstration data frame histopathology. Some of the available variables are:

  • Sex
  • Race
  • Group
  • Grade
  • SurgeryDate
  • LastFollowUpDate
  • Death
  • DeathTime
# load the included data
library(jsurvival)
data(histopathology)
head(histopathology)

Overall survival

The core function of the package is survival(), which calculates Kaplan–Meier estimates and related summaries. The minimal usage requires a data frame with the follow up time and an event indicator.

res <- survival(
  data = histopathology,
  elapsedtime = DeathTime,
  outcome = Death,
  outcomeLevel = "1",
  explanatory = Group,
  ci95 = TRUE,
  risktable = TRUE
)

# results object contains tables and plots
res$plot

Continuous predictors

For analyses with a continuous explanatory variable the survivalcont() function provides an interface that can optionally find a cut‑point for dichotomisation.

res <- survivalcont(
  data = histopathology,
  elapsedtime = DeathTime,
  outcome = Death,
  outcomeLevel = "1",
  contexpl = `Anti-X-intensity`,
  findcut = TRUE
)

Odds ratios

oddsratio() computes odds ratios for binary outcomes with optional adjustment for explanatory factors.

res <- oddsratio(
  data = histopathology,
  outcome = Mortality5yr,
  explanatory = Group
)

Single arm analyses

In situations where only a single treatment group is available, singlearm() summarises survival and provides median estimates.

res <- singlearm(
  data = histopathology,
  elapsedtime = DeathTime,
  outcome = Death,
  outcomeLevel = "1"
)

Multiple groups

The multisurvival() function extends the framework to multiple explanatory variables for a comprehensive analysis across several groups.

res <- multisurvival(
  data = histopathology,
  elapsedtime = DeathTime,
  outcome = Death,
  outcomeLevel = "1",
  explanatory = c(Group, Grade, Race)
)

Further reading

The documentation of each function contains many more options. See help(package = "jsurvival") for details and consult the package website for worked examples.