2017-05-15 19 views

回答

1

顯然,非中心卡方分佈是simply defined as 1 minus the Marcum Q function。在octave-forge的signal package爲此功能提供an implementation(看似與matlab兼容)。

因此,您大概可以簡單地寫自己的ncx2cdf功能如下:

function Out = myncx2cdf (X, V, Delta) 
    Out = 1 - marcumq (sqrt (Delta), sqrt (X), V/2); 
end 

證實MATLAB:

爲相同的X
>> X = randi(100, [1,20]); V = 4; Delta = 10; 
>> ncx2cdf(X, V, Delta)       
ans = 
    1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997 
>> 1 - marcumq(sqrt(Delta), sqrt(X), V/2) 
ans = 
    1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997 

八音會,V,和Delta:

octave:34> pkg load signal 
octave:35> 1 - marcumq(sqrt(Delta), sqrt(X), V/2) 
ans = 
    1.00000 0.94105 0.99988 1.00000 1.00000 1.00000 0.99996 0.55492 0.60929 0.94105 1.00000 0.94105 1.00000 0.92793 1.00000 0.99203 0.81831 0.94105 1.00000 0.99972 

請注意,自由度參數V被限制爲偶數這個實現的價值;如果你想使用奇怪的自由度,例如5,這可以從V = 4和V = 6的結果插值(這在實踐中似乎很好)。

0

運行pkg load statistics後,我找了ncx2cdf,但它給了我以下警告:

the 'ncx2cdf' function belongs to the statistics package from Octave Forge but has not yet been implemented Please read http://www.octave.org/missing.html to learn how you can contribute missing functionality.

嗯......