在Windows 7 64位中执行GLM的Python脚本

1 投票
3 回答
1373 浏览
提问于 2025-04-16 06:06

我正在尝试在一个Python脚本中反复执行GLM(广义线性模型),也就是在一个循环里进行这个操作。

1- 我试着使用Scipy库里的Stats中的glm函数,但它的说明几乎没有,我觉得我没有用对——结果出现了错误信息:

"ValueError: only ttest_ind implemented".
。我在stats.py文件和_support.py文件里找了很久,但没有找到解决办法。

2- 我尝试安装RPY2(希望lgautier或者其他人能看到我的问题),想用R语言的功能。但我在Windows 7 64位系统上,似乎没有成功安装好。出现了错误信息:

    import rpy2.tests
  File "C:\Python26\lib\site-packages\rpy2\tests.py", line 3, in 
    import rpy2.robjects.tests
  File "C:\Python26\lib\site-packages\rpy2\robjects\__init__.py", line 12, in 
    import rpy2.rinterface as rinterface
  File "C:\Python26\lib\site-packages\rpy2\rinterface\__init__.py", line 22, in 
    "This might be because R.exe is nowhere in your Path.")
RuntimeError: Unable to determine R version from the registery.Calling the command 'R RHOME' does not return anything.
This might be because R.exe is nowhere in your Path.

有没有其他方法可以在Python中执行稳健的GLM?我试过一些不错的方法,但还是没搞定……?还有,如何在Windows 7 64位上安装RPY(我是个新手,刚开始学习)并把它和Python连接起来?

3 个回答

-2

我来回答一下:

statsmodels这个库还没有经过充分的开发和测试,所以目前不要使用STATSMODELS来进行广义线性模型(GLM)的分析。虽然rpy2是一个合适的选择,但安装起来有点复杂(你需要把从rpy2压缩包中解压出来的文件复制到/Pythonxx/Lib/site-packages/文件夹里,还需要获取'nose'并放到同样的位置)。

1

在我最后一个评论不久后,我发现了这个:

http://statsmodels.sourceforge.net/

这里有它的GLM文档:

http://statsmodels.sourceforge.net/glm.html

我强烈建议你也对比一下R的fit,确保它的结果和你想的一样。

5

我不明白为什么这里的回答似乎说statsmodels对广义线性模型(GLM)的测试覆盖率不太好。我写了这些测试。模型是经过Stata、R和SAS验证的,测试内容相当全面。如果你发现了什么意外的情况,或者觉得情况并非如此,请向开发者反馈。

https://github.com/statsmodels/statsmodels/blob/master/scikits/statsmodels/genmod/tests/test_glm.py

撰写回答