Chapter 30 Linear Regression

30.1 Linear Regression in R

##          [,1]     [,2]
## [1,] 170.6260 174.7535
## [2,] 174.7535 204.7070

## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -5.491 -2.882 -1.077  1.151 10.494 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -2.4346    24.8950  -0.098    0.925    
## x             1.0242     0.1373   7.460 7.19e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.38 on 8 degrees of freedom
## Multiple R-squared:  0.8743, Adjusted R-squared:  0.8586 
## F-statistic: 55.66 on 1 and 8 DF,  p-value: 7.193e-05
##          [,1]     [,2]
## [1,] 86.22372 70.84882
## [2,] 70.84882 75.73134
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##     33.3041       0.8217
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.3667 -2.8269  0.6699  2.4445  6.8047 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  33.3041    28.9606   1.150 0.283366    
## x             0.8217     0.1594   5.156 0.000867 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.439 on 8 degrees of freedom
## Multiple R-squared:  0.7687, Adjusted R-squared:  0.7398 
## F-statistic: 26.59 on 1 and 8 DF,  p-value: 0.0008675
## [1] "lm"
##                   2.5 %     97.5 %
## (Intercept) -33.4791096 100.087327
## x             0.4542198   1.189152
##        1 
## 181.2076
##        1        2        3        4 
## 176.2775 181.2076 185.3160 189.4245
##        1        2        3        4        5        6        7        8 
## 181.7120 181.7247 174.3574 189.4537 182.3192 189.7933 195.4341 178.4548 
##        9       10 
## 181.9388 169.4279
##        1        2        3        4        5        6        7        8 
## 181.7120 181.7247 174.3574 189.4537 182.3192 189.7933 195.4341 178.4548 
##        9       10 
## 181.9388 169.4279

30.2 Diagnostics

Often we want to run some diagnostics on the model to assess whether our assumptions are justified e.g. whether the residuals are normally distributed or whether there are specific points that have undue influence on the model. In R there are inbuilt functions to do this. Simply use plot(lm(y~x)). This will give you four different plots with diagnostics