Let’s see how different neighborhood matrix styles can impact the estimates of spatial regression models. Run the code below in order to have the data in place for this exercise. (You can ignore any warning messages.)
voting_districts <-
sf::st_read("./data/Stimmbezirk.shp") %>%
sf::st_transform(3035) %>%
dplyr::transmute(Stimmbezirk = as.numeric(nummer))
afd_votes <-
glue::glue(
"https://www.stadt-koeln.de/wahlen/bundestagswahl/09-2021/praesentation/\\
Open-Data-Bundestagswahl476.csv"
) %>%
readr::read_csv2() %>%
dplyr::transmute(Stimmbezirk = `gebiet-nr`, afd_share = (F1 / F) * 100)
election_results <-
dplyr::left_join(
voting_districts,
afd_votes,
by = "Stimmbezirk"
)
immigrants_cologne <-
z11::z11_get_100m_attribute(STAATSANGE_KURZ_2) %>%
terra::crop(election_results) %>%
terra::mask(terra::vect(election_results))
inhabitants_cologne <-
z11::z11_get_100m_attribute(Einwohner) %>%
terra::crop(election_results) %>%
terra::mask(terra::vect(election_results))
immigrant_share_cologne <-
(immigrants_cologne / inhabitants_cologne) * 100
election_results <-
election_results %>%
dplyr::mutate(
immigrant_share =
exactextractr::exact_extract(immigrant_share_cologne, ., 'mean'),
inhabitants =
exactextractr::exact_extract(inhabitants_cologne, ., 'mean')
)
style = "minmax"
in the spdep:nb2listw()
function.
# spdep
queen_neighborhood <-
spdep::poly2nb(
election_results,
queen = TRUE
)
queen_W <- spdep::nb2listw(queen_neighborhood, style = "W")
queen_minmax <- spdep::nb2listw(queen_neighborhood, style = "minmax")
# run regressions
spatial_lag_y_W <-
spatialreg::lagsarlm(
afd_share ~ immigrant_share + inhabitants,
data = election_results,
listw = queen_W
)
spatial_lag_y_minmax <-
spatialreg::lagsarlm(
afd_share ~ immigrant_share + inhabitants,
data = election_results,
listw = queen_minmax
)
spatialreg::impacts(spatial_lag_y_W, listw = queen_W)
## Impact measures (lag, exact):
## Direct Indirect Total
## immigrant_share -0.05948993 -0.09757580 -0.15706572
## inhabitants -0.03734396 -0.06125182 -0.09859578
spatialreg::impacts(spatial_lag_y_minmax, listw = queen_minmax)
## Impact measures (lag, exact):
## Direct Indirect Total
## immigrant_share -0.10719406 -0.08673331 -0.1939274
## inhabitants -0.06450885 -0.05219568 -0.1167045
# There are some slight differences in the estimate of the indirect effects but
# more severe in the calculation of the direct ones.