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.