
Add information from start-stop data to a match_time
object
add_from_start_stop.Rd
This function may be used to add variables saved in the start-stop format to a match_time
object created using the match_time
function. For example, there might be a time-varying variable that was not included in the original data
used in the match_time
call to save memory, that should now be added later. Using this function, the value of these variables at .treat_time
will be added to the data
in the match_time
object.
Arguments
- x
A
match_time
object created using thematch_time
function.- data
A
data.table
like object including at least four columns:id
(the unique case identifier),start
(beginning of interval),stop
(end of interval) and one or more columns defined by thevariables
argument. May also be any object that can be coerced to be adata.table
, such as adata.frame
or atibble
. The dataset should be in the same start-stop format that would be required for a regularmatch_time
call.- id
A single character string specifying a column in
data
, specifying the unique case identifier. By default the same name that was used in the originalmatch_time
is used here.- variable
A single character string specifying a variable in
data
which should be added to the$data
object inside ofx
. Note that ifx$data
already contains columns with the same names as invariables
, an error will be produced.- start
A single character string specifying a column in
data
specifying the beginning of a time-interval. Defaults to"start"
.- stop
A single character string specifying a column in
data
specifying the end of a time-interval. Defaults to"stop"
.- default
A single value that should be used as default if no information can be found in
data
for the required point in time for some individuals. If the supplieddata
does not contain information for someid
at.treat_time
, this default value will be used instead.
Details
Although this function may be useful for very large datasets, if RAM is not an issue we recommend using the merge_start_stop
or similar functions to create a single start-stop dataset to use in match_time
instead. This way, all information contained in the start-stop dataset is automatically included in the output as well, without the need to use this function.
Value
Returns a modified match_time
object. It is essentially the same object as the supplied x
, but it also contains a new column: name
(the time of occurence of the next event).
Examples
library(data.table)
library(MatchTime)
# only execute if packages are available
if (requireNamespace("survival") & requireNamespace("MatchIt")) {
library(survival)
library(MatchIt)
# set random seed to make the output replicably
set.seed(1234)
# load "heart" data from survival package
data("heart")
heart <- heart[, c("id", "start", "stop", "transplant", "age", "surgery")]
}