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 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")

# determine if the proportion of adverse effects differs between the Drug and Placebo groups
# So I need to take two samples from two groups 
p_hats = drug_safety.groupby('trx')['adverse_effects'].value_counts()
print(p_hats)

n_adverse_effects = np.array([p_hats[('Drug', 'Yes')], p_hats[('Placebo', 'Yes')]])
n_rows = np.array([p_hats['Drug'].sum(), p_hats['Placebo'].sum()])

z_score, p_value = proportions_ztest(count=n_adverse_effects, nobs=n_rows, alternative="two-sided")
two_sample_p_value = p_value
# p_value = 0.96 so fail to reject the null hypothesis, no significance difference between the two groups

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

expected, observed, stats = pingouin.chi2_independence(data=drug_safety, x="trx", y="num_effects", correction=False)

print()

num_effects_p_value = stats['pval'].iloc[0]
# pval = 0.61 - fails to reject the null hypothesis, strongly correlated

# Is there a significance difference between the ages of the Drug and placebo group
# To compare two unpaired test, we will use mannwhitney u tes
age_drug = drug_safety[drug_safety["trx"] == "Drug"]["age"]
age_placebo = drug_safety[drug_safety["trx"] == "Placebo"]["age"]
result = pingouin.mwu(x=age_drug, y=age_placebo, alternative='two-sided')
age_group_effects_p_value = result['p-val']
# pval = 0.25, that means not enough evidence that there are not enough strong evidences that the ages of the drugs has a significant difference with the placebo group