predict_qda: Quadratic discrimination prediction

Description Usage Arguments Value See Also Examples

View source: R/predict_qda.R

Description

The function uses the output from the function qda (Section A.3.2) and a P-vector X, and calculates the predicted group for this X.

Usage

1
predict_qda(qd, newx)

Arguments

qd

The output from qda.

newx

A P-vector X whose components match the variables used in the qda function.

Value

A K-vector of the discriminant values d_k^Q(X) in (11.48) for the given X.

See Also

qda, imax

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Load Iris Data
data(iris)

# Build data
x.iris <- as.matrix(iris[, 1:4])
n <- nrow(x.iris)
# Gets group vector (1, ... , 1, 2, ..., 2, 3, ... , 3)
y.iris <- rep(1:3, c(50, 50, 50))

# Perform QDA
qd.iris <- qda(x.iris, y.iris)
yhat.qd <- NULL
for (i in seq_len(n)) {
  yhat.qd <- c(yhat.qd, imax(predict_qda(qd.iris, x.iris[i, ])))
}
table(yhat.qd, y.iris)

msos documentation built on Oct. 31, 2020, 9:07 a.m.