Extract residuals from a fitted model object.
resid
is an alias.
Usage
# S3 method for splm
residuals(object, type = "response", ...)
# S3 method for splm
resid(object, type = "response", ...)
# S3 method for splm
rstandard(model, ...)
# S3 method for spautor
residuals(object, type = "response", ...)
# S3 method for spautor
resid(object, type = "response", ...)
# S3 method for spautor
rstandard(model, ...)
# S3 method for spglm
residuals(object, type = "deviance", ...)
# S3 method for spglm
resid(object, type = "deviance", ...)
# S3 method for spglm
rstandard(model, ...)
# S3 method for spgautor
residuals(object, type = "deviance", ...)
# S3 method for spgautor
resid(object, type = "deviance", ...)
# S3 method for spgautor
rstandard(model, ...)
Arguments
- object
A fitted model object from
splm()
,spautor()
,spglm()
, orspgautor()
.- type
"response"
for response residuals,"pearson"
for Pearson residuals, or"standardized"
for standardized residuals. Forsplm()
andspautor()
fitted model objects, the default is"response"
. Forspglm()
andspgautor()
fitted model objects, deviance residuals are also available ("deviance"
) and are the default residual type.- ...
Other arguments. Not used (needed for generic consistency).
- model
A fitted model object from
splm()
,spautor()
,spglm()
, orspgautor()
.
Details
The response residuals are taken as the response minus the fitted values for the response: \(y - X \hat{\beta}\). The Pearson residuals are the response residuals pre-multiplied by their inverse square 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 2 3 4 5 6
#> 0.45429071 0.18974938 -0.23676158 -0.08380603 0.04065264 0.17723842
#> 7 8 9 10 11 12
#> 0.05119397 -0.16270929 -0.29025062 0.05223842 -0.08070929 -0.12325062
#> 13 14 15 16 17 18
#> -0.18576158 0.02965264 -0.13585832 -0.41280603 0.11065264 -0.31085832
#> 19 20 21 22 23 24
#> -0.20825062 -0.20576158 -0.01485832 0.02929071 -0.24880603 -0.28734736
#> 25 26 27 28 29 30
#> -0.00085832 -0.02680603 -0.28634736 -0.10085832 -0.17770929 -0.19025062
resid(spmod)
#> 1 2 3 4 5 6
#> 0.45429071 0.18974938 -0.23676158 -0.08380603 0.04065264 0.17723842
#> 7 8 9 10 11 12
#> 0.05119397 -0.16270929 -0.29025062 0.05223842 -0.08070929 -0.12325062
#> 13 14 15 16 17 18
#> -0.18576158 0.02965264 -0.13585832 -0.41280603 0.11065264 -0.31085832
#> 19 20 21 22 23 24
#> -0.20825062 -0.20576158 -0.01485832 0.02929071 -0.24880603 -0.28734736
#> 25 26 27 28 29 30
#> -0.00085832 -0.02680603 -0.28634736 -0.10085832 -0.17770929 -0.19025062
residuals(spmod, type = "pearson")
#> 1 2 3 4 5 6 7
#> 2.3759019 1.0094357 -1.2802275 -0.1819747 0.5468322 0.9257146 0.4135878
#> 8 9 10 11 12 13 14
#> -0.5851680 -1.2915602 0.7801232 -0.2748195 -0.3601943 -0.5360591 0.8694383
#> 15 16 17 18 19 20 21
#> -0.2340949 -2.1087283 1.2970536 -1.1653479 -0.4662771 -0.5327342 0.4393293
#> 22 23 24 25 26 27 28
#> 0.8503478 -0.7084916 -0.8974281 0.8069845 0.3976900 -1.0772414 0.2117907
#> 29 30
#> -0.2333682 -0.3655001
residuals(spmod, type = "standardized")
#> 1 2 3 4 5 6 7
#> 2.5264598 1.0864730 -1.3779145 -0.2001888 0.5940130 1.0025422 0.4501727
#> 8 9 10 11 12 13 14
#> -0.6244526 -1.3763618 0.8368581 -0.2912449 -0.3860129 -0.5725495 0.9306823
#> 15 16 17 18 19 20 21
#> -0.2494573 -2.2347624 1.3900258 -1.2446749 -0.4991220 -0.5676948 0.4757905
#> 22 23 24 25 26 27 28
#> 0.9255673 -0.7560554 -0.9563517 0.8656729 0.4228911 -1.1594534 0.2279513
#> 29 30
#> -0.2567263 -0.3970356
rstandard(spmod)
#> 1 2 3 4 5 6 7
#> 2.5264598 1.0864730 -1.3779145 -0.2001888 0.5940130 1.0025422 0.4501727
#> 8 9 10 11 12 13 14
#> -0.6244526 -1.3763618 0.8368581 -0.2912449 -0.3860129 -0.5725495 0.9306823
#> 15 16 17 18 19 20 21
#> -0.2494573 -2.2347624 1.3900258 -1.2446749 -0.4991220 -0.5676948 0.4757905
#> 22 23 24 25 26 27 28
#> 0.9255673 -0.7560554 -0.9563517 0.8656729 0.4228911 -1.1594534 0.2279513
#> 29 30
#> -0.2567263 -0.3970356