A wrapper function for fit_custom_gam. The kis compared to the number of samples and to the max_k. If there is a zero variability in the term, lm is fitted instead. If no model was cretaed (due to errors), the function retun NA_real

fit_gam_safely(
  data_source,
  x_var = "age",
  y_var = "var",
  smooth_basis = c("tp", "cr"),
  error_family = "gaussian(link = 'identity')",
  weights_var = NULL,
  sel_k = 10,
  max_k = 10,
  max_iterations = 200,
  verbose = FALSE
)

Arguments

data_source

Data.frame with columns whose names are set by y_var and x_var

x_var

Character. Name of the X-variable

y_var

Character. Name of the Y-variable

smooth_basis

Character. Name of the Smooth basis to use

error_family

Character. Name of the error family to be used

weights_var

Character. Name of the variable to use as weights

sel_k

Preferred k (wiggliness)

max_k

Maximum k which can be used

max_iterations

Numeric. Maximum number of iterations for GAM to try.

verbose

Logical. Should additional messages be output?

See also