Project 1

Author

Surafel Haile

Project 1 : Distribution of VA Disabilities.

For this project, I will explore a data-set that has information about VA disability compensation recipients across geographic areas in the United States. The data-set contains 3,148 rows and 14 columns, including state, county name, FIPS code, total recipients, disability-rating categories, age groups, and sex. My research question is Which VA disability-rating categories have the highest numbers of recipients, and how does the distribution compare across a few states? 

Data source : VA Disability

Loading the data and the libraries:

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.5.3
Warning: package 'readr' was built under R version 4.5.3
Warning: package 'dplyr' was built under R version 4.5.3
── 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.2     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.1     
── 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(readr)
library(ggplot2)
setwd("C:/Users/suraf/OneDrive/New folder")
veterans <- read.csv("export.csv")
head(veterans)
  FIPS.code   State County.Name Total..Disability.Compensation.Recipients
1      1001 Alabama     Autauga                                     2,949
2      1003 Alabama     Baldwin                                     7,650
3      1005 Alabama     Barbour                                       646
4      1007 Alabama        Bibb                                       324
5      1009 Alabama      Blount                                     1,088
6      1011 Alabama     Bullock                                       223
  SCD.rating..0..to.20. SCD.rating..30..to.40. SCD.rating..50..to.60.
1                   420                    250                    346
2                 1,590                    780                    909
3                   102                     48                     75
4                    52                     37                     37
5                   182                    132                    146
6                    36                     21                     32
  SCD.rating..70..to.90. SCD.rating..100. Age..17.44 Age..45.64
1                    924            1,009        763      1,278
2                  2,249            2,122      1,698      2,591
3                    207              214        108        240
4                    115               83         70        118
5                    342              286        288        326
6                     58               76         51         73
  Age..65.or.older  Male Female
1              908 2,382    567
2            3,360 6,905    745
3              298   564     82
4              136   298     26
5              474 1,011     77
6               99   190     33

First, I loaded the necessary library and imported the data set into Rstudio. I used “head()” to examine the first few rows.

Exploring the data:

colSums(is.na(veterans))
                                FIPS.code 
                                        0 
                                    State 
                                        0 
                              County.Name 
                                        0 
Total..Disability.Compensation.Recipients 
                                        0 
                    SCD.rating..0..to.20. 
                                        0 
                   SCD.rating..30..to.40. 
                                        0 
                   SCD.rating..50..to.60. 
                                        0 
                   SCD.rating..70..to.90. 
                                        0 
                         SCD.rating..100. 
                                        0 
                               Age..17.44 
                                        0 
                               Age..45.64 
                                        0 
                         Age..65.or.older 
                                        0 
                                     Male 
                                        0 
                                   Female 
                                        0 
str(veterans)
'data.frame':   3148 obs. of  14 variables:
 $ FIPS.code                                : chr  "1001" "1003" "1005" "1007" ...
 $ State                                    : chr  "Alabama" "Alabama" "Alabama" "Alabama" ...
 $ County.Name                              : chr  "Autauga" "Baldwin" "Barbour" "Bibb" ...
 $ Total..Disability.Compensation.Recipients: chr  "2,949" "7,650" "646" "324" ...
 $ SCD.rating..0..to.20.                    : chr  "420" "1,590" "102" "52" ...
 $ SCD.rating..30..to.40.                   : chr  "250" "780" "48" "37" ...
 $ SCD.rating..50..to.60.                   : chr  "346" "909" "75" "37" ...
 $ SCD.rating..70..to.90.                   : chr  "924" "2,249" "207" "115" ...
 $ SCD.rating..100.                         : chr  "1,009" "2,122" "214" "83" ...
 $ Age..17.44                               : chr  "763" "1,698" "108" "70" ...
 $ Age..45.64                               : chr  "1,278" "2,591" "240" "118" ...
 $ Age..65.or.older                         : chr  "908" "3,360" "298" "136" ...
 $ Male                                     : chr  "2,382" "6,905" "564" "298" ...
 $ Female                                   : chr  "567" "745" "82" "26" ...
colSums(veterans == "")
                                FIPS.code 
                                        0 
                                    State 
                                        0 
                              County.Name 
                                        0 
Total..Disability.Compensation.Recipients 
                                       13 
                    SCD.rating..0..to.20. 
                                      164 
                   SCD.rating..30..to.40. 
                                      328 
                   SCD.rating..50..to.60. 
                                      315 
                   SCD.rating..70..to.90. 
                                      121 
                         SCD.rating..100. 
                                      161 
                               Age..17.44 
                                      182 
                               Age..45.64 
                                      179 
                         Age..65.or.older 
                                       73 
                                     Male 
                                      464 
                                   Female 
                                      464 

