Get Values From `lm()` Output
lm.Rmd
lm()
Results
set.seed(894252)
n <- 10
x <- rnorm(n)
w <- rnorm(n)
y <- .6 * x + .8 * w + rnorm(n, 0, .8)
lm_out <- lm(y ~ x + w)
summary(lm_out)
#>
#> Call:
#> lm(formula = y ~ x + w)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -0.67227 -0.14777 -0.04515 0.34626 0.45729
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 0.005909 0.200798 0.029 0.977347
#> x 0.690546 0.113232 6.098 0.000492 ***
#> w 1.052031 0.241162 4.362 0.003305 **
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.4224 on 7 degrees of freedom
#> Multiple R-squared: 0.8529, Adjusted R-squared: 0.8109
#> F-statistic: 20.3 on 2 and 7 DF, p-value: 0.00122
The p-Values of Coefficient
text_coef_p(lm_out, "x")
#> [1] "p < 0.001"
text_coef_p(lm_out, "w")
#> [1] "p = 0.003"
text_coef_p(lm_out, "(Intercept)")
#> [1] "p = 0.977"
Confidence Intervals
text_confint(lm_out, "x")
#> [1] "[0.423, 0.958]"
text_confint(lm_out, "w")
#> [1] "[0.482, 1.622]"
text_confint(lm_out, "w", digits = 4)
#> [1] "[0.4818, 1.6223]"
text_confint(lm_out, "w", sep = " - ")
#> [1] "[0.482 - 1.622]"
text_confint(lm_out, "w", brackets = c("(", ")"))
#> [1] "(0.482, 1.622)"
Relevant Options
out2text_coef_digits
out2text_coef_format
out2text_confint_sep
out2text_confint_brackets
out2text_coef_p_digits
out2text_coef_p_format
opt_old <- options(out2text_coef_digits = 5)
text_coef(lm_out, "x")
#> [1] "0.69055"
text_confint(lm_out, "w")
#> [1] "[0.48177, 1.62229]"
text_rsq(lm_out)
#> [1] "0.85294"
options(opt_old)
opt_old <- options(out2text_coef_p_digits = 5)
text_coef_p(lm_out, "x")
#> [1] "p = 0.00049"
text_coef_p(lm_out, "w")
#> [1] "p = 0.00330"
options(opt_old)