prep.lda: Linear discriminant function for lm.rrpp model fits

View source: R/prep.lda.r

prep.ldaR Documentation

Linear discriminant function for lm.rrpp model fits

Description

Function creates arguments for lda or qda from a lm.rrpp fit.

Usage

prep.lda(
  fit,
  tol = 1e-07,
  PC.no = NULL,
  newdata = NULL,
  inherent.groups = FALSE,
  ...
)

Arguments

fit

A linear model fit using lm.rrpp.

tol

A tolerance used to decide if the matrix of data is singular. This value is passed onto both lda and prcomp, internally.

PC.no

An optional argument to define the specific number of principal components (PC) used in analysis. The minimum of this value or the number of PCs resulting from the tol argument will be used.

newdata

An optional matrix (or object coercible to a matrix) for classification. If NULL, all observed data are used.

inherent.groups

A logical argument in case one wishes to have the inherent groups in the model fit revealed. If TRUE, no other analysis will be done than to reveal the groups. This argument should always be FALSE to perform a classification analysis.

...

Arguments passed to lda. See lda for details

Details

This function uses a lm.rrpp fit to produce the data and the groups to use in lda or qda.There are two general purposes of this function that are challenging when using lda, directly. First, this function finds the inherent groups in the lm.rrpp fit, based on factor levels. Second, this function find pseudodata - rather than the observed data - that involve either or both a principal component projection with appropriate (or user-prescribed) dimensions and a transformation. The principal component projection incorporates GLS mean-centering, where appropriate. Transformation involves holding non-grouping model terms constant. This is accomplished by using the fitted values from the lm.rrpp fit and the residuals of a lm.rrpp fit with grouping factors, alone. When, the lm.rrpp fit contains only grouping factors, this function produces raw data projected on principal components.

Regardless of variables input, data are projected onto PCs. The purpose of this function is to predict group association, and working in PC space facilitates this objective.

This is a new function and not all limits and scenarios have been tested before its release. Please report any issues or limitations or strange results to the maintainer.

Notes for RRPP 0.5.0 and subsequent versions

Prior to version 0.5.0, the function, classify, was available. This function has been deprecated. It mimicked lda with added features that are largely retained with prep.lda. However, prep.lda facilitates the much more diverse options available with lda.

Value

A list of arguments that can be passed to lda. As a minimum, these arguments include $x, $grouping, and $tol. If newdata is not NULL, $newdata, using the same transformation and PCs as for the data, will also be included.

Author(s)

Michael Collyer

See Also

lda, predict.lda, qda, predict.qda

Examples


# Using the Pupfish data (see lm.rrpp help for more detail)

data(Pupfish)
Pupfish$logSize <- log(Pupfish$CS) 
fit <- lm.rrpp(coords ~ logSize + Sex * Pop, SS.type = "I", 
data = Pupfish, print.progress = FALSE, iter = 0)

prep.lda(fit, inherent.groups = TRUE) # see groups available
lda.args <- prep.lda(fit, CV = TRUE, PC.no = 6)
lda.args$x
lda.args$grouping

# not run:
# library(MASS)
# LDA <- do.call(lda, lda.args)
# LDA$posterior
# table(lda.args$grouping, LDA$class)


RRPP documentation built on Aug. 16, 2023, 1:06 a.m.