yasa.SleepStatsAgreement.plot_blandaltman#
- SleepStatsAgreement.plot_blandaltman(sleep_stats=None, bias_method='auto', loa_method='auto', ci_method='auto', scatter_kwargs=None, **kwargs)[source]#
Plot Bland-Altman agreement plots for one or more sleep statistics.
Each panel shows observed-minus-reference differences (y-axis) against reference values (x-axis) for one sleep statistic. Bias and limits of agreement are drawn as lines, with optional confidence-interval bands. Methods (parametric, regression, or bootstrap) are chosen automatically per statistic based on the assumption tests stored in
assumptions, or can be set explicitly.- Parameters:
- sleep_statslist or None
List of sleep statistics to plot. Default (None) is to plot all sleep statistics.
- bias_methodstr
If
'param', bias is always the mean difference (horizontal line with an optional CI band). If'regr', bias is always a regression line (no CI band). If'auto'(default), the method is chosen per statistic based on the proportional-bias assumption test.- loa_methodstr
Method used to draw limits of agreement. Options:
'param'— constant LoA: horizontal lines atbias ± 1.96 SD. Always uses this form regardless of assumptions orlog_transform. When the bias is a regression line, the LoA run parallel to it at± 1.96 SDof its residuals (Menghini et al. 2021, eq. 2).'regr'— regression LoA: lines followingbias ± 2.46 (c0 + c1 × ref), wherec0 + c1 × refmodels the absolute residuals of the bias. Always uses this form regardless of assumptions orlog_transform.'log'— Euser LoA: lines followingbias ± slope × ref. Requireslog_transform=Trueand no zero values; raisesValueErrorotherwise.'auto'(default) — uses'log'for the log-transformed statistics (seelog_transform). Otherwise, uses'param'when the homoscedasticity assumption passes and'regr'when it fails.
- ci_methodstr or None
If
'param', parametric CIs are drawn. If'boot', bootstrap CIs are drawn. If'auto'(default), chosen per statistic based on the normality assumption test. IfNone, no confidence intervals are drawn.- scatter_kwargsdict or None
Keyword arguments passed to
matplotlib.pyplot.scatter.- **kwargsdict
Other keyword arguments are passed through to
seaborn.FacetGrid.
- Returns:
- g
seaborn.FacetGrid Seaborn FacetGrid
- g
Examples
>>> import yasa >>> n = 20 >>> ref_hyps = [yasa.simulate_hypnogram(scorer="PSG", seed=i) for i in range(n)] >>> obs_hyps = [ref_hyps[i].simulate_similar(scorer="Device", seed=i) for i in range(n)] >>> eea = yasa.EpochByEpochAgreement(ref_hyps, obs_hyps) >>> sstats = eea.get_sleep_stats() >>> ssa = yasa.SleepStatsAgreement(sstats) >>> stats = ["TST", "WASO", "N1", "REM"] >>> g = ssa.plot_blandaltman(sleep_stats=stats, ci_method="param")