Extract residuals from a fitted model object.
resid
is an alias.
Usage
# S3 method for ssn_lm
residuals(object, type = "response", ...)
# S3 method for ssn_lm
resid(object, type = "response", ...)
# S3 method for ssn_lm
rstandard(model, ...)
# S3 method for ssn_glm
residuals(object, type = "deviance", ...)
# S3 method for ssn_glm
resid(object, type = "deviance", ...)
# S3 method for ssn_glm
rstandard(model, ...)
Arguments
- object
- type
"response"
for response residuals,"pearson"
for Pearson residuals, or"standardized"
for standardized residuals. Forssn_lm()
fitted model objects, the default is"response"
. Forssn_glm()
fitted model objects, deviance residuals are also available ("deviance"
) and are the default residual type.- ...
Other arguments. Not used (needed for generic consistency).
- model
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
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, overwrite = TRUE)
ssn_mod <- ssn_lm(
formula = Summer_mn ~ ELEV_DEM,
ssn.object = mf04p,
tailup_type = "exponential",
additive = "afvArea"
)
residuals(ssn_mod)
#> 1 2 3 4 5 6
#> -2.96157851 -3.41982277 -3.45042255 -3.34691108 -3.29926659 -3.52279984
#> 7 8 9 10 11 12
#> -3.25575512 -3.24575512 -3.39928838 -1.45453378 -0.88397759 0.85366690
#> 13 14 15 16 17 18
#> 0.63657859 0.90009006 0.41360153 0.09122423 -2.28922300 -2.37746727
#> 19 20 21 22 23 24
#> -1.79748906 -2.21102232 -2.05513356 -1.96573333 -1.78928838 -0.58106590
#> 25 26 27 28 29 30
#> -0.26284342 -0.27755443 -0.61228724 -2.05751085 -3.94871040 -3.44813242
#> 31 32 33 34 35 36
#> -0.27920121 -0.28624593 -0.34213470 -0.67797988 -1.14857965 -0.11800167
#> 37 38 39 40 41 42
#> -0.33800167 -0.32389043 -0.18742369 -0.09977919 -0.03860144 -0.41977919
#> 43 44 45
#> -0.51095694 0.45366690 -1.24935375
resid(ssn_mod)
#> 1 2 3 4 5 6
#> -2.96157851 -3.41982277 -3.45042255 -3.34691108 -3.29926659 -3.52279984
#> 7 8 9 10 11 12
#> -3.25575512 -3.24575512 -3.39928838 -1.45453378 -0.88397759 0.85366690
#> 13 14 15 16 17 18
#> 0.63657859 0.90009006 0.41360153 0.09122423 -2.28922300 -2.37746727
#> 19 20 21 22 23 24
#> -1.79748906 -2.21102232 -2.05513356 -1.96573333 -1.78928838 -0.58106590
#> 25 26 27 28 29 30
#> -0.26284342 -0.27755443 -0.61228724 -2.05751085 -3.94871040 -3.44813242
#> 31 32 33 34 35 36
#> -0.27920121 -0.28624593 -0.34213470 -0.67797988 -1.14857965 -0.11800167
#> 37 38 39 40 41 42
#> -0.33800167 -0.32389043 -0.18742369 -0.09977919 -0.03860144 -0.41977919
#> 43 44 45
#> -0.51095694 0.45366690 -1.24935375
rstandard(ssn_mod)
#> 1 2 3 4 5 6
#> -1.31417513 -0.63086161 -0.82725055 -0.24495775 0.03588943 -1.27769827
#> 7 8 9 10 11 12
#> 0.04013139 0.09354178 -0.46311916 -1.01690582 -1.17757570 2.07589613
#> 13 14 15 16 17 18
#> 0.48880470 2.10969532 -0.63391890 -0.79209177 -1.13939584 -1.70158717
#> 19 20 21 22 23 24
#> 1.19810814 -1.25985662 -0.31945666 -0.45882772 -0.27215334 1.97924217
#> 25 26 27 28 29 30
#> 0.44190300 0.40506009 -0.76461961 0.17969367 -1.35425063 -1.70206611
#> 31 32 33 34 35 36
#> 0.13160477 0.08275306 -0.25793553 0.49251121 -2.33954032 1.22724195
#> 37 38 39 40 41 42
#> -0.06535745 0.03484793 -0.03803679 0.52173449 1.15188186 -0.57040629
#> 43 44 45
#> -1.03295041 -0.49183235 -0.56160115