LMR 7.3

library(MASS)
library(faraway)
data(ozone)
head(ozone,n=10)
##    O3   vh wind humidity temp  ibh dpg ibt vis doy
## 1   3 5710    4       28   40 2693 -25  87 250  33
## 2   5 5700    3       37   45  590 -24 128 100  34
## 3   5 5760    3       51   54 1450  25 139  60  35
## 4   6 5720    4       69   35 1568  15 121  60  36
## 5   4 5790    6       19   45 2631 -33 123 100  37
## 6   4 5790    3       25   55  554 -28 182 250  38
## 7   6 5700    3       73   41 2083  23 114 120  39
## 8   7 5700    3       59   44 2654  -2  91 120  40
## 9   4 5770    8       27   54 5000 -19  92 120  41
## 10  6 5720    3       44   51  111   9 173 150  42
g<-lm(O3~temp+humidity+ibh,ozone)
summary(g)
## 
## Call:
## lm(formula = O3 ~ temp + humidity + ibh, data = ozone)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.5291  -3.0137  -0.2249   2.8239  13.9303 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.049e+01  1.616e+00  -6.492 3.16e-10 ***
## temp         3.296e-01  2.109e-02  15.626  < 2e-16 ***
## humidity     7.738e-02  1.339e-02   5.777 1.77e-08 ***
## ibh         -1.004e-03  1.639e-04  -6.130 2.54e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.524 on 326 degrees of freedom
## Multiple R-squared:  0.684,  Adjusted R-squared:  0.6811 
## F-statistic: 235.2 on 3 and 326 DF,  p-value: < 2.2e-16
plot(g)

bc<-boxcox(g,plotit = T,lambda=seq(0.15,0.35,by=0.05))

(best.lam<-bc$x[which(bc$y==max(bc$y))])
## [1] 0.2772727
gbc<-lm(O3^best.lam~temp+humidity+ibh,ozone)
summary(gbc)
## 
## Call:
## lm(formula = O3^best.lam ~ temp + humidity + ibh, data = ozone)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.63030 -0.12606  0.01037  0.14553  0.57837 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.738e-01  7.283e-02  11.999  < 2e-16 ***
## temp         1.544e-02  9.504e-04  16.246  < 2e-16 ***
## humidity     3.533e-03  6.034e-04   5.854 1.17e-08 ***
## ibh         -5.691e-05  7.382e-06  -7.709 1.55e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2038 on 326 degrees of freedom
## Multiple R-squared:  0.7162, Adjusted R-squared:  0.7136 
## F-statistic: 274.2 on 3 and 326 DF,  p-value: < 2.2e-16
plot(gbc)