make_cuminc_df: Calculate data frame of cumulative incidence.

View source: R/make_cuminc_df.R

make_cuminc_dfR Documentation

Calculate data frame of cumulative incidence.

Description

Allows for easy grouping by catogories to get survival data from a Kaplan Meier object as well as the cumulative incidence. TODO – Confidence interval for cumulative incidence.

Usage

make_cuminc_df(data, time, event, ..., type = "right", extend = FALSE)

Arguments

data

A data frame or tibble

time

Vector of integer event times. For right censored data, this is the follow up time. For interval data, the first argument is the starting time for the interval.

event

The status indicator, normally 0=alive, 1=dead. Other choices are TRUE/FALSE (TRUE = death) or 1/2 (2=death). For interval censored data, the status indicator is 0=right censored, 1=event at time, 2=left censored, 3=interval censored. For multiple enpoint data the event variable will be a factor, whose first level is treated as censoring. Although unusual, the event indicator can be omitted, in which case all subjects are assumed to have an event.

...

Unquoted names of variables to group by. Prefer factor or character classes.

type

character string specifying the type of censoring. Possible values are "right", "left", "counting", "interval", "interval2" or "mstate".

extend

logical value: if TRUE, prints information for all specified times, even if there are no subjects left at the end of the specified times. This is only valid if the times argument is present.

Value

A tibble

Examples

library(dplyr)
library(survival)

#### Data for example --------------------------------
# View the preloaded data
dplyr::glimpse(aml)

## Create a variable for smoke ----------------
df <- aml %>%
  mutate(smoke = sample(c("Yes", "No"), size = 23, replace = TRUE)) %>%
  tibble::as_tibble()
df

#### Example #1 --------------------------------

make_cuminc_df(data = df,
               time = time,
               event = status,
               smoke)

#### Example #2 --------------------------------

make_cuminc_df(data = df,
               time = time,
               event = status,
               x, smoke)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.