STA-230 Midterm 2: Opiods and Mental Health Disorders During/After Pregnancy

A researcher (you) is interested in investigating the effect of mental health diagnosis during pregnancy on the prescription of opioids post-partum. It is expected that opioid prescription post-partum will vary substantially by delivery type – vaginal birth versus a Cesarean section.

In order to investigate the issue, we need to analyze insurance claims data. To this end, we have been given access to two files: a membership file (member.csv) and a claims file (claims.csv). Each file contains information on a set of insured women across calendar years 2017-2018.

The membership file is in long format with five variables: member id, year (2017, 2018), month (1-12), date of birth, and insurance plan type (HMO vs PPO). Each woman will have one line for each month/year during which she was insured.

The claims file is also in long format with four variables: member id, date of claim service, a CPT service code and an ICD diagnosis code.

Instructions to prepare our dataset are as follows:

Case inclusion for analysis

Our study is restricted to only those women who were at least 18 years old and younger than 41 (that is 40 and 11 months is fine, 41 years and 0 months is not) at the time of delivery. Additionally, to be sure that we have adequate information regarding prior mental health and subsequent opioid prescription, we require that a woman must be insured in the month of her delivery, for 3 months following her delivery, and for 9 calendar months prior to her delivery.

Primary outcome: opioid prescription

The outcome of interest is the prescription of an opioid within 90 days post-partum. All entries in the claims data have been adjusted to only include post-partum prescriptions so we do not need to worry about dates. opioid prescriptions are identified with the ICD code J0745

Delivery Date and Type

Delivery dates are identified with the ICD codes O80 and O82 (letter “O”) and are stored in the claims file. These entries serve two purposes: using the delivery date for determining the mother’s age at the time of birth and for determining if the delivery was a vaginal birth or a Cesarean.

Mental Health Disorder

The definition used to determine a mental health disorder is given by the ICD codes F41.8 and F32.3. The first of these is related to anxiety disorders, while the second is associated with depression.

Migraine headache

Patients with a history of migraines are identified with ICD code of G43.4. Creating an indicator for this variable (i.e., marking which patients had previously filed a claim related to migraines) will be used to control for opioids that were potentially dispensed for migraines rather than related to delivery

Exploratory Plots

Using the data that you have modified, you should create 3 or 4 plots with ggplot that investigate the relationships between our outcome and our newly constructed covariates or between the covariates themselves. These plots should be exploring the research question posted above.

Data Analysis

For each of these plots you will need to explain statistically what we can learn from it. It is OK to focus on descriptive statistics instead of inferential. It is also a good idea to think of conditional relationships.

Report

Write a short summary of your findings. Write a paragraph answer to the question: Does mental health diagnosis appear to have an effect on the prescriptions of periods post-postpartum?

Data

Here are the two data files provided

member <- read.csv("https://collinn.github.io/data/member.csv")
claims <- read.csv("https://collinn.github.io/data/claims.csv")

Along with a list of ICD codes for reference

ICD Codes
F32.3 \(\qquad \qquad \qquad\) Depression
F41.8 Anxiety
G43.4 Migraine
J0745 opioid Prescription
Z34 Pregnancy Supervision (unused)
O80 Vaginal Birth
O82 Cesarean section

Rules

  1. You will work either individually or with a group of 2 to 3 total individuals.

  2. Course notes and internet are fair game. No gen. AI.

  3. You may not use DASIL

  4. You may ask the mentors questions. They cannot give you assistance, but they can answer if you are doing something correctly or not

  5. You may consult with other individuals in the course outside your group.

  6. You may ask me clarifying questions, which I will do my best to answer. You may also talk to me about what you are doing (sometimes explaining it out loud helps), but I will not be able to give any more direction than this

  7. Final submission will be an R Markdown pdf file, just as we did in the labs. To this end, please consider the following:

    1. Do not print extraneous output. The report should be concise
    2. Leave comments in your code to describe what you are doing
    3. Include names of everybody in your group at the top
  8. Due Sunday 11/29 at 11:59pm. (Updated from Fri 11/27)

Assessment

Your total score in the following will be rounded up to the next multiple of 10. For example, a score of 93 will be rounded up to 100.

Data Processing – 60 pts

  • Inclusion Criteria (20 pts)

    • Age criteria
    • Coverage criteria
  • Variable creation (40 points)

    • Age at delivery
    • delivery type
    • opioid prescription status
    • Migraine status
    • Insurance type
    • Mental Health diagnosis

Report – 30 pts

  • 3-4 Exploratory graphs with explanations as to what the plot is showing (20 pts)
  • give conclusion as to association between mental health diagnosis and opioid prescription (10 pts)
  • Your document should be neatly organized with headers and labels (no points to be gained, some to be lost)

Code submission – 10pts

  • code displayed at end of report in new section, all visible
  • Code should run without errors
  • Comments describing what your code is doing
  • No extra output included in final document

Hints

In no particular order:

  1. This entire endeavor can be done using only packages used in class (230 and 209)

  2. Recall the difference between inner_join() and left_join(). What does each keep? You may need both

  3. In nearly all data processing steps, you will want your data to be grouped by id

  4. Several of the tasks you are asked to complete are specific iterations of more general problems. Think carefully about what you are trying to do when using a search engine for help

  5. Use %in% instead of == for testing if ICD codes are contained within some vector

  6. Many of these covariates can be made in any order – if you are getting stuck preparing one, try moving on to a different one

  7. If you are running into problems, try working with a smaller subset of your data to verify that you are creating variables correctly. Here is a good candidate for doing so:

member_practice <- member[member$id == "PID240296", ]
claims_practice <- claims[claims$id == "PID240296", ]
  1. Once you have processed all the variables you need, remove the columns in the dataset that you don’t and use unique() to be sure that you only have one observation per row. Your final dataset should have 4243 total subjects. If you are in the ballpark of this number, and are spending an inordinate amount of time refining, it is OK to move on to another part.

  2. Here is an example of a function that might be useful. If you understand how it works, you could modify it to do something different

library(lubridate)
happen_after_n <- function(y, m, d, n) {
  m <- m + 12*(y == 2018)
  event <- month(d) + 12*(year(d) == 2018)
  (max(m) - max(event)) >= n
}

# How might you use that function with this?
df <- data.frame(month = rep(1:12, times = 2),
                 year = rep(2017:2018, each = 12), 
                 date1 = "2017-10-10", 
                 date2 = "2018-10-10")