Analyzing Adverse Effects of Neurological Pain Medications Using RStudio

Gustiyan Islahuzaman
10 min readSep 24, 2023

--

Created by Bing Image Creator

Introduction

Understanding the potential side effects of drugs is crucial in the world of healthcare. It not only helps to ensure patient safety, but it also enables medical professionals to choose therapies wisely. In this post, we will examine how to assess and display the side effects of drugs used to treat neurological pain using R, a powerful statistical programming language. Tramal will be the main subject of our analysis, and it will be contrasted with the frequently prescribed prescription Lyrica.

Case Summary

Setting the stage for our analysis is what we’ll do first. With its headquarters in Bern, Switzerland, PricewaterhouseCoopers (PwC) and a network of German physicians are working together on this initiative. The adverse effects of routinely used medications for treating neurological pain are of particular interest to medical professionals. Along with common drugs like gabapentin and lyrica, tramal has demonstrated promise in reducing neurological pain. The idea of contrasting tramal’s side effects with those of a painkiller and lyrica has the doctors curious about which drug would be more appropriate for specific patients.

We will use information from the FDA Adverse Event Reporting System (FAERS), a centralized database maintained by the American FDA, to do this work. FAERS plays a critical role in the FDA’s post-marketing safety surveillance program for drugs and therapeutic biologic products by acting as a repository of data on reports of adverse events and medication errors.

Objective

Based on the information currently accessible from the FDA Adverse Event Reporting System (FAERS), the goal of this study is to thoroughly analyze the adverse effects connected with tramal, a drug used to treat neurological pain. The investigation will pay particular attention to FAERS data from the year 2019. Tramal and Lyrica, another drug frequently given for the treatment of neurological pain, will also be compared in this investigation. Rscript will be used in the project for data analysis and visualization, and the results will be presented as such.

Dataset Overview

Our analysis’s main data source is our FAERS-sourced dataset, which is a valuable repository of real-world data, comprising reports submitted by healthcare professionals, patients, and pharmaceutical companies. We rely on publicly accessible data and information, which you can access by following this link: [Data Source Link]. Our research focuses specifically on data from the year 2019, chosen for its relevance to current practices. In our dataset overview section, we focus on specific subsets of data from the quarterly files. We exclusively utilize the following categories of data for our analysis:

  1. Patient Demographic and Administrative Information (DEMOyyQq.TXT): This file contains essential details about the patients involved in the adverse event reports. Each record in this file corresponds to a single event report. It provides comprehensive demographic information, including patient age, gender, and administrative data. This data is fundamental for understanding the patient population affected by adverse events.
  2. Drug/Biologic Information (DRUGyyQq.TXT): Within this file, we find detailed information about the drugs or biologic products associated with each adverse event report. Multiple medications may be reported for a single event, and this file captures all relevant drug data. Understanding the drugs involved is critical for our analysis.
  3. Medical Dictionary for Regulatory Activities (MedDRA) Terms (REACyyQq.TXT): This file includes the MedDRA terms associated with each adverse event report. MedDRA terms represent the specific medical conditions or reactions reported. Multiple terms may be coded for a single event. This information is vital for identifying and categorizing adverse reactions.
  4. Drug Therapy Start and End Dates (THERyyQq.TXT): In this file, we find data related to the start and end dates of drug therapy for the reported medications. Not all events may have therapy start and end dates, and multiple dates may be associated with a single drug for a single event. Understanding the timing of drug therapy is crucial for our analysis.

Setting Up the Environment

Before we dive into the analysis, let’s get our R environment ready and load the essential tools we’ll be using.

