debugging
[wrf-fire-matlab.git] / cycling / est_max.m
blobc18d75589f264c15eb8b34098433f5e4b8b977bc
1 function perc = est_max(ps,r)
2 %estimate best cut-off for ROS when fitting model
3 %mdl2_1 = fitlm(pc17.red.fmc_g(msk_1),r2(msk_1))
4 %mdl.Coefficients(1,4),(2,4) are the pvaleus
6 stopping = 0;
7 for i = 100:-1:1;%1:100
8 r_cut(i) = i/500;
9 msk1 = r<r_cut(i);
10 msk2 = r > 0.0001;
11 msk = logical(msk1.*msk2);
12 s(i) = sum(msk(:));
13 if s(i) > 20
14     mdl = fitlm(ps.red.fmc_g(msk),r(msk));
15     p(i)=table2array(mdl.Coefficients(2,4));
16     if p(i) <= 0.01 && stopping == 0
17         fprintf('cutoff at ros = %f \n',r_cut(i))
18         stopping = 1;
19         perc = r_cut(i);
20         break
21     end
22 end
24 end%for i
25 % figure,plot(r_cut,p)
26 % title('P-values')
27 % ylim([0 0.1])
28
29
30 % figure,plot(r_cut,s)
31 % title('samples')
32 if perc == []
33     perc = 0.1
34 end
36 end%function