| Title: | Tools of the Trade for Discriminant Analysis |
|---|---|
| Description: | Functions for Discriminant Analysis and Classification purposes. Covers various methods such as descriptive, geometric, linear, quadratic, PLS, as well as qualitative discriminant analyses. Compatibility updates by Renova. |
| Authors: | Gaston Sanchez [aut, cre], Charles Determan [ctb] |
| Maintainer: | Gaston Sanchez <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.29.9001 |
| Built: | 2026-11-13 18:02:25 UTC |
| Source: | https://github.com/renova-r/DiscriMiner |
DiscriMiner contains several functions for Discriminant Analysis and Classification purposes covering various methods such as descriptive, geometric, linear, quadratic, PLS, as well as qualitative discriminant analyses.
| Package: | DiscriMiner |
| Type: | Package |
| Version: | 0.1-23 |
| Date: | 2012-12-20 |
| License: | GPL-3 |
Gaston Sanchez
Maintainer: Gaston Sanchez <[email protected]>
http://www.gastonsanchez.com/discriminer
Lebart L., Piron M., Morineau A. (2006) Statistique exploratoire multidimensionnelle. Dunod, Paris.
Nakache J-P., Confais J. (2003) Statistique explicative appliquee. Editions Technip, Paris.
Saporta G. (2006) Probabilites, analyse des donnees et statistique. Editions Technip, Paris.
Tenenhaus M. (1998) La Regression PLS. Editions Technip, Paris.
Tenenhaus M. (2007) Statistique. Dunod, Paris.
Tuffery S. (2008) Data Mining et Statistique Decisionnelle. Editions Technip, Paris.
Tuffery S. (2011) Data Mining and Statistics for Decision Making. Wiley, Chichester.
Multiple Correspondence Analysis and Related Methods. (2006) Edited by Michael Greenacre and Jorg Blasius. Chapman and Hall/CRC
Calculates between-class covariance matrix
betweenCov(variables, group, div_by_n = FALSE)betweenCov(variables, group, div_by_n = FALSE)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
group |
vector or factor with group memberships (No missing values are allowed) |
div_by_n |
logical indicating division by number of observations |
When div_by_n=TRUE the covariance matrices are
divided by n (number of observations), otherwise they are
divided by n-1
Gaston Sanchez
getWithin, betweenSS,
withinCov, totalCov
## Not run: # load iris dataset data(iris) # between-class covariance matrix (dividing by n-1) betweenCov(iris[,1:4], iris[,5]) # between-class covariance matrix (dividing by n) betweenCov(iris[,1:4], iris[,5], div_by_n=TRUE) ## End(Not run)## Not run: # load iris dataset data(iris) # between-class covariance matrix (dividing by n-1) betweenCov(iris[,1:4], iris[,5]) # between-class covariance matrix (dividing by n) betweenCov(iris[,1:4], iris[,5], div_by_n=TRUE) ## End(Not run)
Calculates between-class sum of squares and cross product matrix (a.k.a. between-class scatter matrix)
betweenSS(variables, group)betweenSS(variables, group)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
group |
vector or factor with group membership (No missing values are allowed) |
Gaston Sanchez
## Not run: # load iris dataset data(iris) # between-class scatter matrix betweenSS(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # load iris dataset data(iris) # between-class scatter matrix betweenSS(iris[,1:4], iris[,5]) ## End(Not run)
Convert a data frame with factors into a super-indicator matrix (a.k.a. complete disjunctive table from the french tableau disjonctive complete)
binarize(variables)binarize(variables)
variables |
data frame with categorical variables (coded as factors) |
A super-indicator matrix of binary data
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
## Not run: # load insurance cars dataset data(insurance) # super-indicator matrix of binary data bin_insure = binarize(insurance[,-1]) head(bin_insure) ## End(Not run)## Not run: # load insurance cars dataset data(insurance) # super-indicator matrix of binary data bin_insure = binarize(insurance[,-1]) head(bin_insure) ## End(Not run)
Quality measures of wines from Bordeaux, France
A data frame with 34 observations on the following 6 variables.
year |
year of harvest |
temperature |
sum of daily average temperatures (in celsius degrees) |
sun |
duration of insolation (in hours) |
heat |
number of super-hot days |
rain |
rain level (in millimeters) |
quality |
wine quality: a factor with levels bad, good, and
medium |
Chapter 10: Analyse Discriminante, page 353.
Tenenhaus M. (2007) Statistique. Dunod, Paris.
## Not run: # load data data(bordeaux) # structure of data str(bordeaux) ## End(Not run)## Not run: # load data data(bordeaux) # structure of data str(bordeaux) ## End(Not run)
Classify provided observations based on a given Discriminant object
classify(DA_object, newdata)classify(DA_object, newdata)
DA_object |
discriminant analysis object |
newdata |
vector or matrix or data frame with variables for which their classes will be calculated |
A DA_object is a discriminant analysis (DA) object
obtained from a geometric predictive DA (class
"geoda"), a linear DA (class "linda"), a
quadratic DA (class "quada"), or a DISQUAL
analysis (class "disqual")
A list with the following elements
scores |
discriminant scores for each observation |
pred_class |
predicted class |
Gaston Sanchez
geoDA, linDA,
quaDA, plsDA,
disqual
## Not run: # load iris dataset data(iris) # linear discriminant analysis my_lin1 = linDA(iris[,1:4], iris$Species) # select a sample of 15 observations set.seed(111) obs = sample(1:nrow(iris), 15) some_data = iris[obs, 1:4] # classify some_data get_classes = classify(my_lin1, some_data) get_classes # compare the results against original class table(iris$Species[obs], get_classes$pred_class) ## End(Not run)## Not run: # load iris dataset data(iris) # linear discriminant analysis my_lin1 = linDA(iris[,1:4], iris$Species) # select a sample of 15 observations set.seed(111) obs = sample(1:nrow(iris), 15) some_data = iris[obs, 1:4] # classify some_data get_classes = classify(my_lin1, some_data) get_classes # compare the results against original class table(iris$Species[obs], get_classes$pred_class) ## End(Not run)
Calculates the correlation ratio between a quantitaive variable and a qualitative variable
corRatio(variable, group)corRatio(variable, group)
variable |
a single quantitative variable |
group |
vector or factor with group memberships (qualitative variable) |
No missing values are allowed
Gaston Sanchez
Tenenhaus, M. (2007) Statistique. Dunod, Paris.
## Not run: # iris dataset data(iris) # correlation ratio between Petal-Length and Species corRatio(iris$Petal.Length, iris$Species) ## End(Not run)## Not run: # iris dataset data(iris) # correlation ratio between Petal-Length and Species corRatio(iris$Petal.Length, iris$Species) ## End(Not run)
Performs a Descriptive Discriminant Analysis (a.k.a. Factorial Discriminant Analysis from the french Analyse Factorielle Discriminante)
desDA(variables, group, covar = "within")desDA(variables, group, covar = "within")
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group memberships |
covar |
character string indicating the covariance
matrix to be used. Options are |
When covar="within" the estimated pooled
within-class covariance matrix is used in the
calculations.
When covar="total" the total
covariance matrix is used in the calculations.
The
difference between covar="within" and
covar="total" is in the obtained eigenvalues.
The estiamted pooled within-class covariance matrix is
actually the within-class covariance matrix divided by
the number of observations minus the number of classes
(see getWithin)
An object of class "desda", basically a list with
the following elements
power |
table with discriminant power of the explanatory variables |
values |
table of eigenvalues |
discrivar |
table of discriminant variables, i.e. the coefficients of the linear discriminant functions |
discor |
table of correlations between the variables and the discriminant axes |
scores |
table of discriminant scores for each observation |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
## Not run: # load bordeaux wines dataset data(bordeaux) # descriptive discriminant analysis with within covariance matrix my_dda1 = desDA(bordeaux[,2:5], bordeaux$quality) my_dda1 # descriptive discriminant analysis with total covariance matrix my_dda2 = desDA(bordeaux[,2:5], bordeaux$quality, covar="total") my_dda2 # plot factor coordinates with ggplot library(ggplot2) bordeaux$f1 = my_dda1$scores[,1] bordeaux$f2 = my_dda1$scores[,2] ggplot(data=bordeaux, aes(x=f1, y=f2, colour=quality)) + geom_hline(yintercept=0, colour="gray70") + geom_vline(xintercept=0, colour="gray70") + geom_text(aes(label=year), size=4) + opts(title="Discriminant Map - Bordeaux Wines (years)") ## End(Not run)## Not run: # load bordeaux wines dataset data(bordeaux) # descriptive discriminant analysis with within covariance matrix my_dda1 = desDA(bordeaux[,2:5], bordeaux$quality) my_dda1 # descriptive discriminant analysis with total covariance matrix my_dda2 = desDA(bordeaux[,2:5], bordeaux$quality, covar="total") my_dda2 # plot factor coordinates with ggplot library(ggplot2) bordeaux$f1 = my_dda1$scores[,1] bordeaux$f2 = my_dda1$scores[,2] ggplot(data=bordeaux, aes(x=f1, y=f2, colour=quality)) + geom_hline(yintercept=0, colour="gray70") + geom_vline(xintercept=0, colour="gray70") + geom_text(aes(label=year), size=4) + opts(title="Discriminant Map - Bordeaux Wines (years)") ## End(Not run)
Measures Discriminant Power of explanatory variables
discPower(variables, group)discPower(variables, group)
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group membership |
No missing values are allowed
A data frame containing the following columns
correl_ratio |
Correlation Ratios |
wilks_lambda |
Wilks Lambda |
F_statistic |
F-statistic |
p_value |
p-value of F-statistic |
Gaston Sanchez
Tenenhaus M. (2007) Statistique. Dunod, Paris.
## Not run: # bordeaux wines dataset data(bordeaux) # discriminant power dp = discPower(bordeaux[,2:5], bordeaux$quality) dp ## End(Not run)## Not run: # bordeaux wines dataset data(bordeaux) # discriminant power dp = discPower(bordeaux[,2:5], bordeaux$quality) dp ## End(Not run)
Implementation of the DISQUAL methodology. Disqual performs a Fishers Discriminant Analysis on components from a Multiple Correspondence Analysis
disqual(variables, group, validation = NULL, learn = NULL, test = NULL, autosel = TRUE, prob = 0.05)disqual(variables, group, validation = NULL, learn = NULL, test = NULL, autosel = TRUE, prob = 0.05)
variables |
data frame with qualitative explanatory variables (coded as factors) |
group |
vector or factor with group memberships |
validation |
type of validation, either
|
learn |
optional vector of indices for a learn-set.
Only used when |
test |
optional vector of indices for a test-set.
Only used when |
autosel |
logical indicating automatic selection of MCA components |
prob |
probability level for automatic selection of
MCA components. Default |
When validation=NULL there is no validation
When validation="crossval" cross-validation is
performed by randomly separating the observations in ten
groups.
When validation="learntest"
validationi is performed by providing a learn-set and a
test-set of observations.
An object of class "disqual", basically a list
with the following elements:
raw_coefs |
raw coefficients of discriminant functions |
norm_coefs |
normalizaed coefficients of discriminant functions, ranging from 0 - 1000 |
confusion |
confusion matrix |
scores |
discriminant scores for each observation |
classification |
assigned class |
error_rate |
misclassification error rate |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
Saporta G. (2006) Probabilites, analyse des donnees et statistique. Editions Technip, Paris.
Saporta G., Niang N. (2006) Correspondence Analysis and Classification. In Multiple Correspondence Analysis and Related Methods, Eds. Michael Greenacre and Jorg Blasius, 371-392. Chapman and Hall/CRC
## Not run: # load insurance dataset data(insurance) # disqual analysis with no validation my_disq1 = disqual(insurance[,-1], insurance[,1], validation=NULL) my_disq1 # disqual analysis with cross-validation my_disq2 = disqual(insurance[,-1], insurance[,1], validation="crossval") my_disq2 ## End(Not run)## Not run: # load insurance dataset data(insurance) # disqual analysis with no validation my_disq1 = disqual(insurance[,-1], insurance[,1], validation=NULL) my_disq1 # disqual analysis with cross-validation my_disq2 = disqual(insurance[,-1], insurance[,1], validation="crossval") my_disq2 ## End(Not run)
Performs a basic Multiple Correspondence Analysis (MCA)
easyMCA(variables)easyMCA(variables)
variables |
data frame with categorical variables (coded as factors) |
An object of class "qualmca", basically a list
with the following elements:
values |
table with eigenvalues |
coefficients |
coefficients of factorial axes |
components |
factor coordinates |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
Saporta G. (2006) Probabilites, analyse des donnees et statistique. Editions Technip, Paris.
## Not run: # load insurance wines dataset data(insurance) # multiple correspondence analysis mca1 = easyMCA(insurance[,-1]) mca1 ## End(Not run)## Not run: # load insurance wines dataset data(insurance) # multiple correspondence analysis mca1 = easyMCA(insurance[,-1]) mca1 ## End(Not run)
Calcualtes the F-statistic between a quantitative variable and a qualitative variable
FRatio(variable, group)FRatio(variable, group)
variable |
a quantitative variable |
group |
a vector or factor with group memberships (i.e. qualitative variable) |
F-statistic and its p-value
Gaston Sanchez
Tenenhaus M. (2007) Statistique. Dunod, Paris.
## Not run: # load bordeaux wines dataset data(bordeaux) # F-statistic ratio between temperature and quality FRatio(bordeaux$temperature, bordeaux$quality) ## End(Not run)## Not run: # load bordeaux wines dataset data(bordeaux) # F-statistic ratio between temperature and quality FRatio(bordeaux$temperature, bordeaux$quality) ## End(Not run)
Performs a Geometric Predictive Discriminant Analysis
geoDA(variables, group, validation = NULL, learn = NULL, test = NULL)geoDA(variables, group, validation = NULL, learn = NULL, test = NULL)
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group memberships |
validation |
type of validation, either
|
learn |
optional vector of indices for a learn-set.
Only used when |
test |
optional vector of indices for a test-set.
Only used when |
When validation=NULL there is no validation
When validation="crossval" cross-validation is
performed by randomly separating the observations in ten
groups.
When validation="learntest"
validationi is performed by providing a learn-set and a
test-set of observations.
An object of class "geoda", basically a list with
the following elements:
functions |
table with discriminant functions |
confusion |
confusion matrix |
scores |
discriminant scores for each observation |
classification |
assigned class |
error_rate |
misclassification error rate |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
Saporta G. (2006) Probabilites, analyse des donnees et statistique. Editions Technip, Paris.
Tuffery S. (2011) Data Mining and Statistics for Decision Making. Wiley, Chichester.
classify, desDA,
linDA, quaDA,
plsDA
## Not run: # load bordeaux wines dataset data(iris) # geometric predictive discriminant analysis with no validation my_geo1 = geoDA(iris[,1:4], iris$Species) my_geo1$confusion my_geo1$error_rate # geometric predictive discriminant analysis with cross-validation my_geo2 = geoDA(iris[,1:4], iris$Species, validation="crossval") my_geo2$confusion my_geo2$error_rate ## End(Not run)## Not run: # load bordeaux wines dataset data(iris) # geometric predictive discriminant analysis with no validation my_geo1 = geoDA(iris[,1:4], iris$Species) my_geo1$confusion my_geo1$error_rate # geometric predictive discriminant analysis with cross-validation my_geo2 = geoDA(iris[,1:4], iris$Species, validation="crossval") my_geo2$confusion my_geo2$error_rate ## End(Not run)
Calculates the estimated within-class covariance matrix
getWithin(variables, group)getWithin(variables, group)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
group |
vector or factor with group memberships (No missing values are allowed) |
The obtained matrix is the estimated within-class
covariance matrix (i.e. within-class covariance matrix
divided by its degrees of freedom n-k, where
n is the number of observations and k is
the number of groups)
Gaston Sanchez
## Not run: # load iris dataset data(iris) # estimated within-class covariance matrix (dividing by n-k) getWithin(iris[,1:4], iris[,5]) # compared to the within-class covariance matrix (dividing by n-1) withinCov(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # load iris dataset data(iris) # estimated within-class covariance matrix (dividing by n-k) getWithin(iris[,1:4], iris[,5]) # compared to the within-class covariance matrix (dividing by n-1) withinCov(iris[,1:4], iris[,5]) ## End(Not run)
Calculates means for each group
groupMeans(variables, group, na.rm = FALSE)groupMeans(variables, group, na.rm = FALSE)
variables |
matrix or data frame with explanatory variables (may contain missing values) |
group |
vector or factor with group memberships |
na.rm |
logical indicating whether missing values should be removed |
matrix of group means (with variables in the rows, and groups in the columns)
Gaston Sanchez
groupVars, groupStds,
groupMedians, groupQuants
## Not run: # dataset iris data(iris) # group means groupMeans(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # dataset iris data(iris) # group means groupMeans(iris[,1:4], iris[,5]) ## End(Not run)
Calculates the medians for each group
groupMedians(variables, group, na.rm = FALSE)groupMedians(variables, group, na.rm = FALSE)
variables |
matrix or data frame with explanatory variables (may contain missing values) |
group |
vector or factor with group memberships |
na.rm |
logical indicating whether missing values should be removed |
matrix of group medians (with variables in the rows, and groups in the columns)
Gaston Sanchez
groupVars, groupStds,
groupMeans, groupQuants
## Not run: # dataset iris data(iris) # group means groupMedians(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # dataset iris data(iris) # group means groupMedians(iris[,1:4], iris[,5]) ## End(Not run)
Calculates the specified quantiles for each group
groupQuants(variables, group, prob, na.rm = FALSE)groupQuants(variables, group, prob, na.rm = FALSE)
variables |
matrix or data frame with explanatory variables (may contain missing values) |
group |
vector or factor with group memberships |
prob |
probability value (numeric value between 0 and 1) |
na.rm |
logical indicating whether missing values should be removed |
matrix of group quantiles (with variables in the rows, and groups in the columns)
Gaston Sanchez
groupMeans, groupVars,
groupStds, groupMedians
## Not run: # dataset iris data(iris) # group quantile prob=20 groupQuants(iris[,1:4], iris[,5], prob=0.20) ## End(Not run)## Not run: # dataset iris data(iris) # group quantile prob=20 groupQuants(iris[,1:4], iris[,5], prob=0.20) ## End(Not run)
Calculates the standard deviations for each group
groupStds(variables, group, na.rm = FALSE)groupStds(variables, group, na.rm = FALSE)
variables |
matrix or data frame with explanatory variables (may contain missing values) |
group |
vector or factor with group memberships |
na.rm |
logical indicating whether missing values should be removed |
matrix of group standard deviations (with variables in the rows, and groups in the columns)
Gaston Sanchez
groupMeans, groupVars,
groupMedians, groupQuants
## Not run: # dataset iris data(iris) # group standard deviations groupStds(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # dataset iris data(iris) # group standard deviations groupStds(iris[,1:4], iris[,5]) ## End(Not run)
Calculates the variances for each group
groupVars(variables, group, na.rm = FALSE)groupVars(variables, group, na.rm = FALSE)
variables |
matrix or data frame with explanatory variables (may contain missing values) |
group |
vector or factor with group memberships |
na.rm |
logical indicating whether missing values should be removed |
matrix of group variances (with variables in the rows, and groups in the columns)
Gaston Sanchez
groupMeans, groupStds,
groupMedians, groupQuants
## Not run: # dataset iris data(iris) # group variances groupVars(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # dataset iris data(iris) # group variances groupVars(iris[,1:4], iris[,5]) ## End(Not run)
Infarctus dataset from Saporta (2006)
A data frame with 101 observations on the following 8 variables.
FRCAR |
Frequence Cardiaque (i.e. heart rate) |
INCAR |
Index Cardique (cardiac index) |
INSYS |
Index Systolique (systolic index) |
PRDIA |
Pression Diastolique (diastolic pressure) |
PAPUL |
Pression Arterielle Pulmonaire (pulmonary artery pressure) |
PVENT |
Pression Ventriculaire (ventricular pressure) |
REPUL |
Resistance Pulmonaire (pulmonary resistance) |
PRONO |
Pronostic (prognosis): a factor with levels
dead and survive |
Chapter 18: Analyse discriminante et regression
logistique, pp 453-454
Saporta G. (2006)
Probabilites, analyse des donnees et statistique.
Editions Technip, Paris.
## Not run: # load data data(infarctus) # summary of variables summary(infarctus) ## End(Not run)## Not run: # load data data(infarctus) # summary of variables summary(infarctus) ## End(Not run)
Dataset of car-insurance customers from Belgium in 1992
A data frame with 1106 observations on the following 10 variables.
Claims |
Group variable. A factor with levels
bad and good
|
Use |
Type of Use. A factor with
levels private and professional
|
Type |
Insurance
Type. A factor with levels companies, female, and
male
|
Language |
Language. A factor with levels
flemish and french
|
BirthCohort |
Birth Cohort. A
factor with levels BD_1890_1949, BD_1950_1973, and
BD_unknown
|
Region |
Geographic Region. A factor with
levels Brussels and Other_regions
|
BonusMalus |
Level of bonus-malus. A factor with levels BM_minus and
BM_plus
|
YearSuscrip |
Year of Subscription. A factor
with levels YS<86 and YS>=86
|
Horsepower |
Horsepower. A factor with levels HP<=39 and HP>=40
|
YearConstruc |
Year of vehicle construction. A factor with levels
YC_33_89 and YC_90_91 |
Dataset for DISQUAL method
Saporta G., Niang N. (2006) Correspondence Analysis and Classification. In Multiple Correspondence Analysis and Related Methods, M. Greenacre and J. Blasius, Eds., pp 371-392. Chapman & Hall/CRC, Boca Raton, Florida, USA.
## Not run: # load data data(insurance) # structure str(insurance) ## End(Not run)## Not run: # load data data(insurance) # structure str(insurance) ## End(Not run)
Performs a Linear Discriminant Analysis
linDA(variables, group, prior = NULL, validation = NULL, learn = NULL, test = NULL, prob = FALSE)linDA(variables, group, prior = NULL, validation = NULL, learn = NULL, test = NULL, prob = FALSE)
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group memberships |
prior |
optional vector of prior probabilities.
Default |
validation |
type of validation, either
|
learn |
optional vector of indices for a learn-set.
Only used when |
test |
optional vector of indices for a test-set.
Only used when |
prob |
logical indicating whether the group classification results should be expressed in probability terms |
When validation=NULL there is no validation
When validation="crossval" cross-validation is
performed by randomly separating the observations in ten
groups.
When validation="learntest" validation
is performed by providing a learn-set and a test-set of
observations.
An object of class "linda", basically a list with
the following elements:
functions |
table with discriminant functions |
confusion |
confusion matrix |
scores |
discriminant scores for each observation |
classification |
assigned class |
error_rate |
misclassification error rate |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
Saporta G. (2006) Probabilites, analyse des donnees et statistique. Editions Technip, Paris.
Tuffery S. (2011) Data Mining and Statistics for Decision Making. Wiley, Chichester.
classify, desDA,
geoDA, quaDA,
plsDA
## Not run: # load iris dataset data(iris) # linear discriminant analysis with no validation my_lin1 = linDA(iris[,1:4], iris$Species) my_lin1$confusion my_lin1$error_rate # linear discriminant analysis with cross-validation my_lin2 = linDA(iris[,1:4], iris$Species, validation="crossval") my_lin2$confusion my_lin2$error_rate # linear discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_lin3 = linDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_lin3$confusion my_lin3$error_rate ## End(Not run)## Not run: # load iris dataset data(iris) # linear discriminant analysis with no validation my_lin1 = linDA(iris[,1:4], iris$Species) my_lin1$confusion my_lin1$error_rate # linear discriminant analysis with cross-validation my_lin2 = linDA(iris[,1:4], iris$Species, validation="crossval") my_lin2$confusion my_lin2$error_rate # linear discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_lin3 = linDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_lin3$confusion my_lin3$error_rate ## End(Not run)
Performs a Partial Least Squares (PLS) Discriminant Analysis by giving the option to include a random leave-k fold out cross validation
plsDA(variables, group, autosel = TRUE, comps = 2, validation = NULL, learn = NULL, test = NULL, cv = "LOO", k = NULL, retain.models = FALSE)plsDA(variables, group, autosel = TRUE, comps = 2, validation = NULL, learn = NULL, test = NULL, cv = "LOO", k = NULL, retain.models = FALSE)
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group memberships |
autosel |
logical indicating automatic selection of
PLS components by cross-validation. Default
|
comps |
integer greater than one indicating the
number of PLS components to retain. Used only when
|
validation |
type of validation, either |
learn |
optional vector of indices for a learn-set.
Only used when |
test |
optional vector of indices for a test-set.
Only used when |
cv |
string indicating the type of crossvalidation.
Avialable options are |
k |
fold left out if using LKO (usually 7 or 10) |
retain.models |
whether to retain lower models (i.e. all lower component results) |
When validation=NULL leave-one-out (loo)
cross-validation is performed.
When
validation="learntest" validation is performed by
providing a learn-set and a test-set of observations.
An object of class "plsda", basically a list with
the following elements:
functions |
table with discriminant functions |
confusion |
confusion matrix |
scores |
discriminant scores for each observation |
loadings |
loadings |
y.loadings |
y loadings |
classification |
assigned class |
error_rate |
misclassification error rate |
components |
PLS components |
Q2 |
quality of loo cross-validation |
R2 |
R-squared coefficients |
VIP |
Variable Importance for Projection |
comp_vars |
correlations between components and variables |
comp_group |
correlations between components and groups |
Charles Determan Jr, Gaston Sanchez
Tenenhaus M. (1998) La Regression PLS. Editions Technip, Paris.
Perez-Enciso M., Tenenhaus M. (2003) Prediction of clinical outcome with microarray data: a partial least squares discriminant analysis (PLS-DA) approach. Human Genetics 112: 581-592.
## Not run: # load iris dataset data(iris) # PLS discriminant analysis specifying number of components = 2 my_pls1 = plsDA(iris[,1:4], iris$Species, autosel=FALSE, comps=2) my_pls1$confusion my_pls1$error_rate # plot circle of correlations plot(my_pls1) # PLS discriminant analysis with automatic selection of components my_pls2 = plsDA(iris[,1:4], iris$Species, autosel=TRUE) my_pls2$confusion my_pls2$error_rate # linear discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_pls3 = plsDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_pls3$confusion my_pls3$error_rate ## End(Not run)## Not run: # load iris dataset data(iris) # PLS discriminant analysis specifying number of components = 2 my_pls1 = plsDA(iris[,1:4], iris$Species, autosel=FALSE, comps=2) my_pls1$confusion my_pls1$error_rate # plot circle of correlations plot(my_pls1) # PLS discriminant analysis with automatic selection of components my_pls2 = plsDA(iris[,1:4], iris$Species, autosel=TRUE) my_pls2$confusion my_pls2$error_rate # linear discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_pls3 = plsDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_pls3$confusion my_pls3$error_rate ## End(Not run)
Performs a Quadratic Discriminant Analysis
quaDA(variables, group, prior = NULL, validation = NULL, learn = NULL, test = NULL, prob = FALSE)quaDA(variables, group, prior = NULL, validation = NULL, learn = NULL, test = NULL, prob = FALSE)
variables |
matrix or data frame with explanatory variables |
group |
vector or factor with group memberships |
prior |
optional vector of prior probabilities.
Default |
validation |
type of validation, either
|
learn |
optional vector of indices for a learn-set.
Only used when |
test |
optional vector of indices for a test-set.
Only used when |
prob |
logical indicating whether the group classification results should be expressed in probability terms |
When validation=NULL there is no validation
When validation="crossval" cross-validation is
performed by randomly separating the observations in ten
groups.
When validation="learntest"
validationi is performed by providing a learn-set and a
test-set of observations.
An object of class "quada", basically a list with
the following elements:
confusion |
confusion matrix |
scores |
discriminant scores for each observation |
classification |
assigned class |
error_rate |
misclassification error rate |
Gaston Sanchez
Lebart L., Piron M., Morineau A. (2006) Statistique Exploratoire Multidimensionnelle. Dunod, Paris.
Tenenhaus G. (2007) Statistique. Dunod, Paris.
Tuffery S. (2011) Data Mining and Statistics for Decision Making. Wiley, Chichester.
classify, desDA,
geoDA, linDA,
plsDA
## Not run: # load iris dataset data(iris) # quadratic discriminant analysis with no validation my_qua1 = quaDA(iris[,1:4], iris$Species) my_qua1$confusion my_qua1$error_rate # quadratic discriminant analysis with cross-validation my_qua2 = quaDA(iris[,1:4], iris$Species, validation="crossval") my_qua2$confusion my_qua2$error_rate # quadratic discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_qua3 = quaDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_qua3$confusion my_qua3$error_rate ## End(Not run)## Not run: # load iris dataset data(iris) # quadratic discriminant analysis with no validation my_qua1 = quaDA(iris[,1:4], iris$Species) my_qua1$confusion my_qua1$error_rate # quadratic discriminant analysis with cross-validation my_qua2 = quaDA(iris[,1:4], iris$Species, validation="crossval") my_qua2$confusion my_qua2$error_rate # quadratic discriminant analysis with learn-test validation learning = c(1:40, 51:90, 101:140) testing = c(41:50, 91:100, 141:150) my_qua3 = quaDA(iris[,1:4], iris$Species, validation="learntest", learn=learning, test=testing) my_qua3$confusion my_qua3$error_rate ## End(Not run)
Calculates total covariance matrix
totalCov(variables, div_by_n = FALSE)totalCov(variables, div_by_n = FALSE)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
div_by_n |
logical indicating division by number of observations |
When div_by_n=TRUE the covariance matrices are
divided by n (number of observations), otherwise they are
divided by n-1
Gaston Sanchez
totalSS, betweenCov,
withinCov
## Not run: # load iris dataset data(iris) # total covariance matrix (dividing by n-1) totalCov(iris[,1:4]) # total covariance matrix (dividing by n) totalCov(iris[,1:4], div_by_n=TRUE) ## End(Not run)## Not run: # load iris dataset data(iris) # total covariance matrix (dividing by n-1) totalCov(iris[,1:4]) # total covariance matrix (dividing by n) totalCov(iris[,1:4], div_by_n=TRUE) ## End(Not run)
Calculates the total sum of squares and cross product matrix (a.k.a. total scatter matrix)
totalSS(variables)totalSS(variables)
variables |
matrix or data frame with explanatory variables |
Gaston Sanchez
## Not run: # load iris dataset data(iris) # total scatter matrix totalSS(iris[,1:4]) ## End(Not run)## Not run: # load iris dataset data(iris) # total scatter matrix totalSS(iris[,1:4]) ## End(Not run)
Calculates the within-class covariance matrix
withinCov(variables, group, div_by_n = FALSE)withinCov(variables, group, div_by_n = FALSE)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
group |
vector or factor with group memberships (No missing values are allowed) |
div_by_n |
logical indicating division by number of observations |
When div_by_n=TRUE the covariance matrices are
divided by n (number of observations), otherwise they are
divided by n-1
Gaston Sanchez
withinSS, betweenCov,
totalCov
## Not run: # load iris dataset data(iris) # within-class covariance matrix (dividing by n-1) withinCov(iris[,1:4], iris[,5]) # within-class covariance matrix (dividing by n) withinCov(iris[,1:4], iris[,5], div_by_n=TRUE) ## End(Not run)## Not run: # load iris dataset data(iris) # within-class covariance matrix (dividing by n-1) withinCov(iris[,1:4], iris[,5]) # within-class covariance matrix (dividing by n) withinCov(iris[,1:4], iris[,5], div_by_n=TRUE) ## End(Not run)
Calculates within-class sum of squares and cross product matrix (a.k.a. within-class scatter matrix)
withinSS(variables, group)withinSS(variables, group)
variables |
matrix or data frame with explanatory variables (No missing values are allowed) |
group |
vector or factor with group memberships (No missing values are allowed) |
Gaston Sanchez
## Not run: # load iris dataset data(iris) # within-class scatter matrix withinSS(iris[,1:4], iris[,5]) ## End(Not run)## Not run: # load iris dataset data(iris) # within-class scatter matrix withinSS(iris[,1:4], iris[,5]) ## End(Not run)