Learn R Programming

teigen (version 2.2.2)

predict.teigen: predict.teigen: Predicting Function for tEIGEN Objects

Description

Provides the fuzzy probability matrix and classification vector for inputted observations assuming the model provided by the teigen object.

Usage

# S3 method for teigen
predict(object, newdata=NULL, modelselect="BIC", …)

Arguments

object

An object of class teigen

newdata

Data frame or matrix of new observations on the same variables used in the fitting of the teigen object. For predicting one observation, a vector is permitted. If NULL, then the observations used in the fitting of the teigen object are inputted.

modelselect

A character string of either "BIC" (default) or "ICL" indicating the desired model-selection criteria to apply to the teigen object.

Arguments to be passed to other functions.

Value

fuzzy

Matrix of fuzzy classification probabilities

classification

Vector of maximum a posteriori classifications

Details

Note that the scale argument from the teigen object is passed along to the predictfunction. See examples below for plotting.

See Also

teigen

Examples

Run this code
# NOT RUN {
set.seed(2521)
ind <- sample(1:nrow(faithful), 20)
set.seed(256)
tfaith_unscaled <- teigen(faithful[-ind,], models = "UUUU", Gs = 2, verbose = FALSE, scale=FALSE)
pred_unscaled <- predict(tfaith_unscaled, faithful[ind,])
set.seed(256)
tfaith_scaled <- teigen(faithful[-ind,], models = "UUUU", Gs = 2, verbose = FALSE, scale=TRUE)
pred_scaled <- predict(tfaith_scaled, faithful[ind,])
identical(pred_unscaled$classification, pred_scaled$classification)

##Plotting UNSCALED
plot(tfaith_unscaled, what="contour")
points(faithful[ind,1], faithful[ind,2], pch=15)
plotcolours <- rainbow(tfaith_unscaled$G)
points(faithful[ind,1], faithful[ind,2], pch=20, col=plotcolours[pred_unscaled$classification])

##Plotting SCALED
plot(tfaith_scaled, what="contour")
points((faithful[ind,1]-tfaith_scaled$info$scalemeans[1])/tfaith_scaled$info$scalesd[1],
       (faithful[ind,2]-tfaith_scaled$info$scalemeans[2])/tfaith_scaled$info$scalesd[2],
       pch=15)
plotcolours <- rainbow(tfaith_scaled$G)
points((faithful[ind,1]-tfaith_scaled$info$scalemeans[1])/tfaith_scaled$info$scalesd[1],
       (faithful[ind,2]-tfaith_scaled$info$scalemeans[2])/tfaith_scaled$info$scalesd[2],
       pch=20, col=plotcolours[pred_scaled$classification])

# }

Run the code above in your browser using DataLab