kNNR Documentation

Hotdeck imputation by the k nearest neighbors method

Description

Hotdeck imputation for one variable by the k nearest neighbors method (random imputation or average over the k nearest neighbors)

Usage

kNN(data, variable, method = c("random", "mean"), k = 3, nomatch = NULL, flag = FALSE, seed = 1024)

Arguments

data

a data.frame

variable

character: name of variable subject to imputation (only one variable allowed)

method

character: random (randomly drawn observations among the k nearest neighbors) or mean (average over the k nearest neighbors)

k

number of nearest neighbors

nomatch

character or character vector of variables that shall not be used for distance calculation (e.g., sampling weight or id-variables)

flag

logical, if TRUE a flag variable is added to data that indicates which observations have been imputed

seed

positive integer: random seed (for method random)

Details

The k nearest neighbors are determined by means of the Gower distance (implemented in the package gower).

Value

A data.frame

warning

You must not call this function unless you really know how it works! Also, the function does not check whether the provided arguments are meaningful. It is the user's responsibility to make sure that the arguments are properly specified.

Author(s)

Tobias Schoch