Skip to content

Commit f085519

Browse files
Added nuisance variables to regression
1 parent b99d344 commit f085519

File tree

3 files changed

+74
-38
lines changed

3 files changed

+74
-38
lines changed

demos/fwe_control.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
for i = 1:nsim
8686
imgs = randn(4,4,4,20);
8787
covariate = [ones(20,1) randn(20,4)];
88-
[pcorr_pos,pcorr_neg] = matlab_tfce('regression',2,imgs,[],covariate);
88+
[pcorr_pos,pcorr_neg] = matlab_tfce('regression',2,imgs,[],covariate,[],[],[],[],[],[],[1 0 0 1 1]);
8989
for j = 1:5
9090
fp(i,j) = sum(pcorr_pos{j}(:)<.05)+sum(pcorr_neg{j}(:)<.05);
9191
end
9292
end
93-
fp/nsim
93+
sum(fp)/nsim

matlab_tfce.m

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
% corrections, is substantially less conservative due to the fact that
2626
% it capitalizes on spatial dependency in the data.
2727
%
28-
% [varargout] = matlab_tfce(analysis,tails,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers)
29-
% [pcorr] = matlab_tfce(analysis,1,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers)
30-
% [pcorr_pos,pcorr_neg] = matlab_tfce(analysis,2,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers)
31-
% [pcorr_fac1,pcorr_fac2,pcorr_int] = matlab_tfce(analysis,1,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers)
28+
% [varargout] = matlab_tfce(analysis,tails,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers,nuisance)
29+
% [pcorr] = matlab_tfce(analysis,1,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers,nuisance)
30+
% [pcorr_pos,pcorr_neg] = matlab_tfce(analysis,2,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers,nuisance)
31+
% [pcorr_fac1,pcorr_fac2,pcorr_int] = matlab_tfce(analysis,1,imgs,imgs2,covariate,nperm,H,E,C,dh,parworkers,nuisance)
3232
%
3333
% Arguments:
3434
%
@@ -89,6 +89,14 @@
8989
% time consuming so it may be more efficient to do outside the package if
9090
% one is running several analyses.
9191
%
92+
% nuisance -- commandline-only argument for specifying which variables in
93+
% a multiple regression are nuisance regressors. Accepts a (1 x predictor)
94+
% binary (0/1 true/false) vector. 1s/trues indicate variables that should
95+
% be treated as nuisance predictors (vs. variables of interest). These
96+
% variables will be included in the model, but will not be subjected to
97+
% TFCE, accelerating calculations. Default is all 0s (i.e. all variables
98+
% treated as of non-nuisance). Ignorned if analysis not regression.
99+
%
92100
% Output:
93101
% If tails == 1, a single output image with the same xyz dimensions as imgs
94102
% consisting of corrected p-values with be returned.
@@ -135,6 +143,7 @@
135143
if nargin > (fixedargn + 1)
136144
covariate = varargin{2};
137145
end
146+
nuisance = zeros([1 size(covariate,2)]);
138147
if nargin > (fixedargn + 2)
139148
if ~isempty(varargin{3})
140149
nperm = varargin{3};
@@ -165,6 +174,11 @@
165174
parworkers = varargin{8};
166175
end
167176
end
177+
if nargin > (fixedargn + 8)
178+
if ~isempty(varargin{9})
179+
nuisance = varargin{9};
180+
end
181+
end
168182

169183
% check that tails are appropriate
170184
if ~(sum(tails==[1 2]))
@@ -270,6 +284,14 @@
270284
end
271285
end
272286

287+
% check nuisance
288+
if strcmp(analysis,'regression')
289+
ns = size(nuisance);
290+
if ~isequal(ns,[1 size(covariate,2)])
291+
error('nuisance size does not equal predictor number');
292+
end
293+
end
294+
273295
%% analysis calls
274296

275297
% indicate analysis start
@@ -325,9 +347,9 @@
325347
% multiple regression
326348
case 'regression'
327349
if tails == 1
328-
pcorr = matlab_tfce_regression(imgs,covariate,tails,nperm,H,E,C,dh);
350+
pcorr = matlab_tfce_regression(imgs,covariate,tails,nperm,H,E,C,dh,nuisance);
329351
else
330-
[pcorr_pos,pcorr_neg] = matlab_tfce_regression(imgs,covariate,tails,nperm,H,E,C,dh);
352+
[pcorr_pos,pcorr_neg] = matlab_tfce_regression(imgs,covariate,tails,nperm,H,E,C,dh,nuisance);
331353
end
332354

