Fits a Gaussian GAM model y ~ s(x) (y ~ x if x is non-numeric) with the numeric response y and the numeric, character or factor predictor x using mgcv::gam() and returns the R-squared of the observations against the predictions (see score_r2()).
Supports cross-validation via the arguments arguments cv_training_fraction (numeric between 0 and 1) and cv_iterations (integer between 1 and n) introduced via ellipsis (...). See preference_order() for further details.
See also
Other preference_order_functions:
f_binomial_gam(),
f_binomial_glm(),
f_binomial_rf(),
f_categorical_rf(),
f_count_gam(),
f_count_glm(),
f_count_rf(),
f_numeric_glm(),
f_numeric_rf(),
preference_order()
Examples
data(vi_smol, package = "spatialData")
df <- data.frame(
y = vi_smol[["vi_numeric"]],
x = vi_smol[["swi_max"]]
)
#no cross-validation
f_numeric_gam(df = df)
#> [1] 0.4983268
#cross-validation
f_numeric_gam(
df = df,
cv_training_fraction = 0.5,
cv_iterations = 10
)
#> [1] 0.4523571 0.4930217 0.4933019 0.4653087 0.4682021 0.4389428 0.5188004
#> [8] 0.4856046 0.4669182 0.4797559
#categorical predictor
df <- data.frame(
y = vi_smol[["vi_numeric"]],
x = vi_smol[["koppen_zone"]]
)
f_numeric_gam(df = df)
#> [1] 0.7071346
