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.

import numpy as np
import pandas as pd
from statsmodels.stats.proportion import proportions_ztest
from scipy.stats import chi2_contingency
from scipy.stats import ttest_ind
from scipy.stats import mannwhitneyu
import pingouin
import seaborn as sns
import matplotlib.pyplot as plt

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

Determine if the proportion of adverse effects differ significantly between Drug and Placebo groups.

Null Hypothesis (H₀)The proportion of individuals with adverse effects is the same in both Drug and Placebo groups. p₁ = p₂
Alternative Hypothesis (H₁)The proportion of adverse effects differs between the two groups. p₁ ≠ p₂
drug_safety.head()
drug_safety.info()

We'll initially split the data into the two sets - drug and placebo, with a ratio of approx. 2:1 - we can assume the drug set will be around 9-11k total rows.

# seperate the data into drug and placebo participants
drug_split = drug_safety[drug_safety["trx"] == 'Drug']
drug_split.info()
placebo_split = drug_safety[drug_safety["trx"] == 'Placebo']
placebo_split.info()
# refine columns of each for purpose of test
drug = drug_split[["trx","adverse_effects"]]
placebo = placebo_split[["trx","adverse_effects"]]

drug.head(2)
# check ratio of adverse effects to none in drug group
drug.groupby(['trx', 'adverse_effects']).size()
# check ratio of adverse effects to none in placebo group
placebo.groupby(['trx', 'adverse_effects']).size()
# create variables for test
drug_yes = drug[(drug['trx'] == 'Drug') & (drug['adverse_effects'] == 'Yes')].shape[0]
drug_total = drug[drug['trx'] == 'Drug'].shape[0]
placebo_yes = placebo[(placebo['trx'] == 'Placebo') & (placebo['adverse_effects'] == 'Yes')].shape[0]
placebo_total = placebo[placebo['trx'] == 'Placebo'].shape[0]

yes_count = [drug_yes, placebo_yes]
total_count = [drug_total, placebo_total]

# run two proportion z-test
z_stat, two_sample_p_value = proportions_ztest(yes_count, total_count)

print(f"P-value: {two_sample_p_value:.4f}")

p-value ≈ 0.96 is way above any typical significance level. There’s no significant difference in the proportion of adverse effects between the Drug and Placebo groups — at least based on this dataset.

We fail to reject the null hypothesis.

alpha = 0.05
if two_sample_p_value < alpha:
    print("Reject the null hypothesis: There is a significant difference in the proportion of adverse effects between the Drug and Placebo groups.")
else:
    print("Fail to reject the null hypothesis: There’s no significant difference in the proportion of adverse effects between the Drug and Placebo groups.")

Find out if the number of adverse effects is independent of the treatment and control groups