This project uses the US County Dataset from OpenIntro. It has 3,142 counties and 15 variables such as state, poverty rate, household income, and unemployment. For this project, I will look at the states and poverty variables.
I wil use R to compare poverty rates in Maryland and Virginia counties. First, I will clean the data and remove missing values. Then, I will calculate the average poverty rate for each state. I will also create a box plot and a histogram to understand and compare the poverty rates.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.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
county <- read.csv("county.csv")
head(county)
## name state pop2000 pop2010 pop2017 pop_change poverty
## 1 Autauga County Alabama 43671 54571 55504 1.48 13.7
## 2 Baldwin County Alabama 140415 182265 212628 9.19 11.8
## 3 Barbour County Alabama 29038 27457 25270 -6.22 27.2
## 4 Bibb County Alabama 20826 22915 22668 0.73 15.2
## 5 Blount County Alabama 51024 57322 58013 0.68 15.6
## 6 Bullock County Alabama 11714 10914 10309 -2.28 28.5
## homeownership multi_unit unemployment_rate metro median_edu
## 1 77.5 7.2 3.86 yes some_college
## 2 76.7 22.6 3.99 yes some_college
## 3 68.0 11.1 5.90 no hs_diploma
## 4 82.9 6.6 4.39 yes hs_diploma
## 5 82.0 3.7 4.02 yes hs_diploma
## 6 76.9 9.9 4.93 no hs_diploma
## per_capita_income median_hh_income smoking_ban
## 1 27841.70 55317 none
## 2 27779.85 52562 none
## 3 17891.73 33368 partial
## 4 20572.05 43404 none
## 5 21367.39 47412 none
## 6 15444.16 29655 none
dim(county)
## [1] 3142 15
data <- county %>%
filter(state == "Maryland" | state == "Virginia") %>%
select(state, poverty) %>%
drop_na()
head(data)
## state poverty
## 1 Maryland 16.8
## 2 Maryland 6.1
## 3 Maryland 9.1
## 4 Maryland 5.7
## 5 Maryland 16.5
## 6 Maryland 5.5
summary(data$poverty)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.90 8.90 12.80 13.83 17.80 37.50
data %>%
group_by(state) %>%
summarize(
average = mean(poverty),
median = median(poverty),
total = n()
)
## # A tibble: 2 × 4
## state average median total
## <chr> <dbl> <dbl> <int>
## 1 Maryland 10.9 9.35 24
## 2 Virginia 14.4 13.4 133
ggplot(data, aes(x = state, y = poverty)) +
geom_boxplot() +
labs(
title = "Poverty Rates in Maryland and Virginia",
x = "States",
y = "Poverty Rate (%)"
)
ggplot(data, aes(x = poverty)) +
geom_histogram(bins = 10) +
labs(title = "Distribution of Poverty Rates",
x = "Poverty Rate (%)",
y = "Number of Counties"
)
I will use two-sample t-test to compare the average poverty rates in Maryland and Virginia and the significance level is 0.05.
The Hypotheses are:
Null Hypothesis: The average rates are equal in Maryland and Virginia
Alternative Hypothesis: The average poverty rates are different in Maryland and Virginia
Perform the T-Test
t.test(poverty ~ state, data = data)
##
## Welch Two Sample t-test
##
## data: poverty by state
## t = -2.9782, df = 37.998, p-value = 0.005028
## alternative hypothesis: true difference in means between group Maryland and group Virginia is not equal to 0
## 95 percent confidence interval:
## -5.894785 -1.123886
## sample estimates:
## mean in group Maryland mean in group Virginia
## 10.85833 14.36767
This project compares poverty rates in Maryland and Virginia. The t-test helps us to see if the averagge poverty rates are different in these two states. In future, I can study more states and look at other things, like income and unemployment to learn more about poverty in the United States.
OpenIntro. U.S. County Dataset. https://www.openintro.org/data/index.php?data=county