analysis(matlab): Box-A pooling variations (b2 vs a2+a, b2+a vs a2)

Add make_boxa_variations.m producing 6 variation folders (data.csv + analyze.m
+ result.txt) for the paper LME over windows 0-5, 6-10, 0-10:
  boxa_a2  B2         vs A2 + Box-A   (b2 vs a2+a)
  boxa_b2  B2 + Box-A vs A2           (b2+a vs a2)
plus variations/boxa_summary.csv (residual / Satterthwaite / random-slope
interaction p). Early window (0-5) is obs-level significant (res p~0.03-0.04)
but n.s. under the honest random-slope test (rs p~0.13); later windows n.s.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Experiments DB Dev
2026-07-23 13:39:01 -04:00
parent b03549982e
commit e1af1af7f4
20 changed files with 1370 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
function make_boxa_variations()
%MAKE_BOXA_VARIATIONS Variation folders for the two Box-A pooling groupings.
% MAKE_BOXA_VARIATIONS() writes variations/<grouping>_<window>/ -- each with
% data.csv + analyze.m (a copy of variation_analyze.m) + result.txt, fitting
% the paper LME (behavior ~ stim + day + stim:day + (1|rat)) on the success
% COUNT -- for:
% boxa_a2 B2 vs A2 + Box-A ("b2 vs a2+a")
% boxa_b2 B2 + Box-A vs A2 ("b2+a vs a2")
% over windows d0_5 (0-5), d6_10 (6-10), d0_10 (0-10). Box-A is the
% single-animal Electrode-Box-A condition, pooled into the control (boxa_a2)
% or the treatment (boxa_b2). Also writes variations/boxa_summary.csv with the
% residual / Satterthwaite / honest random-slope interaction p-values.
thisDir = fileparts(mfilename('fullpath'));
template = fullfile(thisDir, 'variation_analyze.m');
root = fullfile(thisDir, 'variations');
if ~exist(root, 'dir'); mkdir(root); end
Tc = tdcs_load_data();
B2 = 'Electrode-Box-B2'; A2 = 'Electrode-Box-A2'; BOXA = 'Electrode-Box-A';
% grouping name | treatment groups (stim=1) | control groups (stim=0)
groupings = {
'boxa_a2', {B2}, {A2, BOXA}
'boxa_b2', {B2, BOXA}, {A2}
};
windows = {'d0_5', [0 5]; 'd6_10', [6 10]; 'd0_10', [0 10]};
allGroup = cellstr(Tc.group);
rows = {};
for gi = 1:size(groupings, 1)
gname = groupings{gi, 1};
inTreat = ismember(allGroup, groupings{gi, 2});
inCtrl = ismember(allGroup, groupings{gi, 3});
for wi = 1:size(windows, 1)
wname = windows{wi, 1}; w = windows{wi, 2};
sel = (inTreat | inCtrl) & Tc.day >= w(1) & Tc.day <= w(2);
D = Tc(sel, :);
stim = double(inTreat(sel));
Dout = table(string(D.subject), string(D.group), D.day, D.success, ...
D.total, stim, 'VariableNames', ...
{'subject', 'group', 'day', 'success', 'total', 'stim'});
vname = [gname '_' wname];
folder = fullfile(root, vname);
if ~exist(folder, 'dir'); mkdir(folder); end
writetable(Dout, fullfile(folder, 'data.csv'));
copyfile(template, fullfile(folder, 'analyze.m'));
r = localRun(fullfile(folder, 'analyze.m'));
rows(end + 1, :) = {vname, gname, wname, r.nRats, r.nObs, ...
r.interP, r.interPsatt, r.interPrs, r.interEst, r.stimP}; %#ok<AGROW>
fprintf(' %-14s N=%d obs=%3d int p: res=%.3f satt=%.3f rs=%-5s est=%+.2f\n', ...
vname, r.nRats, r.nObs, r.interP, r.interPsatt, localNum(r.interPrs), r.interEst);
end
end
S = cell2table(rows, 'VariableNames', {'variation', 'grouping', 'window', ...
'nRats', 'nObs', 'interaction_p', 'interaction_p_satt', 'interaction_p_rs', ...
'interaction_est', 'stim_p'});
writetable(S, fullfile(root, 'boxa_summary.csv'));
fprintf('\nWrote %d folders + variations/boxa_summary.csv\n', size(rows, 1));
end
function r = localRun(scriptPath)
run(scriptPath);
r = VARRESULT; %#ok<NODEF> (defined by the analyze.m script just run)
end
function s = localNum(x)
if isnan(x); s = 'n/a'; else; s = sprintf('%.3f', x); end
end