Stores additional data and attributes on a generic model class so that it
can be used as the regr
argument to ei_est()
. Given the wide variety of
model classes, there is no guarantee this function will work. However, most
model classes supporting a fitted()
and predict()
method will work as long
as there is no transformation of the predictor variables as part of the model
formula or fitting.
Arguments
- x
- data
A data frame or matrix containing the data used to fit the model, or an
ei_spec()
object (recommended). If the latter, then thepredictors
andoutcome
arguments are ignored and need not be provided.- predictors
<
tidy-select
> Predictor variables. This is thex
variable in ecological regression that is of primary interest. For example, the columns containing the percentage of each racial group.- outcome
<
tidy-select
> Outcome variables. This is they
variable in ecological regression that is of primary interest. For example, the columns containing the percentage of votes for each party.- ...
Additional arguments passed to the
predict()
method.
Value
An ei_wrapped
object, which has the information required to use
the provided x
with ei_est()
.
Examples
data(elec_1968)
spec = ei_spec(elec_1968, vap_white:vap_other, pres_ind_wal, pres_total,
covariates = c(pop_urban, farm))
# Note: this is not a model recommended for valid ecological inference!
m = suppressWarnings(
glm(pres_ind_wal ~ 0 + vap_white + vap_black + vap_other + pop_urban + farm,
data = spec, family = "binomial")
)
m_wrap = ei_wrap_model(m, spec, type = "response")
print(m_wrap)
#> A wrapped <glm/lm> model with 1143 observations
ei_est(m_wrap, data = spec) # notice all estimates nonnegative
#> # A tibble: 3 × 4
#> predictor outcome estimate std.error
#> <chr> <chr> <dbl> <dbl>
#> 1 vap_white pres_ind_wal 0.339 0.0239
#> 2 vap_black pres_ind_wal 0.741 0.0565
#> 3 vap_other pres_ind_wal 0.00000298 0.00539