Package 'ordinalGOF'

Title: Goodness-of-Fit Tests for Ordinal Regression Models
Description: Provides goodness-of-fit tests for ordinal regression models, including the Fagerland-Hosmer ordinal test, reproducing same output as Stata. Supports polr(), vglm(), and binary glm() models.
Authors: Oluwafunto Aladekomo [aut, cre], Evan Kwiatkowski [aut]
Maintainer: Oluwafunto Aladekomo <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-05-25 09:09:52 UTC
Source: https://github.com/funto-aladekomo/ordinalgof

Help Index


Goodness-of-Fit Test for Ordinal Regression Models

Description

Tests the goodness of fit for ordinal regression models, reproducing results equivalent to Stata's output. Supports models from polr(), vglm(), and binary glm().

Usage

ordinalGOF(
  model,
  data,
  catvars = NULL,
  g = 10,
  test = c("hl", "pr.chi2", "pr.dev", "lipsitz"),
  ties = c("stata", "sorted", "equal"),
  show_table = FALSE
)

Arguments

model

A fitted model object. Supported classes: polr (MASS), vglm (VGAM), or glm (stats, binomial family).

data

A data frame used to fit the model.

catvars

Character vector of categorical variable names. Required only when test = "pr.chi2" or test = "pr.dev".

g

Integer. Number of quantile groups (default: 10).

test

Character. The test to perform. One of "hl" (default), "lipsitz", "pr.chi2", or "pr.dev".

ties

Character. Tie-breaking method for grouping. One of "stata" (default), "sorted", or "equal". "stata" reproduces Stata's behavior.

show_table

Logical. If TRUE, prints the observed/expected frequency table. Default is FALSE.

Value

An object of class htest containing:

statistic

The chi-squared test statistic.

parameter

Degrees of freedom.

p.value

The p-value.

method

A character string naming the test used.

Examples

## Not run: 
library(MASS)
m <- polr(drinkordinal ~ naltrexone + sex + basepda, data = dat,
          method = "logistic", Hess = TRUE)
ordinalGOF(m, data = dat, g = 10, test = "hl", ties = "stata")

## End(Not run)