response {regressinator} | R Documentation |
Specify a response variable in terms of predictors
Description
Response variables are related to predictors (and other response variables) through a link function and response distribution. First the expression provided is evaluated using the predictors, to give this response variable's value on the link scale; then the inverse link function and response distribution are used to get the response value. See Details for more information.
Usage
response(expr, family = gaussian(), error_scale = NULL, size = 1L)
Arguments
expr |
An expression, in terms of other predictor or response variables, giving this predictor's value on the link scale. |
family |
The family of this response variable, e.g. |
error_scale |
Scale factor for errors. Used only for linear families,
such as |
size |
When the |
Details
Response variables are drawn based on a typical generalized linear model
setup. Let represent the response variable and
represent the
predictor variables. We specify that
where
Here is the expression
expr
, and both the distribution and
link function are specified by the
family
provided. For instance,
if the family
is gaussian()
, the distribution is Normal and the link is
the identity function; if the family
is binomial()
, the distribution is
binomial and the link is (by default) the logistic link.
Response families
The following response families are supported.
gaussian()
-
The default family is
gaussian()
with the identity link function, specifying the relationshipwhere
is given by
error_scale
. ols_with_error()
Allows specification of custom non-Normal error distributions, specifying the relationship
where
is drawn from an arbitrary distribution, specified by the
error
argument tools_with_error()
.binomial()
Binomial responses include binary responses (as in logistic regression) and responses giving a total number of successes out of a number of trials. The response has distribution
where
is set by the
size
argument andis the link function. The default link is the logistic link, and others can be chosen with the
link
argument tobinomial()
. The defaultis 1, representing a binary outcome.
poisson()
Poisson-distributed responses with distribution
where
is the link function. The default link is the log link, and others can be chosen with the
link
argument topoisson()
.custom_family()
Responses drawn from an arbitrary distribution with arbitrary link function, i.e.
where both
and SomeDistribution are specified by arguments to
custom_family()
.
Evaluation and scoping
The expr
, error_scale
, and size
arguments are evaluated only when
simulating data for this response variable. They are evaluated in an
environment with access to the predictor variables and the preceding response
variables, which they can refer to by name. Additionally, these arguments can
refer to variables in scope when the enclosing population()
was defined.
See the Examples below.
Value
A response_dist
object, to be used in population()
to specify a
population distribution
See Also
predictor()
and population()
to define populations;
ols_with_error()
and custom_family()
for custom response distributions
Examples
# Defining a binomial response. The expressions can refer to other predictors
# and to the environment where the `population()` is defined:
slope1 <- 2.5
slope2 <- -3
intercept <- -4.6
size <- 10
population(
x1 = predictor("rnorm"),
x2 = predictor("rnorm"),
y = response(intercept + slope1 * x1 + slope2 * x2,
family = binomial(), size = size)
)