Native unit-level (or averaged) adjusted predictions for lm
and glm fits with the conventions of
marginaleffects::predictions() (Arel-Bundock): one row per row
of newdata (the model data by default), delta-method standard
errors from the analytic Jacobian and vcov(model), z-based
tests and intervals. For a glm with no type and no
by, inference is done on the link scale and the estimate and
interval are back-transformed (marginaleffects' "invlink(link)");
std.error and statistic are then NA. With
by, unit predictions are averaged within groups on the response
scale. Cross-validated against marginaleffects in the tests.
Arguments
- model
A fitted
lmorglmobject.- newdata
Optional data frame for which to predict. Defaults to the model data when
NULL.- ...
Optional native settings:
type("response"or"link"),by(TRUEor grouping column names),conf_level,vcov(TRUE,FALSEor a matrix) anddf(defaultInf). Any other argument is an error.
Value
A data frame with rowid (or the by columns),
estimate, std.error, statistic, p.value,
s.value, conf.low, conf.high and, unit-level,
the newdata columns.
Examples
set.seed(1)
df <- data.frame(y = rnorm(60), x = rnorm(60), g = factor(rep(c("a", "b"), 30)))
fit <- stats::lm(y ~ x + g, data = df)
head(morie_effects_predictions(fit))
#> rowid estimate std.error statistic p.value s.value conf.low
#> 1 1 0.16035115 0.3251697 0.4931306 0.6219203 0.6851984 -0.47696978
#> 2 2 -0.02059560 0.1584281 -0.1299997 0.8965667 0.1575172 -0.33110890
#> 3 3 0.22076343 0.1739466 1.2691449 0.2043894 2.2906077 -0.12016564
#> 4 4 -0.02296858 0.1574301 -0.1458970 0.8840027 0.1778773 -0.33152592
#> 5 5 0.27133452 0.1857957 1.4603920 0.1441824 2.7940334 -0.09281831
#> 6 6 -0.02864287 0.1567776 -0.1826974 0.8550354 0.2259439 -0.33592134
#> conf.high y x g
#> 1 0.7976721 -0.6264538 2.40161776 a
#> 2 0.2899177 0.1836433 -0.03924000 b
#> 3 0.5616925 -0.8356286 0.68973936 a
#> 4 0.2855888 1.5952808 0.02800216 b
#> 5 0.6354873 0.3295078 -0.74327321 a
#> 6 0.2786356 -0.8204684 0.18879230 b
