Linear Discriminant Analysis (LDA) using R

Data

perform.A = c(63.3, 68.3, 86.7, 52.8, 75, 58, 69.5, 32.7, 60.9, 58.2)
contracts.A = c(24, 30, 33, 19, 30, 22, 28, 13, 17, 18)

perform.B = c(72.8, 88.2, 80.8, 71.3, 81.5, 47.6, 81, 81.4, 83, 76, 74.5)
contracts.B = c(25, 26, 29, 22, 41, 15, 40, 37, 39, 29, 26)

perform.C = c(82.3, 89.7, 81, 85.1, 74.1, 75.9, 74.7, 81.1, 76.4, 81.8)
contracts.C = c(38, 42, 48, 42, 40, 45, 33, 31, 47, 38)

sales = c(perform.A, perform.B, perform.C)
contracts = c(contracts.A , contracts.B , contracts.C)

group = c(rep(1, 10), rep(2, 11), rep(3, 10))
group = factor(group, levels = c(1,2,3), labels = c("A", "B", "C"))

lda.data.frame = data.frame(group, sales, contracts)

1.Linear Discriminant Analysis
library(DiscriMiner)
my_lin1 = linDA(lda.data.frame[,2:3], lda.data.frame$group, prior = c(1/3, 1/3, 1/3))
print(my_lin1)

2. Box's M test
BoxMTest(lda.data.frame[, c(2,3)], lda.data.frame[, 1])
Remark: Function BoxMTest is available here

3. Remark: Quadratic discriminant analysis (QDA)
library(DiscriMiner)
quaDA(lda.data.frame[,2:3], lda.data.frame$group, prior = c(1/3, 1/3, 1/3))

The above example is contained in the paragraph 5.7 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.

Comments