Last Observation Carried Forward
In longitudinal studies it's common that individuals drop out before all responses can be obtained. Measurements obtained before the individual dropped out can be used to impute the unknown measurement(s). The last observation carried forward method is one way to impute values for the missing observations. For the last observation carried forward (LOCF) approach the missing values are replaced by the last observed value of that variable for each individual regardless of when it occurred.
LOCF()
replaces NA
s with the most recent non-NA prior to it.
LOCF(x) ## Default S3 method: LOCF(x) ## S3 method for class 'data.frame' LOCF(x) ## S3 method for class 'matrix' LOCF(x)
x |
a vector, a data.frame or a matrix containing NAs. |
The function will replace all NAs found in a vector with the last earlier value not being NA. In data.frames each column will be treated as described.
It should be noted, that the last observation carried forward approach may result in biased estimates and may underestimate the variability.
a vector with the same dimension as x.
Daniel Wollschlaeger <dwoll@psychologie.uni-kiel.de>
See also the package Hmisc for less coarse imputation functions.
d.frm <- data.frame( tag=rep(c("mo", "di", "mi", "do", "fr", "sa", "so"), 4) , val=rep(c(runif(5), rep(NA,2)), 4) ) d.frm$locf <- LOCF( d.frm$val ) d.frm
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.