R/matnormlda.R
predict.matrixlda.Rd
Classify matrix variate observations in conjunction with matrixlda
.
# S3 method for matrixlda predict(object, newdata, prior = object$prior, ...)
object | object of class |
---|---|
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 |
prior | The prior probabilities of the classes, by default the
proportions in the training set or what was set in the call to
|
... | arguments based from or to other methods |
Returns a list containing the following components:
class
The MAP classification (a factor)
posterior
posterior probabilities for the classes
This function is a method for the generic function predict()
for
class "matrixlda
". It can be invoked by calling predict(x)
for
an object x
of the appropriate class.
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 <- matrixlda(C, groups, prior) predict(D)$posterior[1:10, ] #> [,1] [,2] #> [1,] 0.9999948 5.224846e-06 #> [2,] 0.6942637 3.057363e-01 #> [3,] 0.9999813 1.869044e-05 #> [4,] 0.9999984 1.602533e-06 #> [5,] 0.9993887 6.113309e-04 #> [6,] 0.8503901 1.496099e-01 #> [7,] 0.9999956 4.433919e-06 #> [8,] 0.9999997 2.543128e-07 #> [9,] 0.7600474 2.399526e-01 #> [10,] 0.9535620 4.643805e-02 ## S3 method for class 'matrixlda'