fill.simple {filling}R Documentation

Imputation by Simple Rules

Description

One of the most simplest ways to fill in the missing entries is to apply any simple rule for each variable. In this example, we provide 3 options, "mean", "median", and "random". It assumes that every column has at least one non-missing entries in that for each column, the rule is applied from the subset of non-missing values.

Usage

fill.simple(A, method = c("mean", "median", "random"))

Arguments

A

an (n\times p) partially observed matrix.

method

simple rule to fill in the missing entries in a columnwise manner.

Value

a named list containing

X

an (n\times p) matrix after completion.

References

Gelman A, Hill J (2007). Data analysis using regression and multilevel/hierarchical models, Analytical methods for social research. Cambridge University Press, Cambridge ; New York. ISBN 978-0-521-86706-1 978-0-521-68689-1, OCLC: ocm67375137.

Examples

## load image data of 'lena128'
data(lena128)

## transform 5% of entries into missing
A <- aux.rndmissing(lena128, x=0.05)

## apply all three methods#'
fill1 <- fill.simple(A, method="mean")
fill2 <- fill.simple(A, method="median")
fill3 <- fill.simple(A, method="random")

## visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2), pty="s")
image(A, col=gray((0:100)/100), axes=FALSE, main="original")
image(fill1$X, col=gray((0:100)/100), axes=FALSE, main="method:mean")
image(fill2$X, col=gray((0:100)/100), axes=FALSE, main="method:median")
image(fill3$X, col=gray((0:100)/100), axes=FALSE, main="method:random")
par(opar)


[Package filling version 0.2.3 Index]