knnCMA {CMA} | R Documentation

## Nearest Neighbours

### Description

Ordinary `k` nearest neighbours algorithm from the very fast implementation in the package `class`.

For `S4` method information, see knnCMA-methods.

### Usage

    knnCMA(X, y, f, learnind, ...)

### Arguments

`X`

Gene expression data. Can be one of the following:

- A `matrix`. Rows correspond to observations, columns to variables.
- A `data.frame`, when `f` is not missing (s. below).
- An object of class `ExpressionSet`.

`y`

Class labels. Can be one of the following:

- A `numeric` vector.
- A `factor`.
- A `character` if `X` is an `ExpressionSet` that specifies the phenotype variable.
- `missing`, if `X` is a `data.frame` and a proper formula `f` is provided.

WARNING: The class labels will be re-coded to range from `0` to `K-1`, where `K` is the total number of different classes in the learning set.

`f` | A two-sided formula, if `X` is a `data.frame`. The left part correspond to class labels, the right to variables.
`learnind` | An index vector specifying the observations that belong to the learning set. Must not be missing for this method.
`...` | Further arguments to be passed to `knn` from the package `class`, in particular the number of nearest neighbours to use (argument `k`).

### Value

An object of class `cloutput`.

### Note

Class probabilities are not returned. For a probabilistic variant of `knn`, s. `pknnCMA`.

### Author(s)

Martin Slawski martin.slawski@campus.lmu.de

Anne-Laure Boulesteix http://www.slcmsr.net/boulesteix

### References

Ripley, B.D. (1996)

Pattern Recognition and Neural Networks.

Cambridge University Press

### See Also

`compBoostCMA`, `dldaCMA`, `ElasticNetCMA`, `fdaCMA`, `flexdaCMA`, `gbmCMA`, `ldaCMA`, `LassoCMA`, `nnetCMA`, `pknnCMA`, `plrCMA`, `pls_ldaCMA`, `pls_lrCMA`, `pls_rfCMA`, `pnnCMA`, `qdaCMA`, `rfCMA`, `scdaCMA`, `shrinkldaCMA`, `svmCMA`

### Examples

    ### load Golub AML/ALL data
    data(golub)
    ### extract class labels
    golubY <- golub[,1]
    ### extract gene expression from first 10 genes
    golubX <- as.matrix(golub[,-1])
    ### select learningset
    ratio <- 2/3
    set.seed(111)
    learnind <- sample(length(golubY), size=floor(ratio*length(golubY)))
    ### run k-nearest neighbours
    result <- knnCMA(X=golubX, y=golubY, learnind=learnind, k = 3)
    ### show results
    show(result)
    ftable(result)
    ### multiclass example:
    ### load Khan data
    data(khan)
    ### extract class labels
    khanY <- khan[,1]
    ### extract gene expression
    khanX <- as.matrix(khan[,-1])
    ### select learningset
    set.seed(111)
    learnind <- sample(length(khanY), size=floor(ratio*length(khanY)))
    ### run knn
    result <- knnCMA(X=khanX, y=khanY, learnind=learnind, k = 5)
    ### show results
    show(result)
    ftable(result)

[Package CMA version 1.2.0 Index]