I need to calculate β^0 and β^1 for a simple linear regression yi = β0 + β1xi with 87% confidence intervals for β0 and β1 and have to display my results with three significant digits in the following format:
Est L U
beta0 1.13 0.889 1.37
beta1 3.57 1.950 5.19
What code should I use to get it in this format?
I have done the following, but cannot figure out how to show Intercept and x as beta0 and beta1 with their Estimate and Lower CI and Upper CI:
> M <- lm(y ~ x) # fit linear model
> signif(coef(M), digits = 2) # MLE's of beta
(Intercept) x
-5.40 0.13
>
> signif(confint(M, level = 0.87), digits = 3)
6.5 % 93.5 %
(Intercept) -5.710 -5.160
x 0.127 0.136
I'm doing this in RStudio
EDIT: I've used data.frame to get it like this:
> # data.frame for MLE's of beta with 87% confidence interval for beta0 and beta1
> data.frame(df, stringsAsFactors = )
Est L U
beta0 -5.40 -5.710 -5.160
beta1 0.13 0.127 0.136
> Est <- c(-5.40, 0.13)
> L <- c(-5.710, 0.127)
> U <- c(-5.160, 0.136)
> df <- data.frame(Est,L,U)
> row.names(df) <- c('beta0', 'beta1')
But is there a better way of getting it in this form using the built-in R functions lm, coef, confint?