guess_polr: Predict ordinal outcomes from a polr model

View source: R/misc_functions.R

guess_polrR Documentation

Predict ordinal outcomes from a polr model

Description

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.

Usage

guess_polr(dtb, polr_obj)

Arguments

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 polr from the MASS package representing the fitted ordinal regression model.

Details

This function requires the MASS and matrixStats packages.

Value

The function modifies the input data.table dtb in place by replacing the outcome column with the predicted ordinal category. It returns NULL invisibly.

Examples

## 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)

ChristK/CKutils documentation built on April 11, 2025, 10:11 p.m.