使用Schillings方程计算拟合优度的P值

时间:2015-04-09 11:25:46

标签: matlab statistics curve-fitting data-fitting

“自然方法”最近发表的一篇非常好的论文提供了一种新方法,用于在未充分估算实验误差时计算拟合优度:http://www.nature.com/nmeth/journal/vaop/ncurrent/full/nmeth.3358.html

我正在尝试将其纳入我在MATLAB中的拟合程序中,但我的低级智力正在努力编写正确的方程式。方程式如下图所示 Equations for Gof 我想测试的是观察连续斑块(Rn)的概率,因为观察到最大的斑块是C.

我在MATLAB中对这个等式进行了一些微弱的尝试,但结果并不令人印象深刻。我正在努力在上述等式中确定An,因为当n> C且n <= C右时,我无法在等式之间进行切换。我的代码如下所示 更新:我更新了代码,因此它不再评估为负概率。但它仍然无法正常工作 如果通过创建一个评估n的和的简单函数来启动

function [ an ] = smalSchill( N, C)
% Small function used to evaluate correlation map statistics

an = 0;
for j = 0:C
    an = an + 2^(N-1-j);
end

end

然后在我的脚本中调用

C = 10; % observered continoues patch of either positive or negative correlation
N = 100; % length(Q); % Number of observations
g = 1; % dummy variable used to index the P-values
Pv = ones(N,1); % Vector holding the p-values. P = 1 for all n <= C

for n = C+1:N
    An2 = 0;
    for j = 0:C

        if n-1-j <= C
            An2 = An2 + smalSchill(n-1-j,C);
            break
        else
            iter_count = n-1-j-C;
            An2 = An2 + iter_count*smalSchill(C,C); %iter_count            
        end
    end
    Pv2(n) = 1-An2/2^n;
end

P值按预期开始衰减,但随着n增长,P值收敛到1,这是不正确的 - 它们应收敛到0。

喝彩!

1 个答案:

答案 0 :(得分:1)

我过分复杂了一切 - 并且误解了两个变量的含义。难怪我的代码确实有效。但是我今天开始工作了

N = 1000 % Length of path investigated
patchL = 1:1:20; % length of continious patch which you are interested in testing.
An = zeros(N+1,length(patchL)); % preallocate memory

for zz = 1:length(patchL)
    x = patchL(zz); 

    for n = 0:N

        if n <= x;
            An(n+1,zz) = 2^n;
        else
            An(n+1,zz) = sum(An(n-x:n,zz));
        end
    end
end

AnDist = An(end,:); % supposing last entry (20) is what you are interested in
Dist = AnDist - [0, AnDist(1:end-1)]; % go from cummulative dist to mdf
Dist = Dist./sum(Dist); % normalizing  the mdf