Learn R Programming

StatMatch (version 1.2.0)

RANDwNND.hotdeck: Random Distance hot deck.

Description

This function implements a variant of the distance hot deck method. For each recipient record a subset of of the closest donors is retained and then a donor is selected.

Usage

RANDwNND.hotdeck(data.rec, data.don, match.vars=NULL, 
                 don.class=NULL, dist.fun="Manhattan", 
                 cut.don="rot", k=NULL, weight.don=NULL, ...)

Arguments

data.rec
A numeric matrix or data frame that plays the role of recipient. This data frame must contain the variables (columns), specified via match.vars and don.class, that should be used in the matching. Missing values (
data.don
A matrix or data frame that plays the role of donor. This data frame must contain the variables (columns), specified via match.vars and don.class, that should be used in the matching.
match.vars
A character vector with the names of the variables (the columns in both the data frames) that have to be used to compute distances among records (rows) in data.rec and those in data.don. When no matching variables are considered
don.class
A character vector with the names of the variables (columns in both the data frames) that have to be used to identify donation classes. In this case the computation of distances is limited to those units in data.rec and data.doc
dist.fun
A string with the name of the distance function that has to be used. The following distances are allowed: Manhattan (aka City block; default), Euclidean, Mahalanobis,exact
cut.don
A character string that, jointly with the argument k, identifies the rule to be used to form the subset of the closest donor records.
  • cut.don="rot": (default) then the number of the closest donors to retain is given by$\
k
Depends on the cut.don argument.
weight.don
A character string providing the name of the variable with the weights associated to the donor units in data.don. When this variable is specified, then the selection of a donor among those in the subset of the closest donors is done with pr
...
Additional arguments that may be required by gower.dist, or by maximum.dist, dist

Value

  • A Rlist with the following components:
  • mtc.idsA matrix with the same number of rows of data.rec and two columns. The first column contains the row names of the data.rec and the second column contains the row names of the corresponding donors selected from the data.don. When the input matrices do not contain row names, then a numeric matrix with the indexes of the rows is provided.
  • sum.distA matrix with summary statistics concerning the subset of the closest donors. The first three columns report the minimum, the maximum and the standard deviation of the distances among the recipient record and the donors in the subset of the closest donors, respectively. The 4th column reports the cutting distance, i.e. the value of the distance such that donors at a higher distance are discarded. The 5th column reports the distance between the recipient and the donor chosen at random in the subset of the donors.
  • noadFor each recipient unit, reports the number of donor records in the subset of closest donors.
  • callHow the function has been called.

Details

This function finds a donor record for each record in the recipient data set. The donor is chosen at random in the subset of available donors. This procedure is known as random hot deck (cf. Andridge and Little, 2010). In RANDwNND.hotdeck , the number of closest donors retained to form the subset is determined according to criterion specified with the argument cut.don. The selection of the donor among those in the subset is carried out with equal probability (weight.don=NULL) or with probability proportional to a weight associated to the donors (specified via the weight.don argument). This procedure is is known as weighted random hot deck (cf. Andridge and Little, 2010).

Note that the same donor can be used more than once.

This function can also be used to impute missing values in a data set. In this case data.rec is the part of the initial data set that contains missing values; on the contrary, data.don is the part of the data set without missing values. See Rcode in the Examples for details.

References

Andridge, R.R., and Little, R.J.A. (2010) A Review of Hot Deck Imputation for Survey Non-response. International Statistical Review, 78, 40--64.

D'Orazio, M., Di Zio, M. and Scanu, M. (2006). Statistical Matching: Theory and Practice. Wiley, Chichester.

Rodgers, W.L. (1984). An evaluation of statistical matching. Journal of Business and Economic Statistics, 2, 91--102.

Singh, A.C., Mantel, H., Kinack, M. and Rowe, G. (1993). Statistical matching: use of auxiliary information as an alternative to the conditional independence assumption. Survey Methodology, 19, 59--79.

See Also

NND.hotdeck

Examples

Run this code
require(SDaA)
data(agpop, agsrs, agstrat, package="SDaA") #loads ag data from SDaA
str(agpop)
str(agsrs)
str(agstrat)

# adds variable "region" to agsrs
state.region <- data.frame(xtabs(weight~state+region, data=agstrat))
state.region <- subset(state.region, Freq>0)
agsrs <- merge(agsrs, state.region[,1:2], by="state", all.x=TRUE)

# simulate a statistical matching framework
A <- agsrs[, c("region", "acres82", "farms82", "acres87", "farms87")]
B <- agstrat[, c("region", "acres82", "farms82", "acres92","farms92",
                 "weight")]


# find a donor in the subset of closest donors using cut.don="rot";
# the distance is computed using "acres82" and "farms82"

out.NND.1 <- RANDwNND.hotdeck(data.rec=A, data.don=B,
              match.vars=c("acres82", "farms82") )

# create the synthetic (or fused) data.frame:
# fill in "acres92" and "farms92" in A
fused.1 <- create.fused(data.rec=A, data.don=B,
             mtc.ids=out.NND.1$mtc.ids, z.vars=c("acres92","farms92"))
head(fused.1)

# find a donor in the subset of closest donors using cut.don="rot";
# the distance is computed using "acres82" and "farms82"
# weights are used in selecting the donor

out.NND.2 <- RANDwNND.hotdeck(data.rec=A, data.don=B,
              match.vars=c("acres82", "farms82"), weight.don="weight" )
fused.2 <- create.fused(data.rec=A, data.don=B,
             mtc.ids=out.NND.2$mtc.ids, z.vars=c("acres92","farms92"))
head(fused.2)

# as before, but with a different criteria to reduce the no. of donors:
# the first half (k=0.5) of the closest available donors is retained,
# then a donor is chosen with prob proportional to its weight

out.NND.3 <- RANDwNND.hotdeck(data.rec=A, data.don=B,
             match.vars=c("acres82", "farms82"),
             cut.don="span", k=0.5, weight.don="weight")
fused.3 <- create.fused(data.rec=A, data.don=B,
             mtc.ids=out.NND.3$mtc.ids, z.vars=c("acres92","farms92"))
head(fused.3)


# as before, but the subset of closest donors is formed by considering
# only the first k=5 closest donors

out.NND.4 <- RANDwNND.hotdeck(data.rec=A, data.don=B,
             match.vars=c("acres82", "farms82"),
             cut.don="exact", k=5, weight.don="weight")
fused.4 <- create.fused(data.rec=A, data.don=B,
             mtc.ids=out.NND.4$mtc.ids, z.vars=c("acres92","farms92"))
head(fused.4)


# find a donor in the subset of closest donors using cut.don="rot";
# the distance is computed using "acres82" and "farms82"
# only donors in the same "region" are considered

out.NND.5 <- RANDwNND.hotdeck(data.rec=A, data.don=B, don.class="region",
              match.vars=c("acres82", "farms82") )
fused.5 <- create.fused(data.rec=A, data.don=B,
             mtc.ids=out.NND.5$mtc.ids, z.vars=c("acres92","farms92"), 
             dup.x=TRUE, match.vars="region")
head(fused.5)


# Example of Imputation of missing values
# introducing missing vales in iris
ir.mat <- iris
miss <- rbinom(nrow(iris), 1, 0.3)
ir.mat[miss==1,"Sepal.Length"] <- NA
iris.rec <- ir.mat[miss==1,-1]
iris.don <- ir.mat[miss==0,]

#search for NND donors
imp.NND <- RANDwNND.hotdeck(data.rec=iris.rec, data.don=iris.don,
               match.vars=c("Sepal.Width","Petal.Length", "Petal.Width"),
               don.class="Species")

# imputing missing values
iris.rec.imp <- create.fused(data.rec=iris.rec, data.don=iris.don,
             mtc.ids=imp.NND$mtc.ids, z.vars="Sepal.Length")

# rebuild the imputed data.frame
final <- rbind(iris.rec.imp, iris.don)

Run the code above in your browser using DataLab