Learn R Programming

glmSTARMA (version 1.0.0)

residuals.glmstarma: Residuals for glmstarma and dglmstarma Models

Description

Compute residuals for fitted glmstarma and dglmstarma models.

Usage

# S3 method for glmstarma
residuals(
  object,
  type = c("response", "pearson", "deviance"),
  drop_init = TRUE,
  ignore_dispersion = TRUE
)

# S3 method for dglmstarma residuals( object, type = c("response", "pearson", "deviance"), drop_init = TRUE, ignore_dispersion = TRUE )

Value

A matrix of residuals.

Arguments

object

A fitted glmstarma or dglmstarma object.

type

Type of residuals to compute. Options are "response" (raw residuals), "pearson". See details.

drop_init

Logical; if TRUE, initial first max_time_lag columns of residuals are dropped.

ignore_dispersion

Logical; if TRUE, values are not scaled by the dispersion parameter

Details

The type argument specifies the type of residuals to compute:

  • "response": Raw residuals, computed as the difference between observed and fitted values.

  • "pearson": Pearson residuals, defined as $$r_i = \frac{y_i - \mu_i}{\sqrt{V(\mu_i)}}$$, where \(V(\mu_i)\) is the variance function of the specified family.

  • "deviance": Deviance residuals, defined as $$r_i = 2 \cdot (\ell(y_i; y_i) - \ell(y_i; \mu_i)),$$ i.e. the log-likelihood difference of a saturated model and the fitted model. If ignore_dispersion is set to FALSE, pearson and deviance residuals are scaled by the dispersion parameter(s).

Examples

Run this code
# \donttest{
dat <- load_data("chickenpox", directory = tempdir())
chickenpox <- dat$chickenpox
population_hungary <- dat$population_hungary
W_hungary <- dat$W_hungary

model_autoregressive <- list(past_obs = rep(1, 7))
fit <- glmstarma(chickenpox, model_autoregressive, W_hungary, family = vpoisson("log"),
                 covariates = list(population = population_hungary))
residuals(fit)

mean_model <- list(past_obs = rep(1, 7))
dispersion_model <- list(past_obs = 1)
fit2 <- dglmstarma(chickenpox, mean_model, dispersion_model, mean_family = vquasipoisson("log"),
                   dispersion_link = "log",
                   wlist = W_hungary, 
                   mean_covariates = list(population = population_hungary))
residuals(fit2)
# }

Run the code above in your browser using DataLab