pcaLDA {MethylIT}R 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 = 1.0e-4, method = "moment",
               max.pc = NULL)

## S3 method for class 'pcaLDA'
predict(object, newdata, type = c("lda.pred", "class",
  "posterior", "scores", "pca.ind.coord"), ...)

Arguments

formula

Same as in 'lda'from pakage 'MASS'.

data

Same as in 'lda'from pakage 'MASS'.

grouping

Same as in 'lda' from pakage 'MASS'.

n.pc

Number of principal components to use in the LDA.

scale

Same as in 'prcomp' from pakage 'prcomp'.

center

Same as in 'prcomp' from pakage 'prcomp'.

tol

Same as in 'prcomp' from pakage 'prcomp'.

method

Same as in 'lda'from pakage 'MASS'.

max.pc

Same as in paramter 'rank.' from pakage 'prcomp'.

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" given by function 'predict.lda' from MASS package: 'class', 'posterior', and 'scores' (see ?predict.lda).

...

Not in use.

Details

The principal components (PCs) are obtained using the function 'prcomp' from R pacakage 'stats', while the LDA is performed using the 'lda' function from R package 'MASS'. The current application only use 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.

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)

[Package MethylIT version 0.3.1 ]