View source: R/model_formula.R
model_formula | R Documentation |
Generate Model Formulas
model_formula(
df = NULL,
response = NULL,
predictors = NULL,
term_f = NULL,
term_args = NULL,
random_effects = NULL,
quiet = FALSE
)
df |
(optional; data frame, tibble, or sf). A data frame with responses and predictors. Required if |
response |
(optional; character string or vector) Name/s of response variable/s in |
predictors |
(optional, character vector, output of |
term_f |
(optional; string). Name of function to apply to each term in the formula, such as "s" for |
term_args |
(optional; string). Arguments of the function applied to each term. For example, for "poly" it can be "degree = 2, raw = TRUE". Default: NULL |
random_effects |
(optional, string or character vector). Names of variables to be used as random effects. Each element is added to the final formula as |
quiet |
(optional; logical) If FALSE, messages generated during the execution of the function are printed to the console Default: FALSE |
list if predictors
is a list or length of response
is higher than one, and character vector otherwise.
Other modelling_tools:
case_weights()
,
performance_score_auc()
,
performance_score_r2()
,
performance_score_v()
#using df, response, and predictors
#----------------------------------
df <- vi[1:1000, ]
#additive formulas
formulas_additive <- model_formula(
df = df,
response = c(
"vi_numeric",
"vi_categorical"
),
predictors = vi_predictors_numeric[1:10]
)
formulas_additive
#using a formula in a model
#m <- stats::lm(
# formula = formulas_additive[[1]],
# data = df
# )
# using output of collinear()
#----------------------------------
selection <- collinear(
df = df,
response = c(
"vi_numeric",
"vi_binomial"
),
predictors = vi_predictors_numeric[1:10],
quiet = TRUE
)
#polynomial formulas
formulas_poly <- model_formula(
predictors = selection,
term_f = "poly",
term_args = "degree = 3, raw = TRUE"
)
formulas_poly
#gam formulas
formulas_gam <- model_formula(
predictors = selection,
term_f = "s"
)
formulas_gam
#adding a random effect
formulas_random_effect <- model_formula(
predictors = selection,
random_effects = "country_name"
)
formulas_random_effect
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.