unfold {RcmdrPlugin.survival} | R Documentation |
Convert a Survival Data Set from "Wide" to "Long" Format
Description
Converts a survival-analysis data frame from "wide" format, in which time-varying covariates are separate variables, one per occasion, to "long" or counting-process format in which each occasion is a separate row in the data frame.
Usage
unfold(data, ...)
## S3 method for class 'data.frame'
unfold(data, time, event, cov,
cov.names = paste("covariate", ".", 1:ncovs, sep = ""),
suffix = ".time", cov.times = 0:ncov, common.times = TRUE, lag = 0,
show.progress=TRUE, ...)
Arguments
data |
a data frame to be "unfolded" from wide to long. |
time |
the column number or quoted name of the event/censoring-time variable in data. |
event |
the column number or quoted name of the event/censoring-indicator variable in data. |
cov |
a vector giving the column numbers of the time-dependent covariate
in |
cov.names |
a character string or character vector giving the name or names to be assigned to the time-dependent covariate(s) in the output data set. |
suffix |
the suffix to be attached to the name of the time-to-event variable in the output data set; defaults to '.time'. |
cov.times |
the observation times for the covariate values, including the start
time. This argument can take several forms: (1) The default is integers from 0 to
the number of covariate values (i.e., one more than the length of each vector in |
common.times |
a logical value indicating whether the times of observation
are the same for all individuals; defaults to |
lag |
number of observation periods to lag each value of the time-varying
covariate(s); defaults to |
show.progress |
if |
... |
arguments to be passed down. |
Value
A data frame containing the "long" version of the data set.
Author(s)
John Fox <jfox@mcmaster.ca>
References
John Fox, Marilia Sa Carvalho (2012). The RcmdrPlugin.survival Package: Extending the R Commander Interface to Survival Analysis. Journal of Statistical Software, 49(7), 1-32. doi:10.18637/jss.v049.i07.
Examples
if (interactive()){
head(Rossi, 2)
Rossi.long <- unfold(Rossi, time="week", event="arrest", cov=11:62,
cov.names="emp")
head(Rossi.long, 50)
}