Skip to contents

Returns the link or its inverse from an estimated model, and provides a simple way to extract these functions from complex models with multiple links, such as location scale models.

Usage

link(object, ...)

# S3 method for family
link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for gam
link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for bam
link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for gamm
link(object, ...)

# S3 method for glm
link(object, ...)

# S3 method for list
link(object, ...)

inv_link(object, ...)

# S3 method for family
inv_link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for gam
inv_link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for bam
inv_link(object, parameter = NULL, which_eta = NULL, ...)

# S3 method for gamm
inv_link(object, ...)

# S3 method for list
inv_link(object, ...)

# S3 method for glm
inv_link(object, ...)

extract_link(family, ...)

# S3 method for family
extract_link(family, inverse = FALSE, ...)

# S3 method for general.family
extract_link(family, parameter, inverse = FALSE, which_eta = NULL, ...)

Arguments

object

a family object or a fitted model from which to extract the family object. Models fitted by stats::glm(), mgcv::gam(), mgcv::bam(), mgcv::gamm(), and gamm4::gamm4() are currently supported.

...

arguments passed to other methods.

parameter

character; which parameter of the distribution. Usually "location" but "scale" and "shape" may be provided for location scale models. Other options include "mu" as a synonym for "location", "sigma" for the scale parameter in mgcv::gaulss(), "pi" for the zero-inflation term in mgcv::ziplss(), "power" for the mgcv::twlss() power parameter, "xi", the shape parameter for mgcv::gevlss(), "epsilon" or "skewness" for the skewness and "delta" or "kurtosis" for the kurtosis parameter for mgcv::shash(), or "phi" for the scale parameter of mgcv::gammals() & mgcv::twlss().

which_eta

numeric; the linear predictor to extract for families mgcv::mvn() and mgcv::multinom().

family

a family object, the result of a call to family().

inverse

logical; return the inverse of the link function?

Author

Gavin L. Simpson

Examples

load_mgcv()

link(gaussian())
#> function (mu) 
#> mu
#> <environment: namespace:stats>
link(nb())
#> function (mu) 
#> log(mu)
#> <environment: namespace:stats>

inv_link(nb())
#> function (eta) 
#> pmax(exp(eta), .Machine$double.eps)
#> <environment: namespace:stats>

dat <- data_sim("eg1", seed = 4234)
mod <- gam(list(y ~ s(x0) + s(x1) + s(x2) + s(x3), ~1),
  data = dat,
  family = gaulss
)

link(mod, parameter = "scale")
#> function (mu) 
#> log(1/mu - 0.01)
#> <environment: 0x55e45c2d8d58>
inv_link(mod, parameter = "scale")
#> function (eta) 
#> 1/(exp(eta) + 0.01)
#> <environment: 0x55e45c2d8d58>

## Works with `family` objects too
link(shash(), parameter = "skewness")
#> function (mu) 
#> mu
#> <environment: namespace:stats>