"""Reproducible analysis for: Predicting Diabetes Progression

Generated by thericerca on 2026-07-30 21:02 UTC.
Regenerate the same statistical output on the same data by running this script (or the
matching .ipynb) with the third-party libraries at the top installed.

Statement of the problem:
  This study examines baseline clinical measurements and how well they predict one-year disease progression in patients with diabetes.

Objectives:
  - To describe the disease_progression, bmi, and blood_pressure of the patients.
  - To determine the relationship between bmi and disease_progression.
  - To predict disease_progression from bmi and blood_pressure.

"""

import pandas as pd
import numpy as np
from scipy import stats
import statsmodels.api as sm
import statsmodels.formula.api as smf


# Load the dataset. Point this at your local copy of 'diabetes.csv'.
df = pd.read_csv('diabetes.csv')
print(f'Loaded {len(df)} rows, {len(df.columns)} columns.')
df.head()


# ------------------------------------------------------------------------------
# [1/3] Descriptive Statistics
#   Question: To describe the disease_progression, bmi, and blood_pressure of the patients.
# ------------------------------------------------------------------------------
cols = ['disease_progression', 'bmi', 'blood_pressure']
print(df[cols].describe(include='all').T)


# ------------------------------------------------------------------------------
# [2/3] Spearman Rank Correlation
#   Question: To determine the relationship between bmi and disease_progression.
# ------------------------------------------------------------------------------
a, b = df['disease_progression'].dropna(), df['bmi'].dropna()
pair = pd.concat([a, b], axis=1).dropna()
rho, p_value = stats.spearmanr(pair.iloc[:, 0], pair.iloc[:, 1])
print(f'rho = {rho:.3f}, p = {p_value:.4g}, n = {len(pair)}')


# ------------------------------------------------------------------------------
# [3/3] Multiple Linear Regression
#   Question: To predict disease_progression from bmi and blood_pressure.
# ------------------------------------------------------------------------------
model = smf.ols('Q("disease_progression") ~ Q("bmi") + Q("blood_pressure")', data=df).fit()
print(model.summary())


# ------------------------------------------------------------------------------
# End of thericerca reproducible analysis.
# ------------------------------------------------------------------------------
