The Supplemental Nutritiion Assistance Program (SNAP), known as the Food Stamps is a federal program that helps eligible low-income households purchase food. My project is using annual data participation and program cost on the Food Stamps Program from 1969 through 2015. This Data sets was found in our classrooms Data set file, but was originally collected by the United states Department of Agriculture (USDA) and Food and Nutrition (FNS). The Data set contains three variables, The year, the participants, and the costs. The main goal for my project is to explore how SNAP participation and costs have changed over time. I will also explore if years with more participants had higher program costs.
Loading the Libraries:
This following code loads the packages I need for this project, readr will be used to import My CSV file for the data set, dplyr is used for cleaning and organizing the data, and ggplot2 is going to help create the graphs.
library(readr)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)
Importing Data Set:
Since my data set is a local CSV file, I’m going to use the function readr::read_csv(), per instructed for the project.
food_stamps <- readr::read_csv("food_stamps.csv")
Rows: 47 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (3): year, participants, costs
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Examining the Data Set:
Before cleaning the Data I used some codes like head() to display the first few rows in the data set, str() to display the structure and data types of the variables. dim() to display the number of rows and columns. This helps make sure the data was imported correctly.
This Data Set is already mostly clean since the main variables are numerical. I will check for missing variables and duplicate observations. After checking I see there are no missing values or duplicates so no rows need to be removed.
colSums(is.na(food_stamps))
year participants costs
0 0 0
sum(duplicated(food_stamps))
[1] 0
Creating a Time Period Variable:
In the next code chunks I will create a new variable called “time period.” This will group the years into five time periods. Then I will convert into a factor to keep them in chronological order.
food_stamps <- food_stamps %>%mutate(time_period =case_when( year %in%1969:1979~"1969-1979", year %in%1980:1989~"1980-1989", year %in%1990:1999~"1990-1999", year %in%2000:2009~"2000-2009", year %in%2010:2015~"2010-2015"))
This is just to get a summary statistic, it provides use with information about the the maximum, minimum, median, and mean Values in the data set.
summary(food_stamps)
year participants costs time_period
Min. :1969 Min. : 2.878 Min. : 0.2505 1969-1979:11
1st Qu.:1980 1st Qu.:17.918 1st Qu.:10.0216 1980-1989:10
Median :1992 Median :21.082 Median :17.7894 1990-1999:10
Mean :1992 Mean :23.165 Mean :23.6102 2000-2009:10
3rd Qu.:2004 3rd Qu.:26.432 3rd Qu.:25.8597 2010-2015: 6
Max. :2015 Max. :47.636 Max. :79.8720
Exploring Relationship Between Participation and Costs:
I will us the correlation function to examine the relationship between SNAP participation and program costs. A correlation close to 1 shows a strong positive relationship. After checking the correlation is approximately 0.955, this very strong positive relationship between participation and costs.
cor(food_stamps$participants, food_stamps$costs)
[1] 0.9553043
Exploring Change Over Time:
I will create a line graph to show how SNAP participation has changed from year to year. The x-axis will represent the year and the y-axis will represent participants. The graph shows the participation has increased overtime, there were some periods when it decreased.
ggplot(food_stamps, aes(x = year, y = participants)) +geom_line() +geom_point() +labs(title ="Food Stamps Participation Over Time", x ="Year", y ="Food Stamps Participants (millions)") +theme_minimal()
Final Visualizations:
My final visualization will examine the relationship between Food Stamps participation and costs. Each point represents one year, the colors will represent the five different time periods. The line will show the overall postive relation between participation and cost.
ggplot(food_stamps, aes(x = participants, y = costs, color = time_period)) +geom_point(size =3) +geom_smooth(method ="lm", se =FALSE, color ="black") +scale_color_manual(values =c("1969-1979"="red","1980-1989"="blue","1990-1999"="green","2000-2009"="purple","2010-2015"="orange")) +labs(title ="Food Stamps Participation and Program Costs, 1969-2015",x ="Average Food Stamps Participants (millions)",y ="Total Food Stamps Costs (billions of dollars) ",color ="Time Period",captions ="Source: U.S. Department of Agriculture, Food and Nutrition Service, Supplemental Nutrition Assistance Program National Level Annual Summary: Participation and Costs." ) +theme_classic()
Ignoring unknown labels:
• captions : "Source: U.S. Department of Agriculture, Food and Nutrition
Service, Supplemental Nutrition Assistance Program National Level Annual
Summary: Participation and Costs."
`geom_smooth()` using formula = 'y ~ x'
Analysis:
The data set I chose only needed a small amount of cleaning because the original variables were already stored in numerical formats. First I checked the structure of the data set and confirmed that the year, participants, and costs were appropriate numerical values. I checked for missing values and duplicate observations. There were none so I did not have to remove any observations. Then I created and new categorical variable called time_period to group years into five time periods. I dis this so different periods could be easier to read in the final visualization.
The final Visualization shows the relationship between Food Stamps participation and the total program cost from 1969 to 2015. Each point represents one year, the x-axis show the average food stamps participation in millions of people, and the y-axis shows the total foods stamps cost in billions of dollars. The colors are different each time period. An Interesting pattern is the strong positive relationship between participation and costs. Since the correlation is really close to one it indicates that years with higher participation had higher total costs. The later time periods are at the top right of the graph which shows that participation and program cost were higher in the later years than the earlier years.
I wanted to include more information about the other characteristics that may play a part in Food stamps programs. Age, income, state etc… but none of these are in this data set. If we had some of these variables in the data set we could examine differences between states or demographic groups.
Overall, my analysis shows that food stamps participation and program costs increased substantially between 1969 and 2015. The visualization also shows a strong positive relationship between the number of participants and total program costs. The results show that years with more food stamp participants generally had higher program costs.