Description Usage Arguments Value References Examples
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.
1 | fill.simple(A, method = c("mean", "median", "random"))
|
A |
an (n\times p) partially observed matrix. |
method |
simple rule to fill in the missing entries in a columnwise manner. |
a named list containing
an (n\times p) matrix after completion.
gelman_data_2007filling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.