R Markdown

data(women)
attach(women)

Create a confidence interval:

mod <- lm(weight ~ height)
confint(mod, level = .9)
##                    5 %       95 %
## (Intercept) -98.030599 -77.002734
## height        3.288603   3.611397

Find the correlation between weight and weight:

cor(weight, height)
## [1] 0.9954948

This gives us a value that is very close to 1, so there is a strong relationship between weight and height.

Find the prediction and confidence intervals for the weight when the height is 60 inches:

newdata <- data.frame(height = 60)
(predy <- predict(mod, newdata, interval="predict") )
##        fit      lwr      upr
## 1 119.4833 115.9412 123.0255
(confy <- predict(mod, newdata, interval="confidence") )
##        fit      lwr      upr
## 1 119.4833 118.1823 120.7844

Find which interval is wider and where they are centered:

confy %*% c(0, -1, 1)  
##       [,1]
## 1 2.602107
predy %*% c(0, -1, 1)
##       [,1]
## 1 7.084336
confy[1] == predy[1]
## [1] TRUE

The prediction interval should be (and is) wider.

Print out a summary of information like the F-stat, r^2, p-value, etc.

summary(mod)
## 
## Call:
## lm(formula = weight ~ height)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7333 -1.1333 -0.3833  0.7417  3.1167 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -87.51667    5.93694  -14.74 1.71e-09 ***
## height        3.45000    0.09114   37.85 1.09e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.525 on 13 degrees of freedom
## Multiple R-squared:  0.991,  Adjusted R-squared:  0.9903 
## F-statistic:  1433 on 1 and 13 DF,  p-value: 1.091e-14

\[\hat{y_i}= \hat{\beta_0}+\hat{\beta_1} x_i\]