Run forwards or backwards stepwise and full search variable selection with INLA regression. Only fixed effects will be considered for removal. Use holdout data or within sample data to test new models. Choose the level of interactions and power terms to expand the model formula to. Force part of the model to remain in the model (e.g. the spatial term and intercept) or limit the number of predictor variables during a full search selection.
Usage
INLAstep(
fam1 = "gaussian",
dataf,
spde = NULL,
in_stack = NULL,
invariant = "0 + Intercept",
direction = c("forwards", "backwards", "none"),
y = NULL,
y2 = NULL,
include = NULL,
include_max = NULL,
powerl = 1,
inter = 1,
thresh = 2,
num.threads = 1,
...
)Arguments
- fam1
String defining the likelihood familiy.
- dataf
A
data.frameincluding covariates and response data.- spde
An spde model object for the spatial component.
- in_stack
An
inla.data.stackobject containing all needed data.- invariant
The part of the formula that should not change (e.g. the intercept and the spatial component.)
- direction
string 'forwards' for forward variable selection, 'backwards' for backwards variable elimination and 'none' for a full search across all possible formulas. To limit the number of covariates and computational efforts for a large number of columns in
datafsetinclude_max.- y
String determining the response variable.
- y2
String determining the name of the test response data.
- include
Vector of integers to determine which columns in
datafshould be used. If NULL, use all columns exceptyandy2.- include_max
Integer determining the maximum number or covariates for a full search selected with
direction= 'none'. If NULL, use all columns exceptyandy2.- powerl
Integer up to 3 determining which power terms to include.
- inter
Integer up to 3 determining how many levels of interactions to include.
- thresh
Threshold difference in DIC for whether a new model should replace the old model in 'forward' or 'backward' variable selection.
- num.threads
How many threads to use for INLA computation.
- ...
Further arguments to
INLA::inlafunction.
Examples
if (FALSE) { # \dontrun{
library(INLA)
data(Epil)
stack <- INLA::inla.stack(data = list(y = Epil$y),
A = list(1),
effects = list(data.frame(Intercept = 1, Epil[3:5])))
result <- INLAstep(fam1 = "poisson",
Epil,
in_stack = stack,
invariant = "0 + Intercept",
direction = 'backwards',
include = 3:5,
y = 'y',
y2 = 'y',
powerl = 1,
inter = 1,
thresh = 2)
autoplot(result$best_model, which = c(1, 5), CI = TRUE)
} # }
