if (!require("tidyverse"))
install.packages("tidyverse")
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidyverse)
mydata <- read.csv("https://raw.githubusercontent.com/drkblake/Data/main/Educ_Income_2022.csv")
head(mydata,10)
## GEOID County State PctCollege FamIncome
## 1 47001 Anderson County Tennessee 24.5 75637
## 2 47003 Bedford County Tennessee 17.1 71159
## 3 47005 Benton County Tennessee 11.1 65800
## 4 47007 Bledsoe County Tennessee 10.3 59695
## 5 47009 Blount County Tennessee 26.0 85194
## 6 47011 Bradley County Tennessee 23.9 75270
## 7 47013 Campbell County Tennessee 12.9 61629
## 8 47015 Cannon County Tennessee 17.5 71000
## 9 47017 Carroll County Tennessee 19.8 68542
## 10 47019 Carter County Tennessee 21.1 61776
mydata$DV <- mydata$FamIncome
mydata$IV <- mydata$PctCollege
ggplot(mydata, aes(x = DV)) + geom_histogram(color = "black", fill = "#1f78b4")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mydata, aes(x = IV)) + geom_histogram(color = "black", fill = "#1f78b4")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
options(scipen = 999)
myreg <- lm(DV ~ IV,
data = mydata)
plot(mydata$IV, mydata$DV)
abline(lm(mydata$DV ~ mydata$IV))
According to the scatterplot from the Tennessee data ended up with a
trendline that shows the higher a county’s college education level, the
higher the average household income. However, this is just a comparison
of two variables and should be taken with a grain of salt.