To
find the least-squares regression model, use the lm() command. From that
result, we can find the standard error.
We
will use the cholesterol data from Section 14.1, Table 1.
Age <- c(25, 25, 28, 32, 32, 32, 38, 42, 48, 51, 51, 58, 62, 65)
Cholesterol <- c(180, 195, 186, 180, 210, 197, 239, 183, 204, 221, 243, 208, 228, 269)
Table1 <- data.frame('Age'=Age, "Cholesterol"=Cholesterol)
head(Table1)
## Age Cholesterol
## 1 25 180
## 2 25 195
## 3 28 186
## 4 32 180
## 5 32 210
## 6 32 197
Find
the least-squares regression model and save it as an object. Use the summary() command on the object to obtain the regression
output.
lm_object <- lm(Cholesterol ~ Age, data=Table1)
summary(lm_object)
##
## Call:
## lm(formula = Cholesterol ~ Age, data = Table1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.114 -13.405 -3.117 12.575 34.482
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 151.3537 17.2838 8.757 1.47e-06 ***
## Age 1.3991 0.3917 3.571 0.00384 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 19.48 on 12 degrees of freedom
## Multiple R-squared: 0.5153, Adjusted R-squared: 0.4749
## F-statistic: 12.76 on 1 and 12 DF, p-value: 0.003842
The
test statistic for the explanatory variable, Age, is 3.571 and the P-value is
0.00384 (under Coefficients: in the output).
Mosaic
allows the user to only show the output desired. Consider the msummary()
command on the lm_object.
library(mosaic)
lm_object <- lm(Cholesterol ~ Age, data=Table1)
msummary(lm_object)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 151.3537 17.2838 8.757 1.47e-06 ***
## Age 1.3991 0.3917 3.571 0.00384 **
##
## Residual standard error: 19.48 on 12 degrees of freedom
## Multiple R-squared: 0.5153, Adjusted R-squared: 0.4749
## F-statistic: 12.76 on 1 and 12 DF, p-value: 0.003842
The
test statistic for the explanatory variable, Age, is 3.571 and the P-value is
0.00384.
The
coef(summary()) command on
the lm_object provides just the inference on the
slope and intercept of the linear model.
library(mosaic)
lm_object <- lm(Cholesterol ~ Age, data=Table1)
coef(summary(lm_object))
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 151.353658 17.2837604 8.756987 1.472754e-06
## Age 1.399064 0.3917375 3.571433 3.842261e-03