Extract residuals from a fitted model object.
resid
is an alias.
Usage
# S3 method for class 'ssn_lm'
residuals(object, type = "response", ...)
# S3 method for class 'ssn_lm'
resid(object, type = "response", ...)
# S3 method for class 'ssn_lm'
rstandard(model, ...)
# S3 method for class 'ssn_glm'
residuals(object, type = "deviance", ...)
# S3 method for class 'ssn_glm'
resid(object, type = "deviance", ...)
# S3 method for class '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
#> 0.50256099 0.47318349 0.56793047 -0.01642697 -0.43930648 0.63368951
#> 7 8 9 10 11 12
#> 0.41368951 0.45431200 0.60668549 0.70493449 0.76080999 0.38493449
#> 13 14 15 16 17 18
#> 0.29905899 -2.01370406 -2.43483257 -2.41771208 -2.23996911 -2.18172011
#> 19 20 21 22 23 24
#> -2.38934662 -2.06397713 -2.05397713 -2.19160364 -0.44833458 0.25477788
#> 25 26 27 28 29 30
#> 2.00302688 1.60302688 1.90789034 2.24563332 1.83337629 1.61174176
#> 31 32 33 34 35 36
#> -1.35195305 -1.40308157 -0.73296509 -1.13059160 -1.00121409 -0.86409361
#> 37 38 39 40 41 42
#> -0.58160364 0.67964134 1.05088633 1.05738432 0.83399878 0.22874577
#> 43 44 45
#> -0.90284862 -2.69860765 -2.15561167
resid(ssn_mod)
#> 1 2 3 4 5 6
#> 0.50256099 0.47318349 0.56793047 -0.01642697 -0.43930648 0.63368951
#> 7 8 9 10 11 12
#> 0.41368951 0.45431200 0.60668549 0.70493449 0.76080999 0.38493449
#> 13 14 15 16 17 18
#> 0.29905899 -2.01370406 -2.43483257 -2.41771208 -2.23996911 -2.18172011
#> 19 20 21 22 23 24
#> -2.38934662 -2.06397713 -2.05397713 -2.19160364 -0.44833458 0.25477788
#> 25 26 27 28 29 30
#> 2.00302688 1.60302688 1.90789034 2.24563332 1.83337629 1.61174176
#> 31 32 33 34 35 36
#> -1.35195305 -1.40308157 -0.73296509 -1.13059160 -1.00121409 -0.86409361
#> 37 38 39 40 41 42
#> -0.58160364 0.67964134 1.05088633 1.05738432 0.83399878 0.22874577
#> 43 44 45
#> -0.90284862 -2.69860765 -2.15561167
rstandard(ssn_mod)
#> 1 2 3 4 5 6
#> 0.54482527 0.24902815 0.62481728 0.49000705 -1.25153528 0.58378939
#> 7 8 9 10 11 12
#> -0.24979138 -0.70645636 0.42458717 0.82105356 0.66286002 0.15454106
#> 13 14 15 16 17 18
#> -0.16911790 -1.93108065 -0.94482469 -0.92746033 -0.30105744 -0.08748646
#> 19 20 21 22 23 24
#> -1.03751283 -0.14027557 -0.10922866 -0.52442537 -0.25655729 -1.50792407
#> 25 26 27 28 29 30
#> 1.88733195 0.08022385 0.84150045 2.10218328 0.49121189 0.62967096
#> 31 32 33 34 35 36
#> -0.94695811 -1.16773136 0.66216711 -0.89530470 -0.36015318 -0.34642484
#> 37 38 39 40 41 42
#> -0.34733356 2.77614973 0.15975430 0.24945263 0.41507374 -0.37899919
#> 43 44 45
#> 0.41832097 -1.69498836 -2.69823469