custom_family | R Documentation |
Allows specification of the random component and link function for a response
variable. In principle this could be used to specify any GLM family, but it
is usually easier to use the predefined families, such as gaussian()
and
binomial()
.
custom_family(distribution, inverse_link)
distribution |
The distribution of the random component. This should be in the form of a function taking one argument, the vector of values on the inverse link scale, and returning a vector of draws from the distribution. |
inverse_link |
The inverse link function. |
A GLM is specified by a combination of:
Random component, i.e. the distribution that Y is drawn from
Link function relating the mean of the random component to the linear predictor
Linear predictor
Using custom_family()
we can specify the random component and link
function, while the linear predictor is set in population()
when setting up
the population relationships. A family specified this way can be used to
specify a population (via population()
), but can't be used to estimate a
model (such as with glm()
).
A family object representing this family
ols_with_error()
for the special case of linear regression with
custom error distribution
# A zero-inflated Poisson family
rzeroinfpois <- function(ys) {
n <- length(ys)
rpois(n, lambda = ys * rbinom(n, 1, prob = 0.4))
}
custom_family(rzeroinfpois, exp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.