Learn R Programming

SSN2 (version 0.2.1)

residuals.SSN2: Extract fitted model residuals

Description

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, ...)

Value

The residuals as a numeric vector.

Arguments

object

A fitted model object from ssn_lm() or ssn_glm().

type

"response" for response residuals, "pearson" for Pearson residuals, or "standardized" for standardized residuals. For ssn_lm() fitted model objects, the default is "response". For ssn_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

A fitted model object from ssn_lm() or ssn_glm().

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

Run this code
# 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)
resid(ssn_mod)
rstandard(ssn_mod)

Run the code above in your browser using DataLab