predict.CCM {CCM} | R Documentation |
Classification from a CCM correlation matrix
Description
Classification as a function of a CCM correlation matrix that contains the correlations between test and training samples
Usage
## S3 method for class 'CCM'
predict(object, y, func = mean, ret.scores = FALSE, ...)
Arguments
object |
a CCM correlation matrix object obtained from |
y |
classes corresponding to the training samples (columns) of ‘object’ |
func |
the function that determines how a test sample is classified, defaulting to mean. See details. |
ret.scores |
If set to TRUE then a matrix of results by class are returned (see details); otherwise a vector of classifications/predictions is returned (the default) |
... |
Additional arguments to |
Details
The function func
can be any R function whose first argument is a vector of correlations (x). The CCM assigns each test sample the class that maximizes func(x). If func
is mean (the default), the classification is the class with the highest mean correlation. Other useful values for func
include median and max.
If ret.scores
is TRUE, then a matrix of results by class is returned, where the i(th) column corresponds to the i(th) test sample and each row corresponds to a possible class. Entry (i,j) contains func(x), where x
is a vector of correlations between the i(th) test sample and all training samples with the class in row j.
Value
The test sample classifications as a vector or a matrix of results by class.
Note
If the max function is used for func
, then the CCM is identical to a 1-nearest neighbor classifier with distance = 1 - r, where 'r' is the correlation (pearson or spearman) specified in the call to create.CCM
Author(s)
Garrett M. Dancik and Yuanbin Ru
See Also
Examples
data(data.expr)
data(data.gender)
## split dataset into training / testing ##
train.expr = data.expr[,1:20]
test.expr = data.expr[,21:40]
train.gender = data.gender[1:20]
test.gender = data.gender[21:40]
## CCM using spearman correlation ##
K = create.CCM(test.expr, train.expr, method = "spearman")
## predict based on the class with the highest mean correlation (the default) ##
p = predict(K, train.gender)
table(pred = p, true = test.gender) # check accuracy
## CCM using pearson correlation ##
K = create.CCM(test.expr, train.expr, method = "pearson")
## predict based on the class with the maximum correlation
p = predict(K, train.gender, func = max)
table(pred = p, true = test.gender) # check accuracy