R example output: diagnostics


R output



R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> invisible(options(echo = TRUE))
> library(MPV)
> data(softdrink)
> attach(softdrink)
> softdrink.lm <- lm(y~x1+x2)
>
> # Residuals against x1 -- any evidence of missing trend / non-constant variance
>
> plot(x1, resid(softdrink.lm), bg='red', cex=1, pch=21)
>
> # Residuals against x2 -- any evidence of missing trend / non-constant variance
> plot(x2, resid(softdrink.lm), bg='red', cex=1, pch=21)
>
> # Companion to applied regression library -- install it using "install.packages"
> library(car)
>
> # Partial residual plot for x1
> cr.plots(softdrink.lm, x1, pch=23, bg='red')
>
> # Partial residual plot for x2
> cr.plots(softdrink.lm, x2, pch=23, bg='red')
>
> # Added variable plot for x1
> av.plots(softdrink.lm, x1, pch=23, bg='red')
numeric(0)
>
> # Added variable plot for x2
> av.plots(softdrink.lm, x2, pch=23, bg='red')
numeric(0)
>
> # Bonferroni outlier test
>
> outlier.test(softdrink.lm)

max|rstudent| = 4.31078, degrees of freedom = 21,
unadjusted p = 0.0003090234, Bonferroni p = 0.007725586

Observation: 9
>
> print(dffits(softdrink.lm))
1 2 3 4 5 6
-0.570850478 0.098618619 -0.005203676 0.500801817 -0.039458989 -0.018779374
7 8 9 10 11 12
0.078990030 0.093760764 4.296080927 0.398713071 0.217953207 -0.067670223
13 14 15 16 17 18
0.081259033 0.097362643 0.042584374 -0.097159801 0.033915978 0.365309285
19 20 21 22 23 24
0.186167873 -0.671771402 -0.388501185 -1.195036104 -0.307538544 -0.571139627
25
-0.017626149
>
> print(dfbetas(softdrink.lm))
(Intercept) x1 x2
1 -0.187267279 0.4113118750 -0.434862094
2 0.089793299 -0.0477642427 0.014414155
3 -0.003515177 0.0039483525 -0.002846468
4 0.451964743 0.0882802920 -0.273373097
5 -0.031674102 -0.0133001129 0.024240457
6 -0.014681480 0.0017921068 0.001078986
7 0.078071285 -0.0222783194 -0.011018802
8 0.071202807 0.0333823324 -0.053823961
9 -2.575739806 0.9287433421 1.507550618
10 0.107919369 -0.3381628707 0.341326746
11 -0.034274535 0.0925271540 -0.002686252
12 -0.030268935 -0.0486664488 0.053973390
13 0.072366473 -0.0356212226 0.011335105
14 0.049516699 -0.0670868604 0.061816778
15 0.022279094 -0.0047895025 0.006838236
16 -0.002693186 0.0644208340 -0.084187552
17 0.028855555 0.0064876499 -0.015696507
18 0.248558020 0.1897331043 -0.272430555
19 0.172558506 0.0235737344 -0.098968842
20 0.168036548 -0.2149950233 -0.092915080
21 -0.161928685 -0.2971750929 0.336406248
22 0.398566309 -1.0254140704 0.573140240
23 -0.159852248 0.0372930389 -0.052651959
24 -0.119720216 0.4046225960 -0.465446949
25 -0.016816024 0.0008498979 0.005592192
>
> print(cooks.distance(softdrink.lm))
1 2 3 4 5 6
1.000921e-01 3.375704e-03 9.455785e-06 7.764718e-02 5.432217e-04 1.231067e-04
7 8 9 10 11 12
2.171604e-03 3.051135e-03 3.419318e+00 5.384516e-02 1.619975e-02 1.596392e-03
13 14 15 16 17 18
2.294737e-03 3.292786e-03 6.319880e-04 3.289086e-03 4.013419e-04 4.397807e-02
19 20 21 22 23 24
1.191868e-02 1.324449e-01 5.086063e-02 4.510455e-01 2.989892e-02 1.023224e-01
25
1.084694e-04
>
> print(hatvalues(softdrink.lm))
1 2 3 4 5 6 7
0.10180178 0.07070164 0.09873476 0.08537479 0.07501050 0.04286693 0.08179867
8 9 10 11 12 13 14
0.06372559 0.49829216 0.19629595 0.08613260 0.11365570 0.06112463 0.07824332
15 16 17 18 19 20 21
0.04111077 0.16594043 0.05943202 0.09626046 0.09644857 0.10168486 0.16527689
22 23 24 25
0.39157522 0.04126005 0.12060826 0.06664345
>
> # All of the influence measures
>
> print(influence.measures(softdrink.lm))
Influence measures of
lm(formula = y ~ x1 + x2) :

