本文介绍了R:隐藏假人输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用 R 运行回归的新手.通过做和查看不同的在线教程来学习,这是我正在做的 atm 将 y 回归到 x1 并为 x2x3(但没有交互的假人):

I'm new to running regressions with R. Learning by doing and looking at different online tutorials, here's what I'm doing atm to regress y onto x1 and have dummies for x2 and x3 (but no interacted dummies):

myDataTable[, x2.f := factor(x2)]
myDataTable[, x3.f := factor(x3)]
ols <- myDataTable[, lm(y ~ x1 + x2.f +x3.f)]

现在,我想看看我的回归输出,但它很长,因为 x3summary(ols) 有很多(想想数千个)值不可读.

Now, I would like to look at my regression output, but it's very long, since there's many (think thousands) of values for x3, summary(ols) is unreadable.

如何查看回归输出,隐藏两个因子变量的输出?这应该是相当标准的,但如果我理解正确的话,summary.lm 中的任何参数都不允许这样做.

How can I look at the regression output, hiding the output for the two factor variables? This should be quite standard, but none of the arguments in summary.lm allowed for this, if I understand it correctly.

也就是说,排除阶乘变量,输出将仅适用于 x1:

That is, excluding factorial variables, the output would be only for x1:

> summary(ols, exclude=list(x2.f, x3.f)

Call:
lm(y ~ x1 + x2.f +x3.f)

Residuals:
   Min     1Q Median     3Q    Max
-55.99 -38.66 -10.05  33.91 132.18

Coefficients:
              Estimate Std. Error t value Pr(>|t|)
(Intercept) 49.5283522  0.6035625  82.060  < 2e-16 ***
x1          -0.0002951  0.0000633  -4.663  3.2e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

推荐答案

您可以存储 summary 的输出,然后获取您想要的部分.如果您只需要系数表的一部分 - 这是一个示例:

You can store the output of a summary and then just get the parts you want. If you just want part of the coefficient table - here is an example:

#make example data with 26 factors
X<-rnorm(26000)
Y<-rnorm(26000)
Z<-rep(letters,1000)

#do analysis, store summary and pull rows 1:5 of coefficient table
MyLM<-lm(X~Y+Z)
MySum<-summary(MyLM)
MySum$coef[1:5,]
#### or this produces the same output ###
coef(MySum)[1:5,]

这会给你前五行,你可以使用其他索引方法来得到你想要的任何东西,作为 MySum$coefcoef(MySum) 的输出是一个矩阵.

This will give you the first five rows, you can use other indexing methods to get whatever you want, as the output of MySum$coef and coef(MySum) is a matrix.

例如,我存储了 lmsummary 的结果,但如果您愿意,您可以将所有这些组合在一行中,例如summary(lm(x...))$coef[1:5,]

For the example I stored the results of lm and of summary but you could combine this all in one line if you wanted, e.g. summary(lm(x...))$coef[1:5,]

这篇关于R:隐藏假人输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:05