333355
% unrecognized analysis input

matlab_tfce_regression.m

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [varargout] = matlab_tfce_regression(imgs,preds,tails,nperm,H,E,C,dh)
1+
function [varargout] = matlab_tfce_regression(imgs,preds,tails,nperm,H,E,C,dh,nuisance)
22
% MATLAB_TFCE_REGRESSION computes TFCE corrected p-values for each
33
% parameter in a multiple regression
44
%
@@ -14,6 +14,8 @@
1414
% -- E extent exponent
1515
% -- C connectivity
1616
% -- ndh step number for cluster formation
17+
% -- nuisance specifies which variables are not of interest
18+
% -- omnibusf requests overall model significance test
1719
%
1820
% Output:
1921
% If tails == 1:
@@ -112,15 +114,17 @@
112114
rtstats = bs./serr;
113115
curexceeds = zeros(nvox,npred);
114116
for i = 1:npred
115-
rbrain=NaN(bsize);
116-
rbrain(implicitmask) = rtstats(i,:);
117-
rbrain = transform(rbrain,H,E,C,dh);
118-
rstats = rbrain(implicitmask);
119-
if tails == 2
120-
rstats = abs(rstats);
121-
end
122-
% compare maxima to t-values and increment as appropriate
123-
curexceeds(:,i) = max(rstats) >= tvals(i,:);
117+
if ~nuisance(i)
118+
rbrain=NaN(bsize);
119+
rbrain(implicitmask) = rtstats(i,:);
120+
rbrain = transform(rbrain,H,E,C,dh);
121+
rstats = rbrain(implicitmask);
122+
if tails == 2
123+
rstats = abs(rstats);
124+
end
125+
% compare maxima to t-values and increment as appropriate
126+
curexceeds(:,i) = max(rstats) >= tvals(i,:);
127+
end
124128
end
125129
exceedances = exceedances + curexceeds;
126130

@@ -139,28 +143,38 @@
139143
end
140144

141145
for i = 1:npred
142-
% create corrected p-value image
143-
corrected = exceedances(:,i)./nperm;
144-
pcorr = ones(bsize);
145-
pcorr(implicitmask) = corrected;
146+
if ~nuisance(i)
147+
% create corrected p-value image
148+
corrected = exceedances(:,i)./nperm;
149+
pcorr = ones(bsize);
150+
pcorr(implicitmask) = corrected;
146151

147-
% split into positive and negative effects (if needed)
148-
if tails == 2
149-
btruestat = NaN(bsize);
150-
btruestat(implicitmask) = truestat(i,:);
151-
pos = btruestat>0;
152-
pcorr_pos = pcorr;
153-
pcorr_pos(~pos) = 1;
154-
pcorr_neg = pcorr;
155-
pcorr_neg(pos) = 1;
156-
end
157-
158-
% assign to cormaps
159-
if tails == 1
160-
cormaps{i} = pcorr;
152+
% split into positive and negative effects (if needed)
153+
if tails == 2
154+
btruestat = NaN(bsize);
155+
btruestat(implicitmask) = truestat(i,:);
156+
pos = btruestat>0;
157+
pcorr_pos = pcorr;
158+
pcorr_pos(~pos) = 1;
159+
pcorr_neg = pcorr;
160+
pcorr_neg(pos) = 1;
161+
end
162+
163+
% assign to cormaps
164+
if tails == 1
165+
cormaps{i} = pcorr;
166+
else
167+
cormaps_pos{i} = pcorr_pos;
168+
cormaps_neg{i} = pcorr_neg;
169+
end
161170
else
162-
cormaps_pos{i} = pcorr_pos;
163-
cormaps_neg{i} = pcorr_neg;
171+
% assign to cormaps
172+
if tails == 1
173+
cormaps{i} = NaN;
174+
else
175+
cormaps_pos{i} = NaN;
176+
cormaps_neg{i} = NaN;
177+
end
164178
end
165179
end
166180

0 commit comments

Comments
 (0)