Description Usage Arguments Details Value See Also Examples
View source: R/test_tac.R View source: R/test_tac.R
test_tac
is a helper function for model_gam
,
model_gamm
, and plot_diagnostics
to compute
the (partial) autocorrelation functions. It also tests whether residuals
show temporal autocorrelation (see details).
1 | test_tac(model_resid)
|
model_resid |
A list of residuals from one or many Generalized Additive (Mixed) Models (GAM(M). |
NOTE: if the time series on which the GAM(M) is fitted contains missing values, they need to be accounted for in the residual vector. Observations with one or more NAs in-between will be otherwise considered as having a lag of 1.
The test for temporal autocorrelation is based on the following condition: If any of the acf and any of the pacf values of lag 1 - 5 is greater or lower than 0.4, a TRUE is returned.
The function returns a tibble with one row for each model and three columns:
acf
A list-column with values from the autocorrelation function.
pacf
A list-column with values from the partial autocorrelation function.
tac
logical; if TRUE, temporal autocorrelation was detected
model_gam
, model_gamm
,
plot_diagnostics
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Using models of the Baltic Sea demo data:
# Get model residuals of GAMs
model_resid <- purrr::map(model_gam_ex$model,
~mgcv::residuals.gam(., type = "deviance"))
# test whether model residuals show significant TAC
test_tac(model_resid)
# Works also with GAMMs
model_resid <- purrr::map_if(model_gamm_ex$model,
!is.na(model_gamm_ex$model),
~as.numeric(mgcv::residuals.gam(.$gam, type = "deviance")))
# (exclude those GAMMs that were not fitted)
# test whether model residuals show significant TAC
test_tac(model_resid)$tac
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.