% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mlmodel-count-tests.R
\name{GOFtest}
\alias{GOFtest}
\alias{GOFtest.mlmodel}
\title{Goodness-of-Fit Test for Count Models}
\usage{
GOFtest(object, bins = 0:5)

\method{GOFtest}{mlmodel}(object, bins = 0:5)
}
\arguments{
\item{object}{An object of class \code{"mlmodel.count"} (typically from
\code{ml_poisson()} or \code{ml_negbin()}).}

\item{bins}{Integer vector. Defines the boundaries of the bins used
to group counts. Default is \code{0:5}.}
}
\value{
An object of class \code{"GOFtest.mlmodel"} with components:
\describe{
\item{model}{Description of the fitted model.}
\item{matrix}{A table with observed and predicted frequencies, proportions,
absolute differences, and Pearson contributions per bin.}
\item{test}{A list containing \code{teststat}, \code{df}, and \code{pval} for the overall
goodness-of-fit test.}
}
}
\description{
Performs the Manjon and Martinez (2014) chi-squared goodness-of-fit test
for count data models.
}
\details{
The test compares the observed frequencies with the expected frequencies
predicted by the model across different count bins. It produces both a
binned comparison table and an overall regression-based chi-squared test
statistic.

A low p-value indicates that the model's predicted probabilities do not
adequately match the observed count distribution (model misspecification).
}
\examples{

# Poisson model
fit_pois <- ml_poisson(docvis ~ private + medicaid + age + I(age^2) + 
                       educyr + actlim + totchr, data = docvis)

GOFtest(fit_pois, bins = 0:5)

# Negative binomial model
fit_nb2 <- ml_negbin(docvis ~ private + medicaid + age + I(age^2) + 
                     educyr + actlim + totchr, data = docvis)

GOFtest(fit_nb2)

}
\references{
Manjon, M., & Martinez, O. (2014). 'The chi-squared goodness-of-fit test
for count-data models.' \emph{The Stata Journal}, 14(4), 798-816.
\doi{10.1177/1536867X1401400406}
}
\author{
Alfonso Sanchez-Penalver
}
