Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nm

Nearest Mean Classification


Description

Function for nearest mean classification.

Usage

nm(x, ...)

## Default S3 method:
nm(x, grouping, gamma = 0, ...)
## S3 method for class 'data.frame'
nm(x, ...)
## S3 method for class 'matrix'
nm(x, grouping, ..., subset, na.action = na.fail)
## S3 method for class 'formula'
nm(formula, data = NULL, ..., subset, na.action = na.fail)

Arguments

x

matrix or data frame containing the explanatory variables (required, if formula is not given)

grouping

factor specifying the class for each observation (required, if formula is not given)

formula

formula of the form groups ~ x1 + x2 + .... That is, the response is the grouping factor and the right hand side specifies the (non-factor) discriminators

data

Data frame from which variables specified in formula are preferentially to be taken

gamma

gamma parameter for rbf weight of the distance to mean. If gamma=0 the posterior is 1 for the nearest class (mean) and 0 else.

subset

An index vector specifying the cases to be used in the training sample. (Note: If given, this argument must be named!)

na.action

specify the action to be taken if NAs are found. The default action is for the procedure to fail. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable. (Note: If given, this argument must be named.)

...

further arguments passed to the underlying sknn function

Details

nm is calling sknn with the class means as observations. If gamma>0 a gaussian like density is used to weight the distance to the class means weight=exp(-gamma*distance). This is similar to an rbf kernel. If the distances are large it may be useful to scale the data first.

Value

A list containing the function call and the class means (learn)).

Author(s)

Karsten Luebke, karsten.luebke@fom.de

See Also

Examples

data(B3)
x <- nm(PHASEN ~ ., data = B3)
x$learn
x <- nm(PHASEN ~ ., data = B3, gamma = 0.1)
predict(x)$post

klaR

Classification and Visualization

v0.6-15
GPL-2 | GPL-3
Authors
Christian Roever, Nils Raabe, Karsten Luebke, Uwe Ligges, Gero Szepannek, Marc Zentgraf, David Meyer
Initial release
2020-02-18

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.