predict.gendis: Predict function using a generalized discriminant function

View source: R/predict.gendis.r

predict.gendisR Documentation

Predict function using a generalized discriminant function

Description

predict.gendis applies a generalized discriminant function created with gendis to predict the sex (class) of each individual with measurements in newdata. From the gendis object, the coefficients that define the generalized discriminant function (GDF) are applied to the newdata to obtain the discriminant scores.

Usage

## S3 method for class 'gendis'
predict(object, newdata, type = object$sex, verbose = FALSE, ...)

Arguments

object

an object of class gendis, typically created with gendis

newdata

a data frame with measurements on (new) individuals with variables used to create object. The data should be from a single population. If your data are from multiple populations, use predict for each subset (i.e. for each population).

type

what to predict: the sex or class of each individual (default), the generalized discriminant scores with cutpoint ("GDF" or "GDFscore") or the full output of the unmixing algorithm unmix ("cutpoint")

verbose

logical (default = FALSE). If TRUE a plot of the density of the GDF is produced.

...

other optional arguments

Details

The discriminant score are a linear combination of the variables in newdata that are shared with the variables used to create the object. The linear combination is defined by the GDF coefficients. The discriminant scores are subjected to an unmixing algorithm. This algorithm (unmix) generates a cutpoint below which individuals are predicted to be female (level 1 of factor(sex)) and above which they are predicted to be male (level 2 of factor(sex)). The cutpoint is at the point of intersection of two normal densities with unequal means and variances fitted to the discriminant scores (see unmix for details).

Value

See argument type.

References

van Franeker, J A. ter Braak, C J F. 1993. A generalized discriminant for sexing fulmarine petrels from external measurements. The Auk 110: pp 492-502, https://doi.org/10.2307/4088413 https://edepot.wur.nl/249350

Examples

data("fulmarin")
str(fulmarin)
result <- gendis(population = "population", sex = "sex",
                 measurements = "other_variables", verbose = FALSE ,  data=fulmarin )
data("JanMayenBirds")
sex.predict <- predict(result, newdata = JanMayenBirds, verbose = TRUE)
# one false prediction: (number 32)
data.frame(sex = JanMayenBirds$DISSEX,  sex.predict)[seq(from=2, to = 37, by =5),]

predict(result, JanMayenBirds )
# same as default above
predict(result, JanMayenBirds, type = result$sex, verbose = FALSE)
# GDF score with cutpoint
predict(result, JanMayenBirds, type = "GDF", verbose = FALSE)
# unmix results only
predict(result, JanMayenBirds, type = "cutpoint", verbose = TRUE)




CajoterBraak/Gendis2unmix documentation built on Aug. 5, 2023, 1:36 p.m.