blk.locf | R Documentation |
Performs last observation carried forward (LOCF) imputation on a column of data.
blk.locf(x, id, na.action = c("fill", "carry.back"), fill = NA)
blk.locf2(time, id, observ.x, observ.t, id2 = id, na.action = c("fill", "carry.back"), fill = NA)
blk.nocb(x, id, na.action = c("fill", "carry.forward"), fill = NA)
x |
A vector in |
id,id2 |
A valid |
time |
A vector of times at which to impute values, in |
observ.x |
A vector of obseved values in |
observ.t |
A vector of observation times corresponding to |
na.action |
How to handle times prior to the first observation. See details. |
fill |
A value to use when no other value is appropriate. |
These functions operate on data sets in block-format
.
The simpler blk.locf
fills in
the missing values in x
using the observed values. Time is
implicit; the time-ordering of x
(within blocks of
id
) is required.
For blk.locf2
observations and corresponding times are
specified separately from the times at which imputation is
desired. This function is essentially equivalent to
blk.nearestMatch
with direction = "forward"
and
tol = Inf
.
The parameter na.action
is used to control the result
when there is no previous non-missing value available. With
na.action = "fill"
the valued specified with
fill
is used. With na.action = "carry.back"
,
the earliest available non-missing future value is used.
If there is no non-missing observed values for a level of
id
, the result is NA
for that id
at all time points.
Less frequently used is next observation carried back (NOCB). Here, future observations are used to fill in the missing values at earlier times.
A vector in block-format
with respect to id
.
Benjamin Rich <mail@benjaminrich.net>
block-format
blk.nearestMatch
require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,] # First 4 subjects
dat <- dat[order(dat$Subject, dat$time),]
attach(dat)
cbind(dat, LOCF=blk.locf(conc, Subject))
cbind(dat, LOCF=blk.locf(conc, Subject, na.action="carry.back"))
detach(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.