for data_name, results in all_results.items():
n_obs = n_obs_map.get(data_name)
names = [r["name"] for r in results]
N = len(names)
print(f"\n{'=' * 60}")
print(f" {data_name}")
print(f"{'=' * 60}")
# Parameter summary
summary = summarize_parameters(results, query_parameters, include_std=True, include_ci=True)
save_table(summary, "parameters", data_name)
print("\n## Parameter Summary")
print(summary)
# T-test
df_t, df_p = generate_t_p_matrices(results)
save_table(df_p.to_markdown(), "t_test_p_values", data_name)
print("\n## T-Test P-Values")
print(df_p.to_markdown())
# Winner ratios
if use_aicc and n_obs is not None:
df_winner = aicc_winner_comparison_matrix(results, n_obs)
else:
df_winner = winner_comparison_matrix(results)
save_table(df_winner.to_markdown().replace(" nan ", " "), "winner_ratios", data_name)
print("\n## Winner Ratios")
print(df_winner.to_markdown().replace(" nan ", " "))
df_raw = raw_winner_comparison_matrix(results)
save_table(df_raw.to_markdown().replace(" nan ", " "), "raw_winner_ratios", data_name)
print("\n## Raw Winner Ratios")
print(df_raw.to_markdown().replace(" nan ", " "))
# Delta AIC
ic_label = "AICc" if (use_aicc and n_obs is not None) else "AIC"
if use_aicc and n_obs is not None:
mean_delta, ci_hw, _ = pairwise_aicc_differences(results, n_obs)
else:
mean_delta, ci_hw, _ = pairwise_aic_differences(results)
delta_table = mean_delta.copy().astype(object)
for rl in delta_table.index:
for cl in delta_table.columns:
if rl == cl:
delta_table.loc[rl, cl] = ""
else:
mv, ci = mean_delta.loc[rl, cl], ci_hw.loc[rl, cl]
if mv != mv or ci != ci:
delta_table.loc[rl, cl] = ""
else:
delta_table.loc[rl, cl] = f"{mv:.2f} [{mv - ci:.2f}, {mv + ci:.2f}]"
save_table(delta_table.to_markdown(), f"delta_{ic_label.lower()}", data_name)
print(f"\n## Pairwise Δ{ic_label}")
print(delta_table.to_markdown())
if use_aicc and n_obs is not None:
med_delta, med_ci = pairwise_median_aicc_differences(results, n_obs)
else:
med_delta, med_ci = pairwise_median_aic_differences(results)
med_table = med_delta.copy().astype(object)
for rl in med_table.index:
for cl in med_table.columns:
if rl == cl:
med_table.loc[rl, cl] = ""
else:
m, ci = med_delta.loc[rl, cl], med_ci.loc[rl, cl]
if m != m or ci != ci:
med_table.loc[rl, cl] = ""
else:
med_table.loc[rl, cl] = f"{m:.2f} [{m - ci:.2f}, {m + ci:.2f}]"
save_table(med_table.to_markdown(), f"median_delta_{ic_label.lower()}", data_name)
print(f"\n## Median Δ{ic_label}")
print(med_table.to_markdown())
# Pairwise AICw
col_name = "AICcw" if (use_aicc and n_obs is not None) else "AICw"
aicw_fn = (lambda pair: calculate_aicc_weights(pair, n_obs)) if (use_aicc and n_obs is not None) else calculate_aic_weights
aicw_matrix = pd.DataFrame("", index=names, columns=names)
for i in range(N):
for j in range(i + 1, N):
pair = [results[i], results[j]]
w = aicw_fn(pair).set_index("Model")
aicw_matrix.loc[names[i], names[j]] = f"{w.loc[names[i], col_name]:.4f}"
aicw_matrix.loc[names[j], names[i]] = f"{w.loc[names[j], col_name]:.4f}"
save_table(aicw_matrix.to_markdown(), "pairwise_aicw", data_name)
print(f"\n## Pairwise {col_name}")
print(aicw_matrix.to_markdown())
# Pairwise BMS
xp_matrix = pd.DataFrame("", index=names, columns=names)
pxp_matrix = pd.DataFrame("", index=names, columns=names)
for i in range(N):
for j in range(i + 1, N):
pair = [results[i], results[j]]
bms = bayesian_model_selection(pair, n_obs=n_obs).set_index("Model")
xp_matrix.loc[names[i], names[j]] = f"{bms.loc[names[i], 'Exceedance Probability']:.4f}"
xp_matrix.loc[names[j], names[i]] = f"{bms.loc[names[j], 'Exceedance Probability']:.4f}"
pxp_matrix.loc[names[i], names[j]] = f"{bms.loc[names[i], 'Protected XP']:.4f}"
pxp_matrix.loc[names[j], names[i]] = f"{bms.loc[names[j], 'Protected XP']:.4f}"
save_table(xp_matrix.to_markdown(), "pairwise_xp", data_name)
save_table(pxp_matrix.to_markdown(), "pairwise_pxp", data_name)
print("\n## Pairwise Exceedance Probability")
print(xp_matrix.to_markdown())
print("\n## Pairwise Protected XP")
print(pxp_matrix.to_markdown())