Enrich objects of class family

Share:

Description

Enrich objects of class family with family-specific mathematical functions

Usage

1
2
## S3 method for class 'family'
enrich(object, with = "all", ...)

Arguments

object

an object of class family

with

a character vector with the names of the components to enrich object with

...

extra arguments to be passed to the compute_* functions

Details

family objects specify the details of the models used by functions such as glm. The families implemented in the stats package include binomial, gaussian, Gamma, inverse.gaussian, and poisson. family objects specify particular characteristics of distributions from the exponential family. Such distributions have probability mass or density function of the form

f(y, theta, phi) = exp((y * theta - b(theta) + c_1(y))/(phi/m) - a(-m/phi) + c_2(y))

where m > 0 is an observation weight, and a(.), b(.), c_1(.) and c_2(.) are sufficiently smooth, real-valued functions.

The expected value and the variance of such distributions is mu = b'(theta) and phi * V(mu)/m, respectively, where V(mu) is called the variance function. The parameter phi is called a dispersion parameter.

Characteristics of the exponential family that are already implemented in family objects include:

  • variance: V(.)

  • dev.resids: -2(y c_1'(mu) - y c_1'(y) - b(c'(mu)) + b(c'(y)))

  • aic: -2*sum(log f(y, theta, phi)) + 2*delta where delta is 1 if the family has a dispersion parameter and 0 else

The quasi families differ from the other families in that the variance function is not determined by the family but may be supplied by the user. Also, the quasibinomial and quasipoisson families differ from the binomial and poisson families only in that the dipsersion parameter is estimated to account for overdispersion.

For quasi, dev.resid is m*(y - mu)^2 . For quasibinomial and quasipoisson, dev.resid is the same as for quasibinomial and quasipoisson, respectively. The aic is NA for all quasi families. See quasi for more details.

The enrich method can enrich family family objects with extra characteristics of the family and of the chosen link function. See enrich.link-glm for the enrichment of link-glm objects.

Value

The object object of class family with extra components. get_enrichment_options.family() returns the components and their descriptions.

Examples

1
2
3
4
5
6
7
8
9
## An example from ?glm to illustrate that things still work with
## enriched families
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
print(d.AD <- data.frame(treatment, outcome, counts))
glm.D93 <- glm(counts ~ outcome + treatment, family = enrich(poisson()))
anova(glm.D93)
summary(glm.D93)