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:
| Column | Description |
|---|---|
sex | The gender of the individual |
age | The age of the individual |
week | The week of the drug testing |
trx | The treatment (Drug) and control (Placebo) groups |
wbc | The count of white blood cells |
rbc | The count of red blood cells |
adverse_effects | The presence of at least a single adverse effect |
num_effects | The 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
import pingouin
import seaborn as sns
import matplotlib.pyplot as plt
drug_safety = pd.read_csv("drug_safety.csv")
display(drug_safety.head())
# 1. Whether the proportion of adverse effects differs significantly between the Drug and Placebo groups to know if the pharmaceutical drug created statistically significant side effects
#Two-sample proportions z-test
p_hats = drug_safety.groupby("trx")["adverse_effects"].value_counts()
display(p_hats)
n_adverse_effects = np.array([p_hats[1],p_hats[3]])
n_rows = np.array([p_hats[0] + p_hats[1], p_hats[2] + p_hats[3]])
two_sample_results = proportions_ztest(count = n_adverse_effects,
nobs = n_rows,
alternative = "two-sided")
print(two_sample_results)
print("z-score:", two_sample_results[0],'\n',"p-value:", two_sample_results[1])
#p-value > 0.05
# Conclusion: "There are no statistically significant differences between the Drug and Placebo groups in adverse effects"
# 2. Association between adverse effects and the Drug and Placebo groups
# Chi-square test of independence
num_effects_groups = pingouin.chi2_independence(data = drug_safety,
x = "trx",
y = "num_effects",
correction = False)
display(num_effects_groups)
display("p-value:", num_effects_groups[2]["pval"])
#p-value > 0.05
#Conclusion: "The number of adverse effects is independent of the Drug and Placebo groups."
# 3. Inspecting whether age is normally distributed
#Histogram
sns.histplot(data = drug_safety, x ="age", hue = "trx", kde=True)
plt.show()
#Shapiro-Wilks test
normality_test = pingouin.normality(data = drug_safety,
dv = "age",
group = "trx")
display(normality_test)
#p-value < 0.05
#Conclusion: "Age is not normally distributed in the Drug and Placebo groups."
# 4. Significant difference between the ages of the Drug and Placebo groups
#Mann-Whitney U test
age_vs_groups = drug_safety[["trx", 'age']]
age_vs_groups_wide = age_vs_groups.pivot(columns = "trx",
values = "age")
age_group_effects = pingouin.mwu(x = age_vs_groups_wide["Placebo"],
y = age_vs_groups_wide["Drug"])
# OR
#age_drug = drug_safety.loc[drug_safety["trx"]=="Drug"]["age"]
#age_placebo = drug_safety.loc[drug_safety["trx"]=="Placebo"]["age"]
#age_group_effects = pingouin.mwu(x = age_placebo, y = age_drug)
display(age_group_effects)
display("p-value:", age_group_effects["p-val"])
#p-value > 0.05
#Conclusion: "There is no a significant difference between the ages of the Drug and Placebo groups."