我无法在 matlab 中绘制反伽马 (0.001, 0.001) 的核密度估计

I can't plot the kernel density estimation of an Inverse gamma(0.001, 0.001) in matlab

我正在尝试绘制逆 gamma(0.001, 0.001) 的 ksdensity,但该图只有一个点。我使用的命令是

 alpha1 = 0.001;
    beta1 = 0.001;
    n = 1e+5;
    r=1./gamrnd(alpha1,1/beta1,n,1);  
   [f,xi] = ksdensity(r);
    plot(xi,f,'--m');

f第一项为实数,其余均为NaNxi的第一项是实数,其他都是Inf.

你能帮我解决这个问题吗?

非常感谢。

您是否查看了 r 中生成的数据?我几乎有 49% 的时间得到值 Inf。您选择的参数的 Gamma 分布的许多值似乎为 0,或者实际上,它们太小以至于无法用 Matlab 的标准双精度数字格式表示(最小可能值为 2.225 · 10^-308)。

如果您查看 Wikipedia page for the inverse Gamma distribution, you will see that the mean is not defined for alpha <= 1 and the variance is not defined for alpha <= 2, etc. According to Wolfram Alpha,您的分布众数为 0.000999001,而中位数为 1.90687 · 10^298(仅比最大可能双精度值 1.797 低几个数量级· 10^308!).

模式周围的密度

x = 0.0001:0.0001:0.1;
plot(x, beta1 ^ alpha1 / gamma(alpha1) .* x .^ -(alpha1 + 1) .* exp(- beta1 ./ x))

看起来像这样

但这只占总分布的一小部分(第一个百分位数是 41.2211)。

所以这里的问题不是核密度估计,而是你正在查看的分布具有极端特性,这使得很难从分析公式中绘制密度,更不用说从模拟随机数中估计它了。