% ========================================================================= % interlimb_asymmetry_analysis.m % % Effect of asymmetry-index (formula) choice on the clinical interpretation % of inter-limb hip adduction/abduction strength, using season-long weekly % monitoring data. Seven asymmetry formulas are applied to the same dataset % and compared for magnitude, clinical flagging, direction consistency, % position-group representativeness, and per-player baseline stabilisation. % % This single script reproduces every reported statistic and generates all % main and supplementary figures and the statistical-output workbook. % % ------------------------------------------------------------------------- % USAGE % ------------------------------------------------------------------------- % Place the dataset in the SAME FOLDER as this script and run it. The data % path is resolved relative to the script, so no paths need editing: % % Data_SeasonLong_Anonymous.xlsx % % ------------------------------------------------------------------------- % INPUT DATA FORMAT % ------------------------------------------------------------------------- % Sheet name : 'Raw' (data from row 2; header row 1) % One row per player per testing week. Required columns (by header name): % Participant - numeric player ID % Week - testing-week index % Position - position group label (>= 3 players per group to be used) % AddND, AddD - adduction peak force: non-dominant, dominant limb % AbdND, AbdD - abduction peak force: non-dominant, dominant limb % Additional columns may be present and are ignored. An observation is used % only when all four limb values (AddND, AddD, AbdND, AbdD) are present and % positive. Dominance is defined externally (columns are already ordered as % dominant / non-dominant). % % ------------------------------------------------------------------------- % OUTPUTS (written to the script's folder) % ------------------------------------------------------------------------- % Command Window : all descriptive, direction, agreement, stabilisation and % precision statistics for both muscles. % Workbook : asymmetry_statistical_outputs.xlsx % (descriptives, stabilisation weeks, CI half-widths). % Figures : Fig1..Fig4 (main) and FigS1..FigS9 (supplementary), % each saved as .png (600 dpi) and .svg. % % Figure content: % Fig1 Per-player flagging heatmap (adduction) % Fig2 Formula divergence: (A) Bland-Altman, (B) threshold sensitivity % Fig3 Direction stability (adduction) % Fig4 Per-player baseline stabilisation (adduction) % FigS1 Weekly mean asymmetry across the season (both muscles) % FigS2 Inter-formula correlation matrix % FigS3 Individual vs position-group means (adduction) % FigS4..FigS9 Abduction parallels of the flagging, Bland-Altman, % sensitivity, direction, individual-vs-group and % stabilisation analyses. % % ------------------------------------------------------------------------- % DIRECTION-CONSISTENCY KAPPA % ------------------------------------------------------------------------- % Week-to-week direction agreement is the mean per-player Cohen's kappa for % dominant-limb direction at consecutive observations. Cohen's kappa is % biased downward in small samples, so the benchmark for "no carryover" is % the value expected under independence at these sequence lengths (assessed % by a within-player permutation test in the manuscript), which lies slightly % below zero; a small negative mean kappa therefore indicates chance-level % week-to-week direction, not systematic alternation. % % ------------------------------------------------------------------------- % REQUIREMENTS % ------------------------------------------------------------------------- % MATLAB R2020a or later (uses exportgraphics, tiledlayout, 'omitnan'). % Statistics and Machine Learning Toolbox (corr, tinv). % % ------------------------------------------------------------------------- % CITATION / LICENCE % ------------------------------------------------------------------------- % Citation : Callaway, A.J., Dunne, C., & Williams, J.M. (2026). The choice of % asymmetry index affects clinical interpretation of hip adduction % and abduction strength in elite soccer players: a season-long % investigation. [journal / DOI added on acceptance] % Data : Callaway, A.J., Dunne, C., & Williams, J.M. (2026). Season-Long % Weekly Hip Adduction and Abduction Isometric Strength in Elite % Male Soccer Players: A 36-Week Premier League Dataset (2019-20). % Bournemouth University. https://doi.org/10.18746/bmth.data.00000536 % Authors : Andrew J. Callaway, Cian Dunne, Jonathan M. Williams % Contact : Dr Andrew Callaway, acallaway@bournemouth.ac.uk % School of Allied Health and Exercise Science, Bournemouth University % Licence : MIT (see LICENSE). The dataset is licensed separately via the DOI above. % ========================================================================= clc; clear; close all; %% ===== CONFIGURATION ===================================================== % Data file resolved relative to this script (no manual path editing). scriptDir = fileparts(mfilename('fullpath')); DATA_PATH = fullfile(scriptDir, 'Data_SeasonLong_Anonymous.xlsx'); if ~isfile(DATA_PATH) error(['Data file not found:\n %s\n' ... 'Place Data_SeasonLong_Anonymous.xlsx in the same folder as this script.'], DATA_PATH); end % Constants THRESH_10 = 10; % primary clinical threshold (%) MEAN_TOL = 1.0; % cumulative-mean stabilisation tolerance (percentage points) MIN_OBS = 5; % minimum observations before testing stabilisation X_LIM = [1 36]; % consistent x-axis across season-long figures % Okabe-Ito colour-blind-safe palette OI_blue = [0.00 0.45 0.70]; OI_red = [0.84 0.37 0.00]; OI_gold = [0.95 0.69 0.00]; OI_green = [0.00 0.62 0.45]; OI_purple = [0.55 0.10 0.50]; % Single-limb reliability (Dunne et al., 2022) for the propagated noise floor COV_ADD = 7.35; % adduction single-limb CoV (%) COV_ABD = 4.01; % abduction single-limb CoV (%) %% ======================================================================== % SECTION 1 — STATISTICS (reproduces all reported numbers; both muscles) % ======================================================================== fprintf('\n================ SECTION 1: STATISTICS ================\n'); [T, participants, weeks, formulaNames, formulaLabels, Asym, Abd] = loadData(DATA_PATH); nPlayers = numel(participants); nWeeks = numel(weeks); nF = numel(formulaNames); fprintf('Valid observations: %d | players: %d | weeks: %d\n', height(T), nPlayers, nWeeks); if height(T) ~= 429 warning('Expected 429 valid observations; found %d. Check the data file.', height(T)); end muscleStructs = {Asym, Abd}; muscleDom = {T.AddD, T.AbdD}; muscleNDom = {T.AddND, T.AbdND}; muscleNames = {'Adduction','Abduction'}; checkpoints = [4 8 12 20]; descAll = cell(1,2); stabAll = cell(1,2); ciAll = cell(1,2); kappaAll = zeros(1,2); for mm = 1:2 S = muscleStructs{mm}; dom = muscleDom{mm}; ndom = muscleNDom{mm}; dirVec = sign(dom - ndom); fprintf('\n---------- %s ----------\n', muscleNames{mm}); % ----- Descriptive statistics (manuscript Table 2) ----- Formula = formulaLabels(:); MeanSigned = zeros(nF,1); MeanAbs = zeros(nF,1); SD_signed = zeros(nF,1); Median_ = zeros(nF,1); CoV_abs = zeros(nF,1); MinV = zeros(nF,1); MaxV = zeros(nF,1); Flag10 = zeros(nF,1); Flag15 = zeros(nF,1); for f = 1:nF v = S.(formulaNames{f}); av = abs(v); MeanSigned(f) = mean(v,'omitnan'); MeanAbs(f) = mean(av,'omitnan'); SD_signed(f) = std(v,0,'omitnan'); Median_(f) = median(v,'omitnan'); CoV_abs(f) = std(av,0,'omitnan') / mean(av,'omitnan') * 100; % CoV on absolute values MinV(f) = min(v,[],'omitnan'); MaxV(f) = max(v,[],'omitnan'); Flag10(f) = 100 * sum(av > 10) / sum(~isnan(av)); Flag15(f) = 100 * sum(av > 15) / sum(~isnan(av)); end descAll{mm} = table(Formula, MeanSigned, MeanAbs, SD_signed, Median_, CoV_abs, ... MinV, MaxV, Flag10, Flag15); disp(descAll{mm}); % ----- Within-player CoV (absolute values, players with >= 3 obs) ----- wCoV = nan(nPlayers, nF); for p = 1:nPlayers pIdx = T.Participant == participants(p); for f = 1:nF av = abs(S.(formulaNames{f})(pIdx)); av = av(~isnan(av)); if numel(av) >= 3 wCoV(p,f) = std(av) / mean(av) * 100; end end end fprintf('Within-player CoV (mean across players):'); for f = 1:nF, fprintf(' %s=%.1f%%', formulaLabels{f}, mean(wCoV(:,f),'omitnan')); end fprintf('\n'); % ----- Direction consistency: dominant-stronger %, flip %, per-player kappa ----- domStronger = 100 * sum(dirVec > 0) / sum(dirVec ~= 0); totFlip = 0; totPair = 0; pk = nan(nPlayers,1); for p = 1:nPlayers pIdx = T.Participant == participants(p); [~, ord] = sort(T.Week(pIdx)); d = dirVec(pIdx); d = d(ord); d = d(d ~= 0); if numel(d) >= 2 totFlip = totFlip + sum(diff(d) ~= 0); totPair = totPair + numel(d) - 1; a = double(d(1:end-1) > 0) + 1; b = double(d(2:end) > 0) + 1; pk(p) = computeKappa(a, b); end end flipRate = 100 * totFlip / totPair; kappaMean = mean(pk, 'omitnan'); kappaAll(mm) = kappaMean; fprintf('Dominant stronger: %.1f%% | Direction flips: %.1f%% | Per-player kappa (mean): %.3f\n', ... domStronger, flipRate, kappaMean); % ----- Stabilisation (week-based) and 95%% CI half-widths ----- stabWeek = nan(nPlayers, nF); ciHalf = nan(nPlayers, numel(checkpoints), nF); for p = 1:nPlayers pIdx = T.Participant == participants(p); [pw, ord] = sort(T.Week(pIdx)); for f = 1:nF v = abs(S.(formulaNames{f})(pIdx)); v = v(ord); v = v(~isnan(v)); nV = numel(v); if nV < MIN_OBS, continue; end cm = arrayfun(@(k) mean(v(1:k)), 1:nV); % cumulative mean target = cm(end); for k = MIN_OBS:nV if all(abs(cm(k:end) - target) < MEAN_TOL) stabWeek(p,f) = pw(k); % WEEK number of the k-th observation break; end end for c = 1:numel(checkpoints) cp = checkpoints(c); if nV >= cp ciHalf(p,c,f) = tinv(0.975, cp-1) * std(v(1:cp)) / sqrt(cp); end end end end stabAll{mm} = stabWeek; ciAll{mm} = ciHalf; fprintf('Median stabilisation week:'); for f = 1:nF, fprintf(' %s=%d', formulaLabels{f}, round(median(stabWeek(:,f),'omitnan'))); end fprintf('\n'); fprintf('Median 95%%CI half-width (n = 4 / 8 / 12 / 20):\n'); for f = 1:nF fprintf(' %-7s', formulaLabels{f}); for c = 1:numel(checkpoints) fprintf(' %5.1f%%', median(ciHalf(:,c,f),'omitnan')); end fprintf('\n'); end end % ----- Adduction kappa sanity note ----- % Manuscript (v24+) reports mean per-player kappa = -0.04 for adduction and % benchmarks it against a permutation null of -0.04 (i.e. at chance), NOT the % earlier 0.015 / "greater than zero" claim, which was corrected. A small % negative value here is therefore expected, not an anomaly. fprintf('Adduction per-player direction kappa = %.3f (expected ~ -0.04, at permutation null).\n', kappaAll(1)); %% ----- Position-group representativeness (BSA) — both muscles ----- fprintf('\n---------- Position-group representativeness (BSA) ----------\n'); for mm = 1:2 bsa = muscleStructs{mm}.BSA; % unsigned, >= 0 z = nan(height(T),1); mis = 0; tot = 0; for w = 1:nWeeks for g = 1:4 idx = T.Week == weeks(w) & T.Group == g; vals = bsa(idx); vals = vals(~isnan(vals)); if numel(vals) >= 3 gm = mean(vals); gsd = std(vals); gFlag = gm > 10; if gsd > 0, z(idx) = (bsa(idx) - gm) / gsd; end mis = mis + sum((vals > 10) ~= gFlag); tot = tot + numel(vals); end end end zz = z(~isnan(z)); fprintf('%s: outside +/-1SD %.1f%% (exp 31.7), +/-2SD %.1f%% (exp 4.6), misclassification %.1f%%\n', ... muscleNames{mm}, 100*sum(abs(zz)>1)/numel(zz), 100*sum(abs(zz)>2)/numel(zz), 100*mis/tot); end %% ======================================================================== % SECTION 1b — STABILISATION-BAND SENSITIVITY AND CLUSTER-BOOTSTRAP CIs % Reviewer-requested robustness checks reported in the Methods/Results: % (i) how the stabilisation median moves with the tolerance band % (+/-1pp vs +/-2pp vs a scale-relative 15%-of-final band); and % (ii) cluster-bootstrap (by player) 95% CIs for the flip rate, the % group-mean misclassification rate, and the BAI-2 stabilisation median. % Self-contained: reads the same inputs, defines its own locals. Bootstrap % CIs are estimates; small differences from the manuscript values reflect the % random seed and the percentile method (the manuscript used a seeded run). % ======================================================================== fprintf('\n============ SECTION 1b: SENSITIVITY & BOOTSTRAP ============\n'); NBOOT = 10000; % cluster-bootstrap resamples (by player) TOL2 = 2.0; % wider absolute tolerance band (percentage points) REL_TOL = 0.15; % scale-relative band (fraction of the final cumulative mean) rng(42); % reproducibility (matches the Python cross-check seed) ciFun = @(x) prctile(x, [2.5 97.5]); for mm = 1:2 S = muscleStructs{mm}; dom = muscleDom{mm}; ndom = muscleNDom{mm}; dirVec = sign(dom - ndom); fprintf('\n---------- %s ----------\n', muscleNames{mm}); % ---- stabilisation median week by tolerance band (all formulas) ---- fprintf('Stabilisation median week (tol=1.0pp / tol=2.0pp / rel-15%%):\n'); for f = 1:nF w1 = nan(nPlayers,1); w2 = nan(nPlayers,1); wr = nan(nPlayers,1); for p = 1:nPlayers pIdx = T.Participant == participants(p); [pw, ord] = sort(T.Week(pIdx)); v = abs(S.(formulaNames{f})(pIdx)); v = v(ord); w1(p) = localStabWeek(v, pw, MEAN_TOL, false, MIN_OBS); w2(p) = localStabWeek(v, pw, TOL2, false, MIN_OBS); wr(p) = localStabWeek(v, pw, REL_TOL, true, MIN_OBS); end fprintf(' %-7s %5.0f / %5.0f / %5.0f\n', formulaLabels{f}, ... median(w1,'omitnan'), median(w2,'omitnan'), median(wr,'omitnan')); end % ---- per-player quantities for the cluster bootstrap ---- flips = zeros(nPlayers,1); pairs = zeros(nPlayers,1); baiStab = nan(nPlayers,1); misP = zeros(nPlayers,1); totP = zeros(nPlayers,1); bsa = S.BSA; for p = 1:nPlayers pIdx = T.Participant == participants(p); [pw, ord] = sort(T.Week(pIdx)); d = dirVec(pIdx); d = d(ord); d = d(d ~= 0); if numel(d) >= 2 flips(p) = sum(diff(d) ~= 0); pairs(p) = numel(d) - 1; end v = abs(S.BAI2(pIdx)); v = v(ord); baiStab(p) = localStabWeek(v, pw, MEAN_TOL, false, MIN_OBS); end for w = 1:nWeeks for g = 1:4 idx = T.Week == weeks(w) & T.Group == g; vals = bsa(idx); who = T.Participant(idx); ok = ~isnan(vals); vals = vals(ok); who = who(ok); if numel(vals) >= 3 gFlag = mean(vals) > 10; mmV = (vals > 10) ~= gFlag; for q = 1:numel(who) pp = find(participants == who(q), 1); misP(pp) = misP(pp) + mmV(q); totP(pp) = totP(pp) + 1; end end end end % ---- cluster bootstrap: resample players with replacement ---- bFlip = nan(NBOOT,1); bMis = nan(NBOOT,1); bStab = nan(NBOOT,1); for b = 1:NBOOT s = randi(nPlayers, nPlayers, 1); if sum(pairs(s)) > 0, bFlip(b) = 100 * sum(flips(s)) / sum(pairs(s)); end if sum(totP(s)) > 0, bMis(b) = 100 * sum(misP(s)) / sum(totP(s)); end ss = baiStab(s); ss = ss(~isnan(ss)); if ~isempty(ss), bStab(b) = median(ss); end end fFlip = 100*sum(flips)/sum(pairs); fMis = 100*sum(misP)/sum(totP); fStab = median(baiStab,'omitnan'); c1 = ciFun(bFlip); c2 = ciFun(bMis); c3 = ciFun(bStab); fprintf('Cluster-bootstrap 95%% CIs (NBOOT = %d):\n', NBOOT); fprintf(' Flip rate : %.1f%% [%.1f, %.1f]\n', fFlip, c1(1), c1(2)); fprintf(' Misclassification : %.1f%% [%.1f, %.1f]\n', fMis, c2(1), c2(2)); fprintf(' BAI-2 stabilisation : %.0f wk [%.0f, %.0f]\n', fStab, c3(1), c3(2)); end %% ----- Inter-formula correlations (adduction; signed vs unsigned clusters) ----- signedF = {'LSI2','BAI2','BAI1','SA'}; unsignedF = {'BSA','PctDiff','SI'}; rmin = inf; rmax = -inf; for i = 1:numel(signedF) for j = 1:numel(unsignedF) r = corr(Asym.(signedF{i}), Asym.(unsignedF{j}), 'rows','complete'); rmin = min(rmin, r); rmax = max(rmax, r); end end fprintf('\nAdduction between-cluster correlations: r = %.2f to %.2f\n', rmin, rmax); %% ----- Propagated measurement-error floor (delta method; Discussion) ----- floorAdd = sqrt(COV_ADD^2 + COV_ADD^2); % ~10.4% floorAbd = sqrt(COV_ABD^2 + COV_ABD^2); % ~5.7% fprintf(['\nPropagated typical-error floor (delta method, sqrt(CoV^2 + CoV^2)):\n' ... ' Adduction = %.1f%% Abduction = %.1f%%\n'], floorAdd, floorAbd); %% ----- Per-formula measurement-error floor (rescaled: delta + Monte Carlo) ----- % The single floor above is on the single-limb ratio scale, and is correct only for % LSI-2/BAI-2. Each formula is a different transform of the limb ratio, so its own % noise floor differs. Propagate the per-limb single-trial CoV through EACH formula % under a truly-symmetric null (two equal limbs measured with relative noise) by % Monte Carlo, and (for the signed formulas) by the closed-form delta method as an % exact cross-check. Report each formula's own floor beside its observed |Mean|. rng(42); % reproducibility NSIM_FLOOR = 1e6; covPct = [COV_ADD, COV_ABD]; asymCells = {Asym, Abd}; deltaK = containers.Map(formulaNames, ... {sqrt(2), sqrt(2), NaN, NaN, sqrt(2)/2, NaN, (180/pi)/2/90*sqrt(2)}); floorResults = cell(1,2); fprintf('\nPer-formula measurement-error floor (Monte Carlo, %g draws):\n', NSIM_FLOOR); for mm = 1:2 covFrac = covPct(mm) / 100; Sm = asymCells{mm}; simD = 1 + covFrac * randn(NSIM_FLOOR, 1); simN = 1 + covFrac * randn(NSIM_FLOOR, 1); Formula = formulaLabels(:); ObsAbsMean = nan(nF,1); FloorSD_delta = nan(nF,1); FloorSD_MC = nan(nF,1); FloorAbs_MC = nan(nF,1); ObsOverFloor = nan(nF,1); for f = 1:nF ObsAbsMean(f) = mean(abs(Sm.(formulaNames{f})), 'omitnan'); mc = asymFromLimbs(formulaNames{f}, simD, simN); FloorSD_MC(f) = std(mc, 0, 'omitnan'); FloorAbs_MC(f) = mean(abs(mc), 'omitnan'); FloorSD_delta(f) = deltaK(formulaNames{f}) * covPct(mm); ObsOverFloor(f) = ObsAbsMean(f) / FloorAbs_MC(f); end floorResults{mm} = table(Formula, ObsAbsMean, FloorSD_delta, FloorSD_MC, ... FloorAbs_MC, ObsOverFloor); fprintf('\n %s (limb CoV = %.2f%%; single-scale floor = %.2f%%):\n', ... muscleNames{mm}, covPct(mm), sqrt(2)*covPct(mm)); fprintf(' %-7s %9s %12s %11s %12s %10s\n', ... 'Formula','obs|Mean|','floorSD(dl)','floorSD(mc)','floor|.|(mc)','obs/floor'); for f = 1:nF if isnan(FloorSD_delta(f)), dstr = ' -'; else, dstr = sprintf('%10.2f%%', FloorSD_delta(f)); end fprintf(' %-7s %8.1f%% %s %10.2f%% %11.2f%% %9.2f\n', ... formulaLabels{f}, ObsAbsMean(f), dstr, FloorSD_MC(f), ... FloorAbs_MC(f), ObsOverFloor(f)); end end fprintf(['\n Interpretation: obs/floor is ~constant across formulas within a muscle\n' ... ' (all are monotonic transforms of the same limb ratio), so no formula has a\n' ... ' better signal-to-noise ratio; in particular SA is NOT uniquely within its\n' ... ' own floor. The single-scale floor overstates the floor for SA/BAI-1/SI.\n']); %% ----- Excel exports ----- outFile = fullfile(scriptDir, 'asymmetry_statistical_outputs.xlsx'); writetable(descAll{1}, outFile, 'Sheet', 'Descriptives_Adduction'); writetable(descAll{2}, outFile, 'Sheet', 'Descriptives_Abduction'); for mm = 1:2 writetable(floorResults{mm}, outFile, 'Sheet', ['NoiseFloor_' muscleNames{mm}]); end for mm = 1:2 stabT = array2table(stabAll{mm}, 'VariableNames', formulaNames); stabT.Player = participants; stabT = movevars(stabT, 'Player', 'Before', 1); writetable(stabT, outFile, 'Sheet', ['StabWeeks_' muscleNames{mm}]); ciMed = squeeze(median(ciAll{mm}, 1, 'omitnan')); % checkpoints x formulas ciT = array2table(ciMed, 'VariableNames', formulaNames); ciT.nObs = checkpoints(:); ciT = movevars(ciT, 'nObs', 'Before', 1); writetable(ciT, outFile, 'Sheet', ['CI_HalfWidth_' muscleNames{mm}]); end fprintf('\nSaved: %s\n', outFile); fprintf('================ STATISTICS COMPLETE ================\n\n'); % Reset workspace before figures (keep configuration only) so the tested % figure code below runs exactly as authored, with no variable bleed. clearvars -except DATA_PATH THRESH_10 MEAN_TOL MIN_OBS X_LIM OI_blue OI_red OI_gold OI_green OI_purple %% ======================================================================== % SECTION 2 — FIGURES (Figures 1-8 and Supplementary S1-S6) % ======================================================================== %% ===== SUPPLEMENTARY FIGURE S1: WEEKLY MEAN ASYMMETRY (4-panel) ======== fprintf('\n--- Figure S1: Weekly mean asymmetry (both muscles) ---\n'); [T, participants, weeks, formulaNames, ~, Asym, Abd] = loadData(DATA_PATH); nWeeks = numel(weeks); weeklyMeans_add = NaN(nWeeks, numel(formulaNames)); weeklyMeans_abd = NaN(nWeeks, numel(formulaNames)); weeklyMeans_add_abs = NaN(nWeeks, numel(formulaNames)); weeklyMeans_abd_abs = NaN(nWeeks, numel(formulaNames)); for w = 1:nWeeks idx = T.Week == weeks(w); for f = 1:numel(formulaNames) weeklyMeans_add(w,f) = mean(Asym.(formulaNames{f})(idx), 'omitnan'); weeklyMeans_abd(w,f) = mean(Abd.(formulaNames{f})(idx), 'omitnan'); weeklyMeans_add_abs(w,f) = mean(abs(Asym.(formulaNames{f})(idx)), 'omitnan'); weeklyMeans_abd_abs(w,f) = mean(abs(Abd.(formulaNames{f})(idx)), 'omitnan'); end end signedIdx = [1, 2, 5]; bsaIdx = 3; bai1Idx = 5; saIdx = 7; signedCols = [OI_blue; OI_red; OI_gold]; signedLabels = {'LSI-2','BAI-2','BAI-1'}; figure('Name','Fig1','Position',[50 50 1500 1000]); tiledlayout(2, 2, 'TileSpacing','compact','Padding','compact'); % Panel A: Adduction signed ax1 = nexttile; hold on; for i = 1:numel(signedIdx) plot(weeks, weeklyMeans_add(:,signedIdx(i)), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, ... 'Color', signedCols(i,:), 'DisplayName', signedLabels{i}); end yline(0, '--', 'Color', [0.6 0.6 0.6], 'LineWidth', 1, 'HandleVisibility','off'); ylabel('Asymmetry (%)', 'FontSize', 11, 'FontName', 'Arial'); xlabel('Week', 'FontSize', 11, 'FontName', 'Arial'); legend('Location','southwest','FontSize',9); xlim(X_LIM); grid on; box on; set(gca,'FontSize',10,'FontName','Arial'); text(ax1, 0.02, 0.97, 'A', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel B: Adduction unsigned (dual y-axis) ax2 = nexttile; yyaxis left; h_bsa = plot(weeks, weeklyMeans_add_abs(:,bsaIdx), '-o', ... 'LineWidth', 2.0, 'MarkerSize', 3.5, 'Color', OI_blue, ... 'DisplayName', 'BSA (= %Diff)'); hold on; yline(10, 'r--', 'LineWidth', 1.0, 'HandleVisibility','off'); ylabel('BSA / %Diff (%)', 'Color', OI_blue, 'FontSize', 11); ax2.YColor = OI_blue; ylim([0 ceil(max(weeklyMeans_add_abs(:,bsaIdx))*1.15)]); yyaxis right; h_bai1 = plot(weeks, weeklyMeans_add_abs(:,bai1Idx), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, 'Color', OI_red, ... 'DisplayName', '|BAI-1| (= |SI|)'); hold on; h_sa = plot(weeks, weeklyMeans_add_abs(:,saIdx), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, 'Color', OI_green, ... 'DisplayName', 'SA'); ylabel('|BAI-1| / SA (%)', 'Color', OI_red, 'FontSize', 11); ax2.YColor = OI_red; ylim([0 ceil(max([weeklyMeans_add_abs(:,bai1Idx); weeklyMeans_add_abs(:,saIdx)])*1.15)]); xlabel('Week', 'FontSize', 11); legend([h_bsa, h_bai1, h_sa], 'Location','northwest','FontSize',9); grid on; box on; xlim(X_LIM); set(gca,'FontSize',10,'FontName','Arial'); text(ax2, 0.98, 0.97, 'B', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top','HorizontalAlignment','right','Color','k', ... 'BackgroundColor','w','Margin',2); % Panel C: Abduction signed ax3 = nexttile; hold on; for i = 1:numel(signedIdx) plot(weeks, weeklyMeans_abd(:,signedIdx(i)), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, ... 'Color', signedCols(i,:), 'DisplayName', signedLabels{i}); end yline(0, '--', 'Color', [0.6 0.6 0.6], 'LineWidth', 1, 'HandleVisibility','off'); ylabel('Asymmetry (%)', 'FontSize', 11); xlabel('Week', 'FontSize', 11); legend('Location','southwest','FontSize',9); xlim(X_LIM); grid on; box on; set(gca,'FontSize',10,'FontName','Arial'); text(ax3, 0.02, 0.97, 'C', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel D: Abduction unsigned (dual y-axis) ax4 = nexttile; yyaxis left; h_bsa_d = plot(weeks, weeklyMeans_abd_abs(:,bsaIdx), '-o', ... 'LineWidth', 2.0, 'MarkerSize', 3.5, 'Color', OI_blue, ... 'DisplayName', 'BSA (= %Diff)'); hold on; yline(10, 'r--', 'LineWidth', 1.0, 'HandleVisibility','off'); ylabel('BSA / %Diff (%)', 'Color', OI_blue, 'FontSize', 11); ax4.YColor = OI_blue; ylim([0 ceil(max(weeklyMeans_abd_abs(:,bsaIdx))*1.15)]); yyaxis right; h_bai1_d = plot(weeks, weeklyMeans_abd_abs(:,bai1Idx), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, 'Color', OI_red, ... 'DisplayName', '|BAI-1| (= |SI|)'); hold on; h_sa_d = plot(weeks, weeklyMeans_abd_abs(:,saIdx), '-o', ... 'LineWidth', 1.8, 'MarkerSize', 3.5, 'Color', OI_green, ... 'DisplayName', 'SA'); ylabel('|BAI-1| / SA (%)', 'Color', OI_red, 'FontSize', 11); ax4.YColor = OI_red; ylim([0 ceil(max([weeklyMeans_abd_abs(:,bai1Idx); weeklyMeans_abd_abs(:,saIdx)])*1.15)]); xlabel('Week', 'FontSize', 11); legend([h_bsa_d, h_bai1_d, h_sa_d], 'Location','northwest','FontSize',9); grid on; box on; xlim(X_LIM); set(gca,'FontSize',10,'FontName','Arial'); text(ax4, 0.98, 0.97, 'D', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top','HorizontalAlignment','right','Color','k', ... 'BackgroundColor','w','Margin',2); saveFig('FigS1_FormulaTimeSeries'); %% ===== SUPPLEMENTARY FIGURE S2: PEARSON CORRELATION MATRIX ============== fprintf('\n--- Figure S2: Correlation matrix ---\n'); [T, ~, ~, formulaNames, formulaLabels, Asym, ~] = loadData(DATA_PATH); mat = NaN(height(T), numel(formulaNames)); for f = 1:numel(formulaNames) mat(:,f) = Asym.(formulaNames{f}); end C = corr(mat, 'rows','complete'); displayLabels = {'LSI-2 (Schiltz)','BAI-2 (Wong)','BSA (Impellizzeri)', ... '%Diff (Bishop)','BAI-1 (Kobayashi)','SI (Shorter)','SA (Zifchock)'}; figure('Name','Fig2','Position',[100 100 950 800]); imagesc(C); colormap(redblue()); caxis([-1 1]); cb = colorbar; cb.Label.String = 'Pearson r'; for i = 1:size(C,1) for j = 1:size(C,2) col = 'w'; if abs(C(i,j)) < 0.5; col = 'k'; end text(j, i, sprintf('%.2f', C(i,j)), ... 'HorizontalAlignment','center', 'Color', col, ... 'FontSize', 10, 'FontName','Arial'); end end set(gca, 'XTick', 1:numel(formulaNames), 'XTickLabel', displayLabels, ... 'YTick', 1:numel(formulaNames), 'YTickLabel', displayLabels); xtickangle(45); set(gca, 'FontSize', 10, 'FontName','Arial'); saveFig('FigS2_CorrelationMatrix'); %% ===== FIGURE 1: PER-PLAYER FLAGGING HEATMAP (Adduction) =============== fprintf('\n--- Figure 1: Per-player flagging heatmap (adduction) ---\n'); [T, participants, ~, formulaNames, formulaLabels, Asym, ~] = loadData(DATA_PATH); nPlayers = numel(participants); nFormulas = numel(formulaNames); flagMatrix = NaN(nPlayers, nFormulas); for p = 1:nPlayers idx = T.Participant == participants(p); for f = 1:nFormulas vals = abs(Asym.(formulaNames{f})(idx)); flagMatrix(p, f) = 100 * sum(vals > THRESH_10, 'omitnan') / sum(~isnan(vals)); end end figure('Name','Fig3','Position',[100 100 900 700]); imagesc(flagMatrix); colormap(flipud(hot)); cb = colorbar; cb.Label.String = 'Flagging rate at 10% (%)'; caxis([0 100]); set(gca, 'XTick', 1:nFormulas, 'XTickLabel', formulaLabels, ... 'YTick', 1:nPlayers, 'YTickLabel', cellstr(num2str((1:nPlayers)'))); xlabel('Asymmetry Formula', 'FontSize', 11); ylabel('Player', 'FontSize', 11); xtickangle(45); set(gca, 'FontSize', 10, 'FontName','Arial'); saveFig('Fig1_FlaggingHeatmap'); %% ===== FIGURE 2, PANEL A (data): BLAND-ALTMAN |BSA| vs |BAI-2| ========== fprintf('\n--- Figure 2A: Bland-Altman (data for merged figure) ---\n'); [T, ~, ~, ~, ~, Asym, ~] = loadData(DATA_PATH); bsa_abs = abs(Asym.BSA); bai2_abs = abs(Asym.BAI2); ba_mean = (bsa_abs + bai2_abs) / 2; ba_diff = bsa_abs - bai2_abs; mean_d = mean(ba_diff, 'omitnan'); sd_d = std(ba_diff, 0, 'omitnan'); loa_hi = mean_d + 1.96 * sd_d; loa_lo = mean_d - 1.96 * sd_d; x_theory = linspace(0.001, 0.9999, 1000); bsa_th = (1 - x_theory) * 100; bai2_th = 2*(1 - x_theory) ./ (1 + x_theory) * 100; mean_th = (bsa_th + bai2_th) / 2; diff_th = bsa_th - bai2_th; in_range = mean_th <= max(ba_mean)*1.05 & mean_th >= 0; mean_th = mean_th(in_range); diff_th = diff_th(in_range); % NOTE (v4): the Bland-Altman plot is no longer saved on its own. Its data % (ba_mean, ba_diff, mean_d, loa_hi, loa_lo, mean_th, diff_th) persist and are % drawn as PANEL A of the merged Figure 2, built in the section below. %% ===== FIGURE 2 (merged): (A) BLAND-ALTMAN + (B) SENSITIVITY (Adduction) ===== fprintf('\n--- FIGURE 2: Divergence (Bland-Altman) + threshold sensitivity ---\n'); [T, ~, ~, formulaNames, formulaLabels, Asym, ~] = loadData(DATA_PATH); nFormulas = numel(formulaNames); plotIdx = [1, 2, 3, 5, 7]; plotLabels = formulaLabels(plotIdx); plotCols = [OI_blue; OI_red; OI_gold; OI_green; OI_purple]; thresholds = 0:0.5:25; flagRates = NaN(numel(thresholds), nFormulas); for f = 1:nFormulas vals = abs(Asym.(formulaNames{f})); nObs = sum(~isnan(vals)); for t = 1:numel(thresholds) flagRates(t, f) = 100 * sum(vals > thresholds(t), 'omitnan') / nObs; end end % Both panels' data are now in scope; draw them side by side as Figure 2. figure('Name','Fig2','Position',[100 100 1500 600]); tiledlayout(1, 2, 'Padding', 'compact', 'TileSpacing', 'compact'); % --- Panel A: Bland-Altman |BSA| vs |BAI-2| --- ax1 = nexttile; hold(ax1, 'on'); yline(ax1, mean_d, 'k-', 'LineWidth', 1.6, 'DisplayName', sprintf('Mean diff = %.2f%%', mean_d)); yline(ax1, loa_hi, '--', 'LineWidth', 1.2, 'Color', [0.5 0.5 0.5], 'DisplayName', sprintf('+1.96 SD = %.2f%%', loa_hi)); yline(ax1, loa_lo, '--', 'LineWidth', 1.2, 'Color', [0.5 0.5 0.5], 'DisplayName', sprintf('-1.96 SD = %.2f%%', loa_lo)); xline(ax1, 10, ':', 'Color', [0.55 0.55 0.55], 'LineWidth', 1.2, 'HandleVisibility', 'off'); plot(ax1, mean_th, diff_th, '-', 'LineWidth', 2.5, 'Color', OI_blue, ... 'DisplayName', 'Theoretical: -100(1-x)^{2}/(1+x)'); scatter(ax1, ba_mean, ba_diff, 18, OI_red, 'filled', 'MarkerFaceAlpha', 0.55, ... 'DisplayName', 'Observations'); xlabel(ax1, 'Mean of |BSA| and |BAI-2| (%)', 'FontSize', 11); ylabel(ax1, 'Difference: |BSA| - |BAI-2| (%)', 'FontSize', 11); xlim(ax1, [0 max(ba_mean)*1.1]); legend(ax1, 'Location', 'southwest', 'FontSize', 9); grid(ax1, 'on'); box(ax1, 'on'); set(ax1, 'FontSize', 10, 'FontName', 'Arial'); title(ax1, 'A', 'FontWeight', 'bold', 'FontSize', 13, ... 'Units', 'normalized', 'Position', [-0.12 1.03 0], 'HorizontalAlignment', 'left'); % --- Panel B: threshold sensitivity --- ax2 = nexttile; hold(ax2, 'on'); for i = 1:numel(plotIdx) plot(ax2, thresholds, flagRates(:, plotIdx(i)), '-', 'LineWidth', 2.0, ... 'Color', plotCols(i,:), 'DisplayName', plotLabels{i}); end xline(ax2, 10, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0, 'HandleVisibility', 'off'); xline(ax2, 15, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0, 'HandleVisibility', 'off'); xlabel(ax2, 'Asymmetry threshold (%)', 'FontSize', 11); ylabel(ax2, 'Observations flagged (%)', 'FontSize', 11); xlim(ax2, [0 25]); ylim(ax2, [0 100]); legend(ax2, 'Location', 'northeast', 'FontSize', 10); grid(ax2, 'on'); box(ax2, 'on'); set(ax2, 'FontSize', 10, 'FontName', 'Arial'); title(ax2, 'B', 'FontWeight', 'bold', 'FontSize', 13, ... 'Units', 'normalized', 'Position', [-0.12 1.03 0], 'HorizontalAlignment', 'left'); saveFig('Fig2_Divergence'); %% ===== FIGURE 3: DIRECTION (3-panel merged) — Adduction ================ fprintf('\n--- Figure 3: Direction 3-panel (adduction) ---\n'); [T, participants, weeks, ~, ~, Asym, ~] = loadData(DATA_PATH); nPlayers = numel(participants); nWeeks = numel(weeks); % Compute rolling consistency for panel C windows = [3, 5, 8]; windowCols = [OI_blue; OI_red; OI_green]; consistencyPct = NaN(nWeeks, numel(windows)); for wi = 1:numel(windows) win = windows(wi); for w = 1:(nWeeks - win + 1) consistent = 0; valid = 0; for p = 1:nPlayers idx = T.Participant == participants(p); playerWeeks = T.Week(idx); playerDirs = sign(Asym.BAI2(idx)); in_win = playerWeeks >= weeks(w) & playerWeeks <= weeks(w + win - 1); dirs = playerDirs(in_win); dirs = dirs(dirs ~= 0); if numel(dirs) >= 2 valid = valid + 1; if all(dirs == dirs(1)); consistent = consistent + 1; end end end if valid > 0 consistencyPct(w, wi) = 100 * consistent / valid; end end end figure('Name','Fig6','Position',[80 80 1400 950]); tiledlayout(2, 2, 'TileSpacing','compact','Padding','compact'); % Panel A: BSA spaghetti (unsigned) ax1 = nexttile; hold on; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = abs(Asym.BSA(idx)); plot(pw, vals(si), '-', 'Color', [0.4 0.4 0.4 0.4], 'LineWidth', 0.8, ... 'HandleVisibility', 'off'); end h_thr = yline(10, 'r--', 'LineWidth', 1.5, 'DisplayName', '10% threshold'); xlabel('Week', 'FontSize', 11); ylabel('BSA Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); legend(h_thr, 'Location', 'northeast', 'FontSize', 9); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax1, 0.02, 0.97, 'A', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel B: BAI-2 spaghetti (signed) ax2 = nexttile; hold on; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = Asym.BAI2(idx); plot(pw, vals(si), '-', 'Color', [0.4 0.4 0.4 0.4], 'LineWidth', 0.8, ... 'HandleVisibility', 'off'); end yline(0, 'k-', 'LineWidth', 1.0, 'HandleVisibility','off'); h_thr2 = yline(10, 'r--', 'LineWidth', 1.5, 'DisplayName', '\pm10% threshold'); yline(-10, 'r--', 'LineWidth', 1.5, 'HandleVisibility','off'); xlabel('Week', 'FontSize', 11); ylabel('BAI-2 Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); legend(h_thr2, 'Location', 'east', 'FontSize', 9); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax2, 0.02, 0.97, 'B', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel C: rolling direction consistency (spans both columns) ax3 = nexttile([1 2]); hold on; for wi = 1:numel(windows) plot(weeks, consistencyPct(:, wi), '-o', 'LineWidth', 2.0, ... 'MarkerSize', 4, 'Color', windowCols(wi,:), ... 'DisplayName', sprintf('%d-week window', windows(wi))); end xlabel('Week', 'FontSize', 11); ylabel('Players with Consistent Direction (%)', 'FontSize', 11); xlim(X_LIM); ylim([0 100]); legend('Location', 'south', 'Orientation', 'horizontal', 'FontSize', 10); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax3, 0.01, 0.97, 'C', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); saveFig('Fig3_Direction'); %% ===== SUPPLEMENTARY FIGURE S3: INDIVIDUAL VS GROUP (5-panel) — Adduction fprintf('\n--- Figure S3: Individual vs group 5-panel (adduction) ---\n'); [T, participants, weeks, ~, ~, Asym, ~] = loadData(DATA_PATH); nPlayers = numel(participants); nWeeks = numel(weeks); % Panel A: z-score heatmap groups = unique(T.Group); zMatrix = NaN(nPlayers, nWeeks); for w = 1:nWeeks for g = 1:numel(groups) idx = T.Week == weeks(w) & T.Group == groups(g); vals = abs(Asym.BSA(idx)); if sum(~isnan(vals)) < 3; continue; end gMean = mean(vals, 'omitnan'); gSD = std(vals, 0, 'omitnan'); if gSD == 0; continue; end playerInGroup = unique(T.Participant(idx)); for pp = 1:numel(playerInGroup) pIdx = find(participants == playerInGroup(pp)); playerVal = abs(Asym.BSA(T.Week == weeks(w) & T.Participant == playerInGroup(pp))); if ~isempty(playerVal) && ~isnan(playerVal(1)) zMatrix(pIdx, w) = (playerVal(1) - gMean) / gSD; end end end end groupNames = {'Goalkeepers', 'Defenders', 'Midfielders', 'Forwards'}; groupCols = [OI_blue; OI_red; OI_green; OI_gold]; figure('Name','Fig7','Position',[60 60 1500 1100]); tiledlayout(3, 2, 'TileSpacing','compact','Padding','compact'); % Panel A: z-score heatmap — spans both columns of row 1 axA = nexttile([1 2]); imagesc(zMatrix, 'AlphaData', ~isnan(zMatrix)); colormap(redblue()); caxis([-3 3]); cb = colorbar; cb.Label.String = 'z-score (player vs group mean, BSA)'; set(gca, 'YTick', 1:nPlayers, 'YTickLabel', cellstr(num2str((1:nPlayers)'))); xlabel('Week', 'FontSize', 11); ylabel('Player', 'FontSize', 11); set(gca, 'FontSize', 10, 'FontName','Arial'); text(axA, 0.005, 0.95, 'A', 'Units','normalized','FontSize',13, ... 'FontWeight','bold','VerticalAlignment','top','Color','k', ... 'BackgroundColor','w','Margin',2); % Panels B-E: per-group spaghetti panelLetters = {'B','C','D','E'}; for g = 1:numel(groups) nexttile; hold on; groupPlayers = unique(T.Participant(T.Group == groups(g))); nLabel = numel(groupPlayers); h_player = []; for p = 1:nLabel idx = T.Participant == groupPlayers(p); [pw, si] = sort(T.Week(idx)); vals = abs(Asym.BSA(idx)); if p == 1 h_player = plot(pw, vals(si), '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'DisplayName', 'Individual players'); else plot(pw, vals(si), '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'HandleVisibility', 'off'); end end gMeans = NaN(nWeeks, 1); gSDs = NaN(nWeeks, 1); for w = 1:nWeeks idx = T.Week == weeks(w) & T.Group == groups(g); vals = abs(Asym.BSA(idx)); gMeans(w) = mean(vals, 'omitnan'); gSDs(w) = std(vals, 0, 'omitnan'); end if nLabel >= 3 valid = ~isnan(gMeans) & ~isnan(gSDs); x = weeks(valid); y_up = gMeans(valid) + gSDs(valid); y_down = gMeans(valid) - gSDs(valid); h_band = fill([x; flipud(x)], [y_up; flipud(y_down)], groupCols(g,:), ... 'FaceAlpha', 0.20, 'EdgeColor', 'none', 'DisplayName', '\pm1 SD'); end h_mean = plot(weeks, gMeans, '-', 'LineWidth', 2.0, 'Color', groupCols(g,:), ... 'DisplayName', 'Group mean'); h_thr = yline(10, 'r--', 'LineWidth', 1.0, 'DisplayName', '10% threshold'); excludedNote = ''; if nLabel < 3; excludedNote = ' — excluded, n<3'; end xlabel('Week', 'FontSize', 11); ylabel('BSA Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); % For Forwards (n=1): legend treats single line as the player, no group mean if nLabel >= 3 legend([h_mean, h_band, h_thr, h_player], 'Location', 'northeast', 'FontSize', 8); elseif nLabel == 1 % Single player only — relabel to avoid misleading "Group mean" legend legend(h_mean, 'Player (n=1, excluded)', 'Location', 'northeast', 'FontSize', 8); else legend([h_mean, h_thr, h_player], 'Location', 'northeast', 'FontSize', 8); end grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); % Combined panel letter + group name in top-left (replaces both old title and old letter) text(0.02, 0.97, sprintf('%s %s (n=%d)%s', panelLetters{g}, groupNames{g}, nLabel, excludedNote), ... 'Units','normalized','FontSize',11,'FontWeight','bold', ... 'VerticalAlignment','top','BackgroundColor','w','Margin',2); end saveFig('FigS3_IndividualVsGroup'); %% ===== FIGURE 4: PER-PLAYER STABILISATION (Adduction) ================== fprintf('\n--- Figure 4: Cumulative mean stabilisation (adduction) ---\n'); [T, participants, ~, ~, ~, Asym, ~] = loadData(DATA_PATH); nPlayers = numel(participants); figure('Name','Fig8','Position',[100 100 1500 450]); tiledlayout(1, 3, 'TileSpacing','compact','Padding','compact'); % Three panels span the full range of stabilisation behaviour observed: % SA - lowest magnitude / earliest apparent stabilisation (median ~8 weeks) % BSA - most clinically prevalent unsigned formula (median ~19 weeks) % BAI-2 - recommended signed formula (median ~19 weeks) % LSI-2 (median ~23 weeks) and BAI-1/SI (median ~15 weeks) are omitted from % the main figure to keep the visual contrast clear; per-player stabilisation % values for all seven formulas are tabulated in Supplementary Tables S1-S4. formulaList = {'SA', 'BSA', 'BAI2'}; panelLabels = {'A — SA', 'B — BSA / %Diff', 'C — BAI-2'}; for fi = 1:numel(formulaList) nexttile; hold on; stabPoints_week = NaN(nPlayers, 1); % store week of stabilisation h_player_first = []; h_stab_first = []; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = abs(Asym.(formulaList{fi})(idx)); vals = vals(si); valid = ~isnan(vals); vals = vals(valid); pw_valid = pw(valid); % corresponding weeks for the valid values if numel(vals) < MIN_OBS; continue; end cumMean = arrayfun(@(k) mean(vals(1:k)), 1:numel(vals)); finalMean = mean(vals); % Plot cumulative mean against actual week number if isempty(h_player_first) h_player_first = plot(pw_valid, cumMean, '-', ... 'Color', [0.6 0.6 0.6 0.5], 'LineWidth', 0.8, ... 'DisplayName', 'Player cumulative mean'); else plot(pw_valid, cumMean, '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'HandleVisibility','off'); end % Find stabilisation: store WEEK at which stabilised (not observation index) for k = MIN_OBS:numel(vals) remaining = arrayfun(@(j) mean(vals(1:j)), k:numel(vals)); if all(abs(remaining - finalMean) <= MEAN_TOL) stabPoints_week(p) = pw_valid(k); if isempty(h_stab_first) h_stab_first = plot(pw_valid(k), cumMean(k), 'o', ... 'MarkerFaceColor', OI_red, 'MarkerEdgeColor', OI_red, ... 'MarkerSize', 6, 'LineStyle','none', ... 'DisplayName', 'Stabilisation point'); else plot(pw_valid(k), cumMean(k), 'o', 'MarkerFaceColor', OI_red, ... 'MarkerEdgeColor', OI_red, 'MarkerSize', 6, ... 'HandleVisibility','off'); end break; end end end medStab = median(stabPoints_week, 'omitnan'); h_med = []; if ~isnan(medStab) h_med = xline(medStab, '-', 'Color', OI_red, 'LineWidth', 2.0, ... 'DisplayName', sprintf('Median = week %.0f', medStab)); end xlabel('Week', 'FontSize', 11); ylabel('Cumulative Mean |Asymmetry| (%)', 'FontSize', 11); title(panelLabels{fi}, 'FontSize', 11, 'FontWeight', 'normal'); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); legend_handles = h_player_first; if ~isempty(h_stab_first); legend_handles = [legend_handles, h_stab_first]; end if ~isempty(h_med); legend_handles = [legend_handles, h_med]; end legend(legend_handles, 'Location', 'northwest', 'FontSize', 9); fprintf(' %s median stabilisation: week %.0f\n', formulaList{fi}, medStab); end saveFig('Fig4_Stabilisation'); fprintf('\n--- MAIN FIGURES COMPLETE (Figs 1-4) ---\n'); %% ===== SUPPLEMENTARY FIGURE S4: PER-PLAYER FLAGGING HEATMAP (Abduction) = fprintf('\n--- Figure S4: Per-player flagging heatmap (abduction) ---\n'); [T, participants, ~, formulaNames, formulaLabels, ~, Abd] = loadData(DATA_PATH); nPlayers = numel(participants); nFormulas = numel(formulaNames); flagMatrix = NaN(nPlayers, nFormulas); for p = 1:nPlayers idx = T.Participant == participants(p); for f = 1:nFormulas vals = abs(Abd.(formulaNames{f})(idx)); flagMatrix(p, f) = 100 * sum(vals > THRESH_10, 'omitnan') / sum(~isnan(vals)); end end figure('Name','FigS1','Position',[100 100 900 700]); imagesc(flagMatrix); colormap(flipud(hot)); cb = colorbar; cb.Label.String = 'Flagging rate at 10% (%)'; caxis([0 100]); set(gca, 'XTick', 1:nFormulas, 'XTickLabel', formulaLabels, ... 'YTick', 1:nPlayers, 'YTickLabel', cellstr(num2str((1:nPlayers)'))); xlabel('Asymmetry Formula', 'FontSize', 11); ylabel('Player', 'FontSize', 11); xtickangle(45); set(gca, 'FontSize', 10, 'FontName','Arial'); saveFig('FigS4_FlaggingHeatmap_Abd'); %% ===== SUPPLEMENTARY FIGURE S5: BLAND-ALTMAN (Abduction) =============== fprintf('\n--- Figure S5: Bland-Altman (abduction) ---\n'); [T, ~, ~, ~, ~, ~, Abd] = loadData(DATA_PATH); bsa_abs = abs(Abd.BSA); bai2_abs = abs(Abd.BAI2); ba_mean = (bsa_abs + bai2_abs) / 2; ba_diff = bsa_abs - bai2_abs; mean_d = mean(ba_diff, 'omitnan'); sd_d = std(ba_diff, 0, 'omitnan'); loa_hi = mean_d + 1.96 * sd_d; loa_lo = mean_d - 1.96 * sd_d; x_theory = linspace(0.001, 0.9999, 1000); bsa_th = (1 - x_theory) * 100; bai2_th = 2*(1 - x_theory) ./ (1 + x_theory) * 100; mean_th = (bsa_th + bai2_th) / 2; diff_th = bsa_th - bai2_th; in_range = mean_th <= max(ba_mean)*1.05 & mean_th >= 0; mean_th = mean_th(in_range); diff_th = diff_th(in_range); figure('Name','FigS2','Position',[100 100 820 580]); hold on; yline(mean_d, 'k-', 'LineWidth', 1.6, 'DisplayName', sprintf('Mean diff = %.2f%%', mean_d)); yline(loa_hi, '--', 'LineWidth', 1.2, 'Color', [0.5 0.5 0.5], 'DisplayName', sprintf('+1.96 SD = %.2f%%', loa_hi)); yline(loa_lo, '--', 'LineWidth', 1.2, 'Color', [0.5 0.5 0.5], 'DisplayName', sprintf('-1.96 SD = %.2f%%', loa_lo)); xline(10, ':', 'Color', [0.55 0.55 0.55], 'LineWidth', 1.2, ... 'Label', '10%', 'LabelVerticalAlignment', 'bottom', 'HandleVisibility', 'off'); plot(mean_th, diff_th, '-', 'LineWidth', 2.5, 'Color', OI_blue, ... 'DisplayName', 'Theoretical: -100(1-x)^{2}/(1+x)'); scatter(ba_mean, ba_diff, 18, OI_red, 'filled', 'MarkerFaceAlpha', 0.55, ... 'DisplayName', 'Observations'); xlabel('Mean of |BSA| and |BAI-2| (%)', 'FontSize', 11); ylabel('Difference: |BSA| - |BAI-2| (%)', 'FontSize', 11); xlim([0 max(ba_mean)*1.1]); legend('Location', 'southwest', 'FontSize', 9); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); saveFig('FigS5_BlandAltman_Abd'); %% ===== SUPPLEMENTARY FIGURE S6: SENSITIVITY (Abduction) ================ fprintf('\n--- Figure S6: Sensitivity (abduction) ---\n'); [T, ~, ~, formulaNames, formulaLabels, ~, Abd] = loadData(DATA_PATH); nFormulas = numel(formulaNames); plotIdx = [1, 2, 3, 5, 7]; plotLabels = formulaLabels(plotIdx); plotCols = [OI_blue; OI_red; OI_gold; OI_green; OI_purple]; thresholds = 0:0.5:25; flagRates = NaN(numel(thresholds), nFormulas); for f = 1:nFormulas vals = abs(Abd.(formulaNames{f})); nObs = sum(~isnan(vals)); for t = 1:numel(thresholds) flagRates(t, f) = 100 * sum(vals > thresholds(t), 'omitnan') / nObs; end end figure('Name','FigS3','Position',[100 100 900 600]); hold on; for i = 1:numel(plotIdx) plot(thresholds, flagRates(:, plotIdx(i)), '-', 'LineWidth', 2.0, ... 'Color', plotCols(i,:), 'DisplayName', plotLabels{i}); end xline(10, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0, ... 'Label', '10% threshold', 'HandleVisibility', 'off'); xline(15, '--', 'Color', [0.5 0.5 0.5], 'LineWidth', 1.0, ... 'Label', '15% threshold', 'HandleVisibility', 'off'); xlabel('Asymmetry threshold (%)', 'FontSize', 11); ylabel('Observations flagged (%)', 'FontSize', 11); xlim([0 25]); ylim([0 100]); legend('Location', 'northeast', 'FontSize', 10); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); saveFig('FigS6_Sensitivity_Abd'); %% ===== SUPPLEMENTARY FIGURE S7: DIRECTION 3-panel (Abduction) ========== fprintf('\n--- Figure S7: Direction 3-panel (abduction) ---\n'); [T, participants, weeks, ~, ~, ~, Abd] = loadData(DATA_PATH); nPlayers = numel(participants); nWeeks = numel(weeks); windows = [3, 5, 8]; windowCols = [OI_blue; OI_red; OI_green]; consistencyPct = NaN(nWeeks, numel(windows)); for wi = 1:numel(windows) win = windows(wi); for w = 1:(nWeeks - win + 1) consistent = 0; valid = 0; for p = 1:nPlayers idx = T.Participant == participants(p); playerWeeks = T.Week(idx); playerDirs = sign(Abd.BAI2(idx)); in_win = playerWeeks >= weeks(w) & playerWeeks <= weeks(w + win - 1); dirs = playerDirs(in_win); dirs = dirs(dirs ~= 0); if numel(dirs) >= 2 valid = valid + 1; if all(dirs == dirs(1)); consistent = consistent + 1; end end end if valid > 0 consistencyPct(w, wi) = 100 * consistent / valid; end end end figure('Name','FigS4','Position',[80 80 1400 950]); tiledlayout(2, 2, 'TileSpacing','compact','Padding','compact'); % Panel A: BSA spaghetti ax1 = nexttile; hold on; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = abs(Abd.BSA(idx)); plot(pw, vals(si), '-', 'Color', [0.4 0.4 0.4 0.4], 'LineWidth', 0.8, ... 'HandleVisibility', 'off'); end h_thr = yline(10, 'r--', 'LineWidth', 1.5, 'DisplayName', '10% threshold'); xlabel('Week', 'FontSize', 11); ylabel('BSA Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); legend(h_thr, 'Location', 'northeast', 'FontSize', 9); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax1, 0.02, 0.97, 'A', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel B: BAI-2 spaghetti ax2 = nexttile; hold on; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = Abd.BAI2(idx); plot(pw, vals(si), '-', 'Color', [0.4 0.4 0.4 0.4], 'LineWidth', 0.8, ... 'HandleVisibility', 'off'); end yline(0, 'k-', 'LineWidth', 1.0, 'HandleVisibility','off'); h_thr2 = yline(10, 'r--', 'LineWidth', 1.5, 'DisplayName', '\pm10% threshold'); yline(-10, 'r--', 'LineWidth', 1.5, 'HandleVisibility','off'); xlabel('Week', 'FontSize', 11); ylabel('BAI-2 Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); legend(h_thr2, 'Location', 'east', 'FontSize', 9); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax2, 0.02, 0.97, 'B', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); % Panel C: rolling consistency (spans both columns) ax3 = nexttile([1 2]); hold on; for wi = 1:numel(windows) plot(weeks, consistencyPct(:, wi), '-o', 'LineWidth', 2.0, ... 'MarkerSize', 4, 'Color', windowCols(wi,:), ... 'DisplayName', sprintf('%d-week window', windows(wi))); end xlabel('Week', 'FontSize', 11); ylabel('Players with Consistent Direction (%)', 'FontSize', 11); xlim(X_LIM); ylim([0 100]); legend('Location', 'south', 'Orientation', 'horizontal', 'FontSize', 10); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); text(ax3, 0.01, 0.97, 'C', 'Units','normalized','FontSize',14, ... 'FontWeight','bold','VerticalAlignment','top', ... 'BackgroundColor','w','Margin',2); saveFig('FigS7_Direction_Abd'); %% ===== SUPPLEMENTARY FIGURE S8: INDIVIDUAL VS GROUP 5-panel (Abduction) = fprintf('\n--- Figure S8: Individual vs group 5-panel (abduction) ---\n'); [T, participants, weeks, ~, ~, ~, Abd] = loadData(DATA_PATH); nPlayers = numel(participants); nWeeks = numel(weeks); groups = unique(T.Group); zMatrix = NaN(nPlayers, nWeeks); for w = 1:nWeeks for g = 1:numel(groups) idx = T.Week == weeks(w) & T.Group == groups(g); vals = abs(Abd.BSA(idx)); if sum(~isnan(vals)) < 3; continue; end gMean = mean(vals, 'omitnan'); gSD = std(vals, 0, 'omitnan'); if gSD == 0; continue; end playerInGroup = unique(T.Participant(idx)); for pp = 1:numel(playerInGroup) pIdx = find(participants == playerInGroup(pp)); playerVal = abs(Abd.BSA(T.Week == weeks(w) & T.Participant == playerInGroup(pp))); if ~isempty(playerVal) && ~isnan(playerVal(1)) zMatrix(pIdx, w) = (playerVal(1) - gMean) / gSD; end end end end groupNames = {'Goalkeepers', 'Defenders', 'Midfielders', 'Forwards'}; groupCols = [OI_blue; OI_red; OI_green; OI_gold]; figure('Name','FigS5','Position',[60 60 1500 1100]); tiledlayout(3, 2, 'TileSpacing','compact','Padding','compact'); axA = nexttile([1 2]); imagesc(zMatrix, 'AlphaData', ~isnan(zMatrix)); colormap(redblue()); caxis([-3 3]); cb = colorbar; cb.Label.String = 'z-score (player vs group mean, BSA)'; set(gca, 'YTick', 1:nPlayers, 'YTickLabel', cellstr(num2str((1:nPlayers)'))); xlabel('Week', 'FontSize', 11); ylabel('Player', 'FontSize', 11); set(gca, 'FontSize', 10, 'FontName','Arial'); text(axA, 0.005, 0.95, 'A', 'Units','normalized','FontSize',13, ... 'FontWeight','bold','VerticalAlignment','top','Color','k', ... 'BackgroundColor','w','Margin',2); panelLetters = {'B','C','D','E'}; for g = 1:numel(groups) nexttile; hold on; groupPlayers = unique(T.Participant(T.Group == groups(g))); nLabel = numel(groupPlayers); h_player = []; for p = 1:nLabel idx = T.Participant == groupPlayers(p); [pw, si] = sort(T.Week(idx)); vals = abs(Abd.BSA(idx)); if p == 1 h_player = plot(pw, vals(si), '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'DisplayName', 'Individual players'); else plot(pw, vals(si), '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'HandleVisibility', 'off'); end end gMeans = NaN(nWeeks, 1); gSDs = NaN(nWeeks, 1); for w = 1:nWeeks idx = T.Week == weeks(w) & T.Group == groups(g); vals = abs(Abd.BSA(idx)); gMeans(w) = mean(vals, 'omitnan'); gSDs(w) = std(vals, 0, 'omitnan'); end if nLabel >= 3 valid = ~isnan(gMeans) & ~isnan(gSDs); x = weeks(valid); y_up = gMeans(valid) + gSDs(valid); y_down = gMeans(valid) - gSDs(valid); h_band = fill([x; flipud(x)], [y_up; flipud(y_down)], groupCols(g,:), ... 'FaceAlpha', 0.20, 'EdgeColor', 'none', 'DisplayName', '\pm1 SD'); end h_mean = plot(weeks, gMeans, '-', 'LineWidth', 2.0, 'Color', groupCols(g,:), ... 'DisplayName', 'Group mean'); h_thr = yline(10, 'r--', 'LineWidth', 1.0, 'DisplayName', '10% threshold'); excludedNote = ''; if nLabel < 3; excludedNote = ' — excluded, n<3'; end xlabel('Week', 'FontSize', 11); ylabel('BSA Asymmetry (%)', 'FontSize', 11); xlim(X_LIM); % For Forwards (n=1): legend treats single line as the player, no group mean if nLabel >= 3 legend([h_mean, h_band, h_thr, h_player], 'Location', 'northeast', 'FontSize', 8); elseif nLabel == 1 % Single player only — relabel to avoid misleading "Group mean" legend legend(h_mean, 'Player (n=1, excluded)', 'Location', 'northeast', 'FontSize', 8); else legend([h_mean, h_thr, h_player], 'Location', 'northeast', 'FontSize', 8); end grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); % Combined panel letter + group name in top-left (replaces both old title and old letter) text(0.02, 0.97, sprintf('%s %s (n=%d)%s', panelLetters{g}, groupNames{g}, nLabel, excludedNote), ... 'Units','normalized','FontSize',11,'FontWeight','bold', ... 'VerticalAlignment','top','BackgroundColor','w','Margin',2); end saveFig('FigS8_IndividualVsGroup_Abd'); %% ===== SUPPLEMENTARY FIGURE S9: STABILISATION (Abduction) ============== fprintf('\n--- Figure S9: Cumulative mean stabilisation (abduction) ---\n'); [T, participants, ~, ~, ~, ~, Abd] = loadData(DATA_PATH); nPlayers = numel(participants); figure('Name','FigS6','Position',[100 100 1500 450]); tiledlayout(1, 3, 'TileSpacing','compact','Padding','compact'); % Three panels matching Figure 8 (adduction); see Figure 8 comment for rationale. formulaList = {'SA', 'BSA', 'BAI2'}; panelLabels = {'A — SA', 'B — BSA / %Diff', 'C — BAI-2'}; for fi = 1:numel(formulaList) nexttile; hold on; stabPoints_week = NaN(nPlayers, 1); % store week of stabilisation h_player_first = []; h_stab_first = []; for p = 1:nPlayers idx = T.Participant == participants(p); [pw, si] = sort(T.Week(idx)); vals = abs(Abd.(formulaList{fi})(idx)); vals = vals(si); valid = ~isnan(vals); vals = vals(valid); pw_valid = pw(valid); % corresponding weeks for the valid values if numel(vals) < MIN_OBS; continue; end cumMean = arrayfun(@(k) mean(vals(1:k)), 1:numel(vals)); finalMean = mean(vals); % Plot cumulative mean against actual week number if isempty(h_player_first) h_player_first = plot(pw_valid, cumMean, '-', ... 'Color', [0.6 0.6 0.6 0.5], 'LineWidth', 0.8, ... 'DisplayName', 'Player cumulative mean'); else plot(pw_valid, cumMean, '-', 'Color', [0.6 0.6 0.6 0.5], ... 'LineWidth', 0.8, 'HandleVisibility','off'); end % Find stabilisation: store WEEK at which stabilised (not observation index) for k = MIN_OBS:numel(vals) remaining = arrayfun(@(j) mean(vals(1:j)), k:numel(vals)); if all(abs(remaining - finalMean) <= MEAN_TOL) stabPoints_week(p) = pw_valid(k); if isempty(h_stab_first) h_stab_first = plot(pw_valid(k), cumMean(k), 'o', ... 'MarkerFaceColor', OI_red, 'MarkerEdgeColor', OI_red, ... 'MarkerSize', 6, 'LineStyle','none', ... 'DisplayName', 'Stabilisation point'); else plot(pw_valid(k), cumMean(k), 'o', 'MarkerFaceColor', OI_red, ... 'MarkerEdgeColor', OI_red, 'MarkerSize', 6, ... 'HandleVisibility','off'); end break; end end end medStab = median(stabPoints_week, 'omitnan'); h_med = []; if ~isnan(medStab) h_med = xline(medStab, '-', 'Color', OI_red, 'LineWidth', 2.0, ... 'DisplayName', sprintf('Median = week %.0f', medStab)); end xlabel('Week', 'FontSize', 11); ylabel('Cumulative Mean |Asymmetry| (%)', 'FontSize', 11); title(panelLabels{fi}, 'FontSize', 11, 'FontWeight', 'normal'); grid on; box on; set(gca, 'FontSize', 10, 'FontName','Arial'); legend_handles = h_player_first; if ~isempty(h_stab_first); legend_handles = [legend_handles, h_stab_first]; end if ~isempty(h_med); legend_handles = [legend_handles, h_med]; end legend(legend_handles, 'Location', 'northwest', 'FontSize', 9); fprintf(' %s median stabilisation: week %.0f\n', formulaList{fi}, medStab); end saveFig('FigS9_Stabilisation_Abd'); fprintf('\n========== ALL FIGURES COMPLETE (4 main + 9 supplementary) ==========\n'); %% ===== LOCAL FUNCTIONS =================================================== function [T, participants, weeks, formulaNames, formulaLabels, Asym, Abd] = loadData(dataPath) opts = spreadsheetImportOptions('NumVariables', 23); opts.Sheet = 'Raw'; opts.DataRange = 'A2:W602'; opts.VariableNames = {'Player','Date','Participant','Week','MD','MD_Group', ... 'Mass','Height','Position','Player_Group','Group', ... 'AddND','AddD','AbdND','AbdD', ... 'DomVsNonDomAdd','DomVsNonDomAbd','DomAddAbd','NonDomAddAbd', ... 'NormAddND','NormAddD','NormAbdND','NormAbdD'}; opts.VariableTypes = {'categorical','datetime','double','double','categorical', ... 'double','double','double','categorical','categorical','double', ... 'double','double','double','double', ... 'double','double','double','double', ... 'double','double','double','double'}; opts = setvaropts(opts, {'Player','MD','Position','Player_Group'}, 'EmptyFieldRule','auto'); opts = setvaropts(opts, 'Date', 'InputFormat',''); T = readtable(dataPath, opts, 'UseExcel', false); valid = ~isnan(T.AddND) & ~isnan(T.AddD) & ~isnan(T.AbdND) & ~isnan(T.AbdD) ... & T.AddD > 0 & T.AddND > 0 & T.AbdD > 0 & T.AbdND > 0; T = T(valid, :); participants = unique(T.Participant); weeks = unique(T.Week); formulaNames = {'LSI2','BAI2','BSA','PctDiff','BAI1','SI','SA'}; formulaLabels = {'LSI-2','BAI-2','BSA','%Diff','BAI-1','SI','SA'}; dom = T.AddD; ndom = T.AddND; str = max(dom, ndom); wk = min(dom, ndom); Asym.LSI2 = (1 - ndom ./ dom) * 100; Asym.BAI2 = 2*(dom - ndom) ./ (dom + ndom) * 100; Asym.BSA = (str - wk) ./ str * 100; Asym.PctDiff = 100 ./ str .* wk * -1 + 100; Asym.BAI1 = (dom - ndom) ./ (dom + ndom) * 100; Asym.SI = (str - wk) ./ (str + wk) * 100; Asym.SA = (45 - atand(ndom ./ dom)) ./ 90 * 100; dom = T.AbdD; ndom = T.AbdND; str = max(dom, ndom); wk = min(dom, ndom); Abd.LSI2 = (1 - ndom ./ dom) * 100; Abd.BAI2 = 2*(dom - ndom) ./ (dom + ndom) * 100; Abd.BSA = (str - wk) ./ str * 100; Abd.PctDiff = 100 ./ str .* wk * -1 + 100; Abd.BAI1 = (dom - ndom) ./ (dom + ndom) * 100; Abd.SI = (str - wk) ./ (str + wk) * 100; Abd.SA = (45 - atand(ndom ./ dom)) ./ 90 * 100; end function saveFig(name) exportgraphics(gcf, [name '.png'], 'Resolution', 600); print(gcf, name, '-dsvg'); fprintf(' Saved: %s.png + %s.svg\n', name, name); end function cmap = redblue() n = 64; r = [linspace(0, 1, n/2)'; linspace(1, 1, n/2)']; g = [linspace(0, 1, n/2)'; linspace(1, 0, n/2)']; b = [linspace(1, 1, n/2)'; linspace(1, 0, n/2)']; cmap = [r, g, b]; end function k = computeKappa(a, b) % Cohen's kappa for two paired categorical vectors (categories coded 1/2). % Degenerate case (a single category present) returns 0, matching the % "no measurable agreement beyond a fixed call" interpretation used for % players who never change direction. a = a(:); b = b(:); n = numel(a); cats = unique([a; b]); if numel(cats) < 2 || n < 2 k = 0; return; end C = zeros(numel(cats)); for i = 1:n r = find(cats == a(i)); c = find(cats == b(i)); C(r,c) = C(r,c) + 1; end po = sum(diag(C)) / n; pe = sum( (sum(C,1)/n) .* (sum(C,2)'/n) ); if pe == 1, k = 0; else, k = (po - pe) / (1 - pe); end end function v = asymFromLimbs(name, D, N) % Apply one asymmetry formula to dominant (D) / non-dominant (N) limb vectors. Sg = max(D, N); Wk = min(D, N); switch name case 'LSI2', v = (1 - N ./ D) * 100; case 'BAI2', v = 2 * (D - N) ./ (D + N) * 100; case 'BSA', v = (Sg - Wk) ./ Sg * 100; case 'PctDiff', v = (Sg - Wk) ./ Sg * 100; case 'BAI1', v = (D - N) ./ (D + N) * 100; case 'SI', v = (Sg - Wk) ./ (D + N) * 100; case 'SA', v = (45 - atand(N ./ D)) / 90 * 100; otherwise, error('asymFromLimbs: unknown formula %s', name); end end function wk = localStabWeek(v, pw, tol, isRel, minObs) % First WEEK at which the cumulative mean of v enters and remains within % the tolerance band of its final value, for all subsequent observations. % v - per-player absolute asymmetry values, sorted by week (may hold NaN) % pw - the corresponding week numbers, same length and order as v % tol - band width: percentage points if isRel == false, else a % fraction of the final cumulative mean % isRel - true for a scale-relative band, false for an absolute band % Returns NaN if the band is never satisfied (or < minObs observations). wk = NaN; ok = ~isnan(v); v = v(ok); pw = pw(ok); nV = numel(v); if nV < minObs, return; end cm = arrayfun(@(k) mean(v(1:k)), 1:nV); target = cm(end); band = tol; if isRel, band = tol * abs(target); end if band == 0, return; end for k = minObs:nV if all(abs(cm(k:end) - target) < band) wk = pw(k); return; end end end