predict.rlda | R Documentation |
Classify multivariate observations with linear classification rules built with additional information in conjunction with rlda
.
## S3 method for class 'rlda'
predict(object, newdata, prior = object$prior,
gamma = object$gamma, grouping = NULL, ...)
object |
An object of class |
newdata |
A data frame of cases to be classified, containing the variables used on creating |
prior |
The prior probabilities of class membership. If unspecified, |
gamma |
A vector of values specifying which rules to take among the ones in |
grouping |
A numeric vector or factor with numeric levels specifying the class for each observation. If present, true error rate will be estimated from |
... |
Arguments based from or to other methods. |
This function is a method for the generic function predict()
for class 'rlda'
.
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 |
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.
David Conde
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/.
rlda
, err.est.rlda
, rqda
, predict.rqda
, err.est.rqda
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.