dfb.1_ dfb.x1 dfb.x2 dffit cov.r cook.d hat inf
1 -0.18727 0.41131 -0.43486 -0.5709 0.871 1.00e-01 0.1018
2 0.08979 -0.04776 0.01441 0.0986 1.215 3.38e-03 0.0707
3 -0.00352 0.00395 -0.00285 -0.0052 1.276 9.46e-06 0.0987
4 0.45196 0.08828 -0.27337 0.5008 0.876 7.76e-02 0.0854
5 -0.03167 -0.01330 0.02424 -0.0395 1.240 5.43e-04 0.0750
6 -0.01468 0.00179 0.00108 -0.0188 1.200 1.23e-04 0.0429
7 0.07807 -0.02228 -0.01102 0.0790 1.240 2.17e-03 0.0818
8 0.07120 0.03338 -0.05382 0.0938 1.206 3.05e-03 0.0637
9 -2.57574 0.92874 1.50755 4.2961 0.342 3.42e+00 0.4983 *
10 0.10792 -0.33816 0.34133 0.3987 1.305 5.38e-02 0.1963
11 -0.03427 0.09253 -0.00269 0.2180 1.172 1.62e-02 0.0861
12 -0.03027 -0.04867 0.05397 -0.0677 1.291 1.60e-03 0.1137
13 0.07237 -0.03562 0.01134 0.0813 1.207 2.29e-03 0.0611
14 0.04952 -0.06709 0.06182 0.0974 1.228 3.29e-03 0.0782
15 0.02228 -0.00479 0.00684 0.0426 1.192 6.32e-04 0.0411
16 -0.00269 0.06442 -0.08419 -0.0972 1.369 3.29e-03 0.1659
17 0.02886 0.00649 -0.01570 0.0339 1.219 4.01e-04 0.0594
18 0.24856 0.18973 -0.27243 0.3653 1.069 4.40e-02 0.0963
19 0.17256 0.02357 -0.09897 0.1862 1.215 1.19e-02 0.0964
20 0.16804 -0.21500 -0.09292 -0.6718 0.760 1.32e-01 0.1017
21 -0.16193 -0.29718 0.33641 -0.3885 1.238 5.09e-02 0.1653
22 0.39857 -1.02541 0.57314 -1.1950 1.398 4.51e-01 0.3916 *
23 -0.15985 0.03729 -0.05265 -0.3075 0.890 2.99e-02 0.0413
24 -0.11972 0.40462 -0.46545 -0.5711 0.948 1.02e-01 0.1206
25 -0.01682 0.00085 0.00559 -0.0176 1.231 1.08e-04 0.0666
>
> proc.time()
[1] 0.63 0.05 0.72 0.00 0.00
>

Plots


Plot #1: Residuals against x1 -- any evidence of missing trend / non-constant variance


Plot #2: Residuals against x2 -- any evidence of missing trend / non-constant variance


Plot #3: Partial residual plot for x1


Plot #4: Partial residual plot for x2


Plot #5: Added variable plot for x1


Plot #6: Added variable plot for x2