% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mlmodel-tests.R
\name{lrtest}
\alias{lrtest}
\alias{lrtest.mlmodel}
\title{Likelihood Ratio Test for Nested mlmodel Objects}
\usage{
lrtest(object_1, object_2, ...)

\method{lrtest}{mlmodel}(object_1, object_2, ...)
}
\arguments{
\item{object_1}{A fitted model object inheriting from \code{"mlmodel"}.
Typically the restricted (smaller) model.}

\item{object_2}{A fitted model object inheriting from \code{"mlmodel"}.
Typically the unrestricted (larger) model.
The order of \code{object_1} and \code{object_2} does not matter — the function
automatically determines which is the restricted model.}

\item{...}{Further arguments passed to methods (currently not used).}
}
\value{
An object of class \code{"lrtest.mlmodel"} with the test statistic,
degrees of freedom, and p-value.
}
\description{
Performs a likelihood ratio test comparing two nested models fitted with
the same estimator (e.g. \code{ml_lm}, \code{ml_logit}, \code{ml_negbin}, etc.).
}
\details{
The likelihood ratio test statistic is calculated as:
\deqn{LR = 2 \times (\log L_{\text{unrestricted}} - \log L_{\text{restricted}})}

Under the null hypothesis that the restricted model is correct, \code{LR} follows
a \eqn{\chi^2} distribution with degrees of freedom equal to the difference
in the number of parameters between the two models.

\strong{Important:} The two models must be nested (the restricted model must be
a special case of the unrestricted one) and fitted on exactly the same sample.
The restricted model must have a lower (or equal) log-likelihood.
}
\examples{

# Linear model example
data(mroz)
mroz$incthou <- mroz$faminc / 1000

fit_small <- ml_lm(incthou ~ age + huswage, data = mroz)
fit_large <- ml_lm(incthou ~ age + I(age^2) + huswage + educ + unem, 
                   data = mroz)

lrtest(fit_small, fit_large)

# You can also reverse the order — the function detects the restricted model
lrtest(fit_large, fit_small)

}
\seealso{
\code{\link[=waldtest]{waldtest()}}, \code{\link[=IMtest]{IMtest()}}, \code{\link[=vuongtest]{vuongtest()}}
}
\author{
Alfonso Sanchez-Penalver
}
