Residuals for ols
residuals.ols.RdComputes various residuals and measures of influence for a
fit from ols.
Arguments
- object
object created by
ols. Depending ontype, you may have had to specifyx=TRUEtools.- type
type of residual desired.
"ordinary"refers to the usual residual."score"is the matrix of score residuals (contributions to first derivative of log likelihood).dfbetaanddfbetasmean respectively the raw and normalized matrix of changes in regression coefficients after deleting in turn each observation. The coefficients are normalized by their standard errors.hatcontains the leverages — diagonals of the “hat” matrix.dffitanddffitscontain respectively the difference and normalized difference in predicted values when each observation is omitted. The Slm.influencefunction is used. Whentype="hscore", the ordinary residuals are divided by one minus the corresponding hat matrix diagonal element to make residuals have equal variance. Whentype="influence.measures"the model is converted to anlmmodel andinfluence.measures(object)$infmatis returned. This is a matrix with dfbetas for all predictors, dffit, cov.r, Cook's d, and hat. Fortype="studentized"studentized leave-out-one residuals are computed. See the help file forinfluence.measuresfor more details.- ...
ignored
Value
a matrix or vector, with places for observations that were originally
deleted by ols held by NAs
Examples
set.seed(1)
x1 <- rnorm(100)
x2 <- rnorm(100)
x1[1] <- 100
y <- x1 + x2 + rnorm(100)
f <- ols(y ~ x1 + x2, x=TRUE, y=TRUE)
resid(f, "dfbetas")
#> Intercept x1 x2
#> 1 0.0214792 -1.9890e+00 -1.0515e-04
#> 2 0.1624541 -1.4264e-02 1.2633e-02
#> 3 0.1462485 -3.7509e-02 -1.3812e-01
#> 4 -0.0339635 -2.0799e-03 -7.1306e-03
#> 5 -0.2235785 2.7109e-02 1.4892e-01
#> 6 0.2777151 -1.9924e-02 4.8653e-01
#> 7 0.0678307 -9.2997e-04 5.2181e-02
#> 8 0.0565733 1.3008e-03 5.4613e-02
#> 9 -0.0019196 5.0703e-05 -8.3376e-04
#> 10 0.0613358 -1.7820e-03 1.0336e-01
#> 11 -0.0212894 -2.2512e-05 1.3764e-02
#> 12 0.0356295 -3.6231e-03 -1.6252e-02
#> 13 -0.0367406 2.7298e-03 -5.3060e-02
#> 14 -0.1393879 5.1702e-02 9.1889e-02
#> 15 0.0908260 -9.2193e-04 -1.6392e-02
#> 16 0.1423171 -1.9981e-02 -5.4473e-02
#> 17 -0.0336663 4.4589e-03 1.0264e-02
#> 18 -0.1238286 4.1232e-03 3.1962e-02
#> 19 0.0631806 3.1190e-04 3.4708e-02
#> 20 -0.0076647 4.7331e-04 1.1557e-03
#> 21 -0.1698389 8.6843e-03 8.5555e-02
#> 22 0.0045717 2.4591e-04 6.3459e-03
#> 23 -0.0643622 7.4738e-03 1.2393e-02
#> 24 -0.0363234 1.1402e-02 5.9780e-03
#> 25 -0.1146350 6.1869e-03 7.8968e-03
#> 26 0.1826480 -1.2198e-02 1.3837e-01
#> 27 -0.0348783 4.5052e-03 1.5764e-03
#> 28 -0.1609446 4.0907e-02 2.4965e-03
#> 29 0.0135238 -2.7601e-03 -9.3940e-03
#> 30 0.0212780 -1.9021e-03 -6.5581e-03
#> 31 -0.0973792 -3.0184e-03 -1.0237e-02
#> 32 -0.2824841 4.5205e-02 1.6785e-01
#> 33 -0.0633405 2.2403e-03 -3.6857e-02
#> 34 0.0445482 -9.9541e-03 -7.2920e-02
#> 35 -0.0062671 1.3835e-03 -2.1039e-03
#> 36 -0.0189379 4.9565e-03 3.1311e-02
#> 37 0.0507747 -8.5563e-03 -1.4511e-02
#> 38 -0.1188548 1.7992e-02 6.2819e-02
#> 39 0.0979612 -4.1690e-03 -6.5065e-02
#> 40 -0.0033479 1.2290e-04 7.4749e-05
#> 41 0.0557827 -1.4806e-02 -1.1717e-01
#> 42 0.1107792 -6.1841e-03 1.3381e-01
#> 43 0.0105525 -1.6531e-03 -1.9190e-02
#> 44 -0.0887037 7.5396e-03 4.0623e-02
#> 45 0.1039668 -2.6747e-02 -1.2192e-01
#> 46 -0.1984536 4.6020e-02 1.5271e-01
#> 47 -0.0507382 -2.9532e-03 -1.0528e-01
#> 48 -0.0272119 8.5049e-04 -1.5223e-03
#> 49 -0.0242391 5.1369e-03 3.3196e-02
#> 50 0.0853583 -1.1568e-02 -1.5299e-01
#> 51 0.0132589 -5.2537e-04 6.6247e-03
#> 52 0.0377658 -6.4202e-03 3.5531e-04
#> 53 -0.0106551 1.0300e-03 3.2156e-03
#> 54 -0.0303713 8.7133e-03 2.9261e-02
#> 55 0.0550681 -3.6408e-03 -8.9150e-02
#> 56 0.0985653 2.0332e-03 -1.1280e-01
#> 57 -0.2432451 1.8969e-02 -2.5180e-01
#> 58 0.0505521 -1.2915e-02 -3.1782e-02
#> 59 0.0262210 -3.9109e-03 -3.9039e-02
#> 60 -0.0381933 6.3239e-05 -7.1130e-02
#> 61 0.0908574 1.4537e-02 4.5159e-02
#> 62 -0.0411369 5.3097e-03 8.9885e-03
#> 63 -0.0260654 -7.1553e-04 -2.8943e-02
#> 64 0.0891181 -4.2275e-03 8.2930e-02
#> 65 0.1611301 -3.6378e-02 -1.0098e-01
#> 66 0.0397327 1.9345e-03 8.6544e-02
#> 67 -0.0446331 1.3477e-02 1.0808e-02
#> 68 -0.1203459 7.0020e-03 1.8597e-01
#> 69 -0.0351308 3.6356e-03 4.1454e-03
#> 70 -0.0922236 -1.1373e-02 -2.4633e-02
#> 71 -0.0185521 -1.5107e-03 -4.2265e-02
#> 72 0.0373744 -6.3851e-03 5.1265e-03
#> 73 -0.0842834 1.5384e-03 -4.2901e-02
#> 74 0.2580059 -5.2989e-02 -1.3752e-02
#> 75 0.0117449 -2.9923e-03 -3.7953e-03
#> 76 0.1071639 -8.8209e-03 -1.9946e-04
#> 77 -0.2301992 2.2811e-02 -1.9019e-01
#> 78 0.0904545 2.1199e-03 1.8583e-01
#> 79 -0.1315078 4.4692e-03 -1.4062e-01
#> 80 0.0997969 -8.5477e-03 1.2292e-01
#> 81 0.0299898 -7.6159e-03 -3.9083e-02
#> 82 -0.0388383 2.2083e-03 -3.9745e-02
#> 83 0.1269136 2.9205e-03 3.4386e-02
#> 84 -0.0766894 2.8191e-02 1.1971e-01
#> 85 -0.0573739 9.0558e-04 -3.2923e-02
#> 86 -0.0999405 8.6539e-03 1.3222e-02
#> 87 -0.0644883 -5.6921e-03 -9.7412e-02
#> 88 0.0847220 -1.6343e-02 -6.6687e-02
#> 89 0.0370739 -3.7632e-03 -1.5653e-02
#> 90 0.0886617 -1.3024e-02 -8.5650e-02
#> 91 -0.0410437 7.1553e-03 6.3896e-03
#> 92 0.0360625 1.3550e-03 1.6573e-02
#> 93 0.0168777 -7.0522e-04 -1.2701e-02
#> 94 -0.1415199 -2.0211e-03 -1.2534e-01
#> 95 0.1573141 -4.7429e-03 -2.0366e-01
#> 96 0.0052202 -6.5717e-04 -5.7649e-03
#> 97 0.0871631 -1.1744e-02 1.2543e-01
#> 98 0.0844836 -2.0124e-02 -8.9702e-02
#> 99 -0.0048801 9.7082e-04 -2.1626e-03
#> 100 -0.0336388 6.1219e-03 1.2484e-02
which.influence(f)
#> $Intercept
#> [1] "5" "6" "32" "57" "74" "77"
#>
#> $x1
#> [1] "1"
#>
#> $x2
#> [1] "6" "57" "95"
#>
i <- resid(f, 'influence.measures') # dfbeta, dffit, etc.