Create a character string for a mgcv::gam formula
Source:R/smooth_formula_string.R
smooth_formula_string.RdCreate a character string that wraps appropriate variables in a dataframe with s() smooth functions. Based on the datatype of each variable, it determines whether it is a numeric variable to be smoothed:
Non-numeric: no smoothing.
Numeric: determine knots based on the number of unique values for that variable:
<= 4: no smoothing5 to 19(inclusive): smooth function with knots equal to the floored half of the number of unique values. E.g., 6 unique values receive 3 knots, 7 will receive 3 knots, and 8 will receive 4 knots.>= 20: smooth function with no specified number of knots, allowing thegam()function to detect the appropriate number.
Arguments
- data
dataframe. All the variables in
dataexcepty_colwill be listed in the resulting formula string. To exclude any variables, assign asdataonly the subset of variables desired.- y_col
character(1). Name of the y outcome variable.
- smooth_fun
character(1). Function to use for smooth wraps; default is 's' for the
s()function.- bs
See documentation for
autogam()- expand_parametric
logical(1). If
TRUE(default), explicitly list each non-smooth (parametric) term. IfFALSE, use.to lump together all non-smooth terms.