Skip to content

Instantly share code, notes, and snippets.

@robwschlegel
Created June 20, 2017 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwschlegel/9cf462809edf8c60b2282a341be96e92 to your computer and use it in GitHub Desktop.
Save robwschlegel/9cf462809edf8c60b2282a341be96e92 to your computer and use it in GitHub Desktop.
# 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