-
Notifications
You must be signed in to change notification settings - Fork 252
/
Copy pathcorrectfit.m
99 lines (92 loc) · 3.79 KB
/
correctfit.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% CORRECTFIT - correct fit using observed p-values. Use this function
% if for some reason, the distribution of p values is
% not uniform between 0 and 1
%
% Usage:
% >> [p phat pci zerofreq] = correctfit(pval, 'key', 'val');
%
% Inputs:
% pval - input p value
%
% Optional inputs:
% 'allpval' - [float array] collection of p values drawn from random
% distributions (theoretically uniform).
% 'gamparams' - [phat pci zerofreq] parameter for gamma function fitting.
% zerofreq is the frequency of occurrence of p=0.
% 'zeromode' - ['on'|'off'] enable estimation of frequency of pval=0
% (this might lead to high pval). Default is 'on'.
%
% Outputs:
% p - corrected p value.
% phat - phat GAMFIT parameter.
% pci - phat GAMFIT parameter.
% zerofreq - frequency of occurrence of p=0.
%
% Authors: Arnaud Delorme, SCCN/INC/UCSD, La Jolla, 2003-
%
% See also: BOOTSTAT
% Copyright (C) 7/02/03 Arnaud Delorme, SCCN/INC/UCSD
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function [pval, PHAT, PCI, zerofreq] = correctfit(pval, varargin)
if nargin < 2
help correctfit;
disp('You need to specify one optional input');
return;
end
g = finputcheck( varargin, { 'allpval' 'real' [0 1] [];
'zeromode' 'string' {'on','off'} 'on';
'gamparams' 'real' [] []}, 'correctfit');
if ischar(g), error(g); end
if ~isempty(g.gamparams)
PHAT = g.gamparams(1);
PCI = g.gamparams(2);
zerofreq = g.gamparams(3);
elseif ~isempty(g.allpval)
nonzero = find(g.allpval(:) ~= 0);
zerofreq = (length(g.allpval(:))-length(nonzero))/ length(g.allpval(:));
tmpdat = -log10( g.allpval(nonzero) ) + 1E-10;
[PHAT, PCI] = gamfit( tmpdat );
PHAT = PHAT(1);
PCI = PCI(2);
end
if pval == 0
if strcmpi(g.zeromode, 'on')
pval = zerofreq;
end
else
tmppval = -log10( pval ) + 1E-10;
pval = 1-gamcdf( tmppval, PHAT, PCI);
end
if 1 % plotting
if exist('tmpdat') == 1
figure; hist(tmpdat, 100); hold on;
mult = ylim;
tmpdat = linspace(0.00001,10, 300);
normy = gampdf( tmpdat, PHAT, PCI);
plot( tmpdat, normy/max(normy)*mult(2)*3, 'r');
end
end