View source: R/PLNLDAfit-S3methods.R
predict.PLNLDAfit | R Documentation |
Predict group of new samples
## S3 method for class 'PLNLDAfit'
predict(
object,
newdata,
type = c("posterior", "response", "scores"),
scale = c("log", "prob"),
prior = NULL,
control = PLN_param(backend = "nlopt"),
...
)
object |
an R6 object with class |
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 |
... |
additional parameters for S3 compatibility. Not used |
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").
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.