predict.PLNLDAfit: Predict group of new samples

Description Usage Arguments Value Examples

View source: R/PLNLDAfit-S3methods.R

Description

Predict group of new samples

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'PLNLDAfit'
predict(
  object,
  newdata,
  type = c("posterior", "response", "scores"),
  scale = c("log", "prob"),
  prior = NULL,
  control = list(),
  ...
)

Arguments

object

an R6 object with class PLNLDAfit

newdata

A data frame in which to look for variables, offsets and counts with which to predict.

type

The type of prediction required. The default are posterior probabilities for each group (in either unnormalized log-scale or natural probabilities, see "scale" for details), "response" is the group with maximal posterior probability and "scores" is the average score along each separation axis in the latent space, with weights equal to the posterior probabilities.

scale

The scale used for the posterior probability. Either log-scale ("log", default) or natural probabilities summing up to 1 ("prob").

prior

User-specified prior group probabilities in the new data. If NULL (default), prior probabilities are computed from the learning set.

control

a list for controlling the optimization. See PLN() for details.

...

additional parameters for S3 compatibility. Not used

Value

A matrix of posterior probabilities for each group (if type = "posterior"), a matrix of (average) scores in the latent space (if type = "scores") or a vector of predicted groups (if type = "response").

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data(trichoptera)
trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate)
myLDA <- PLNLDA(Abundance ~ 0 + offset(log(Offset)),
                grouping = Group,
                data = trichoptera)
## Not run: 
post_probs <- predict(myLDA, newdata = trichoptera, type = "posterior", scale = "prob")
head(round(post_probs, digits = 3))
predicted_group <- predict(myLDA, newdata = trichoptera, type = "response")
table(predicted_group, trichoptera$Group, dnn = c("predicted", "true"))

## End(Not run)

PLNmodels documentation built on March 16, 2021, 5:07 p.m.