Skip to content

Hypothesis Testing in Healthcare: Drug Safety

A pharmaceutical company GlobalXYZ has just completed a randomized controlled drug trial. To promote transparency and reproducibility of the drug's outcome, they (GlobalXYZ) have presented the dataset to your organization, a non-profit that focuses primarily on drug safety.

The dataset provided contained five adverse effects, demographic data, vital signs, etc. Your organization is primarily interested in the drug's adverse reactions. It wants to know if the adverse reactions, if any, are of significant proportions. It has asked you to explore and answer some questions from the data.

The dataset drug_safety.csv was obtained from Hbiostat courtesy of the Vanderbilt University Department of Biostatistics. It contained five adverse effects: headache, abdominal pain, dyspepsia, upper respiratory infection, chronic obstructive airway disease (COAD), demographic data, vital signs, lab measures, etc. The ratio of drug observations to placebo observations is 2 to 1.

For this project, the dataset has been modified to reflect the presence and absence of adverse effects adverse_effects and the number of adverse effects in a single individual num_effects.

The columns in the modified dataset are:

ColumnDescription
sexThe gender of the individual
ageThe age of the individual
weekThe week of the drug testing
trxThe treatment (Drug) and control (Placebo) groups
wbcThe count of white blood cells
rbcThe count of red blood cells
adverse_effectsThe presence of at least a single adverse effect
num_effectsThe number of adverse effects experienced by a single individual

The original dataset can be found here.

Your organization has asked you to explore and answer some questions from the data collected. See the project instructions.

For easy understanding, This project is about analyzing data from a clinical trial to see if a new drug is safe and effective. The trial compared the drug to a placebo (a dummy treatment) to see if there were any differences in the number of adverse effects between the two groups.

I am sure you're wondering what P–Value is. P-value is a measure of how likely it is that the results of the study are due to chance rather than the treatment itself.

The project instructions are simple :

  1. Compare the number of adverse effects: Between the group that took the drug and the group that took the placebo.
  2. Determine if the differences are significant: Using statistical tests to see if the differences between the two groups are due to chance or if they're real.
  3. Draw conclusions about the safety and effectiveness of the drug: Based on the results of the analysis

This project is important because it helps to:

  1. Ensure the safety of new treatments: By identifying potential side effects and adverse reactions.
  2. Improve the effectiveness of new treatments*: By comparing the results of the treatment to a placebo.
  3. Inform decision-making: By providing valuable data that can help doctors, researchers, and policymakers make informed decisions about new treatments.
# Import packages
import numpy as np
import pandas as pd
from statsmodels.stats.proportion import proportions_ztest
import pingouin
import seaborn as sns
import matplotlib.pyplot as plt

# Load the dataset
drug_safety = pd.read_csv("drug_safety.csv")

# Start coding here...
print(drug_safety.head())
# I start by retrieving the count of adverse_effects column values for each trx group
adv_eff_by_trx = drug_safety.groupby("trx").adverse_effects.value_counts()

print(adv_eff_by_trx)
#the total number of rows in each group
adv_eff_by_trx_totals = adv_eff_by_trx.groupby("trx").sum()
print(adv_eff_by_trx_totals)
# here is an array of the "Yes" counts for each group
yeses = [adv_eff_by_trx["Drug"]["Yes"], adv_eff_by_trx["Placebo"]["Yes"]]
print(yeses)
#an array of the total number of rows in each group
n = [adv_eff_by_trx_totals["Drug"], adv_eff_by_trx_totals["Placebo"]]
print(n)
#two-sided z-test on the two proportions, 

#A two-sided z-test is a statistical test used to determine if there is a significant difference between the sample mean and the population mean.  

#Simply put,the sample mean could be either significantly greater than or less than the population mean.

two_sample_results = proportions_ztest(yeses, n)
print(two_sample_results)
#find the p-value

#The p-value is a measure used in hypothesis testing to help you decide whether to reject the null hypothesis.

#A low p-value (typically ≤ 0.05) suggests that the observed data is unlikely under the null hypothesis, so you might reject the null hypothesis.

#A high p-value (> 0.05) suggests that the observed data is consistent with the null hypothesis, so you might fail to reject the null hypothesis.

two_sample_p_value = two_sample_results[1]
print(two_sample_p_value)
# num_effects and trx are independent?
num_effects_groups = pingouin.chi2_independence(
    data=drug_safety, x="num_effects", y="trx")
print(num_effects_groups)
#yes
#Extract the p-value
num_effects_p_value = num_effects_groups[2]["pval"][0]
print(num_effects_p_value)
#histogram plotted with Seaborn
sns.histplot(data=drug_safety, x="age", hue="trx")
# Not compulsory but,confirm the histogram's output by conducting a normality test

# To choose between unpaired t-test and Wilcoxon-Mann-Whitney test
normality = pingouin.normality(
    data=drug_safety,
    dv='age',
    group='trx',
    method='shapiro', # the default
    alpha=0.05) # 0.05 is also the default

print(normality)
# Select the age of the Drug group
age_trx = drug_safety.loc[drug_safety["trx"] == "Drug", "age"]

# Select the age of the Placebo group
age_placebo = drug_safety.loc[drug_safety["trx"] == "Placebo", "age"]

print(age_trx)
print(age_placebo)