Here are the key libraries we’ll be using:

  • gridExtra: This library helps us arrange multiple plots neatly on a page, allowing us to create sophisticated layouts by combining various plots.
  • dplyr: Think of dplyr as your data manipulation toolbox. It simplifies tasks like filtering, selecting, arranging, and summarizing data, making data handling a breeze.
  • ggplot2: If you love beautiful and customizable plots, ggplot2 is your go-to. It lets us create stunning visuals, one layer at a time, with an intuitive approach.
  • zoo: For handling time series data, zoo is our trusty companion. It offers handy tools for managing time-based data, filling in gaps, and performing calculations.
  • lubridate: Dealing with dates and times? Lubridate has got you covered. It simplifies tasks related to parsing, manipulating, and formatting date-time information.
  • xtable: Need to generate tables in different formats like LaTeX, HTML, or plain text? Xtable is the go-to choose, offering flexibility for customizing table appearance and content.
  • car: For statistical modeling and data analysis tasks, car provides a suite of tools. It’s especially handy for regression analysis, ANOVA, and diagnostic plots.
  • forcats: When working with categorical data, forcats comes to the rescue. It offers functions to reorder factor levels, recode categories, and handle categorical variables effectively.
  • tableHTML: Want to create interactive HTML tables with features like sorting, filtering, and pagination? TableHTML is your solution, enhancing the presentation of tabular data.
  • readr: For fast and efficient data importing, readr is the way to go. It supports various file formats like CSV, TSV, Excel, and more, making data loading a breeze.

These libraries will empower us to efficiently manage and visualize our data for a smoother analysis journey. Let’s get started!

# Load necessary libraries
library(gridExtra)
library(dplyr)
library(ggplot2)
library(zoo)
library(lubridate)
library(xtable)
library(car)
library(forcats)
library(tableHTML)
library(readr)

# Set the working directory to where your data files are located
setwd("~/Data Fears PwC")

# Define years and quarters for data extraction
years <- c("19")
quarters <- c("1", "2", "3", "4")

# Define a generic path for data files
generic <- "faers_ascii_20"

Data Preprocessing

Let’s now read the data files to find the demographic data, medication history, therapeutic information, and adverse reactions. Data will be cleaned, column names will be standardized, and pertinent data will be combined.

# Read in the data files for demographic, drug, therapy, and reaction data
# Perform data cleaning and standardization

# Create empty master datasets
demoDF <- data.frame()
drugDF <- data.frame()
drugDFAll <- data.frame()
therDF <- data.frame()
reactDF <- data.frame()

# Define relevant columns
relevantDemoColumns <- c("primaryid", "age", "sex", "wt", "reporter_country", "event_dt", "init_fda_dt")
relevantDrugColumns <- c("primaryid", "drugname", "drug_seq", "Freq")
relevantTherColumns <- c("primaryid", "dsg_drug_seq", "start_dt", "end_dt", "dur")
relevantReactColumns <- c("primaryid", "pt")

# Define drug names of interest
drugnames <- c("tramal", "lyrica")

# Loop through years and quarters to read and process data
for (year in years) {
for (quarter in quarters) {
# Construct file paths based on year and quarter
pathdemo <- paste(generic, year, "q", quarter, "/ascii/DEMO", year, "Q", quarter, ".txt", sep="")
pathdrug <- paste(generic, year, "q", quarter, "/ascii/DRUG", year, "Q", quarter, ".txt", sep="")
pathther <- paste(generic, year, "q", quarter, "/ascii/THER", year, "Q", quarter, ".txt", sep="")
pathreact <- paste(generic, year, "q", quarter, "/ascii/REAC", year, "Q", quarter, ".txt", sep="")

# Read in the data files
demo <- read_delim(pathdemo, delim="$")
drug <- read_delim(pathdrug, delim="$")
ther <- read_delim(pathther, delim="$")
react <- read_delim(pathreact, delim="$")

# Standardize column names
colnames(demo) <- tolower(colnames(demo))
colnames(drug) <- tolower(colnames(drug))
colnames(ther) <- tolower(colnames(ther))
colnames(react) <- tolower(colnames(react))

# Check and fix column name inconsistencies
if (!"sex" %in% colnames(demo)) {
names(demo)[names(demo) == 'gndr_cod'] <- 'sex'
}

# Rename columns if needed (e.g., "isr" to "primaryid")
if ("isr" %in% colnames(demo)) {
names(demo)[names(demo) == 'isr'] <- 'primaryid'
names(drug)[names(drug) == 'isr'] <- 'primaryid'
names(ther)[names(ther) == 'isr'] <- 'primaryid'
names(react)[names(react) == 'isr'] <- 'primaryid'
}

# Merge drug frequency information with drug data
drugunique <- drug[!duplicated(drug[, c("primaryid", "drugname")]),]
drugfreq <- as.data.frame(table(drugunique$primaryid))
drug <- merge(drug, drugfreq, by.x="primaryid", by.y="Var1", all.x = TRUE)
names(drug)[names(drug) == 'Freq.x'] <- 'Freq'

# Select relevant columns
demo <- demo[, relevantDemoColumns]
drug <- drug[, relevantDrugColumns]
ther <- ther[, relevantTherColumns]
react <- react[, relevantReactColumns]

# Change drug names to lowercase for consistency
drug$drugname <- tolower(drug$drugname)

# Append data to master datasets
drugAll <- drug
drug <- drug[which(drug$drugname %in% drugnames),]

# Create year and yearquarter columns
drug$datequarter <- as.yearqtr(2000 + as.numeric(year) + (as.numeric(quarter) - 1) * 0.25)
drug$dateyear <- as.factor(2000 + as.numeric(year))

drugDF <- rbind(drugDF, drug)
drugDFAll <- rbind(drugDFAll, drugAll)
demoDF <- rbind(demoDF, demo)
therDF <- rbind(therDF, ther)
reactDF <- rbind(reactDF, react)
}
}

