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.
unfold(data, ...)# S3 method for 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, ...)
A data frame containing the "long" version of the data set.
a data frame to be "unfolded" from wide to long.
the column number or quoted name of the event/censoring-time variable in data.
the column number or quoted name of the event/censoring-indicator variable in data.
a vector giving the column numbers of the time-dependent covariate
in data
, or a list of vectors if there is more than one time-varying
covariate.
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.
the suffix to be attached to the name of the time-to-event variable in the output data set; defaults to '.time'.
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 cov
).
(2) An arbitrary numerical vector with one more entry than the length of each
vector in cov
. (3) The columns in the input data set that give the observations times for each
individual. There should be one more column than the length of each vector in cov
.
a logical value indicating whether the times of observation
are the same for all individuals; defaults to TRUE
.
number of observation periods to lag each value of the time-varying
covariate(s); defaults to 0
.
if TRUE
, the default, show a progress bar as the observations are processed.
arguments to be passed down.
John Fox <jfox@mcmaster.ca>
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. tools:::Rd_expr_doi("10.18637/jss.v049.i07").
if (interactive()){
head(Rossi, 2)
Rossi.long <- unfold(Rossi, time="week", event="arrest", cov=11:62,
cov.names="emp")
head(Rossi.long, 50)
}
Run the code above in your browser using DataLab