% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_model_fit.R
\name{plot_model_fit}
\alias{plot_model_fit}
\title{Plot model-fit diagnostics}
\usage{
plot_model_fit(
  model,
  model_name = NULL,
  type = c("auto", "all", "residual", "qq", "scale_location", "cooks",
    "observed_predicted", "calibration"),
  bins = 10,
  base_size = 13
)
}
\arguments{
\item{model}{A fitted \code{lm} or \code{glm} model, or a
\code{uni_reg()} / \code{multi_reg()} result.}

\item{model_name}{Optional model name to select when \code{model} contains
multiple fitted models. Quoted and bare names are accepted.}

\item{type}{Plot type. One of \code{"auto"}, \code{"all"},
\code{"residual"}, \code{"qq"}, \code{"scale_location"},
\code{"cooks"}, \code{"observed_predicted"}, or \code{"calibration"}.
Quoted and bare values are accepted.}

\item{bins}{Number of groups used for binomial calibration plots.}

\item{base_size}{Base font size for the plot theme.}
}
\value{
A \code{ggplot2} object for a single plot, or a patchwork object when
  multiple diagnostics are requested.
}
\description{
Visualise model fit for fitted regression models and models stored inside
\code{uni_reg()} or \code{multi_reg()} results.
}
\details{
\code{plot_model_fit()} is a visual check of how a fitted model behaves, not
a formal model-selection rule. For survival models, use \code{check_ph()} for Cox
proportional hazards diagnostics and \code{plot_surv_fit()} for parametric
survival model fit.

For binomial models, \code{type = "calibration"} compares grouped predicted
probabilities with observed event proportions. This is most informative for
multivariable models, where predictions vary across many patients. A
univariable binary predictor may produce only two calibration points; that is
expected and simply reflects the two fitted probabilities in the model.
Logistic residual plots often show two bands because the outcome is coded as
event/non-event.
}
\examples{
fit_lm <- lm(mpg ~ wt + hp, data = mtcars)
plot_model_fit(fit_lm)

fit_glm <- glm(am ~ mpg + wt, data = mtcars, family = binomial())
plot_model_fit(fit_glm, type = calibration, bins = 4)

uni_fit <- uni_reg(mtcars, am, c(mpg, wt), approach = logit)
plot_model_fit(uni_fit, model_name = mpg, type = residual)

}
