hssm.Link
hssm.Link ¶
Link(
name,
link=None,
linkinv=None,
linkinv_backend=None,
bounds: tuple[float, float] | None = None,
)
Bases: Link
Representation of a generalized link function.
This object contains two main functions. One is the link function itself, the function that maps values in the response scale to the linear predictor, and the other is the inverse of the link function, that maps values of the linear predictor to the response scale.
The great majority of users will never interact with this class unless they want to
create a custom Family with a custom Link. This is automatically handled for
all the built-in families.
Parameters:
-
name–The name of the link function. If it is a known name, it's not necessary to pass any other arguments because functions are already defined internally. If not known, all of
ink,linkinvandlinkinv_backendmust be specified. -
link(optional, default:None) –A numerical function that maps the response to the linear predictor. Known as the :math:
gfunction in GLM jargon. This function operates outside the PyMC graph and does not need to support PyTensor tensors. It does not need to be specified whennameis a known name. -
linkinv(optional, default:None) –A numerical function that maps the linear predictor to the response. Known as the :math:
g^{-1}function in GLM jargon, it is used for operations such as posterior prediction outside the PyMC graph. It does not need to be specified whennameis a known name. -
linkinv_backend(optional, default:None) –The symbolic inverse link used to build the PyMC graph. It must accept PyTensor tensors and return a symbolic PyTensor expression. It does not need to be specified when
nameis a known name because Bambi supplies the backend implementation for built-in links. -
bounds(optional, default:None) –Bounds of the response scale. Only needed when
nameisgen_logit.
Examples:
Use any link name supported by Bambi:
A custom link requires forward, inverse, and PyTensor-compatible inverse functions:
>>> import numpy as np
>>> import pytensor.tensor as pt
>>> custom_log = hssm.Link(
... "custom_log",
... link=np.log, # Numerical: response -> linear predictor
... linkinv=np.exp, # Numerical: predictions outside the PyMC graph
... linkinv_backend=pt.exp, # Symbolic: used inside the PyMC graph
... )
HSSM also provides a generalized logit for bounded response scales: