Methodolgy
Methodolgy
# Convert to DataFrame
df = pd.DataFrame(data)
# SEX
contingency_table_sex = create_contingency_table(df['sex'],
df[status])
chi2_stat_sex, p_val_sex, dof_sex, ex_sex =
chi2_contingency(pd.crosstab(df['sex'], df[status]))
# BMI
bins_bmi = [0, 30, 40, 50, float('inf')]
df['BMI Category'] = pd.cut(df['BMI'], bins=bins_bmi,
labels=["<=30", "31-40", "41-50", "51+"])
contingency_table_bmi = create_contingency_table(df['BMI
Category'], df[status])
chi2_stat_bmi, p_val_bmi, dof_bmi, ex_bmi =
chi2_contingency(pd.crosstab(df['BMI Category'], df[status]))
# SURGERY
contingency_table_surgery =
create_contingency_table(df['surgery'], df[status])
chi2_stat_surgery, p_val_surgery, dof_surgery, ex_surgery =
chi2_contingency(pd.crosstab(df['surgery'], df[status]))
# Display results
print(f"n (Deficient,Normal): ,n = {total_deficient}
({percent_deficient}%),n = {total_normal}({percent_normal}%)")
print(f"Age (Deficient,Normal): ,{mean_age_deficient:.2f} ±
{sd_age_deficient:.2f},{mean_age_normal:.2f} ± {sd_age_normal:.2f}")
# Simulate the ages using the given mean and standard deviation
np.random.seed(0) # For reproducibility
ages_deficient = np.random.normal(mean_age_deficient,
sd_age_deficient, total_deficient)
ages_normal = np.random.normal(mean_age_normal, sd_age_normal,
total_normal)
print(f"T-statistic: {t_stat.round(3)}")
print(f"P-value: ,{p_value.round(3)}")
print_csv_format(contingency_table_age, "Contingency Table for
Age")
print(f"\nChi-square statistic: {chi2_stat_age.round(3)}")
print(f"P-value: ,{p_val_age.round(3)}")
print_csv_format(contingency_table_sex, "Contingency Table for
Sex")
print(f"\nChi-square statistic: {chi2_stat_sex.round(3)}")
print(f"P-value: ,{p_val_sex.round(3)}")
# Simulate the ages using the given mean and standard deviation
np.random.seed(0) # For reproducibility
bmi_deficient = np.random.normal(mean_bmi_deficient,
sd_bmi_deficient, total_deficient)
bmi_normal = np.random.normal(mean_bmi_normal, sd_bmi_normal,
total_normal)
print(f"T-statistic: {t_stat.round(3)}")
print(f"P-value: ,{p_value.round(3)}")
print_csv_format(contingency_table_bmi, "Contingency Table for
BMI")
print(f"\nChi-square statistic: {chi2_stat_bmi.round(3)}")
print(f"P-value: ,{p_val_bmi.round(3)}")
print_csv_format(contingency_table_surgery, "Contingency Table for
Surgery")
print(f"\nChi-square statistic: {chi2_stat_surgery.round(3)}")
print(f"P-value: ,{p_val_surgery.round(3)}")
Analysis for
haemoglobin_status--------------------------------------------
n (Deficient,Normal): ,n = 11(34.4%),n = 21(65.6%)
Age (Deficient,Normal): ,40.09 ± 10.79,48.14 ± 13.99
T-statistic: -1.045
P-value: ,0.305
Analysis for
Ionized_Ca_status--------------------------------------------
n (Deficient,Normal): ,n = 9(28.1%),n = 23(71.9%)
Age (Deficient,Normal): ,41.78 ± 12.54,46.78 ± 13.70
T-statistic: 0.116
P-value: ,0.909