% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/glmest.R
\name{predict_glm}
\alias{predict_glm}
\title{Predict from a GLM with modified coefficients}
\usage{
predict_glm(
  object,
  p = coef(object),
  data,
  offset = NULL,
  type = c("response", "link"),
  ...
)
}
\arguments{
\item{object}{A fitted \code{glm} object.}

\item{p}{Numeric vector of coefficients (defaults to \code{coef(x)}).}

\item{data}{Optional data frame for computing the model matrix and
response. If missing, the original model matrix from the fitted
object is used.}

\item{offset}{Optional offset vector. If \code{NULL} (default), the
offset stored in the fitted model (\code{x$offset}) is used.}

\item{type}{Character; \code{"response"} (default) returns predictions on
the response scale via the inverse link function, \code{"link"} returns
predictions on the linear predictor scale.}

\item{...}{Additional arguments (currently unused).}
}
\value{
Numeric vector of predictions with a \code{"grad"} attribute
containing the gradient (Jacobian) of predictions with respect to
the coefficients. When \code{type = "link"}, the gradient is simply the
model matrix \code{X}.
}
\description{
Compute predictions from a fitted \link[stats:glm]{stats::glm} object, optionally
substituting new parameter values. Unlike \link[stats:predict.glm]{stats::predict.glm}, this
function allows the user to supply an arbitrary coefficient vector \code{p},
which is useful for computing predictions at counterfactual parameter
values (e.g., during optimization or simulation). The returned value
also includes a \code{"grad"} attribute containing the Jacobian of predictions
with respect to the coefficients.
}
\examples{
m <- glm(mpg ~ hp + wt, data = mtcars)
p0 <- coef(m)
# Predictions at fitted coefficients match predict.glm
all.equal(as.numeric(predict_glm(m)), fitted(m))
# Predictions with modified coefficients
predict_glm(m, p = p0 * 1.1)
}
\seealso{
\link[stats:predict.glm]{stats::predict.glm}, \link{score.glm}
}
