thresh_gam fits a Generalized Additive Model (GAM) with a threshold
formulation using the
by argument in the smoothing function
gam(IND ~ s(pressure1, by = threshold_variable_low) +
s(pressure 1, by = threshold threshold_variable_high)).
The threshold value is estimated from the data and chosen by minimizing
the GCV score (termed "gcvv" in the threshold-GAM object) over an interval
defined by the lower and upper quantiles (see the
arguments respectively) of the threshold variable.
thresh_gam(model, ind_vec, press_vec, t_var, name_t_var, k, a, b)
A single GAM object from the model tibble needed to extract the family and the link function.
A vector with the IND training observations (including or excluding defined outliers).
A vector with the training observations (including or excluding defined outliers) of pressure 1 (i.e. the original significant pressure in the GAM(M)).
A vector with the training observations (including or excluding defined outliers) of the threshold variable (i.e. a second pressure variable).
The name of the threshold variable (pressure 2). t_var will be named after this string in the model formula.
Choice of knots (for the smoothing function
The lower quantile value of the selected threshold variable, which the estimated threshold is not allowed to exceed; the default is 0.2.
The upper quantile value of the selected threshold variable, which the estimated threshold is not allowed to exceed; the default is 0.8.
The function returns a
gam object with the additional class
All method functions for
gam can be applied to this function. The object
has four additional elements:
The threshold value of the best threshold-GAM.
The GCV of the best threshold-GAM.
A vector of the GCV values of all fitted threshold-GAMs.
A vector of all tested threshold values within the boundaries set by the lower and upper quantiles.
A logical vector indicating missing values.
thresh_gam creates first a sequence of evenly spaced threshold values
within the boundaries set by the lower and upper quantiles (defined by a and b).
For each threshold value that leads to a new splitting of the threshold
variables a threshold-GAM is applied: one smoothing function is applied
to only those observations where the threshold variable has been below the threshold
value for the given time step (year). A second smoothing function is applied to
observations where the threshold variable is above the prior defined threshold.
From the list of computed models the threshold-GAM with the lowest Generalized
Cross Validation (GCV) and its threshold value are selected and returned. For more
infos on threshold-GAMs see also the details section in
# Using some models of the Baltic Sea demo data in this package test <- thresh_gam(model = model_gam_ex$model[], ind_vec = ind_init_ex$ind_train[], press_vec = ind_init_ex$press_train[], t_var = ind_init_ex$press_train[], name_t_var = "Ssum", k = 4, a = 0.2, b = 0.8)