contToDisc: Continuous To Discrete Transformation

View source: R/DiscSurvDataTransform.R

contToDiscR Documentation

Continuous To Discrete Transformation

Description

Discretizes continuous time variable into a specified grid of censored data for discrete survival analysis. It is a data preprocessing step, before the data can be extendend in long format and further analysed with discrete survival models.

Usage

contToDisc(
  dataShort,
  timeColumn,
  intervalLimits,
  equi = FALSE,
  timeAsFactor = FALSE
)

Arguments

dataShort

Original data in short format (class "data.frame"). Descriptions of data formats are available in discSurv-package.

timeColumn

Name of the column of discrete survival times (class "character").

intervalLimits

Right interval borders (class "numeric"), e. g. if the intervals are [0, a_1), [a_1, a_2), [a_2, a_max), then intervalLimits = c(a_1, a_2, a_max)

equi

Specifies if argument intervalLimits should be interpreted as number of equidistant intervals (class "logical").

timeAsFactor

Specifies if the computed discrete time intervals should be converted to a categorical variable (class "logical"). Default is FALSE. In the default settings the discret time intervals are treated as quantitative (class "numeric").

Value

Gives the data set expanded with a first column "timeDisc". This column includes the discrete time intervals (class "factor").

Note

In discrete survival analysis the survival times have to be categorized in time intervals. Therefore this function is required, if there are observed continuous survival times. Arguments to this function have to be specified in the required formats. Other objects are not supported. For example a common mistake is the usage of tibble data formats, that are not of class "data.frame".

Author(s)

Thomas Welchowski t.welchowski@psychologie.uzh.ch

References

\insertRef

tutzModelDiscdiscSurv

See Also

dataLong, dataLongTimeDep, dataLongCompRisks

Examples


# Example copenhagen stroke study data
library(pec)
data(cost)
head(cost)

# Convert observed times to months
# Right borders of intervals [0, a_1), [a_1, a_2), ... , [a_{\max-1}, a_{\max})
IntBorders <- 1:ceiling(max(cost$time)/30)*30

# Select subsample
subCost <- cost [1:100, ]
CostMonths <- contToDisc(dataShort=subCost, timeColumn = "time", intervalLimits = IntBorders)
head(CostMonths)

# Select subsample giving number of equidistant intervals
CostMonths <- contToDisc(dataShort = subCost, timeColumn = "time", intervalLimits = 10, equi = TRUE)
head(CostMonths)


discSurv documentation built on April 29, 2026, 9:07 a.m.