forked from MBB-team/VBA-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBA_Bin2Cont.m
47 lines (42 loc) · 1.33 KB
/
VBA_Bin2Cont.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
function [stacky,stdy,gridg,stdg] = VBA_Bin2Cont(gx,y,maxn)
% transform binary data into continuous intervals (for display purposes)
% function [stacky,stdy,gridg] = VBA_Bin2Cont(gx,y,maxn)
% This function first partitions the data according to percentiles of the
% empirical disitrbution of conditional likelihoods. Then, within each of
% these cells, it calculates the mean and standard deviation of the data.
% IN:
% - gx: the matrix of conditional likelihoods p(y=1|P,m)
% - y: the binary data matrix
% - maxn: the maximum number of cells composing the partition
% OUT:
% - stacky/stdy: the average (standard deviation, resp.) of data points
% lying within each partition cell
% - gridg/stdy: the average (standard deviation, resp.) of conditional
% likelihoods within each partition cell
if isempty(gx)
stacky = [];
stdy = [];
gridg = [];
stdg = [];
return
end
y = y(:);
gx = gx(:);
ny = numel(y);
try;maxn;catch;maxn=min([floor(ny/2),8]);end
ne = min([maxn,ny]);
p = 0:(1/ne):1;
sg = sort(gx);
ind = ceil(p*length(sg)) + [1,zeros(1,size(p,2)-1)];
edges = sg(ind);
stacky = zeros(ne,1);
stdy = zeros(ne,1);
gridg = zeros(ne,1);
stdg = zeros(ne,1);
for i=1:ne
ind = find(gx>=edges(i)&gx<=edges(i+1));
stacky(i) = mean(y(ind));
stdy(i) = std(y(ind));
gridg(i) = mean(gx(ind));
stdg(i) = std(gx(ind));
end