ReshapeData {BayesSurvival}R Documentation

Reshape right censored data to be used with a piecewise exponential prior.

Description

To draw from the posterior of the piecewise exponential priors implemented in this package, it is convenient to convert the data so that two vectors are obtained: one containing the total amount of time all individuals were under follow-up during each interval, and one containing the number of events that happened during each interval. This function takes a dataframe with a column of times (the minimum of the time of the event and the time of censoring) and a column indicating the status (0 if censored, 1 if the event was observed) and reshapes it into the desired format. Most users will not use this function directly, but will instead use the main function BayesSurv, which uses the present function.

Usage

ReshapeData(
  df,
  time = "time",
  event = "event",
  K = ceiling((dim(df)[1]/log(dim(df)[1]))^(1/2)),
  time.max = max(df[[time]])
)

Arguments

df

A dataframe, containing at minimum a column with follow-up times and a column with a status indicator (event observed or censored).

time

The name of the column in the dataframe containing the (possibly right-censored) follow-up times, that is, the minimum of the time of the event and the time of censoring. Input the name as character/string.

event

The name of the column in the dataframe containing the status indicator, which must be coded as: 0 = censored, 1 = event observed. Input the name as character/string.

K

The number of intervals to be used in the piecewise exponential (histogram) prior. Default is set to K = (n / \log{n})^{1/2}, with n the number of observations, as recommended by Castillo and Van der Pas (2020).

time.max

The maximum follow-up time to consider, corresponding to the parameter tau in Castillo and Van der Pas (2020).

Value

failures

A vector of length K, containing for each interval the number of individuals who had an event during that interval.

exposures

A vector of length K, containing for each interval the total amount of time all individuals together were under follow-up during that interval.

References

Castillo and Van der Pas (2020). Multiscale Bayesian survival analysis. <arXiv:2005.02889>.

See Also

BayesSurv, which computes the posterior mean and the radius of the credible band for the cumulative hazard function as well as the survival, and the posterior mean for the hazard. These objects can then be visualized by using PlotBayesSurv.


[Package BayesSurvival version 0.2.0 Index]