This function fits multiple generalized additive models (GAMs) using the fit_gam_safely() function. GAMs are fitted to each dataset defined by the group_var argument in the input data_source data frame. The number of models fitted is equal to the number of unique levels of the group_var. The function returns a data frame with one row per group, including the original group identifier and the fitted GAM model for that group.

fit_multiple_gams(
  data_source,
  x_var = "age",
  y_var = "var",
  group_var = "dataset_id",
  smooth_basis = c("tp", "cr"),
  error_family = "gaussian(link = 'identity')",
  weights_var = NULL,
  max_k = 10,
  max_iterations = 200,
  verbose = TRUE
)

Arguments

data_source

Data frame with x_var, y_var, and group_var

x_var

Character. Name of the X-variable

y_var

Character. Name of the Y-variable

group_var

Character. Name of the variable used for identification of groups.

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

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?

Value

A data frame containing the original grouping variable and the corresponding fitted GAM model for each group.

See also