View source: R/misc_functions.R
guess_polr | R Documentation |
This function generates predictions from a polr (proportional odds logistic regression) model for ordinal data. It computes the linear predictor from the input data.table using the model matrix of the provided polr object, applies the logistic transformation to the model thresholds, and determines the predicted category as the sum of thresholds that are less than a reference value. The predicted ordinal outcome replaces the original outcome column in the data.table.
guess_polr(dtb, polr_obj)
dtb |
A data.table containing the predictor variables used for prediction and a column with a name corresponding to the outcome variable prefixed with 'rank_'. |
polr_obj |
An object of class |
This function requires the MASS
and matrixStats
packages.
The function modifies the input data.table dtb
in place by replacing the outcome column with the predicted
ordinal category. It returns NULL
invisibly.
## Not run:
library(MASS)
library(matrixStats)
library(data.table)
# Assuming polr_model is a fitted polr object and dtb is your data.table with predictors and a column named, for example, 'rank_y'
guess_polr(dtb, polr_model)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.