在MATLAB中查找卡方分布的分位数值(Finding quantile values for chi squared distribution In MATLAB)
我正在尝试对我给出的不同数据执行所谓的Ljung Box测试。 我想检查一下我的数据是否在卡方分布的0.95分位数内。 我可以在表格中找到这个值(例如http://www.unc.edu/~farkouh/usefull/chi.html )。 数据具有不同的样本大小,导致卡方分布的不同自由度,并且手动查找所有值将花费大量时间。
我想知道在matlab中是否有任何方法我可以自动找到这些值然后在我的for循环中使用这些不同的值?
I am trying to perform a so called Ljung Box test on different data I have been given. I want to check whether my data is within a 0.95 quantile of the chi squared distribution. This value I can find in tables (such as http://www.unc.edu/~farkouh/usefull/chi.html). The data have varying sample size resulting in different degrees of freedom for the chi-squared distribution and looking up all values manually would take a lot of time.
I am wondering whether there is any way in matlab I can find these values automatically and then to use these different values in my for-loop?
原文:https://stackoverflow.com/questions/23324277
更新时间:2019-12-02 07:43
相关问答
您可以chi2gof这种方式为函数指定一个函数的句柄 : chi2gof : a = ...
b = ...
c = ...
F = @(x)a*exp(-b*x-c*x.^2); % Technically this is an anonymous function
[H,P,STATS] = chi2gof(data,'cdf',F)
或者在特殊情况下: a = ...
b = ...
c = ...
F = @(x,a,b,c)a*exp(-b*x-c*x.^2);
[H,P,STATS]
...
我认为scipy.stats.probplot会做你想要的。 有关详细信息,请参阅文档 。 import numpy as np
import pylab
import scipy.stats as stats
measurements = np.random.normal(loc = 20, scale = 5, size=100)
stats.probplot(measurements, dist="norm", plot=pylab)
pylab.show()
结果 I thi
...
您可以传递一个匿名函数@(x,y) 1 - sum((x - y).^2 ./ (x + y) / 2) ./(x @(x,y) 1 - sum((x - y).^2 ./ (x + y) / 2)作为kernel_function参数。 You can pass an anonymous function @(x,y) 1 - sum((x - y).^2 ./ (x + y) / 2) as the kernel_function argument.
你可以用ncx2inv (统计工具箱)来做到这ncx2inv : p = 0.02; %// probability (i.e. quantile)
df = 2; %// degrees of freedom
n = 0; %// non-centrality parameter. Set to 0 to generate the provided table
result = ncx2inv(1-p, df, n);
在此示例中,根据提供的表格,结果为7.824 。 You can do i
...
在36个值处,您的样本集非常小。 从维基百科关于卡方检验的文章的第二句(重点补充): 它适用于大样本的非配对数据。 在这种情况下,通常意味着大约至少100左右。 在此处阅读有关此测试的更多假设 。 备择方案 您可以在Matlab中尝试kstest ,它基于Kolmogorov-Smirnov测试 : [h,p] = kstest(V,'cdf',[V(:) expcdf(V(:),expfit(V))])
或者尝试lillietest ,它基于Lilliefors测试,并且具有专门用于指数分布式
...
问题出现在问题的第二句中: “ S / sig^2具有非中心卡方分布,其自由度= n且非中心性参数= n*mu^2 ” 该非中心性参数不正确。 它应该是n*(mu/sig)^2 。 非中心卡方分布的标准定义是它是具有平均μ和标准差1的正常变量的平方和。 您使用标准偏差sig常规变量计算S 让我们将该分布写为N(mu, sig**2) 。 通过使用正态分布的位置比例属性,我们有 N(mu, sig**2) = mu + sig*N(0, 1) = sig*(mu/sig + N(0,1)) = si
...
有几件事。 2.2e-16 不是 R中值的精度下限; 它只是R默认使用format.pval打印非常小的p值的format.pval : format.pval(1e-20)
## [1] "< 2.22e-16"
小于约1e-320的值向下舍入为零: 1e-330
## [1] 0
@ SeverinPappadeux的建议是完全正确的: pchisq(121231,1,lower.tail=FALSE,log.p=TRUE)
## [1] -60621.58
这相当于10 ^( - 26
...
正如评论中所提到的,当使用负数作为索引参数时,您的移位代码是错误的,这是因为Java在使用%运算符时处理负值。 为了安全起见,您应该执行以下操作: // shift a letter to another letter shftAmt spaces away
static char shift(int shftAmt, char c) {
if (let2nat(c) < 0 || let2nat(c) > Z_TO_A - 1) {
return c;
} else {
...
你有统计工具箱吗? 如是, >> binoinv(.025,60,.4)
ans =
17
>> norminv(.975,0,1)
ans =
1.9600
如果没有,您可以使用以下等价: 反正常CDF可以用erfinv函数表示 二项式CDF可以用betainc函数表示 Do you have the Statistics toolbox? If yes, >> binoinv(.025,60,.4)
ans =
17
>> norminv(.975,0
...
您应该调试程序并发现循环中存在溢出,k = 149。 对于k = 148,Bruch的值是3.3976725289e + 304。 布鲁赫的下一次计算溢出。 修复就是编码 for i := 1 to k do
Bruch := Bruch / (f + 2 * i);
Summand := power(chi, 2 * k) * Bruch;
通过此更改,在第156次迭代后得到值IntegralChi(138.609137,4) = 1.76835197E-7 。 请注意,您的计算(即使对于
...