These functions help construct calls to various types of models.
construct_model(data, ...)
# S3 method for class 'data.frame'
construct_model(
data,
formula,
method,
method.args = list(),
package = "base",
env = caller_env(),
...
)
# S3 method for class 'survey.design'
construct_model(
data,
formula,
method,
method.args = list(),
package = "survey",
env = caller_env(),
...
)
reformulate2(
termlabels,
response = NULL,
intercept = TRUE,
env = parent.frame(),
pattern_term = NULL,
pattern_response = NULL
)
bt(x, pattern = NULL)
bt_strip(x)construct_model.data.frame() (data.frame) a data frame
construct_model.survey.design() (survey.design) a survey design object
These dots are for future extensions and must be empty.
(formula)
a formula
(string)
string of function naming the function to be called, e.g. "glm".
If function belongs to a library that is not attached, the package name
must be specified in the package argument.
(named list)
named list of arguments that will be passed to method.
Note that this list may contain non-standard evaluation components.
If you are wrapping this function in other functions, the argument
must be passed in a way that does not evaluate the list, e.g.
using rlang's embrace operator {{ . }}.
(string)
a package name that will be temporarily loaded when function
specified in method is executed.
The environment in which to evaluate expr. This
environment is not applicable for quosures because they have
their own environments.
character vector giving the right-hand side of a model formula. May be zero-length.
a character string, symbol or call giving the left-hand
side of a model formula, or NULL.
logical: should the formula have an intercept?
(character)
character vector, typically of variable names
DEPRECATED
depends on the calling function
construct_model(): Builds models of the form method(data = data, formula = formula, method.args!!!).
If the package argument is specified, that package is temporarily attached
when the model is evaluated.
reformulate2(): This is a copy of reformulate() except that variable
names that contain a space are wrapped in backticks.
bt(): Adds backticks to a character vector.
bt_strip(): Removes backticks from a string if it begins and ends with a backtick.
construct_model(
data = mtcars,
formula = am ~ mpg + (1 | vs),
method = "glmer",
method.args = list(family = binomial),
package = "lme4"
) |>
broom.mixed::tidy()
#> # A tibble: 3 × 7
#> effect group term estimate std.error statistic p.value
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 fixed NA (Intercept) -8.70 4.12 -2.11 0.0347
#> 2 fixed NA mpg 0.409 0.199 2.05 0.0403
#> 3 ran_pars vs sd__(Intercept) 0.790 NA NA NA
construct_model(
data = mtcars |> dplyr::rename(`M P G` = mpg),
formula = reformulate2(c("M P G", "cyl"), response = "hp"),
method = "lm"
) |>
ard_regression() |>
dplyr::filter(stat_name %in% c("term", "estimate", "p.value"))
#> {cards} data frame: 6 x 8
#> variable context stat_name stat_label stat fmt_fun
#> 1 M P G regressi… term term `M P G` NULL
#> 2 M P G regressi… estimate Coeffici… -2.775 1
#> 3 M P G regressi… p.value p-value 0.213 1
#> 4 cyl regressi… term term cyl NULL
#> 5 cyl regressi… estimate Coeffici… 23.979 1
#> 6 cyl regressi… p.value p-value 0.003 1
#> ℹ 2 more variables: warning, error