Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Statistical Comparison — Group A vs J

Boxplots interactifs et tests Mann-Whitney U pour chaque feature acoustique. Un p-value < 0.05 indique une différence significative entre les groupes.

import os
import json
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from scipy.stats import mannwhitneyu
import warnings
warnings.filterwarnings('ignore')
outputs_folder = "../outputs"
data = []
for sound_folder in os.listdir(outputs_folder):
    json_path = os.path.join(outputs_folder, sound_folder, "results.json")
    if os.path.exists(json_path):
        with open(json_path, "r") as f:
            result = json.load(f)
            result["group"] = sound_folder[0]
            data.append(result)

df = pd.DataFrame(data)
print(f"✓ {len(df)} sons chargés")
✓ 52 sons chargés
features_stats = {
    "F0 mean (Hz)":           "f0_mean",
    "Intensity (RMS)":         "global_intensity",
    "Spectral centroid (Hz)":  "spectral_centroid_mean",
    "Bandwidth (Hz)":          "spectral_bandwidth_mean",
    "Rolloff (Hz)":            "spectral_rolloff_mean",
    "Duration (s)":            "duration",
}

fig = make_subplots(rows=2, cols=3, subplot_titles=list(features_stats.keys()))

for i, (label, col) in enumerate(features_stats.items()):
    r, c = divmod(i, 3)
    for grp, color in [("A", "#1f77b4"), ("J", "#ff7f0e")]:
        vals = df[df["group"] == grp][col].values
        fig.add_trace(
            go.Box(y=vals, name=f"Group {grp}", marker_color=color,
                   showlegend=(i == 0)),
            row=r+1, col=c+1
        )

fig.update_layout(height=700, title="Group A vs J — Acoustic Features", boxmode="group")
fig.show()
Loading...

Tests Mann-Whitney U

results = []
for label, col in features_stats.items():
    a = df[df["group"] == "A"][col].values
    j = df[df["group"] == "J"][col].values
    _, p = mannwhitneyu(a, j, alternative="two-sided")
    sig = "***" if p < 0.001 else "**" if p < 0.01 else "*" if p < 0.05 else "ns"
    results.append({
        "Feature": label,
        "Mean A": round(a.mean(), 3),
        "Mean J": round(j.mean(), 3),
        "p-value": round(p, 4),
        "Sig.": sig
    })

pd.DataFrame(results)
Loading...