source: issm/branches/trunk-larour-SLPS2020/src/m/contrib/larour/confidenceintervals.m

Last change on this file was 25588, checked in by Eric.Larour, 4 years ago

CHG: diverse

File size: 879 bytes
Line 
1function level=confidenceintervals(x,h,threshold)
2%CONFIDENCEINTERVALS: build confidence interval from histogram.
3
4 nods=size(h,1); nbins=size(h,2);
5
6 %make sure h is one column smaller than x
7 if size(x,2) ~= (size(h,2)+1),
8 error('x should be one column larger than the histogram');
9 end
10
11 %First build cdf:
12 c=[zeros(nods,1) cumsum(h,2)];
13
14 %In percentage:
15 threshold=threshold/100;
16
17 flags=zeros(nods,nbins+1);
18 pos=find(c<threshold);
19 flags(pos)=1;
20 diffc=diff(flags,1,2);
21
22 [ind,j]=find(diffc==-1);
23 indices=zeros(nods,1);
24 indices(ind)=j;
25
26 %threshold was passed between j and j+1 for each node. try
27 %to pin down the fraction better:
28 idx = sub2ind(size(c), [1:size(c,1)]', indices);
29 idx2 = sub2ind(size(c), [1:size(c,1)]', indices+1);
30 val1=c(idx);
31 val2=c(idx2);
32 x1=x(idx);
33 x2=x(idx2);
34
35 fraction=(threshold-val1)./(val2-val1);
36 level=x1+fraction.*(x2-x1);
Note: See TracBrowser for help on using the repository browser.