import csv
from pathlib import Path
import glmm
import pandas as pd
DATA_PATH = Path(__file__).resolve().parents[3] / "validation" / "data" / "empirical" / "cake.csv"
with open(DATA_PATH, newline="") as f:
rows = list(csv.DictReader(f))
angle = [float(r["angle"]) for r in rows]
temp = [float(r["temp"]) for r in rows]
recipe_labels = [r["recipe"] for r in rows]
replicate = [r["replicate"] for r in rows]
data = {
"angle": angle,
"recipe": recipe_labels,
"temp": temp,
"replicate": replicate,
}
fit_a = glmm.fit(data, "angle ~ recipe*temp + (1 | recipe:replicate)")
print("=== base = A (default, no declared order) ===")
fit_a.summary()
data_b = dict(data)
data_b["recipe"] = pd.Categorical(recipe_labels, categories=["B", "A", "C"])
fit_b = glmm.fit(data_b, "angle ~ recipe*temp + (1 | recipe:replicate)")
print("\n=== base = B (pandas.Categorical(categories=['B', 'A', 'C'])) ===")
fit_b.summary()
print(
"\nSame fit, different parameterization: fitted values and loglik agree "
"(loglik A={:.10g}, loglik B={:.10g}, delta={:.3g}); only which contrasts "
"are directly readable off beta changes.".format(
fit_a.loglik, fit_b.loglik, fit_b.loglik - fit_a.loglik
)
)
print("\n(cake carries no goldens/ entry -- a run, not an oracle-pinned result)")