# Save the cleaned datasets for future analysis
save(drugDF, file="drugDFCase.Rda")
save(drugDFAll, file="drugDFAllCase.Rda")
save(demoDF, file="demoDFCase.Rda")
save(therDF, file="therDFCase.Rda")
save(reactDF, file="reactDFCase.Rda")
The Cleaned Datasets Results

Analyzing Adverse Effects

With our data cleaned and organized, we can now analyze the adverse effects associated with Tramal and Lyrica.

# Merge adverse reactions with drug data
drugUnique <- drugDF[!duplicated(drugDF[, c("primaryid", "drugname")]),]
reactdrug <- merge(reactDF, drugUnique, by = "primaryid", all.x = TRUE)
reactdrug <- na.omit(reactdrug)
reactdrug <- reactdrug[!duplicated(reactdrug[, c("primaryid", "pt")]),]

# Optional: Merge with patient demographics for future modeling
reactdrugdemo <- merge(reactdrug, demoDF, by = "primaryid", all.x = TRUE)

# Optional: Create a unique key for drugs within events
therDF$drugKey <- paste(therDF$primaryid, therDF$dsg_drug_seq, sep="")
reactdrugdemo$drugKey <- paste(reactdrugdemo$primaryid, reactdrugdemo$drug_seq, sep="")

# Merge therapy data with the merged dataset using the drugKey
drugdemotherreact <- merge(reactdrugdemo, therDF, by = "drugKey", all.x = TRUE)

# Make all adverse effects lowercase for consistency
drugdemotherreact$pt <- tolower(drugdemotherreact$pt)

# Rename dataset for convenience
tl <- drugdemotherreact

# Filter data for Tramal and Lyrica
tramal_df <- tl[tl$drugname == "tramal",]
lyrica_df <- tl[tl$drugname == "lyrica",]

# Count and visualize the top 10 adverse effects for Tramal and Lyrica
top5AdverseEffectsTramadol <- count(tramal_df, pt, sort=TRUE)[1:10,]
top5AdverseEffectsLyrica <- count(lyrica_df, pt, sort=TRUE)[1:10,]
Top 10 Adverse Effects for Lyrica

In our exploration of the adverse effects associated with the medication “Lyrica,” we’ve uncovered some valuable insights based on the provided data. Let’s delve into the analysis of these findings:

  1. Most Common Adverse Effect: The most frequently reported adverse effect among individuals taking Lyrica is “pain.” This suggests that a significant number of patients experienced pain as a side effect while using the medication. Pain can be a crucial consideration for both patients and healthcare providers, as it may impact treatment decisions and patient comfort.
  2. Effectiveness Concerns: “Drug ineffective” is the second most common adverse effect. This finding raises questions about the effectiveness of Lyrica in some cases. When over 3000 individuals report that the drug was ineffective, it highlights the need for careful monitoring of treatment outcomes and potential adjustments to the medication regimen.
  3. General Discomfort: “Malaise” and “feeling abnormal” are also notable adverse effects. These terms describe a general feeling of discomfort or unease. The substantial number of cases associated with these effects underscores the importance of assessing the overall well-being of patients taking Lyrica beyond just specific symptoms.
  4. Off-Label Use: It’s noteworthy that “off-label use” appears as an adverse effect. This suggests that Lyrica is sometimes prescribed for purposes not officially approved by regulatory authorities. Understanding the reasons for off-label use and its potential consequences is crucial for patient safety.
  5. Localized Pain: “Pain in extremity” specifically highlights pain experienced in the arms or legs. This localized pain may have implications for patients’ mobility and daily activities, warranting careful consideration.
  6. Side Effects Impacting Quality of Life: Both “fatigue” and “insomnia” are adverse effects that can significantly impact a patient’s quality of life. Fatigue can lead to decreased energy levels, while insomnia can disrupt sleep patterns. These effects may need to be managed alongside the primary condition.
  7. Nausea and Withdrawal: “Nausea” and “withdrawal syndrome” are also reported adverse effects. Nausea can be distressing for patients, and withdrawal symptoms when discontinuing the medication highlight the need for proper guidance on medication cessation.