Here, I examined the data types to determine whether the recipient counts were stored as numbers or text. As the results show, several count columns are currently stored as text because the numbers contain commas. These may need to be converted before calculations. I also checked the data-set for missing values to identify columns with incomplete information. There doesn’t seem to any missing values here. Finally, I looked for empty strings in the data, because the some info not being available. Empty strings will affect the conversion of characters to numbers, so they have to be filtered out.

veterans_clean <- veterans %>%
  filter(State != "",County.Name != "",FIPS.code != "",
    Total..Disability.Compensation.Recipients != "",
    
    SCD.rating..0..to.20. != "",
    SCD.rating..30..to.40. != "",
    SCD.rating..50..to.60. != "",
    SCD.rating..70..to.90. != "",
    SCD.rating..100. != "",
    
    Age..17.44 != "",
    Age..45.64 != "",
    Age..65.or.older != "",
    
    Male != "",
    Female != ""
  )

“Veterans_clean” is the cleaned version of the original data. Using “filter()”, it removes rows that contain empty strings in any of the columns. This makes sure all the retained records have values in all the specified columns before further analysis.

Converting the values to numeric:

#Compensation
VTDCR <- as.numeric(gsub(",", "",veterans_clean$Total..Disability.Compensation.Recipients))
#Ratings
num_rating_0_20<-
  as.numeric(gsub(",", "", veterans_clean$SCD.rating..0..to.20.))

num_rating_30_40<-
  as.numeric(gsub(",", "", veterans_clean$SCD.rating..30..to.40.))

num_rating_50_60 <-
  as.numeric(gsub(",", "", veterans_clean$SCD.rating..50..to.60.))

num_rating_70_90 <-
  as.numeric(gsub(",", "", veterans_clean$SCD.rating..70..to.90.))

num_rating_100 <-
  as.numeric(gsub(",", "", veterans_clean$SCD.rating..100.))

As mentioned previously, the data-set originally stored the recipient counts as character variables. For example, a value such as “2,949” was stored as a text rather than a number. I used “gsub()” to remove the commas and “as.numeric()” to convert the values into numbers.

Calculating the total recipients for each rating category:

rating_totals <- data.frame(
  Rating = c("0%-20%", "30%-40%", "50%-60%", "70%-90%", "100%"),
  Recipients = c(
    sum(num_rating_0_20),
    sum(num_rating_30_40),
    sum(num_rating_50_60),
    sum(num_rating_70_90),
    sum(num_rating_100)
  )
)
head(rating_totals)
   Rating Recipients
1  0%-20%    1209113
2 30%-40%     661063
3 50%-60%     725975
4 70%-90%    1858544
5    100%    1838115

This new data frame contains the five disability-rating categories and their corresponding total recipient counts. The “sum()“ function adds the reported counts in each numeric rating variable to calculate the total for each category.

Visualizations:

ggplot(rating_totals, aes(x = Rating, y = Recipients, fill= Rating)) +
  geom_bar(stat= "identity")+
  scale_fill_brewer(palette = "Set1")+
  labs(
    title = "VA Disability Recipients by Rating Category",
    x = "Disability Rating",
    y = "Number of Recipients",
    caption = "U.S. Department of Veterans Affairs"
  ) +
  theme_minimal()

This bar chart compares the total number of VA disabilities compensation recipients across five disability rating categories. The graph shows that the 70%-90% and 100% categories have the highest reported recipients. The 30% -40% category has the lowest amount of recipients. For the 0%-20% category as well as the 30% -40% one the count runs to a little above 500,000 recipients. An important information is that these ratings represent the VA’s assessment of the severity of service-connected disabilities. Higher ratings generally indicate greater disability.

percentage_num_100 <- num_rating_100 / VTDCR * 100
veterans_clean$Pct_100 <- percentage_num_100
head(veterans_clean$Pct_100)
[1] 34.21499 27.73856 33.12693 25.61728 26.28676 34.08072

Before the next visualization, this code calculates the percentage of VA disabilities compensation recipients who have 100% disability rating. It then stores the calculated percentage in a new column called Pct_100 in the veterans_clean data-set.

veterans_clean %>%
  filter(State %in% c("Maryland", "Virginia", "Pennsylvania")) %>%
  ggplot(aes(x = State, y = Pct_100, fill = State)) +
  geom_boxplot() +
  scale_fill_discrete() +
  labs(
    title = "County-Level Counts of 100% Disability Ratings",
    x = "State",
    y = "Percentage of Recipients with a 100% Rating",
    fill = "State",
    caption = "U.S. Department of Veterans Affairs"
  ) +
  theme_minimal()

The last visualization compares the percentage of VA disability compensation recipients with a 100% disability rating across counties in Maryland, Pennsylvania, and Virginia. Maryland has the highest median percentage, at 29%, followed by Virginia at about 28%. Pennsylvania has the lowest median, at around 24%. Virginia shows a wider spread of county percentages. Maryland also has few counties with unusually high percentages, while Pennsylvania’s county percentage appear more closely grouped.