Extract residuals from a fitted model object.
resid
is an alias.
Arguments
- object
- type
"raw"
for raw residuals,"pearson"
for Pearson residuals, or"standardized"
for standardized residuals. The default is"raw"
.- ...
Other arguments. Not used (needed for generic consistency).
- model
Details
The raw residuals are taken as the response minus the fitted values for the response: \(y - X \hat{\beta}\). The Pearson residuals are the raw residuals pre-multiplied by their square (Cholesky) root. The standardized residuals are Pearson residuals divided by the square root of one minus the leverage (hat) value. The standardized residuals are often used to check model assumptions, as they have mean zero and variance approximately one.
rstandard()
is an alias for residuals(model, type = "standardized")
.
Examples
spmod <- splm(z ~ water + tarp,
data = caribou,
spcov_type = "exponential", xcoord = x, ycoord = y
)
residuals(spmod)
#> [1] 0.45429071 0.18974938 -0.23676158 -0.08380603 0.04065264 0.17723842
#> [7] 0.05119397 -0.16270929 -0.29025062 0.05223842 -0.08070929 -0.12325062
#> [13] -0.18576158 0.02965264 -0.13585832 -0.41280603 0.11065264 -0.31085832
#> [19] -0.20825062 -0.20576158 -0.01485832 0.02929071 -0.24880603 -0.28734736
#> [25] -0.00085832 -0.02680603 -0.28634736 -0.10085832 -0.17770929 -0.19025062
resid(spmod)
#> [1] 0.45429071 0.18974938 -0.23676158 -0.08380603 0.04065264 0.17723842
#> [7] 0.05119397 -0.16270929 -0.29025062 0.05223842 -0.08070929 -0.12325062
#> [13] -0.18576158 0.02965264 -0.13585832 -0.41280603 0.11065264 -0.31085832
#> [19] -0.20825062 -0.20576158 -0.01485832 0.02929071 -0.24880603 -0.28734736
#> [25] -0.00085832 -0.02680603 -0.28634736 -0.10085832 -0.17770929 -0.19025062
residuals(spmod, type = "pearson")
#> [1] 1.24354161 -0.74916779 -2.30559697 -0.44278589 0.35871793 -0.02931481
#> [7] -0.34571722 -1.02400240 -1.32650258 0.77634627 -0.92543182 -0.60809279
#> [13] -0.54052868 0.81134318 -0.43085195 -1.97679013 1.48571342 -1.19999035
#> [19] -0.38403412 -0.37322840 0.70808016 0.83480943 -0.68844111 -0.61998523
#> [25] 1.01690321 0.29172182 -1.04855852 0.39380299 -0.12048301 -0.26755398
residuals(spmod, type = "standardized")
#> [1] 2.36883087 -0.82694464 -2.46935217 -0.48966899 0.38269818 -0.03079095
#> [7] -0.37578310 -1.06632080 -1.40640481 0.83497430 -0.95033683 -0.64355505
#> [13] -0.56645079 0.87526900 -0.45332541 -2.10877831 1.57318435 -1.25444887
#> [19] -0.41085218 -0.39045652 0.74280455 0.91130982 -0.73024812 -0.65149198
#> [25] 1.05208876 0.29986852 -1.10903948 0.41060223 -0.13412488 -0.28592438
rstandard(spmod)
#> [1] 2.36883087 -0.82694464 -2.46935217 -0.48966899 0.38269818 -0.03079095
#> [7] -0.37578310 -1.06632080 -1.40640481 0.83497430 -0.95033683 -0.64355505
#> [13] -0.56645079 0.87526900 -0.45332541 -2.10877831 1.57318435 -1.25444887
#> [19] -0.41085218 -0.39045652 0.74280455 0.91130982 -0.73024812 -0.65149198
#> [25] 1.05208876 0.29986852 -1.10903948 0.41060223 -0.13412488 -0.28592438