In this project, we’ll look at opioid claims data for Medicaid members as reported by the Centers for Medicare and Medicaid Services. This will give us insight into which U.S. regions have the most prevalent prescription rates, which could be an indicator for where there may be more opioid abuse.
First we stack tables since our data is presented in separate tables for each year (2013-2016).
library(plyr)
library(stringr)
library(tidyr)
paths <- dir(getwd(), pattern = "\\.csv$", full.names = TRUE)
names(paths) <- basename(paths)
opioid <- ldply(paths, read.csv, stringsAsFactors = FALSE)
head(opioid)
## .id State.Name State.Abbreviation State.FIPS Opioid.Claims
## 1 2013.csv National NA 33,422,522
## 2 2013.csv Alabama AL 1 504,324
## 3 2013.csv Alaska AK 2 69,853
## 4 2013.csv Arizona AZ 4 1,120,106
## 5 2013.csv Arkansas AR 5 291,737
## 6 2013.csv California CA 6 3,000,477
## Fee.for.Service.Opioid.Claims Managed.Care.Opioid.Claims
## 1 15,334,279 18,088,243
## 2 504,324 0
## 3 69,853 0
## 4 8,280 1,111,826
## 5 291,737 0
## 6 1,095,604 1,904,873
## Long.Acting.Opioid.Claims Fee.for.Service.Long.Acting.Opioid.Claims
## 1 2,508,754 1,288,140
## 2 20,446 20,446
## 3 7,689 7,689
## 4 120,732 651
## 5 11,972 11,972
## 6 223,998 114,085
## Managed.Care.Long.Acting.Opioid.Claims Overall.Claims
## 1 1,220,614 501,002,691
## 2 0 8,306,380
## 3 0 865,816
## 4 120,081 12,248,771
## 5 0 4,353,274
## 6 109,913 48,341,735
## Fee.for.Service.Overall.Claims Managed.Care.Overall.Claims
## 1 235,141,689 265,861,002
## 2 8,306,380 0
## 3 865,816 0
## 4 33,691 12,215,080
## 5 4,353,274 0
## 6 20,345,050 27,996,685
## Opioid.Prescribing.Rate Fee.for.Service.Opioid.Prescribing.Rate
## 1 6.67 6.52
## 2 6.07 6.07
## 3 8.07 8.07
## 4 9.14 24.58
## 5 6.70 6.70
## 6 6.21 5.39
## Managed.Care.Opioid.Prescribing.Rate Long.Acting.Opioid.Prescribing.Rate
## 1 6.8 7.51
## 2 NA 4.05
## 3 NA 11.01
## 4 9.1 10.78
## 5 NA 4.10
## 6 6.8 7.47
## Fee.for.Service.Long.Acting.Opioid.Prescribing.Rate
## 1 8.40
## 2 4.05
## 3 11.01
## 4 7.86
## 5 4.10
## 6 10.41
## Managed.Care.Long.Acting.Opioid.Prescribing.Rate
## 1 6.75
## 2 NA
## 3 NA
## 4 10.80
## 5 NA
## 6 5.77
## Change.in.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Fee.for.Service.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Managed.Care.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Fee.for.Service.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Managed.Care.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
colnames(opioid)[1] <- "year" #renames id column to year
opioid$year <- str_extract(opioid$year, "^.{4}") #removes ".csv" from year
opioid$year <- as.numeric(opioid$year)
head(opioid)
## year State.Name State.Abbreviation State.FIPS Opioid.Claims
## 1 2013 National NA 33,422,522
## 2 2013 Alabama AL 1 504,324
## 3 2013 Alaska AK 2 69,853
## 4 2013 Arizona AZ 4 1,120,106
## 5 2013 Arkansas AR 5 291,737
## 6 2013 California CA 6 3,000,477
## Fee.for.Service.Opioid.Claims Managed.Care.Opioid.Claims
## 1 15,334,279 18,088,243
## 2 504,324 0
## 3 69,853 0
## 4 8,280 1,111,826
## 5 291,737 0
## 6 1,095,604 1,904,873
## Long.Acting.Opioid.Claims Fee.for.Service.Long.Acting.Opioid.Claims
## 1 2,508,754 1,288,140
## 2 20,446 20,446
## 3 7,689 7,689
## 4 120,732 651
## 5 11,972 11,972
## 6 223,998 114,085
## Managed.Care.Long.Acting.Opioid.Claims Overall.Claims
## 1 1,220,614 501,002,691
## 2 0 8,306,380
## 3 0 865,816
## 4 120,081 12,248,771
## 5 0 4,353,274
## 6 109,913 48,341,735
## Fee.for.Service.Overall.Claims Managed.Care.Overall.Claims
## 1 235,141,689 265,861,002
## 2 8,306,380 0
## 3 865,816 0
## 4 33,691 12,215,080
## 5 4,353,274 0
## 6 20,345,050 27,996,685
## Opioid.Prescribing.Rate Fee.for.Service.Opioid.Prescribing.Rate
## 1 6.67 6.52
## 2 6.07 6.07
## 3 8.07 8.07
## 4 9.14 24.58
## 5 6.70 6.70
## 6 6.21 5.39
## Managed.Care.Opioid.Prescribing.Rate Long.Acting.Opioid.Prescribing.Rate
## 1 6.8 7.51
## 2 NA 4.05
## 3 NA 11.01
## 4 9.1 10.78
## 5 NA 4.10
## 6 6.8 7.47
## Fee.for.Service.Long.Acting.Opioid.Prescribing.Rate
## 1 8.40
## 2 4.05
## 3 11.01
## 4 7.86
## 5 4.10
## 6 10.41
## Managed.Care.Long.Acting.Opioid.Prescribing.Rate
## 1 6.75
## 2 NA
## 3 NA
## 4 10.80
## 5 NA
## 6 5.77
## Change.in.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Fee.for.Service.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Managed.Care.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Fee.for.Service.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
## Change.in.Managed.Care.Long.Acting.Opioid.Prescribing.Rate
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
Next, we tidy our data by creating a “type of claim” variable and coverting our table from wide to tall.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
tidyOp <- select(opioid, year:Managed.Care.Overall.Claims) %>%
gather("TypeOfClaim", "claims", Opioid.Claims:Managed.Care.Overall.Claims)
head(tidyOp)
## year State.Name State.Abbreviation State.FIPS TypeOfClaim claims
## 1 2013 National NA Opioid.Claims 33,422,522
## 2 2013 Alabama AL 1 Opioid.Claims 504,324
## 3 2013 Alaska AK 2 Opioid.Claims 69,853
## 4 2013 Arizona AZ 4 Opioid.Claims 1,120,106
## 5 2013 Arkansas AR 5 Opioid.Claims 291,737
## 6 2013 California CA 6 Opioid.Claims 3,000,477
tidyOp$claims <- as.numeric(gsub(",","",tidyOp$claims)) #converts claims to numeric after translating out commas
head(tidyOp)
## year State.Name State.Abbreviation State.FIPS TypeOfClaim claims
## 1 2013 National NA Opioid.Claims 33422522
## 2 2013 Alabama AL 1 Opioid.Claims 504324
## 3 2013 Alaska AK 2 Opioid.Claims 69853
## 4 2013 Arizona AZ 4 Opioid.Claims 1120106
## 5 2013 Arkansas AR 5 Opioid.Claims 291737
## 6 2013 California CA 6 Opioid.Claims 3000477
We also designate which region each state is in for our regional analysis.
northeast <- c("CT","ME","MA","NH","RI","VT","NJ","NY","PA")
midwest <- c("IL","IN","MI","OH","WI","IA","KS","MN","MO","NE","ND","SD")
south <- c("DE","FL","GA","MD","NC","SC","VA","DC","WV","AL","KY","MS","TN","AR","LA","OK","TX")
west <- c("AZ","CO","ID","MT","NV","NM","UT","WY","AK","HI","CA","OR","WA")
tidyOp$region[tidyOp$State.Abbreviation %in% northeast] <- "northeast"
tidyOp$region[tidyOp$State.Abbreviation %in% midwest] <- "midwest"
tidyOp$region[tidyOp$State.Abbreviation %in% south] <- "south"
tidyOp$region[tidyOp$State.Abbreviation %in% west] <- "west"
head(tidyOp)
## year State.Name State.Abbreviation State.FIPS TypeOfClaim claims
## 1 2013 National NA Opioid.Claims 33422522
## 2 2013 Alabama AL 1 Opioid.Claims 504324
## 3 2013 Alaska AK 2 Opioid.Claims 69853
## 4 2013 Arizona AZ 4 Opioid.Claims 1120106
## 5 2013 Arkansas AR 5 Opioid.Claims 291737
## 6 2013 California CA 6 Opioid.Claims 3000477
## region
## 1 <NA>
## 2 south
## 3 west
## 4 west
## 5 south
## 6 west
Finally, we analyze opioid prescription levels by plotting claims by region and by year from 2013-2016.
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following object is masked _by_ '.GlobalEnv':
##
## midwest
ggplot(tidyOp, aes(x = year, y = claims)) + geom_bar(stat = "identity", aes(color = TypeOfClaim)) + xlab("Year") + ylab("Number of Claims") + facet_grid(~region)
From this chart, we can look at the NA region, which is the national level of opioid claims, and see that opioid prescriptions have increased year over year from 2013-2016. Opioid prescriptions have also increased for every consecutive year within each region of the U.S. The South seems to have the highest level of opioid prescriptions compared to other regions. These results are in line with what has recently brought on increased awareness for the opioid epidemic.