Learn R Programming

Momocs (version 1.4.1)

reLDA: "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)

# S3 method for default reLDA(newdata, LDA)

# S3 method for PCA reLDA(newdata, LDA)

# S3 method for Coe reLDA(newdata, LDA)

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

Arguments

newdata

to use, a PCA or any Coe object

LDA

a LDA object

Examples

Run this code
# 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

Run the code above in your browser using DataLab