blk.locf: Last Observation Carried Forward

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Performs last observation carried forward (LOCF) imputation on a column of data.

Usage

1
2
3
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)

Arguments

x

A vector in block-format with respect to id, containing both observed values and missing values, which must be ordered chronologically within each block.

id,id2

A valid block-format ID.

time

A vector of times at which to impute values, in block-format with respect to id.

observ.x

A vector of obseved values in block-format with respect to id2.

observ.t

A vector of observation times corresponding to observ.x, in block-format with respect to id2.

na.action

How to handle times prior to the first observation. See details.

fill

A value to use when no other value is appropriate.

Details

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.

Value

A vector in block-format with respect to id.

Author(s)

Ben Rich <benjamin.rich@certara.com>

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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)

benjaminrich/PCSmisc documentation built on May 24, 2019, 5:02 a.m.