custom_family {regressinator}R Documentation

Family representing a GLM with custom distribution and link function

Description

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().

Usage

custom_family(distribution, inverse_link)

Arguments

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.

Details

A GLM is specified by a combination of:

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()).

Value

A family object representing this family

See Also

ols_with_error() for the special case of linear regression with custom error distribution

Examples

# 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)

[Package regressinator version 0.1.3 Index]