Learn R Programming

rModeling (version 0.0.3)

fnPcaLda: Build a classifier using PCA-LDA

Description

a classification function based on PCA following LDA. This function can be cooperated into crossValidation by setting parameter method=fnPcaLda

Usage

fnPcaLda(data, label, batch = NULL, nPC = 10, 
           cv = c("none", "CV", "BV")[1], 
           nPart = 10, ...)

Arguments

data

a data matrix, with samples saved in rows and features in columns.

label

a vector of response variables (i.e., group/concentration info), must be the same length as the number of samples.

batch

a vector of batch variables (i.e., batch/patient ID), must be given in case of cv='BV'. Ideally, this should be the identification of the samples at the highest hierarchy (e.g., the patient ID rather than the spectral ID). Ignored for cv='None' or cv='CV'.

nPC

an integer, the number of principal components to be used in LDA.

cv

a character value, specifying the type of cross-validation.

nPart

an integer, the number of folds to be split for cross-validation. Equivalent to nFold of crossValidation for cv='CV' and to nBatch for cv='BV'. (NOTE: use nPart=0 for leave-one-batch out cross-validaiton). Ignored for cv='None'.

parameters for prcomp (cv='None') or crossValidation.

Value

For cv='none', a list of elements:

PCA

PCA model

LDA

LDA model

nPC

nPC used for modeling

For cv='CV' or cv='BV', a list of elements:

Fold

a list, each giving the sample indices of a fold

True

a vector of characters, groundtruth response variables, collected for each fold when it is used as testing data

Pred

a vector of characters, predicted results, collected for each fold when it is used as testing data

Summ

a list, the output of function predSummary. A confusion matrix (if classify=TRUE) from confusionMatrix or RMSE (if classify=FALSE) calculated from each fold being predicted.

Details

build a classifier based on the given data and return an object including the PCA and LDA models in case of cv='none'. Otherwise, a cross-validaiton is performed if cv='CV' or cv='BV', corresponding to normal k-fold or batch-wise cross-validation, respectively. In the latter two cases, the function returns the results of the cross-validation (i.e., the output from crossValidation.

References

S. Guo, T. Bocklitz, et al., Common mistakes in cross-validating classification models. Analytical methods 2017, 9 (30): 4410-4417.

See Also

crossValidation, tunePcaLda, lda, prcomp

Examples

Run this code
# NOT RUN {
  data(DATA)
  ### perform classification with a 3-fold cross-validaiton
  RES1 <- fnPcaLda(data=DATA$spec
                   ,label=DATA$labels
                   ,batch=DATA$batch
                   ,nPC=3
                   ,cv=c('none', 'CV', 'BV')[2]
                   ,nPart=3
                   ,center=TRUE
                   ,scale=FALSE)
 
# }

Run the code above in your browser using DataLab