尝试使用 scipy 拟合学生的 t 分布时出现异常

Anomalies when trying to fit student's t distribution using scipy

我正在尝试将 t 分布拟合到我拥有的一些数据。为了测试它,我首先尝试从固定分布生成一个样本并尝试适应它。下面是我正在使用的代码。

samp = t.rvs(loc=0, scale=0.6, df=1.3, size=150)

param = t.fit(samp)

x = linspace(-5,5,100)

pdf_fitted = t.pdf(x,loc=param[0],scale=param[1],df=param[2])
pdf = t.pdf(x,loc=0,scale=0.6,df=1.3)

title('Student\'s t Distribution')
plot(x,pdf_fitted,'r-',x,pdf,'b-')
hist(samp, normed=1,alpha=0.3)
show()
print(param)

现在,人们会认为 pdfpdf_fitted 本质上是一样的。然而,事实并非如此。当显示图时,原始分布和拟合分布看起来非常不同。而且,获得的参数与指定的参数(loc=0,scale=0.6,df=1.3)根本不匹配!这让我感到困惑,因为我只是调整 http://glowingpython.blogspot.com/2012/07/distribution-fitting-with-scipy.html 中的代码以使用 t 分布。有人能告诉我拟合 t 分布是否有任何细微差别吗?谢谢

scipy.stats.treturns(df, loc, scale)fit方法,所以这一行

pdf_fitted = t.pdf(x,loc=param[0],scale=param[1],df=param[2])

应该是

pdf_fitted = t.pdf(x, loc=param[1], scale=param[2], df=param[0])

您链接到的示例使用正态分布,它没有额外的形状参数,因此在这种情况下,param[0] 是位置,param[1] 是比例。