pcaLDA: Linear Discriminant Analysis (LDA) using Principal Component...

pcaLDAR Documentation

Linear Discriminant Analysis (LDA) using Principal Component Analysis (PCA)

Description

The principal components (PCs) for predictor variables provided as input data are estimated and then the individual coordinates in the selected PCs are used as predictors in the LDA

Predict using a PCA-LDA model built with function 'pcaLDA'

Usage

pcaLDA(
  formula = NULL,
  data = NULL,
  grouping = NULL,
  n.pc = 1,
  scale = FALSE,
  center = FALSE,
  tol = 1e-04,
  method = "moment",
  max.pc = NULL,
  columns = 9L,
  ...
)

predict.pcaLDA(
  object,
  newdata,
  type = c("lda.pred", "class", "posterior", "scores", "pca.ind.coord", "all"),
  ...
)

Arguments

formula

Same as in lda from package 'MASS'.

data

Same as in lda from package 'MASS' or an object from "pDMP" or "InfDiv" class.

grouping

Same as in lda from package 'MASS'.

n.pc

Number of principal components to use in the LDA.

scale, center, tol, max.pc

Same as in prcomp from package 'prcomp'.

method

Same as in lda from package 'MASS'.

columns

Optional. Only used if 'data' belong to the "pDMP" or "InfDiv" class. Default is 9L.

...

Not in use.

object

To use with function 'predict'. A 'pcaLDA' object containing a list of two objects: 1) an object of class inheriting from 'lda' and 2) an object of class inheriting from 'prcomp'.

newdata

To use with function 'predict'. New data for classification prediction

type

To use with function 'predict'. The type of prediction required. The default is 'all' basic predictions: classes and posterior classification probabilities. Option 'lda.pred' returns the object given by function 'predict.lda' from MASS package: 'class', 'posterior', 'scores' (cases scores on discriminant variables, see lda.

Details

The principal components (PCs) are obtained using the function 'prcomp' from R package 'stats', while the LDA is performed using the 'lda' function from R package 'MASS'. The current application only uses basic functionalities of mentioned functions. As shown in the example, pcaLDA' function can be used in general classification problems.

Value

Function 'pcaLDA' returns an object ('pcaLDA' class) consisting of list with two objects:

  1. 'lda': an object of class lda from package 'MASS'.

  2. 'pca': an object of class prcomp from package 'stats'.

For information on how to use these objects see ?lda and ?prcomp.

See Also

pcaQDA, lda and predict.lda

Examples

data(iris)
ld1 <- pcaLDA(formula = Species ~ Petal.Length + Sepal.Length + Sepal.Width,
data = iris, n.pc = 1, max.pc = 2, scale = TRUE, center = TRUE)

## ===== Prediction ===== ##
ld2 <- pcaLDA(formula = Species ~., data = iris, n.pc = 1, max.pc = 2,
scale = TRUE, center = TRUE)

set.seed(123)
idx <- sample.int(150, 40)
newdata <- iris[idx, 1:4]
newdata.prediction <- predict(ld2, newdata = newdata)

## ==== The confusion matrix
x <- data.frame(TRUE.class = iris$Species[idx],
PRED.class = newdata.prediction$class)
table(x)


genomaths/MethylIT documentation built on Feb. 3, 2024, 1:24 a.m.