使用 R 的逻辑回归
我现在正在使用 R 运行逻辑回归,但我似乎无法获得许多有用的模型拟合统计数据。我正在寻找类似于 SAS 的指标:
http://www.ats .ucla.edu/stat/sas/output/sas_logit_output.htm
有谁知道我可以如何(或使用哪些包)来提取这些统计信息?
谢谢
I am running logistic regressions using R right now, but I cannot seem to get many useful model fit statistics. I am looking for metrics similar to SAS:
http://www.ats.ucla.edu/stat/sas/output/sas_logit_output.htm
Does anyone know how (or what packages) I can use to extract these stats?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个泊松回归示例:
现在定义一个函数来拟合具有相同响应、族等的仅截距模型,计算汇总统计量,并将它们组合成一个表(矩阵)。下面的
update
命令中的公式.~1
表示“使用相同的响应变量 [用波形符 LHS 上的点表示] 重新拟合模型,但仅使用截距项 [由波浪号右侧的1
表示]”现在应用该函数:
结果:
编辑:
anova(glm.D93,test="Chisq")
对包含 df、偏差(=-2 对数似然)、残差 df、残差偏差的偏差表进行顺序分析,以及似然比检验(卡方检验)p-值。drop1(glm.D93)
给出一个表格,其中包含每个单项删除的 AIC 值(df、偏差等);drop1(glm.D93,test="Chisq")
还给出了 LRT 测试 p 值。Here's a Poisson regression example:
Now define a function to fit an intercept-only model with the same response, family, etc., compute summary statistics, and combine them into a table (matrix). The formula
.~1
in theupdate
command below means "refit the model with the same response variable [denoted by the dot on the LHS of the tilde] but with only an intercept term [denoted by the1
on the RHS of the tilde]"Now apply the function:
The results:
EDIT:
anova(glm.D93,test="Chisq")
gives a sequential analysis of deviance table containing df, deviance (=-2 log likelihood), residual df, residual deviance, and the likelihood ratio test (chi-squared test) p-value.drop1(glm.D93)
gives a table with the AIC values (df, deviances, etc.) for each single-term deletion;drop1(glm.D93,test="Chisq")
additionally gives the LRT test p value.当然,带有 family="binomial" 参数的
glm
是逻辑回归最常用的函数。因素对比的默认处理是不同的。 R 使用处理对比,SAS(我认为)使用总和对比。您可以在 R-help 上查找这些技术问题。在过去的十多年里,它们已经被讨论了很多很多次。我看到 Greg Snow 在“rms”中提到了
lrm
。它的优点是得到“rms”方法套件中其他几个函数的支持。我也会使用它,但是学习 rms 包可能需要一些额外的时间。我没有看到可以创建类似 SAS 输出的选项。如果您想比较类似问题的软件包,UCLA StatComputing 页面还有另一个资源: http://www.ats.ucla.edu/stat/r/dae/default.htm,其中在SPSS、SAS、Stata和R中举例说明了大量方法。
Certainly
glm
with a family="binomial" argument is the function most commonly used for logistic regression. The default handling of contrasts of factors is different. R uses treatment contrasts and SAS (I think) uses sum contrasts. You can look these technical issues up on R-help. They have been discussed many, many times over the last ten+ years.I see Greg Snow mentioned
lrm
in 'rms'. It has the advantage of being supported by several other functions in the 'rms' suite of methods. I would use it , too, but learning the rms package may take some additional time. I didn't see an option that would create SAS-like output.If you want to compare the packages on similar problems that UCLA StatComputing pages have another resource: http://www.ats.ucla.edu/stat/r/dae/default.htm , where a large number of methods are exemplified in SPSS, SAS, Stata and R.
使用
rms
包中的lrm
函数可能会给出您正在寻找的输出。Using the
lrm
function in therms
package may give you the output that you are looking for.