Consider a linear model in R:
frame <- data.frame(y=rnorm(100), a=rnorm(100), b=rnorm(100))
frame["c"] <- frame["y"] + 2*rnorm(100)
model <- lm(y ~ a + b + c, data=frame) #lm
Calling summary(model)
produces the following output in the console:
Call:
lm(formula = y ~ a + b + c, data = frame)
Residuals:
Min 1Q Median 3Q Max
-2.13983 -0.54933 0.01975 0.44218 2.38721
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.060624 0.088597 -0.684 0.4955
a 0.009773 0.088171 0.111 0.9120
b 0.157979 0.080924 1.952 0.0538 .
c 0.188913 0.039788 4.748 7.17e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.8464 on 96 degrees of freedom
Multiple R-squared: 0.2146, Adjusted R-squared: 0.1901
F-statistic: 8.745 on 3 and 96 DF, p-value: 3.478e-05
I would like to only print the coefficients part, the exact complement of this thread, like so:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.060624 0.088597 -0.684 0.4955
a 0.009773 0.088171 0.111 0.9120
b 0.157979 0.080924 1.952 0.0538 .
c 0.188913 0.039788 4.748 7.17e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
This is not possible by calling coef(summary(model))
as suggested here, since that produces
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.060624 0.088597 -0.684 0.4955
a 0.009773 0.088171 0.111 0.9120
b 0.157979 0.080924 1.952 0.0538
c 0.188913 0.039788 4.748 7.17e-06
which lacks the significance marks on the right. Preferably, the solution doesn't involve re-programming the entire summary()
body as suggested in the thread above.
You're looking for printCoefmat
.
printCoefmat(coef(summary(model)))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.019348 0.089500 0.2162 0.8293
a 0.023219 0.101134 0.2296 0.8189
b 0.085962 0.085934 1.0003 0.3197
c 0.190828 0.042007 4.5427 1.615e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1