https://github.com/ejikeugba/gofcat
Goodness-of-fit tests for categorical response models
https://github.com/ejikeugba/gofcat
brant-test brier-scores hosmer-lemeshow-test likelihood-ratio-test lipsitz-test log-loss-score-metric logistic-regression misclassification ordinal-regression proportional-odds-test pseudo-r2 pulkstenis-robinson-test
Last synced: 5 months ago
JSON representation
Goodness-of-fit tests for categorical response models
- Host: GitHub
- URL: https://github.com/ejikeugba/gofcat
- Owner: ejikeugba
- License: gpl-2.0
- Created: 2021-12-26T16:18:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-02T05:08:15.000Z (over 3 years ago)
- Last Synced: 2025-10-25T01:42:50.732Z (8 months ago)
- Topics: brant-test, brier-scores, hosmer-lemeshow-test, likelihood-ratio-test, lipsitz-test, log-loss-score-metric, logistic-regression, misclassification, ordinal-regression, proportional-odds-test, pseudo-r2, pulkstenis-robinson-test
- Language: R
- Homepage: https://ejikeugba.github.io/gofcat/
- Size: 315 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = FALSE,
warning = FALSE,
out.width = "100%"
)
```
# gofcat
[](https://www.repostatus.org/#active)
[](https://app.codecov.io/gh/ejikeugba/gofcat?branch=main)
[](https://CRAN.R-project.org/package=gofcat)
[](https://CRAN.R-project.org/package=gofcat)
[](https://www.gnu.org/licenses/gpl-2.0.en.html)
[](https://ci.appveyor.com/project/ejikeugba/gofcat)
[](https://github.com/ejikeugba/gofcat/actions)
### Overview
Crucial post-estimation (goodness-of-fit) tests for some widely used categorical response models (CRM) are implemented in this package. It currently supports inputs from objects of class serp(), clm(), polr(), multinom(), mlogit(), vglm() and glm(). Available tests include the Hosmer-Lemeshow tests for the binary, multinomial and ordinal logistic regression; the Lipsitz and the Pulkstenis-Robinson tests for the ordinal models. The proportional odds, adjacent-category, and constrained continuation-ratio models are particularly supported at ordinal level. Tests for the proportional odds assumptions in ordinal models are also possible with the Brant and the Likelihood-Ratio tests. Moreover, several summary measures of predictive strength (Pseudo R-squared), and some useful error metrics, including, the brier score, misclassification rate and logloss are also available for the binary, multinomial and ordinal models.
### Example
``` r
require(serp)
set.seed(1)
n <- 200
dt <- data.frame(y = ordered(rbinom(n,2,0.5)), x1 = factor(rbinom(n,2,0.7)), x2 = runif(n))
sp <- serp(y ~ x1 + x2, slope="parallel", link = "logit", reverse= TRUE, data = dt)
```
``` r
## Goodness-of-fit
# Hosmer-Lemeshow test
hosmerlem(sp, tables = TRUE)
hosmerlem(sp, tables = TRUE, customFreq = rep(20,10))
# Lipsitz test
lipsitz(sp)
lipsitz(sp, customFreq = rep(20, 10))
# Pulkstenis-Robinson test
pulkroben(sp, test = "chisq", tables = TRUE)
pulkroben(sp, test = "deviance", tables = TRUE)
```
``` r
## Proportional odds test
brant.test(sp)
brant.test(sp, global = TRUE, call = TRUE)
LR.test(sp, call = TRUE)
```
``` r
## Error metrics
erroR(sp, type = "brier")
erroR(sp, type = "logloss")
erroR(sp, type = "misclass")
# with dataframe and custom threshold
df <- data.frame(y, sp$fitted.values)
erroR(df, type = "misclass", thresh = 0.7)
```
``` r
## Summary metrics
Rsquared(sp, measure = "ugba")
Rsquared(sp, measure = "mcfadden")
```
### Installation and Use
Before installing `gofcat`, it is encouraged to have a recent version of [R](https://cran.r-project.org/bin/windows/base/) installed. The released version of `gofcat` can be installed from [CRAN](https://cran.r-project.org/package=gofcat) with:
``` r
install.packages("gofcat")
```
or the development version from [GitHub](https://github.com/ejikeugba/gofcat) with:
``` r
if (!require("devtools")) install.packages("devtools")
devtools::install_github("ejikeugba/gofcat")
```
Load `gofcat` into R environment with:
```{r, eval = FALSE}
library(gofcat)
```
### Community Guidelines
Pull requests are welcomed! Please submit your contributions to `gofcat`
through the list of `Pull Requests`, following the [contributing
guidelines](https://github.com/ejikeugba/gofcat/blob/main/.github/contributing.md). To
report issues and/or seek support, please file a new ticket in the
[issue](https://github.com/ejikeugba/gofcat/issues) tracker, and expect
a feedback ASAP!
### Code of Conduct
Please note that `gofcat` is released with a [Contributor Code of
Conduct](https://github.com/ejikeugba/gofcat/blob/main/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
### References
Fagerland, M. W. and Hosmer, D. W. (2017). How to test for goodness of fit
in ordinal logistic regression models. *Stata Journal*, 17, 668-686.
Ugba, E. R. and Gertheiss, J. (2018). An Augmented Likelihood Ratio Index
for Categorical Response Models. In *Proceedings of 33rd International Workshop on Statistical Modelling*, Bristol, 293-298.
Ugba, E. R. (2021). serp: An R package for smoothing in ordinal
regression *Journal of Open Source Software*, 6(66), 3705.