在R中使用summary
函数时,是否有可以传递的选项只显示变量的子集?
在我的例子中,我运行了一个面板回归,我有几个解释变量,并且有许多虚拟变量,其系数我不想呈现。我想有一种简单的方法可以做到这一点,但无法在函数文档中找到它。感谢
答案 0 :(得分:2)
假设您运行的回归与基本summary()
模型的lm()
行为相似:
# set up data
x <- 1:100 * runif(100, .01, .02)
y <- 1:100 * runif(100, .01, .03)
# run a very basic linear model
mylm <- lm(x ~ y)
summary(mylm)
# we can save summary of our linear model as a variable
mylm_summary <- summary(mylm)
# we can then isolate coefficients from this summary (summary is just a list)
mylm_summary$coefficients
#output:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.2007199 0.04352267 4.611846 1.206905e-05
y 0.5715838 0.03742379 15.273273 1.149594e-27
# note that the class of this "coefficients" object is a matrix
class(mylm_summ$coefficients)
# output
[1] "matrix"
# we can convert that matrix into a data frame so it is easier to work with and subset
mylm_df_coefficients <- data.frame(mylm_summary$coefficients)
答案 1 :(得分:2)
它位于文档中,但您必须查找print
的关联summary.plm
方法。参数是subset
。使用它,如下例所示:
library(plm)
data("Grunfeld", package = "plm")
mod <- plm(inv ~ value + capital, data = Grunfeld)
print(summary(mod), subset = c("capital"))