Skip to contents

Extract fitted values from fitted model objects. fitted.values is an alias.

Usage

# S3 method for ssn_lm
fitted(object, type = "response", ...)

# S3 method for ssn_lm
fitted.values(object, type = "response", ...)

# S3 method for ssn_glm
fitted(object, type = "response", ...)

# S3 method for ssn_glm
fitted.values(object, type = "response", ...)

Arguments

object

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

type

"response" for fitted values of the response, "tailup" for fitted values of the tailup random errors, "taildown" for fitted values of the taildown random errors, "euclid" for fitted values of the Euclidean random errors, "nugget" for fitted values of the nugget random errors, or "randcov" for fitted values of the random effects. If from ssn_glm(), "link" for fitted values on the link scale. The default is "response".

...

Other arguments. Not used (needed for generic consistency).

Value

The fitted values according to type.

Details

When type is "response", the fitted values for each observation are the standard fitted values \(X \hat{\beta}\). When type is "tailup", "taildown", "euclid", or "nugget" the fitted values for each observation are (generally) the best linear unbiased predictors of the respective random error. When type is "randcov", the fitted values for each level of each random effect are (generally) the best linear unbiased predictors of the corresponding random effect. The fitted values for type "tailup", "taildown", "euclid", "nugget", and "randcov" can generally be used to check assumptions for each component of the fitted model object (e.g., check a Gaussian assumption).

If from ssn_glm(), when type is "response", the fitted values for each observation are the standard fitted values on the inverse link scale: \(g^{-1}\)(\(X \hat{\beta} + \nu\)), where \(g(.)\) is a link function, \(\beta\) are the fixed effects, and \(\nu\) are the spatial and random effects.

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"
)
fitted(ssn_mod)
#>        1        2        3        4        5        6        7        8 
#> 14.34158 14.13982 13.88042 13.47691 13.41927 13.33280 13.01576 13.01576 
#>        9       10       11       12       13       14       15       16 
#> 12.92929 14.02453 13.30398 13.24633 12.58342 12.17991 11.77640 11.22878 
#>       17       18       19       20       21       22       23       24 
#> 14.39922 14.19747 13.70749 13.62102 13.76513 13.50573 12.92929 12.64107 
#>       25       26       27       28       29       30       31       32 
#> 12.35284 12.23755 11.63229 13.21751 12.69871 12.46813 14.88920 15.20625 
#>       33       34       35       36       37       38       39       40 
#> 15.06213 15.89798 15.63858 15.40800 15.40800 15.26389 15.17742 15.11978 
#>       41       42       43       44       45 
#> 15.14860 15.11978 15.09096 13.24633 11.45935 
fitted.values(ssn_mod)
#>        1        2        3        4        5        6        7        8 
#> 14.34158 14.13982 13.88042 13.47691 13.41927 13.33280 13.01576 13.01576 
#>        9       10       11       12       13       14       15       16 
#> 12.92929 14.02453 13.30398 13.24633 12.58342 12.17991 11.77640 11.22878 
#>       17       18       19       20       21       22       23       24 
#> 14.39922 14.19747 13.70749 13.62102 13.76513 13.50573 12.92929 12.64107 
#>       25       26       27       28       29       30       31       32 
#> 12.35284 12.23755 11.63229 13.21751 12.69871 12.46813 14.88920 15.20625 
#>       33       34       35       36       37       38       39       40 
#> 15.06213 15.89798 15.63858 15.40800 15.40800 15.26389 15.17742 15.11978 
#>       41       42       43       44       45 
#> 15.14860 15.11978 15.09096 13.24633 11.45935