Classify matrix variate observations in conjunction with matrixqda.

# S3 method for matrixqda
predict(object, newdata, prior = object$prior, ...)

Arguments

object

object of class matrixqda

newdata

array or list of new observations to be classified. If newdata is missing, an attempt will be made to retrieve the data used to fit the matrixqda object.

prior

The prior probabilities of the classes, by default the proportions in the training set or what was set in the call to matrixqda.

...

arguments based from or to other methods

Value

Returns a list containing the following components:

class

The MAP classification (a factor)

posterior

posterior probabilities for the classes

Details

This function is a method for the generic function predict() for class "matrixqda". It can be invoked by calling predict(x) for an object x of the appropriate class.

See also

Examples


set.seed(20180221)
# construct two populations of 3x4 random matrices with different means
A <- rmatrixnorm(30, mean = matrix(0, nrow = 3, ncol = 4))
B <- rmatrixnorm(30, mean = matrix(1, nrow = 3, ncol = 4))
C <- array(c(A, B), dim = c(3, 4, 60)) # combine together
groups <- c(rep(1, 30), rep(2, 30)) # define groups
prior <- c(.5, .5) # set prior
D <- matrixqda(C, groups, prior) # fit model
predict(D)$posterior[1:10, ] # predict, show results of first 10
#>            [,1]         [,2]
#>  [1,] 0.9999992 8.354945e-07
#>  [2,] 0.6689069 3.310931e-01
#>  [3,] 0.9999807 1.934361e-05
#>  [4,] 0.9999978 2.172959e-06
#>  [5,] 0.9988560 1.144023e-03
#>  [6,] 0.8339787 1.660213e-01
#>  [7,] 0.9999852 1.481745e-05
#>  [8,] 0.9999996 4.176989e-07
#>  [9,] 0.9167050 8.329505e-02
#> [10,] 0.9869554 1.304462e-02
## S3 method for class "matrixqda"