Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

carrying out a Linear Discriminant Analysis

I’m analyzing the data set data(wine) from the R package gclus.

I split the data set according to the proportions 70:30 into a training and a test set.

library(gclus)
data("wine")
sample_size <- floor(0.70 * nrow(wine))
set.seed(123)
train_index <- sample(seq_len(nrow(wine)), size = sample_size)
train <- wine[train_index, ]
test <- wine[-train_index, ]

How could I now carry out LDA for the following data subsets:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. wine[c("Class", "Ash", "OD280", "Nonflavanoid")]
  2. wine[c("Class", "Hue", "Magnesium", "Flavanoids", "Alcohol", "Malic", "Intensity", "Alcalinity", "Proline")] .

>Solution :

You can use the function lda in MASS package:

MASS::lda(Class~Ash+OD280+Nonflavanoid, train)
Call:
lda(Class ~ Ash + OD280 + Nonflavanoid, data = train)

Prior probabilities of groups:
        1         2         3 
0.3225806 0.3790323 0.2983871 

Group means:
       Ash    OD280 Nonflavanoid
1 2.487500 3.163250    0.2950000
2 2.255106 2.766809    0.3727660
3 2.456486 1.714865    0.4575676

Coefficients of linear discriminants:
                    LD1       LD2
Ash           0.8918665  3.862102
OD280        -2.3406276 -0.482271
Nonflavanoid  1.2410102 -5.865365

Proportion of trace:
   LD1    LD2 
0.8966 0.1034 

You can do the same for the second case

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading