Learn R Programming

CCM (version 1.2)

predict.CCM: 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 CCM
predict(object, y, func = mean, ret.scores = FALSE, ...)

Arguments

object

a CCM correlation matrix object obtained from create.CCM

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 func

Value

The test sample classifications as a vector or a matrix of results by class.

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.

See Also

create.CCM

Examples

Run this code
# NOT RUN {
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
# }

Run the code above in your browser using DataLab