Project: Hypothesis Testing in Healthcare
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    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

    # Import packages
    import numpy as np
    import pandas as pd
    from scipy.stats import norm
    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")
    

    1. The distribution of adverse effects

    a) Count plot showing the number of adverse effects in the Drug and Placebo groups.

    # count plot to show the number of adverse effects (num_effects) in the Drug and Placebo groups.
    plot_num_eff = sns.countplot(x='num_effects' , data=drug_safety , hue= 'trx')
    plt.xlabel('Number of Adverse Effects')
    plt.title('Distribution of the Number of Effects Between the Groups')
    plt.show()

    2. Two samples proportions z test

    b ) Two-sample Z-test to determine if the proportion of adverse effects differs significantly between the Drug and Placebo groups

    # Define the counts and sample sizes for the two groups
    group1_counts = drug_safety.loc[drug_safety['trx'] == 'Drug', 'adverse_effects'].value_counts()
    group2_counts = drug_safety.loc[drug_safety['trx'] == 'Placebo', 'adverse_effects'].value_counts()
    
    group1_successes = group1_counts['Yes']
    group1_total = group1_counts.sum()
    
    group2_successes = group2_counts['Yes']
    group2_total = group2_counts.sum()
    
    # Perform the two-sample proportions z-test
    stat, p_value = proportions_ztest([group1_successes, group2_successes], [group1_total, group2_total])
    
    # Round the z statistic and p-value to three decimal places
    two_samp_z_stat = round(stat, 3)
    two_samp_z_p_value = round(p_value, 3)
    
    two_samp_z_stat, two_samp_z_p_value

    3. Association between adverse effects and the groups

    c ) Testing whether num_effects and trx are independent to determine whether trx influences the number of effects.

    
    # Determine if num_effects and trx are independent
    expected, observed, stats = pingouin.chi2_independence(
        data=drug_safety, x="num_effects", y="trx")
    
    # Round the test statistics to three decimal places
    stats = stats.round(3)
    
    # Extract the Pearson row as pearson_num_effect_trx
    pearson_num_effect_trx = stats[stats["test"] == "pearson"]

    4. Distribution of age in the Drug and Placebo groups.

    d ) Histograms to visualize the distribution of age in both groups.

    import matplotlib.pyplot as plt
    
    # Create a histogram for the age distribution in the drug group
    plt.hist(drug_group['age'], bins=10, color='blue', alpha=0.5)
    plt.xlabel('Age')
    plt.ylabel('Frequency')
    plt.title('Distribution of Age in Drug Group')
    plt.show()
    
    # Create a histogram for the age distribution in the placebo group
    plt.hist(placebo_group['age'], bins=10, color='orange', alpha=0.5)
    plt.xlabel('Age')
    plt.ylabel('Frequency')
    plt.title('Distribution of Age in Placebo Group')
    plt.show()

    5. Significant difference between the ages of both groups.