predict.rlda: Restricted Linear Discriminant Analysis. Multivariate...

View source: R/rlda.R

predict.rldaR Documentation

Restricted Linear Discriminant Analysis. Multivariate Observations Classification

Description

Classify multivariate observations with linear classification rules built with additional information in conjunction with rlda.

Usage

## S3 method for class 'rlda'
predict(object, newdata, prior = object$prior,
        gamma = object$gamma, grouping = NULL, ...)

Arguments

object

An object of class 'rlda'.

newdata

A data frame of cases to be classified, containing the variables used on creating object. A vector will be interpreted as a row vector.

prior

The prior probabilities of class membership. If unspecified, object$prior probabilities are used. If present, the probabilities must be specified in the order of the factor levels.

gamma

A vector of values specifying which rules to take among the ones in object. If unspecified, all rules built with object$gamma will be used. If present, gamma must be contained in object$gamma.

grouping

A numeric vector or factor with numeric levels specifying the class for each observation. If present, true error rate will be estimated from newdata.

...

Arguments based from or to other methods.

Details

This function is a method for the generic function predict() for class 'rlda'.

Value

A list with components

call

The (matched) function call.

class

Matrix with the classification for each rule (in columns).

prior

The prior probabilities of the classes used.

posterior

Array with the posterior probabilities of the classes for each rule.

error.rate

True error rate estimation (when grouping specified) for each rule, based on newdata.

Note

If there are missing values in newdata, corresponding observations will not be classified.

If there are missing values in grouping, corresponding observations will not be considered on calculating the true error rate.

Author(s)

David Conde

References

Conde, D., Fernandez, M. A., Rueda, C., and Salvador, B. (2012). Classification of samples into two or more ordered populations with application to a cancer trial. Statistics in Medicine, 31, 3773-3786.

Conde, D., Fernandez, M. A., Salvador, B., and Rueda, C. (2015). dawai: An R Package for Discriminant Analysis with Additional Information. Journal of Statistical Software, 66(10), 1-19. URL http://www.jstatsoft.org/v66/i10/.

See Also

rlda, err.est.rlda, rqda, predict.rqda, err.est.rqda

Examples

data(Vehicle2)
levels(Vehicle2$Class)
## "bus" "opel" "saab" "van"

data <- Vehicle2
levels(data$Class) <- c(4, 2, 1, 3)  
## classes ordered by increasing size
## 
## according to variable definitions, we can 
## consider the following restrictions on the means vectors:
## mu11, mu21 >= mu31 >= mu41
## mu12, mu22 >= mu32 >= mu42
## 
## we have 6 restrictions, 3 predictors and 4 classes, so
## resmatrix must be a 6 x 12 matrix:

A <- matrix(0, ncol = 12, nrow = 6)
A[t(matrix(c(1, 1, 2, 2, 3, 4, 4, 5, 5, 7, 6, 8), nrow = 2))] <- -1
A[t(matrix(c(1, 7, 2, 8, 3, 7, 4, 8, 5, 10, 6, 11), nrow = 2))] <- 1

set.seed(983)
values <- runif(dim(data)[1])
trainsubset <- values < 0.2
testsubset <- values >= 0.2
obj <- rlda(Class ~ Kurt.Maxis + Holl.Ra + Sc.Var.maxis,
            data, subset = trainsubset, gamma = c(0, 0.5, 1),
            resmatrix = A)
pred <- predict(obj, newdata = data[testsubset,], 
                grouping = data[testsubset, "Class"],
                prior = rep(1/4, 4))
pred$error.rate
## we can see that the test error rate of the restricted
## rules decrease with gamma:
##                       gamma=0 gamma=0.5  gamma=1
## True error rate (%): 40.86957  39.71014 39.71014

dawai documentation built on Oct. 15, 2024, 5:06 p.m.