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 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")
# Count the late column values for each trx group
adverse_effects_by_trx= drug_safety.groupby('trx')['adverse_effects'].value_counts()
# Create an array of the "Yes" counts for each trx group
success_counts = np.array([adverse_effects_by_trx['Drug'].get('Yes',0),adverse_effects_by_trx['Placebo'].get('Yes',0)])
# Create an array of the total number of rows in each trx group
n = np.array([adverse_effects_by_trx['Drug'].sum(),adverse_effects_by_trx['Placebo'].sum()])
z_score, p_value = proportions_ztest(count=success_counts,nobs=n,alternative="two-sided")
two_sample_p_value= p_value
# Test if num_effects and trx are independent to determine whether trx influences the number of effects.
# Proportion of trx grouped by num_effects
props = drug_safety.groupby('num_effects')['trx'].value_counts(normalize=True)
# Convert props to wide format
wide_props = props.unstack()
# Determine if trx and num_effects are independent
expected, observed, stats = pingouin.chi2_independence(data=drug_safety,x="num_effects",y="trx")
num_effects_p_value = stats.loc[stats['test'] == 'pearson', 'pval'].values[0]
# Plot histograms for age in each treatment group
plt.figure(figsize=(12, 6))
sns.histplot(data=drug_safety, x='age', hue='trx', kde=True, bins=30)
plt.title('Distribution of Age in Treatment Groups')
plt.xlabel('Age')
plt.ylabel('Frequency')
plt.show()
shapiro_results = pingouin.normality(data=drug_safety,dv='age',group='trx')
# Select the age and trx columns
age_vs_trx = drug_safety[['age','trx']]
# Convert age_vs_trx into wide format
age_vs_trx_wide = age_vs_trx.pivot(columns='trx',
values='age')
# Run a two-sided Wilcoxon-Mann-Whitney test on weight_kilograms vs. late
wmw_test = pingouin.mwu(x=age_vs_trx_wide['Drug'],y=age_vs_trx_wide['Placebo'],alternative="two-sided")
age_group_effects_p_value = wmw_test['p-val']