last.event: last.event

last.eventR Documentation

last.event

Description

Calculates the time to the last occurrence of specified binary events for each subject in a panel data structure. This is particularly useful for understanding the timing of the last event in longitudinal analyses.

Usage

last.event(
  dat,
  id.name,
  outcome.names,
  t1.name,
  append.to.table = FALSE,
  event.name = "last.event"
)

Arguments

dat

A data frame structured as panel data.

id.name

The character name of the identifying variable within dat, used to track subjects across multiple rows of data.

outcome.names

A character vector of variable names from dat, expected to be binary, indicating the events of interest. The function determines the last time each outcome becomes true (1) for each unique id.

t1.name

The character name of the time variable within dat representing the start (left endpoint) of observation intervals.

append.to.table

A logical indicating whether to append the calculated last event times as new columns to the original data frame (TRUE) or return them as a separate data frame (FALSE).

event.name

The name to give the event time columns when they are appended to the data, specifically for the last event times.

Value

If append.to.table is FALSE, the function returns a data table with the calculated times to the last event for each subject and specified outcome, keyed by the id.name. Each outcome will have its own column named according to the event.name parameter, appended with the outcome name (e.g., "outcome.last.event" for last event times). If append.to.table is TRUE, the original data table is returned with these new columns appended. This enables detailed analysis on the timing of last events relative to the subjects' overall observation periods within the panel data.


tvtools documentation built on Oct. 8, 2024, 5:09 p.m.