Identify what variables are strongly associated with the standard of living. To that end, do the following:
library(openintro)
library(ggplot2)
library(dplyr)
# Load data
data(countyComplete) # It comes from the openintro package
# Create a new variable, rural
countyComplete$rural <- ifelse(countyComplete$density < 500, "rural", "urban")
countyComplete$rural <- factor(countyComplete$rural)
Create a scatterplot of per_capita_income and bachelors in the data set
# Scatterplot
ggplot(data = countyComplete, aes(x = per_capita_income, y = bachelors)) + geom_point()
Interpretation
Create a boxplot of per_capita_income and bachelors
# Boxplot
ggplot(data = countyComplete,
aes(x = cut(per_capita_income, breaks = 5), y = bachelors)) +
geom_boxplot()
Interpretation
Add the rural variable to the scatterplot of per_capita_income and bachelors to see whether there is any difference in their relationship between rural and urban
# Body dimensions scatterplot
ggplot(data = countyComplete, aes(x = per_capita_income, y = bachelors, color = factor(rural))) +
geom_point()
Interpretation
Compute correlation coefficient between income_per_capita and bachelors (2.1 Computing correlation). Interpret it. Keep in mind that correlation coefficients do not show causation but only association.
# Compute correlation
countyComplete %>%
summarize(N = n(), r = cor(per_capita_income, bachelors))
## N r
## 1 3143 0.7924464
Interpretation