reLDA: "Redo" a LDA on new data

View source: R/mult-LDA.R

reLDAR Documentation

"Redo" a LDA on new data

Description

Basically a wrapper around predict.lda from the package MASS. Uses a LDA model to classify new data.

Usage

reLDA(newdata, LDA)

## Default S3 method:
reLDA(newdata, LDA)

## S3 method for class 'PCA'
reLDA(newdata, LDA)

## S3 method for class 'Coe'
reLDA(newdata, LDA)

Arguments

newdata

to use, a PCA or any Coe object

LDA

a LDA object

Value

a list with components (from ?predict.lda ).

  • class factor of classification

  • posterior posterior probabilities for the classes

  • x the scores of test cases

  • res data.frame of the results

  • CV.tab a confusion matrix of the results

  • CV.correct proportion of the diagonal of CV.tab

  • newdata the data used to calculate passed to predict.lda

Note

Uses the same number of PC axis as the LDA object provided. You should probably use rePCA in conjunction with reLDA to get 'homologous' scores.

Examples

# We select the first 10 individuals in bot,
# for whisky and beer bottles. It will be our referential.
bot1   <- slice(bot, c(1:10, 21:30))
# Same thing for the other 10 individuals.
# It will be our unknown dataset on which we want
# to calculate classes.
bot2   <- slice(bot, c(11:20, 31:40))

# We calculate efourier on these two datasets
bot1.f <- efourier(bot1, 8)
bot2.f <- efourier(bot2, 8)

# Here we obtain our LDA model: first, a PCA, then a LDA
bot1.p <- PCA(bot1.f)
bot1.l <- LDA(bot1.p, "type")

# we redo the same PCA since we worked with scores
bot2.p <- rePCA(bot1.p, bot2.f)

# we finally "predict" with the model obtained before
bot2.l <- reLDA(bot2.p, bot1.l)
bot2.l


vbonhomme/Momocs documentation built on Nov. 13, 2023, 8:54 p.m.