Learn R Programming

yaImpute (version 1.0-3)

yai: Find K nearest neighbors

Description

Given a set of observations, yai 1) separates the observations into reference and target observations, 2) applies the specified method to project X-variables into a Euclidean space (not always, see argument method), and 3) finds the k-nearest neighbors within the referenece observations and between the reference and target observations. An alternative method using randomForest classification and regression trees is provided for steps 2 and 3. Target observations are those with values for X-variables and not for Y-variables, while reference observations are those with no missing values for X-and Y-variables (see Details for the exception).

Usage

yai(x=NULL,y=NULL,data=NULL,k=1,noTrgs=FALSE,noRefs=FALSE,
    nVec=NULL,pVal=.05,method="msn",ann=TRUE,mtry=NULL,ntree=500,
    rfMode="buildClasses")

Arguments

x
1) a matrix or data frame containing the X-variables for all observations. Row names are the identification for the observation, or 2) a one-sided formula defining the X-variables as a linear formula. If a formula is coded for x,
y
1) a matrix or data frame containing the Y-variables for the reference observations, or 2) a one-sided formula defining the Y-variables as a linear formula.
data
when x and y are formulas, then data is a data frame or matrix that contains all the variables. The observations are split by yai into two sets.
k
the number of nearest neighbors; default is 1.
noTrgs
when TRUE, skip finding neighbors for target observations.
noRefs
when TRUE, skip finding neighbors for reference observations.
nVec
number of canonical vectors to use (methods msn and msn2), or number of independent of X-variables reference data when method mahalanobis. When NULL, the number is set by the function.
pVal
significant level for canonical vectors, used when method is msn or msn2.
method
is the strategy finding neighbors; the options are the quoted key words (see details): [object Object] ann{TRUE if ann is used to find neighbors, FALSE if a slow search is used.}