predict.rcar: make classification from a "rcar" object.

Description Usage Arguments Value Examples

View source: R/Predict.R

Description

This function gives the predicted class of a new data records from a "rcar" or "cv.rcar" object at a single value of lambda.

Usage

1
predict.rcar(object, newdata, lambd)

Arguments

object:

Fitted "rcar" or "cv.rcar" object.

newdata:

Matrix of new values for x at which predictions are to be made. Must be a matrix; can be sparse as in Matrix package.

Value

The predicted classes using RCAR approach.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Vote<-na.omit(Vote)
nrow(Vote)
set.seed(1)
train<-sample(232,202)
vote.train<- vote[train,]
vote.test <-vote[-train,]

Select a random subset of 202 observations out of the original 232 observations in vote dataset,
the selected sample will be used to train the "rcar" and "cv.rcar" ojects, while the rest will be used to estimate the test error.


vote.cv<-cv.rcar(vote.train, y.rank = 1, s=0.2, c=0.8)
best.lambda<-vote.cv$Accurate.Model$Best.lambda

vote.pred<-predict.rcar(vote.cv,vote.test) #While the lambd, value of lambda, is not specified, the programme uses the value of lambda corresponding the minimum mean cross-validated error.
table(vote$Class.Name[-train], vote.pred)

vote.pred<-predict.rcar(vote.cv,vote.test, lambd = 0) #] predicted value with lambda=0
table(vote$Class.Name[-train], vote.pred)


vote.racar<-rcar(vote.train, y.rank = 1, s=0.2, c=0.8,lambd=best.lambda)
vote.pred<-predict.rcar(vote.racar,vote.test)
table(vote$Class.Name[-train], vote.pred)

azemi/RCAR documentation built on May 7, 2019, 2:54 a.m.