find_at_risk: Calculate at-risk table

View source: R/find_at_risk.R

find_at_riskR Documentation

Calculate at-risk table

Description

This function calculates the number of individuals at risk and number of events at each distinct event time (and censoring time if include_cens==TRUE).

Usage

find_at_risk(formula, data, include_cens = TRUE, timefix = TRUE)

Arguments

formula

Formula object. The response (on the left of the ~ operator) must be a survival object as returned by the Surv function. The terms (on the right of the ~ operator) must include the treatment arm indicator, and additionally can include strata using the strata function.

data

Data frame containing time-to-event data.

include_cens

Boolean indicating whether to include values corresponding to censoring times

timefix

Deal with floating point issues (as in the survival package). Default is TRUE. May need to set FALSE for simulated data.

Value

Data frame

Returns a data frame with the following columns:

  • time t_j

  • number of events in each of the treatments at t_j

  • combined number of events in both treatments at event time t_j

  • number of individuals at risk in each of the treatment groups just before time t_j

  • combined number of individuals at risk in both treatment groups just before time t_j

Examples

library(nphRCT)
set.seed(1)
sim_data <- sim_events_delay(
  event_model=list(
    duration_c = 36,
    duration_e = c(6,30),
    lambda_c = log(2)/9,
    lambda_e = c(log(2)/9,log(2)/18)
  ),
  recruitment_model=list(
    rec_model="power",
    rec_period = 12,
    rec_power = 1
  ),
  n_c=5,
  n_e=5,
  max_cal_t = 36
)
#with censoring times included
find_at_risk(formula=survival::Surv(event_time,event_status)~group,
  data=sim_data,
  include_cens=TRUE)
#with censoring times excluded
find_at_risk(formula=survival::Surv(event_time,event_status)~group,
  data=sim_data,
  include_cens=FALSE)

nphRCT documentation built on June 27, 2024, 5:08 p.m.