\HeaderA{kNN}{k-Nearest Neighbour Imputation}{kNN}
\aliasA{gowerD}{kNN}{gowerD}
\aliasA{maxCat}{kNN}{maxCat}
\aliasA{sampleCat}{kNN}{sampleCat}
\aliasA{which.minN}{kNN}{which.minN}
\keyword{manip}{kNN}
%
\begin{Description}\relax
k-Nearest Neighbour Imputation based on a variation of the Gower Distance for numerical, categorical, ordered and semi-continous variables.
\end{Description}
%
\begin{Usage}
\begin{verbatim}
kNN(data, variable = colnames(data), metric = NULL, k = 5,
    dist_var = colnames(data), weights = NULL, numFun = median,
    catFun = maxCat, makeNA = NULL, NAcond = NULL, impNA = TRUE,
    donorcond = NULL, mixed = vector(), trace = FALSE, imp_var = TRUE,
    imp_suffix = "imp", addRandom = FALSE)
sampleCat(x)
maxCat(x)
gowerD(data.x, data.y = data.x, weights = NULL, numerical, factors,
    orders, mixed, levOrders)
which.minN(x, n)
\end{verbatim}
\end{Usage}
%
\begin{Arguments}
\begin{ldescription}
\item[\code{data}] 
data.frame or matrix

\item[\code{variable}] 
variables where missing values should be imputed

\item[\code{metric}] 
metric to be used for calculating the distances between

\item[\code{k}] 
number of Nearest Neighbours used

\item[\code{dist\_var}] 
names or variables to be used for distance calculation

\item[\code{weights}] 
weights for the variables for distance calculation

\item[\code{numFun}] 
function for aggregating the k Nearest Neighbours in the case of a numerical variable

\item[\code{catFun}] 
function for aggregating the k Nearest Neighbours in the case of a categorical variable

\item[\code{makeNA}] 
vector of values, that should be converted to NA

\item[\code{NAcond}] 
a condition for imputing a NA

\item[\code{impNA}] 
TRUE/FALSE whether NA should be imputed

\item[\code{donorcond}] 
condition for the donors e.g. ">5"

\item[\code{trace}] 
TRUE/FALSE if additional information about the imputation process should be printed

\item[\code{imp\_var}] 
TRUE/FALSE if a TRUE/FALSE variables for each imputed variable should be created show the imputation status

\item[\code{imp\_suffix}] 
suffix for the TRUE/FALSE variables showing the imputation status

\item[\code{addRandom}] 
TRUE/FALSE if an additional random variable should be added for distance calculation

\item[\code{x}] 
factor or character vector / numerical vector for which.minN

\item[\code{data.x}] 
data frame or matrix    

\item[\code{data.y}] 
data frame or matrix

\item[\code{numerical}] 
names of numerical variables

\item[\code{factors}] 
names of factors

\item[\code{orders}] 
names of ordered variables

\item[\code{mixed}] 
names of mixed variables

\item[\code{levOrders}] 
list of the ordered levels for each factor

\item[\code{n}] 
number of ordered smallest values

\end{ldescription}
\end{Arguments}
%
\begin{Details}\relax
The function sampleCat samples with probabilites corresponding to the occurrence of the level in the NNs.
The function maxCat chooses the level with the most occurrences and random if the maximum is not unique.
The function gowerD is used by kNN to compute the distances for numerical, factor ordered and semi-continous variables.
The function which.minN is used by kNN.
\end{Details}
%
\begin{Value}
the imputed data set.
\end{Value}
%
\begin{Author}\relax
Alexander Kowarik
\end{Author}
%
\begin{Examples}
\begin{ExampleCode}
data(sleep)
kNN(sleep)
\end{ExampleCode}
\end{Examples}
