Fills-in missing values in the recipient dataset with values observed on the donors units
Fills-in missing values in the recipient dataset with values observed on the donors units
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)
Arguments
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 data.don and the name or the index of the corresponding donor record (row) in data.don. Note that this type of matrix is returned by the functions NND.hotdeck, RANDwNND.hotdeck, rankNND.hotdeck, and mixed.mtc.
Details
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.
Returns
The data frame data.rec missing values (NAs) filled in.
References
D'Orazio, M., Di Zio, M. and Scanu, M. (2006). Statistical Matching: Theory and Practice. Wiley, Chichester.
# introduce missing values# in Petal.Length of iris datasetset.seed(13579)pos <- sample(x =1:nrow(iris), size =15, replace =FALSE)iris.rec <- iris[pos,]# recipient data.frame with missing valuesiris.rec[,"Petal.Length"]<-NAiris.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 Specieout.NND <- NND.hotdeck(data.rec=iris.rec, data.don=iris.don, match.vars=c("Petal.Width"), don.class="Species")# impute missingiris.rec.imp <- create.imputed(data.rec=iris.rec, data.don=iris.don, mtc.ids=out.NND$mtc.ids)summary(iris.rec.imp$Petal.Length)