"""Reproducible analysis for: Iris Flower Measurements

Generated by thericerca on 2026-07-30 21:04 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 the morphological measurements of iris flowers and how the sepal and petal dimensions relate to one another.

Objectives:
  - To describe the sepal_length, sepal_width, petal_length, and petal_width of the flowers.
  - To determine the relationship between petal_length and petal_width.
  - To determine the relationship between sepal_length and petal_length.
  - To determine the relationship between sepal_length and sepal_width.

"""

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 'iris.csv'.
df = pd.read_csv('iris.csv')
print(f'Loaded {len(df)} rows, {len(df.columns)} columns.')
df.head()


# ------------------------------------------------------------------------------
# [1/4] Descriptive Statistics
#   Question: To describe the sepal_length, sepal_width, petal_length, and petal_width of the flowers.
# ------------------------------------------------------------------------------
cols = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
print(df[cols].describe(include='all').T)


# ------------------------------------------------------------------------------
# [2/4] Spearman Rank Correlation
#   Question: To determine the relationship between petal_length and petal_width.
# ------------------------------------------------------------------------------
a, b = df['petal_length'].dropna(), df['petal_width'].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/4] Spearman Rank Correlation
#   Question: To determine the relationship between sepal_length and petal_length.
# ------------------------------------------------------------------------------
a, b = df['sepal_length'].dropna(), df['petal_length'].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)}')


# ------------------------------------------------------------------------------
# [4/4] Spearman Rank Correlation
#   Question: To determine the relationship between sepal_length and sepal_width.
# ------------------------------------------------------------------------------
a, b = df['sepal_length'].dropna(), df['sepal_width'].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)}')


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