Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# 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