create.imputed | R Documentation |
Imputes the missing values (NAs) in the recipient dataset with values observed on the donors units after search of donors with NND or random hotdeck.
create.imputed(data.rec, data.don, mtc.ids)
data.rec |
A matrix or data frame that has missing values. |
data.don |
A matrix or data frame that is used for donation (imputation). |
mtc.ids |
A matrix with two columns. Each row must contain the name or the index of the recipient record (row) in |
This function allows the missing values (NAs) in the recipient to be filled in with values observed in the donor dataset after searching for donors via NND or random hotdeck using the functions available in the package, i.e. NND.hotdeck
, RANDwNND.hotdeck
, rankNND.hotdeck
, and mixed.mtc
.
If the same record in the recipient dataset has 2 or more NAs, they will all be replaced with the values observed for that unit on the selected donor; this is equivalent to joint hotdeck imputation.
The data frame data.rec
missing values (NAs) filled in.
Marcello D'Orazio mdo.statmatch@gmail.com
D'Orazio, M., Di Zio, M. and Scanu, M. (2006). Statistical Matching: Theory and Practice. Wiley, Chichester.
NND.hotdeck
RANDwNND.hotdeck
rankNND.hotdeck
# introduce missing values
# in Petal.Length of iris dataset
set.seed(13579)
pos <- sample(x = 1:nrow(iris), size = 15,
replace = FALSE)
iris.rec <- iris[pos, ] # recipient data.frame with missing values
iris.rec[, "Petal.Length"] <- NA
iris.don <- iris[-pos, ] # donor data.frame ALL observed
# find the closest donors using NND hot deck;
# distances are computed on "Petal.Width"
# donors only of the same Specie
out.NND <- NND.hotdeck(data.rec=iris.rec, data.don=iris.don,
match.vars=c("Petal.Width"),
don.class="Species")
# impute missing
iris.rec.imp <- create.imputed(data.rec=iris.rec, data.don=iris.don,
mtc.ids=out.NND$mtc.ids)
summary(iris.rec.imp$Petal.Length)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.