1

When using the summary function in R, is there an option I can pass in there to present only a subset of the variables?

In my example, I ran a panel regression with plm() (from package plm) I have several explanatory variables, and have many dummy variables whose coefficients I do not want to present. I suppose there is a simple way to do this, but couldn't find it in the function documentation.

Helix123
  • 3,502
  • 2
  • 16
  • 36
splinter
  • 3,727
  • 8
  • 37
  • 82

2 Answers2

3

It is in the documentation, but you have to look for the associacted print method for summary.plm. The argument is subset. Use it as in the following example:

library(plm)
data("Grunfeld", package = "plm")
mod <- plm(inv ~ value + capital, data = Grunfeld)
print(summary(mod), subset = c("capital"))
Helix123
  • 3,502
  • 2
  • 16
  • 36
2

Assuming the regression you ran behaves similarly as the summary() of a basic lm() model:

# 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)
TaylorV
  • 846
  • 9
  • 13