Created
June 20, 2017 01:23
-
-
Save robwschlegel/9cf462809edf8c60b2282a341be96e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here we run linear models on all available data against GDP per capita | |
# We are not controlling for country or year | |
lm_data_all <- data_long %>% | |
left_join(., gdp_per_capita[,-5], by = c("ccode", "country.name", "year")) %>% | |
rename(., value = value.x, gdp = value.y) %>% | |
group_by(variable) %>% | |
mutate(n = sum(!is.na(gdp))) %>% | |
ungroup() %>% | |
nest(-n, -variable) %>% | |
mutate(fit = map(data, ~ lm(value ~ gdp, data = .)), | |
results = map(fit, glance)) %>% | |
unnest(results) %>% | |
select(n, variable, adj.r.squared, p.value) %>% | |
arrange(-adj.r.squared) %>% | |
filter(variable != "gdp_per_capita") | |
# These data are best represented with a table | |
knitr::kable(lm_data_all, digits = 3, caption = "R^2 and p-values for the relationship between several metrics and GDP per capita. Years and country of sampling were not controlled for.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment