HiDimDA (version 0.2-4)

RFlda: High-Dimensional Factor-based Linear Discriminant Analysis.

Description

‘RFlda’ finds the coefficients of a linear discriminant rule based on a correlation (or covariance) matrix estimator that tries to approximate the true correlation (covariance) by the closest (according to a Frobenius norm) correlation (covariance) compatible with a q-factor model.

Usage

# S3 method for default
RFlda(data, grouping, q = 1, prior = "proportions", 
CorrAp = TRUE, maxq=5, VSelfunct = SelectV,
ldafun=c("canonical","classification"), nstarts = 1, 
CVqtrials=1:3, CVqfolds=3, CVqrep=1, CVqStrt=TRUE, ...)

# S3 method for data.frame RFlda(data, ...)

Value

If algument ‘ldafun’ is set to “canonical” an object of class ‘RFcanlda’, which extends class ‘canldaRes’, with the following components:

prior

The prior probabilities used.

means

The class means.

scaling

A matrix which transforms observations to discriminant functions, normalized so that the within groups covariance matrix is spherical.

svd

The singular values, which give the ratio of the between- and within-group standard deviations on the linear discriminant variables. Their squares are the canonical F-statistics.

vkpt

A vector with the indices of the variables kept in the discriminant rule if the number of variables kept is less than ‘ncol(data)’. NULL otherwise.

nvkpt

The number of variables kept in the discriminant rule if this number is less than‘ncol(data)’. NULL otherwise.

q

The number of o factors used in the factor model chosen.

SigFq

An object of class ‘SigFq’ with the q-factor model approximation to the within groups covariance matrix. ‘SigFq’ objects have specialized methods for matrix inversion, multiplication, and element-wise arithmetic operations.

SigFqInv

An object of class ‘SigFqInv’ with the q-factor model approximation to the within groups precision (inverse covariance) matrix. ‘SigFqInv’ objects have specialized methods for matrix inversion, multiplication, and element-wise arithmetic operations.

N

The number of observations used.

call

The (matched) function call.

If algument ‘ldafun’ is set to “classification” an object of class ‘RFcllda’, which extends class ‘clldaRes’, with the following components:

prior

The prior probabilities used.

means

The class means.

coef

A matrix with the coefficients of the k-1 classification functions.

cnst

A vector with the thresholds (2nd members of linear classification rules) used in classification rules that assume equal priors.

vkpt

A vector with the indices of the variables kept in the discriminant rule if the number of variables kept is less than ‘ncol(data)’. NULL otherwise.

nvkpt

The number of variables kept in the discriminant rule if this number is less than‘ncol(data)’. NULL, otherwise.

q

The number of o factors used in the factor model chosen.

SigFq

An object of class ‘SigFq’ with the q-factor model approximation to the within groups covariance matrix. ‘SigFq’ objects have specialized methods for matrix inversion, multiplication, and element-wise arithmetic operations.

SigFqInv

An object of class ‘SigFqInv’ with the q-factor model approximation to the within groups precision (inverse covariance) matrix. ‘SigFqInv’ objects have specialized methods for matrix inversion, multiplication, and element-wise arithmetic operations.

N

The number of observations used.

call

The (matched) function call.

Arguments

data

Matrix or data frame of observations.

grouping

Factor specifying the class for each observation.

q

Number of factors assumed by the model. This argument can be set to a fixed number between 1 and the argument of ‘maxq’, or to the string “CVq”. In the latter case the number of factors is chosen amongst the values of the argument ‘CVqtrials’, by minimizing a cross-validated estimate of the error rate.

prior

The prior probabilities of class membership. If unspecified, the class proportions for the training set are used. If present, the probabilities should be specified in the order of the factor levels.

CorrAp

A boolean flag indicating whether the approximation error of the correlation (default), or of the covariance matrix , should be minimized.

maxq

Upper limit on the values allowed for argument ‘q’.

VSelfunct

Variable selection function. Either the string “none” (no selection is to be performed) or a function that takes ‘data’ and ‘grouping’ as its first two arguments and returns a list with two components: (i) ‘nvkpt’ - the number of variables to be used in the Discriminant rule; and (ii) ‘vkptInd’ - the indices of the variables to be used in the Discriminant rule. The default is the ‘SelectV’ function that, by default, selects variables by the Expanded HC scheme described in Duarte Silva (2011).

ldafun

Type of discriminant linear functions computed. The alternatives are “canonical” for maximum-discrimination canonical linear functions and “classification” for direct-classification linear functions.

nstarts

Number of different randomly generated starting points used in the minimization of the Frobenius norm of the correlation (or covariance) matrix approximation.

CVqtrials

Vector of values to be tried for the number of factors assumed by the model, when argument ‘q’ is set to “CVq”.

CVqfolds

Number of training sample folds to be created in each replication of the cross-validation procedure for choosing the number of factors, when argument ‘q’ is set to “CVq”.

CVqrep

Number of replications to be performed in the cross-validation procedure for choosing the number of factors, when argument ‘q’ is set to “CVq”.

CVqStrt

Boolean flag indicating if, in the cross-validation procedure for choosing the number of factors when argument ‘q’ is set to “CVq”, the folds should be stratified according to the original class proportions (default), or randomly generated from the whole training sample ignoring class membership.

...

Further arguments passed to or from other methods.

Author

A. Pedro Duarte Silva

References

Pedro Duarte Silva, A. (2011) “Two Group Classification with High-Dimensional Correlated Data: A Factor Model Approach”, Computational Statistics and Data Analysis, 55 (1), 2975-2990.

See Also

FrobSigAp, SelectV, SigFq, SigFqInv, predict.canldaRes, predict.clldaRes, AlonDS

Examples

Run this code

#train classifier with 10 genes (after a logarithmic transformation) 
# on Alon's Colon Cancer Data set. 

log10genes <- log10(AlonDS[,-1])

ldarule1 <- RFlda(log10genes,AlonDS$grouping,Selmethod="fixedp",maxp=10)     

# get in-sample classification results

predict(ldarule1,log10genes,grpcodes=levels(AlonDS$grouping))$class           	       

# compare classifications with true assignments

cat("Original classes:\n")
print(AlonDS$grouping)             		 

# Estimate error rates by four-fold cross-validation.
# Note: In cross-validation analysis it is recommended to set 
# the argument 'ldafun' to "classification", in order to speed up 
# computations by avoiding unecessary eigen-decompositions 

if (FALSE) {

CrosValRes1 <- DACrossVal(log10genes,AlonDS$grouping,TrainAlg=RFlda,
Selmethod="fixedp",ldafun="classification",maxp=10,kfold=4,CVrep=1)
summary(CrosValRes1[,,"Clerr"])

# Find the best factor model amongst the choices q=1 or 2

ldarule2 <- RFlda(log10genes,AlonDS$grouping,q="CVq",CVqtrials=1:2,
Selmethod="fixedp",ldafun="classification",maxp=10)
cat("Best error rate estimate found with q =",ldarule2$q,"\n")

# Perform the analysis finding the number of selected genes 
# by the Expanded HC scheme 

ldarule3 <- RFlda(log10genes,AlonDS$grouping,q=ldarule2$q)     
cat("Number of selected genes =",ldarule3$nvkpt,"\n")

# get classification results

predict(ldarule3,log10genes,grpcodes=levels(AlonDS$grouping))$class           	       

}

Run the code above in your browser using DataCamp Workspace