首先,我对Mathematica不太了解,而且我已经很长时间没有做过统计了。在
我一直在尝试(Google和RTFM)使用scipy.stats.linregress
来重现MathematicaLinearModelFit
函数产生的结果。现在很明显,除了最简单的情况外,这是不可能的。在
LinearModelFit[ydata, 1/(2 n - x)^100, x]
产生16.3766 + <<70>>/(2580 - x)^100
如果有人能为我指出正确的方向,我将不胜感激。在
提前谢谢。在
数据:http://pastebin.com/RTp5em0W
Mathematica笔记本的屏幕截图:http://imgur.com/owMg3r8
注:我没有做数学工作。ddd是可以在pastebin链接上找到的数据。分母中的y应该是x
一个不需要复杂功能的简单算法可以用任何语言编写。在
导入
y
数据。在线性回归系数}通过求解正态方程得到。(推导见下文注释)。一旦计算出来,它们就可以被重用,而不需要求解器。在
^{pr2}$a
和{根据模型,
X
被线性化为x
。在计算工程量:
执行系数公式:
在线性化数据上绘制回归线(带缩放)。在
重新应用该模型,最小二乘拟合为:
a + b/(2 n - X)^100
这与Mathematica的内置解决方案匹配,如下所示。在
同时计算R的平方。在
检查Mathematica的内置功能。在
关于正规方程的注记
来源:Econometric Methods
我不知道python的解决方案,但解决这个问题的一种方法是根据作为
LinearModelFit
参数提供的函数形式转换x数据:相当于:
^{pr2}$您应该能够很容易地进行这种转换,并在python中使用标准线性回归。但是,由于指数较大,您可能会遇到精度问题。在
相关问题 更多 >
编程相关推荐