| model_gaim | R Documentation |
A wrapper for cgaim::cgaim() enabling multiple GAIM models based on a
grouping variable. Currently does not support Constrained GAIM (CGAIM)s.
model_gaim(
data,
yvar,
neighbour = 0,
index.vars,
index.ind,
s.vars = NULL,
linear.vars = NULL,
verbose = FALSE,
...
)
data |
Training data set on which models will be trained. Must be a data
set of class |
yvar |
Name of the response variable as a character string. |
neighbour |
If multiple models are fitted: Number of neighbours of each
key (i.e. grouping variable) to be considered in model fitting to handle
smoothing over the key. Should be an |
index.vars |
A |
index.ind |
An |
s.vars |
A |
linear.vars |
A |
verbose |
Logical; controls whether progress messages (model indices) are printed during fitting. Defaults to FALSE. |
... |
Other arguments not currently used. (Note that the arguments in
|
Group-wise Additive Index Model (GAIM) can be written in the form
y_{i} = \sum_{j = 1}^{p} g_{j}(\boldsymbol{\alpha}_{j}^{T}\boldsymbol{x}_{ij}) +
\varepsilon_{i}, \quad i = 1, \dots, n,
where y_{i} is the univariate
response, \boldsymbol{x}_{ij} \in \mathbb{R}^{l{j}}, j = 1,
\dots, p are pre-specified non-overlapping subsets of
\boldsymbol{x}_{i}, and \boldsymbol{\alpha}_j are the
corresponding index coefficients, g_{j} is an unknown (possibly
nonlinear) component function, and \varepsilon_{i} is the random
error, which is independent of \boldsymbol{x}_{i}.
An object of class gaimFit. This is a tibble with two
columns:
key |
The level of the grouping variable (i.e. key of the training data set). |
fit |
Information of the fitted model
corresponding to the |
Each row of the column fit is an
object of class cgaim. For details refer cgaim::cgaim().
model_smimodel, model_backward,
model_ppr, model_gam, model_lm
library(dplyr)
library(tibble)
library(tidyr)
library(tsibble)
# Simulate data
n = 1005
set.seed(123)
sim_data <- tibble(x_lag_000 = runif(n)) |>
mutate(
# Add x_lags
x_lag = lag_matrix(x_lag_000, 5)) |>
unpack(x_lag, names_sep = "_") |>
mutate(
# Response variable
y = (0.9*x_lag_000 + 0.6*x_lag_001 + 0.45*x_lag_003)^3 + rnorm(n, sd = 0.1),
# Add an index to the data set
inddd = seq(1, n)) |>
drop_na() |>
select(inddd, y, starts_with("x_lag")) |>
# Make the data set a `tsibble`
as_tsibble(index = inddd)
# Predictors taken as index variables
index.vars <- colnames(sim_data)[3:7]
# Assign group indices for each predictor
index.ind = c(rep(1, 3), rep(2, 2))
# Predictors taken as non-linear variables not entering indices
s.vars = "x_lag_005"
# Model fitting
gaimModel <- model_gaim(data = sim_data,
yvar = "y",
index.vars = index.vars,
index.ind = index.ind,
s.vars = s.vars)
# Fitted model
gaimModel$fit[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.