-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathClassifyPoly.m
48 lines (38 loc) · 1.47 KB
/
ClassifyPoly.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function goodCellsii = ClassifyPoly(ydata,dat,goodCellsi,zscore)
% get Udata along with goodCellsi - analysis of good cells from other analyses
% output goodCellsii - analysis of remaining good cells using polynomial fit
% minimum number of cells required to calculate polynomial fits
nCellcrit = 5;
% initialize output
goodCellsii = goodCellsi;
% calculate statistics
Umean = mean(dat);
Ustd = std(dat);
Uskew = skewness(dat);
% find only the non nan values
nanmem = isnan(Umean)|isnan(Ustd)|isnan(Uskew);
%% outlier removal algorithm
outlier=1;
% while there may be an outlier
while outlier
% if there are a minimum of 5 points in the profile
goodCellsiimem = find(goodCellsii&~nanmem');
if length(goodCellsiimem)>nCellcrit
% find outliers on Umean profile
[fresult,gof,output]=fit(ydata(goodCellsiimem)',Umean(goodCellsiimem)','poly3');
% assuming zscore of 2.58 or 99%
b=abs(output.residuals)>zscore*std(output.residuals);
% find outliers on Ustd profile
[fresult,gof,output]=fit(log(ydata(goodCellsiimem)'),Ustd(goodCellsiimem)','poly3');
c=abs(output.residuals)>zscore*std(output.residuals);
% find outliers on Uskew profile
[fresult,gof,output]=fit(log(ydata(goodCellsiimem)'),Uskew(goodCellsiimem)','poly3');
d=abs(output.residuals)>zscore*std(output.residuals);
e=b|c|d;
outlier = sum(e)>1;
goodCellsii(goodCellsiimem(e))=0;
else
outlier = 0;
end
end
end