View source: R/make_link_structure.R
| make_link_structure | R Documentation |
A helper function that constructs a list containing the link function, its inverse, and the derivative of the mean function. It extends the standard 'make.link' by adding support for the "loglog" link.
make_link_structure(link = link)
link |
A character string specifying the name of the link function. Accepted values are '"logit"', '"probit"', '"cloglog"', and '"loglog"'. |
This function is primarily used internally by the 'barma()' function to process the 'link' argument. It standardizes the way link functions are handled within the model fitting process.
For the "logit", "probit", and "cloglog" links, the function acts as a wrapper around the base R 'make.link'.
For the "loglog" link, which is not available in 'make.link', the necessary components are defined explicitly:
Link function: g(\mu) = -\log(-\log(\mu))
Inverse link function: g^{-1}(\eta) = \exp(-\exp(-\eta))
Derivative \frac{d\mu}{d\eta}: \exp(-\exp(-\eta)) \times \exp(-\eta)
If an unsupported link is provided, the function will stop and return an error message listing the available options.
A list with three components:
linkfun |
The link function, which transforms the mean |
linkinv |
The inverse link function, which transforms the linear predictor |
mu.eta |
The derivative of the inverse link function with respect to |
Original R code by: Fabio M. Bayer (Federal University of Santa Maria, <bayer@ufsm.br>) Modified and improved by: Everton da Costa (Federal University of Pernambuco, <everto.cost@gmail.com>)
barma, make.link
# --- Create a logit link structure ---
logit_link <- make_link_structure(link = "logit")
# Apply the link function
mu <- 0.5
eta <- logit_link$linkfun(mu)
print(eta) # Should be 0
# Apply the inverse link function
mu_restored <- logit_link$linkinv(eta)
print(mu_restored) # Should be 0.5
# --- Create a loglog link structure ---
loglog_link <- make_link_structure(link = "loglog")
# Apply the loglog link function
mu_loglog <- 0.8
eta_loglog <- loglog_link$linkfun(mu_loglog)
print(eta_loglog)
# Apply the inverse loglog link function
mu_restored_loglog <- loglog_link$linkinv(eta_loglog)
print(mu_restored_loglog) # Should be ~0.8
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.