Advertising data – summaries

adv <- read.csv("http://www.stats.ox.ac.uk/~laws/LMs/data/advert.csv")
adv.lm <- lm(sales ~ TV + radio + newspaper, data = adv)
options(digits = 3)
summary(adv.lm)
## 
## Call:
## lm(formula = sales ~ TV + radio + newspaper, data = adv)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.828 -0.891  0.242  1.189  2.829 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.93889    0.31191    9.42   <2e-16 ***
## TV           0.04576    0.00139   32.81   <2e-16 ***
## radio        0.18853    0.00861   21.89   <2e-16 ***
## newspaper   -0.00104    0.00587   -0.18     0.86    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.69 on 196 degrees of freedom
## Multiple R-squared:  0.897,  Adjusted R-squared:  0.896 
## F-statistic:  570 on 3 and 196 DF,  p-value: <2e-16
names(adv.lm)
##  [1] "coefficients"  "residuals"     "effects"       "rank"         
##  [5] "fitted.values" "assign"        "qr"            "df.residual"  
##  [9] "xlevels"       "call"          "terms"         "model"

There are convenient ways to extract the coefficients, fitted values, residuals, RSS, residual degrees of freedom (\(n-p\)) of a model.

coef(adv.lm)
## (Intercept)          TV       radio   newspaper 
##     2.93889     0.04576     0.18853    -0.00104
head(fitted(adv.lm)) # use head() here to avoid too much output
##    1    2    3    4    5    6 
## 20.5 12.3 12.3 17.6 13.2 12.5
head(resid(adv.lm))
##      1      2      3      4      5      6 
##  1.576 -1.938 -3.008  0.902 -0.289 -5.278
deviance(adv.lm) # RSS
## [1] 557
df.residual(adv.lm) # n - p
## [1] 196

We have shown that \(RSS/(n-p)\) is an unbiased estimator of \(\sigma^2\). The residual standard error defined by \(\sqrt{RSS/(n-p)}\) is an estimate of \(\sigma\).

sqrt(deviance(adv.lm)/df.residual(adv.lm))
## [1] 1.69
adv.sum <- summary(adv.lm)
names(adv.sum)
##  [1] "call"          "terms"         "residuals"     "coefficients" 
##  [5] "aliased"       "sigma"         "df"            "r.squared"    
##  [9] "adj.r.squared" "fstatistic"    "cov.unscaled"
adv.sum$sigma
## [1] 1.69