library("faraway")
data("teengamb")
teengamb
## sex status income verbal gamble
## 1 1 51 2.00 8 0.00
## 2 1 28 2.50 8 0.00
## 3 1 37 2.00 6 0.00
## 4 1 28 7.00 4 7.30
## 5 1 65 2.00 8 19.60
## 6 1 61 3.47 6 0.10
## 7 1 28 5.50 7 1.45
## 8 1 27 6.42 5 6.60
## 9 1 43 2.00 6 1.70
## 10 1 18 6.00 7 0.10
## 11 1 18 3.00 6 0.10
## 12 1 43 4.75 6 5.40
## 13 1 30 2.20 4 1.20
## 14 1 28 2.00 6 3.60
## 15 1 38 3.00 6 2.40
## 16 1 38 1.50 8 3.40
## 17 1 28 9.50 8 0.10
## 18 1 18 10.00 5 8.40
## 19 1 43 4.00 8 12.00
## 20 0 51 3.50 9 0.00
## 21 0 62 3.00 8 1.00
## 22 0 47 2.50 9 1.20
## 23 0 43 3.50 5 0.10
## 24 0 27 10.00 4 156.00
## 25 0 71 6.50 7 38.50
## 26 0 38 1.50 7 2.10
## 27 0 51 5.44 4 14.50
## 28 0 38 1.00 6 3.00
## 29 0 51 0.60 7 0.60
## 30 0 62 5.50 8 9.60
## 31 0 18 12.00 2 88.00
## 32 0 30 7.00 7 53.20
## 33 0 38 15.00 7 90.00
## 34 0 71 2.00 10 3.00
## 35 0 28 1.50 1 14.10
## 36 0 61 4.50 8 70.00
## 37 0 71 2.50 7 38.50
## 38 0 28 8.00 6 57.20
## 39 0 51 10.00 6 6.00
## 40 0 65 1.60 6 25.00
## 41 0 48 2.00 9 6.90
## 42 0 61 15.00 9 69.70
## 43 0 75 3.00 8 13.30
## 44 0 66 3.25 9 0.60
## 45 0 62 4.94 6 38.00
## 46 0 71 1.50 7 14.40
## 47 0 71 2.50 9 19.20
str(teengamb)
## 'data.frame': 47 obs. of 5 variables:
## $ sex : int 1 1 1 1 1 1 1 1 1 1 ...
## $ status: int 51 28 37 28 65 61 28 27 43 18 ...
## $ income: num 2 2.5 2 7 2 3.47 5.5 6.42 2 6 ...
## $ verbal: int 8 8 6 4 8 6 7 5 6 7 ...
## $ gamble: num 0 0 0 7.3 19.6 0.1 1.45 6.6 1.7 0.1 ...
model <- lm(teengamb$gamble~ teengamb$sex + teengamb$status + teengamb$income + teengamb$verbal)
model
##
## Call:
## lm(formula = teengamb$gamble ~ teengamb$sex + teengamb$status +
## teengamb$income + teengamb$verbal)
##
## Coefficients:
## (Intercept) teengamb$sex teengamb$status teengamb$income
## 22.55565 -22.11833 0.05223 4.96198
## teengamb$verbal
## -2.95949
summary(model)
##
## Call:
## lm(formula = teengamb$gamble ~ teengamb$sex + teengamb$status +
## teengamb$income + teengamb$verbal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -51.082 -11.320 -1.451 9.452 94.252
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 22.55565 17.19680 1.312 0.1968
## teengamb$sex -22.11833 8.21111 -2.694 0.0101 *
## teengamb$status 0.05223 0.28111 0.186 0.8535
## teengamb$income 4.96198 1.02539 4.839 1.79e-05 ***
## teengamb$verbal -2.95949 2.17215 -1.362 0.1803
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.69 on 42 degrees of freedom
## Multiple R-squared: 0.5267, Adjusted R-squared: 0.4816
## F-statistic: 11.69 on 4 and 42 DF, p-value: 1.815e-06
max(model$residuals)
## [1] 94.25222
class(model$residuals)
## [1] "numeric"
model$residuals
## 1 2 3 4 5 6
## 10.6507430 9.3711318 5.4630298 -17.4957487 29.5194692 -2.9846919
## 7 8 9 10 11 12
## -7.0242994 -12.3060734 6.8496267 -10.3329505 1.5934936 -3.0958161
## 13 14 15 16 17 18
## 0.1172839 9.5331344 2.8488167 17.2107726 -25.2627227 -27.7998544
## 19 20 21 22 23 24
## 13.1446553 -15.9510624 -16.0041386 -9.5801478 -27.2711657 94.2522174
## 25 26 27 28 29 30
## 0.6993361 -9.1670510 -25.8747696 -8.7455549 -6.8803097 -19.8090866
## 31 32 33 34 35 36
## 10.8793766 15.0599340 11.7462296 -3.5932770 -14.4016736 45.6051264
## 37 38 39 40 41 42
## 20.5472529 11.2429290 -51.0824078 8.8669438 -1.4513921 -3.8361619
## 43 44 45 46 47
## -4.3831786 -14.8940753 5.4506347 1.4092321 7.1662399
str(model$residuals)
## Named num [1:47] 10.65 9.37 5.46 -17.5 29.52 ...
## - attr(*, "names")= chr [1:47] "1" "2" "3" "4" ...
model$fitted.values
## 1 2 3 4 5 6
## -10.6507430 -9.3711318 -5.4630298 24.7957487 -9.9194692 3.0846919
## 7 8 9 10 11 12
## 8.4742994 18.9060734 -5.1496267 10.4329505 -1.4934936 8.4958161
## 13 14 15 16 17 18
## 1.0827161 -5.9331344 -0.4488167 -13.8107726 25.3627227 36.1998544
## 19 20 21 22 23 24
## -1.1446553 15.9510624 17.0041386 10.7801478 27.3711657 61.7477826
## 25 26 27 28 29 30
## 37.8006639 11.2670510 40.3747696 11.7455549 7.4803097 29.4090866
## 31 32 33 34 35 36
## 77.1206234 38.1400660 78.2537704 6.5932770 28.5016736 24.3948736
## 37 38 39 40 41 42
## 17.9527471 45.9570710 57.0824078 16.1330562 8.3513921 73.5361619
## 43 44 45 46 47
## 17.6831786 15.4940753 32.5493653 12.9907679 12.0337601
teengamb$income
## [1] 2.00 2.50 2.00 7.00 2.00 3.47 5.50 6.42 2.00 6.00 3.00
## [12] 4.75 2.20 2.00 3.00 1.50 9.50 10.00 4.00 3.50 3.00 2.50
## [23] 3.50 10.00 6.50 1.50 5.44 1.00 0.60 5.50 12.00 7.00 15.00
## [34] 2.00 1.50 4.50 2.50 8.00 10.00 1.60 2.00 15.00 3.00 3.25
## [45] 4.94 1.50 2.50
cor(model$fitted.values, teengamb$income)
## [1] 0.857142