View source: R/modeling_phrases.R
specify_mean_model | R Documentation |
A wrapper for lm
and glm
which
allows the user to specify the form of the model for the mean response of
the data generating process.
specify_mean_model(data, formula, family, ...)
data |
an optional data frame containing the variables appearing in
|
formula |
an object of class " |
family |
a description of the error distribution and link function to
be used in the model. See |
... |
additional arguments to pass to |
specify_mean_model
provides a single interface to both lm
and
glm
with two noticable differences:
The intercept is not specified by default.
The notation "constant" can be used in the formula statement in
order to specify terms which do not require parameters, which are typically
specified by offset()
in base R. The difference is that "constant"
allows scalar terms.
If family
is not specified, then lm
is used to fit the model.
Otherwise, glm
is used to fit the model.
an objet of type lm
or glm
depending on whether
family
is specified.
# specify a linear model
fit_reg <- specify_mean_model(mpg ~ 1 + hp, data = mtcars)
summary(fit_reg)
# intercept is not included by default
fit_0_intercept <- specify_mean_model(mpg ~ hp, data = mtcars)
summary(fit_0_intercept)
# use 'constant()' to prevent parameter from being fit
fit_restricted <- specify_mean_model(mpg ~ constant(3) + hp, data = mtcars)
summary(fit_restricted)
# specify a logistic regression model
fit_logistic <- specify_mean_model(am ~ 1 + hp,
family = binomial,
data = mtcars)
summary(fit_logistic)
# using piping
mtcars |> specify_mean_model(mpg ~ 1 + hp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.