Top 10 Adverse Effects for Tramal

Let’s delve into an analysis of the adverse effects linked to the medication “Tramadol” based on the provided data. Here’s what we’ve uncovered:

  1. Nausea (64 cases): Nausea emerges as the most commonly reported adverse effect of Tramadol. It indicates that a significant number of individuals experience a sensation of wanting to vomit while using the medication. Nausea can be a distressing side effect that patients and healthcare providers should be aware of and prepared to manage.
  2. Pyrexia (45 cases): Pyrexia, or the presence of a fever, was reported in 45 cases among those using Tramadol. Elevated body temperature can be a concern and may require medical attention, especially in individuals with underlying health conditions.
  3. Abdominal Pain (43 cases): Abdominal pain, a discomfort or ache in the belly area, affected 43 individuals taking Tramadol. For the comfort and safety of the patient, it is essential to understand the type and level of this pain.
  4. White Blood Cell Count Increased (34 cases): In 34 cases, Tramadol was associated with an increase in white blood cell count. Changes in blood cell counts can be a noteworthy side effect, and healthcare providers should closely monitor such cases.
  5. Diarrhoea (33 cases): Diarrhoea, characterized by loose or watery stools, was reported in 33 cases as an adverse effect of Tramadol. Managing this gastrointestinal side effect is essential to ensure patient well-being.
  6. Dyspnoea (31 cases): Dyspnoea, or difficulty in breathing, occurred in 31 cases. Breathing difficulties are a serious concern and should be addressed promptly.
  7. Ileus (31 cases): Ileus, a condition where the bowels do not function correctly, was reported in 31 cases. This condition can be a sign of a more complex issue and necessitates medical attention.
  8. Abdominal Distension (30 cases): Abdominal distension, or a bloated abdomen, affected 30 individuals. This can be uncomfortable and may indicate underlying concerns.
  9. Dementia (29 cases): Dementia, a cognitive disorder, was reported in 29 cases. Understanding the relationship between Tramadol and cognitive effects is essential, particularly in older populations.
  10. Malignant Neoplasm Progression (29 cases): Malignant neoplasm progression, indicating the advancement of cancer, was also reported in 29 cases. The connection between Tramadol and cancer progression warrants further investigation.
# Create bar plots for the top adverse effects
t <- top5AdverseEffectsTramadol %>%
ggplot(aes(x = reorder(pt, n), y = n)) +
geom_bar(stat = "identity", aes(fill = n)) +
coord_flip() +
ggtitle("Tramal") +
theme(legend.position = "None")

l <- top5AdverseEffectsLyrica %>%
ggplot(aes(x = reorder(pt, n), y = n)) +
geom_bar(stat = "identity", aes(fill = n)) +
coord_flip() +
ggtitle("Lyrica") +
theme(legend.position = "None")

# Display the bar plots side by side
grid.arrange(t, l, ncol=2)
Bar Plots for the Top Adverse Effects

Conclusion

In this extensive investigation, we delved into the area of side effects connected with neurological painkillers. We have provided insightful information for healthcare practitioners by carefully examining Tramal, Lyrica, and using FAERS data. Our study gives them the knowledge they need to choose treatments for neurological pain more wisely, eventually improving patient care and safety.

--

--

Gustiyan Islahuzaman
Gustiyan Islahuzaman

Written by Gustiyan Islahuzaman

Data Analyst focused on Power BI dashboard creation. Sharing tips and tricks for data analysis with Python, R, SQL, Excel, Looker Studio, Tableau, and Power BI.

No responses yet