| predict_glm | R Documentation |
Compute predictions from a fitted stats::glm object, optionally
substituting new parameter values. Unlike stats::predict.glm, this
function allows the user to supply an arbitrary coefficient vector p,
which is useful for computing predictions at counterfactual parameter
values (e.g., during optimization or simulation). The returned value
also includes a "grad" attribute containing the Jacobian of predictions
with respect to the coefficients.
predict_glm(
object,
p = coef(object),
data,
offset = NULL,
type = c("response", "link"),
...
)
object |
A fitted |
p |
Numeric vector of coefficients (defaults to |
data |
Optional data frame for computing the model matrix and response. If missing, the original model matrix from the fitted object is used. |
offset |
Optional offset vector. If |
type |
Character; |
... |
Additional arguments (currently unused). |
Numeric vector of predictions with a "grad" attribute
containing the gradient (Jacobian) of predictions with respect to
the coefficients. When type = "link", the gradient is simply the
model matrix X.
stats::predict.glm, score.glm
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.