forked from crcox/iterativelasso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeOutliers.m
32 lines (29 loc) · 1.03 KB
/
removeOutliers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [Aredux, reduxFilter]=removeOutliers(A)
% This function will z-score the row and column means and remove those
% which have a z-score greater than 5. The process it performed on
% columns, and then rows. Each time outliers are removed, the reduced data
% is checked again for outliers, until no outliers remain.
Aredux=A;
% For columns...
outliers = abs(zscore(mean(A,1))) > 5;
outCount = sum(outliers);
% outliers = [];
while outCount > 0
z = outliers;
outliers(~z) = abs(zscore(mean(A(:,~z),1))) > 5;
outCount = sum(outliers(~z));
end
reduxFilter.voxels = ~outliers;
Aredux(:,outliers) = [];
% For rows...
outliers = abs(zscore(mean(Aredux,2))) > 5;
outliers = outliers'; % Mean by row creates a vector n-by-1 instead of 1-by-n.
outCount = sum(outliers);
while outCount > 0
z = outliers;
outliers(~z) = abs(zscore(mean(Aredux(~z,:),2))) > 5;
outCount = sum(outliers(~z));
end
reduxFilter.stimuli = ~outliers;
Aredux(outliers,:) = [];
end