predict.fda: Classify by Flexible Discriminant Analysis

Description Usage Arguments Value See Also Examples

View source: R/predict.fda.R

Description

Classify observations in conjunction with fda.

Usage

1
2
## S3 method for class 'fda'
predict(object, newdata, type, prior, dimension, ...)

Arguments

object

an object of class "fda".

newdata

new data at which to make predictions. If missing, the training data is used.

type

kind of predictions: type = "class" (default) produces a fitted factor, type = "variates" produces a matrix of discriminant (canonical) variables, type = "posterior" produces a matrix of posterior probabilities (based on a gaussian assumption), and type = "hierarchical" produces the predicted class in sequence for models of all dimensions.

prior

the prior probability vector for each class; the default is the training sample proportions.

dimension

the dimension of the space to be used, no larger than the dimension component of object.

...

further arguments to be passed to or from methods.

Value

An appropriate object depending on type. object has a component fit which is regression fit produced by the method argument to fda. There should be a predict method for this object which is invoked. This method should itself take as input object and optionally newdata.

See Also

fda, mars, bruto, polyreg, softmax, confusion

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
data(iris)
irisfit <- fda(Species ~ ., data = iris)
irisfit
## Call:
## fda(x = iris$x, g = iris$g)
## 
## Dimension: 2 
##
## Percent Between-Group Variance Explained:
##     v1  v2 
##  99.12 100
confusion(predict(irisfit, iris), iris$Species)
##            Setosa Versicolor Virginica
##     Setosa     50          0         0
## Versicolor      0         48         1
##  Virginica      0          2        49
## attr(, "error"):
## [1] 0.02

Example output

Loading required package: class
Loaded mda 0.4-9

Call:
fda(formula = Species ~ ., data = iris)

Dimension: 2 

Percent Between-Group Variance Explained:
    v1     v2 
 99.12 100.00 

Degrees of Freedom (per dimension): 5 

Training Misclassification Error: 0.02 ( N = 150 )
            true
predicted    setosa versicolor virginica
  setosa         50          0         0
  versicolor      0         48         1
  virginica       0          2        49

mda documentation built on Nov. 17, 2017, 4:26 a.m.

Related to predict.fda in mda...