Learn R Programming

survival (version 3.8-6)

lvcf: Last Value Carried Forward

Description

Replace missing values in a covariate with the last non-missing value, separately for each id.

Usage

lvcf(id, x, time)

Value

an updated copy of x

Arguments

id

subject identifier

x

the covariate which will be modified

time

optional; used to sort observations within subject

Author

Terry Therneau

Details

If an analysis includes a covariate that was measured repeatedly, cholesterol say, the data may often include visits where this was not measured. It is convenient in that case to use, for each subject, the most recently measured value. When a value is extended beyond the last measurement, rather that just replacement of intermediate values, there is the potential for bias, e.g., if the reason for discontinuation is predictive of the future trajectory of values.

If time is missing, then the order of the values within subject is assumed to be the calendar time order. It is not necessary for the the data to be sorted by id.

See Also

tmerge

Examples

Run this code
newplat <- with(pbcseq, lvcf(id, platelet))
table(is.na(pbcseq$platelet), is.na(newplat))

Run the code above in your browser using DataLab