Produces estimates of overall conditional means from a fitted ecological inference model or Riesz representer. If both a regression model and a Riesz representer are provided, a debiased machine learning (DML) estimate is produced.
Arguments
- regr
A fitted regression model, from
ei_ridge()
, or another kind of regression model wrapped withei_wrap_model()
. Ifriesz
is not provided andregr
is anei_riesz()
object, thenriesz
will be set to the value ofregr
andregr
will be set toNULL
. This is so users can call this function asei_est(<riesz>, data = <data>)
.- riesz
A fitted Riesz representer, from
ei_riesz()
, or a matrix of Riesz weights- data
The data frame, matrix, or ei_spec object that was used to fit the regression or Riesz representer.
- total
<
tidy-select
> A variable containing the total number of observations in each aggregate unit. For example, the column containing the total number of voters. Required ifdata
is not anei_spec()
object andriesz
is not provided.- subset
<
data-masking
> An optional indexing vector describing the subset of units over which to calculate estimates.- outcome
<
data-masking
> A vector or matrix of outcome variables. Only required if bothriesz
is provided alone (withoutregr
) anddata
is not an ei_spec object.- conf_level
A numeric specifying the level for confidence intervals. If
FALSE
(the default), no confidence intervals are calculated. Standard errors are always returned.- x, object
An object of class
ei_est
- which
Which column of
ei_est
to convert to a matrix. For example, passwhich="std.error"
to return standard errors instead of estimates. Partial matching supported.- ...
Additional arguments (ignored)
Value
A data frame with estimates. It has class ei_est
, supporting
several methods, and two additional attributes: vcov
, containing the
estimated covariance matrix for the estimates, and n
, containing the
number of aggregate units used in estimation (the number of rows in
data
).
Methods (by generic)
as.matrix(ei_est)
: Format estimates, standard errors, or other columns as a matrix.vcov(ei_est)
: Extract full covariance matrix of estimatesnobs(ei_est)
: Extract number of units covered by estimates
Examples
data(elec_1968)
spec = ei_spec(elec_1968, vap_white:vap_other, pres_dem_hum:pres_abs,
total = pres_total, covariates = c(state, pop_urban, farm))
m = ei_ridge(spec)
rr = ei_riesz(spec, penalty = m$penalty)
ei_est(regr = m, data = spec, conf_level = 0.95) # Plug-in estimate
#> # A tibble: 12 × 6
#> predictor outcome estimate std.error conf.low conf.high
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 vap_white pres_dem_hum 0.230 0.0222 0.186 0.273
#> 2 vap_black pres_dem_hum 0.588 0.0457 0.499 0.678
#> 3 vap_other pres_dem_hum 1.55 0.181 1.20 1.91
#> 4 vap_white pres_rep_nix 0.382 0.0284 0.326 0.438
#> 5 vap_black pres_rep_nix -0.0775 0.0165 -0.110 -0.0452
#> 6 vap_other pres_rep_nix 0.494 0.0722 0.353 0.636
#> 7 vap_white pres_ind_wal 0.387 0.0251 0.338 0.436
#> 8 vap_black pres_ind_wal 0.488 0.0446 0.401 0.576
#> 9 vap_other pres_ind_wal -1.05 0.131 -1.30 -0.790
#> 10 vap_white pres_abs 0.00152 0.000251 0.00102 0.00201
#> 11 vap_black pres_abs 0.00109 0.000227 0.000641 0.00153
#> 12 vap_other pres_abs 0.00117 0.000471 0.000250 0.00210
ei_est(riesz = rr, data = spec) # Weighted (Riesz) estimate
#> # A tibble: 12 × 4
#> predictor outcome estimate std.error
#> <chr> <chr> <dbl> <dbl>
#> 1 vap_white pres_dem_hum 0.230 0.0224
#> 2 vap_black pres_dem_hum 0.588 0.0948
#> 3 vap_other pres_dem_hum 1.55 1.98
#> 4 vap_white pres_rep_nix 0.382 0.0237
#> 5 vap_black pres_rep_nix -0.0775 0.0695
#> 6 vap_other pres_rep_nix 0.494 1.49
#> 7 vap_white pres_ind_wal 0.387 0.0286
#> 8 vap_black pres_ind_wal 0.488 0.115
#> 9 vap_other pres_ind_wal -1.05 1.98
#> 10 vap_white pres_abs 0.00152 0.000252
#> 11 vap_black pres_abs 0.00109 0.000840
#> 12 vap_other pres_abs 0.00117 0.0134
est = ei_est(regr = m, riesz = rr, data = spec) # Double/debiased ML estimate
as.matrix(est)
#> outcome
#> predictor pres_dem_hum pres_rep_nix pres_ind_wal pres_abs
#> vap_white 0.2296810 0.3814135 0.3873821 0.0015233731
#> vap_black 0.5856278 -0.0768011 0.4901049 0.0010683650
#> vap_other 1.6370000 0.5979725 -1.2351002 0.0001277371
as.matrix(est, "std.error")
#> outcome
#> predictor pres_dem_hum pres_rep_nix pres_ind_wal pres_abs
#> vap_white 0.02346882 0.03061363 0.02459608 0.0002801522
#> vap_black 0.04997948 0.02670867 0.05056769 0.0005101309
#> vap_other 0.47024050 0.33462988 0.55488723 0.0058597394
vcov(est)[1:4, 1:4]
#> vap_white:pres_dem_hum vap_black:pres_dem_hum
#> vap_white:pres_dem_hum 0.0005507857 0.0004144159
#> vap_black:pres_dem_hum 0.0004144159 0.0024979486
#> vap_other:pres_dem_hum 0.0021912165 0.0056012709
#> vap_white:pres_rep_nix 0.0006103741 0.0007945676
#> vap_other:pres_dem_hum vap_white:pres_rep_nix
#> vap_white:pres_dem_hum 0.002191216 0.0006103741
#> vap_black:pres_dem_hum 0.005601271 0.0007945676
#> vap_other:pres_dem_hum 0.221126131 0.0045939440
#> vap_white:pres_rep_nix 0.004593944 0.0009371944
est = ei_est(m, rr, data = spec, subset = (state == "Alabama"))
as.matrix(est)
#> outcome
#> predictor pres_dem_hum pres_rep_nix pres_ind_wal pres_abs
#> vap_white 0.006649839 0.16292434 0.8158650 0.014560791
#> vap_black 0.733211508 -0.04036185 0.2995285 0.007621831
#> vap_other 1.803101753 0.16471677 -0.9702721 0.002453595
nobs(est)
#> [1] 67