loclda function

Localized Linear Discriminant Analysis (LocLDA)

Localized Linear Discriminant Analysis (LocLDA)

A localized version of Linear Discriminant Analysis. latin1

loclda(x, ...) ## S3 method for class 'formula' loclda(formula, data, ..., subset, na.action) ## Default S3 method: loclda(x, grouping, weight.func = function(x) 1/exp(x), k = nrow(x), weighted.apriori = TRUE, ...) ## S3 method for class 'data.frame' loclda(x, ...) ## S3 method for class 'matrix' loclda(x, grouping, ..., subset, na.action)

Arguments

  • formula: Formula of the form ‘groups ~ x1 + x2 + ...’ .

  • data: Data frame from which variables specified in formula are to be taken.

  • x: Matrix or data frame containing the explanatory variables (required, if formula is not given).

  • grouping: (required if no formula principal argument is given.) A factor specifying the class for each observation.

  • weight.func: Function used to compute local weights. Must be finite over the interval [0,1]. See Details below.

  • k: Number of nearest neighbours used to construct localized classification rules. See Details below.

  • weighted.apriori: Logical: if TRUE, class prior probabilities are computed using local weights (see Details below). If FALSE, equal priors for all classes actually occurring in the train data are used.

  • subset: An index vector specifying the cases to be used in the training sample.

  • na.action: A function to specify the action to be taken if NAs are found. The default action is for the procedure to fail. An alternative is na.omit

    which leads to rejection of cases with missing values on any required variable.

  • ...: Further arguments to be passed to loclda.default.

Details

This is an approach to apply the concept of localization described by Tutz and Binder (2005) to Linear Discriminant Analysis. The function loclda generates an object of class loclda

(see Value below). As localization makes it necessary to build an individual decision rule for each test observation, this rule construction has to be handled by predict.loclda. For convenience, the rule building procedure is still described here.

To classify a test observation xsx_s, only the k nearest neighbours of xsx_s within the train data are used. Each of these k train observations xi,i=1,...,kx_i, i=1,...,k, is assigned a weight wiw_i according to

wi=K(xixsdk),i=1,,kwi:=K(xixs/dk),i=1,...,k, w_i = K\left(\frac{||x_i-x_s||}{d_k}\right), i=1,\dots,kw_i := K ( ||x_i - x_s|| / d_k ), i=1,...,k,

where K is the weighting function given by weight.func, xixs||x_i - x_s||

is the euclidian distance of xix_i and xsx_s

and dkd_k is the euclidian distance of xsx_s

to its kk-th nearest neighbour. With these weights for each class Ag,g=1,...,GA_g, g=1,...,G, its weighted empirical mean mu_g_hat and weighted empirical covariance matrix are computed. The estimated pooled (weighted) covariance matrix SigmahatSigma_hat is then calculated from the individual weighted empirical class covariance matrices. If weighted.apriori is TRUE (the default), prior class probabilities are estimated according to:

priorg:=i=1k(wiI(xiAg))i=1k(wi)priorg:=[Sumi=1,..,k(wiI(xiinAg))]/[Sumi=1,...,k(wi)],g=1,...,G, prior_g := \frac{\sum_{i=1}^k \left(w_i \cdot I (x_i \in A_g)\right)}{\sum_{i=1}^k \left( w_i \right)}prior_g := [ Sum_{i=1,..,k} ( w_i * I(x_i in A_g) ) ] / [ Sum_{i=1,...,k} ( w_i ) ], g = 1,...,G,

where I is the indicator function. If FALSE, equal priors for all classes are used. In analogy to Linear Discriminant Analysis, the decision rule for xsx_s is

A^:=argmaxg1,,G(posteriorg)Ahat:=argmaxgin1,...,G(posteriorg), \hat{A} := argmax_{g \in 1,\dots,G} (posterior_g)A_hat := argmax_{g in 1,...,G} (posterior_g),

where

posterior_g := prior_g \cdot \exp{\left( (-\frac{1}{2}) t(x_s-\hat{\mu}_g)\hat{\Sigma}^{-1}(x_s-\hat{\mu}_g)\right)}posterior_g := prior_g * exp [ (-1/2) * t( x_s - mu_g_hat ) * Sigma_hat^(-1) * ( x_s - mu_g_hat ) ] .

If posteriorg<1e150forallgin1,...,Gposterior_g < 1e-150 for all g in 1,...,G, posteriorgposterior_g is set to 1/G1/G for all gin1,...,Gg in 1,...,G

and the test observation xsx_s is simply assigned to the class whose weighted mean has the lowest euclidian distance to xsx_s.

Returns

A list of class loclda containing the following components: - call: The (matched) function call.

  • learn: Matrix containing the values of the explanatory variables for all train observations.

  • grouping: Factor specifying the class for each train observation.

  • weight.func: Value of the argument weight.func.

  • k: Value of the argument k.

  • weighted.apriori: Value of the argument weighted.apriori.

References

Tutz, G. and Binder, H. (2005): Localized classification. Statistics and Computing 15, 155-166.

Author(s)

Marc Zentgraf (marc-zentgraf@gmx.de ) and Karsten Luebke (karsten.luebke@fom.de )

See Also

predict.loclda, lda

Examples

benchB3("lda")$l1co.error benchB3("loclda")$l1co.error