R/inverse_link.R

Defines functions inverse_link

Documented in inverse_link

#' Inverse link function, used for GLM fitting.
#'
#' @param x scalar, vector, or matrix input.
#' @param link the link function, one of \code{"identity"}, \code{"log"}, \code{"sqrt"},
#' \code{"logit"}, \code{"probit"}, \code{"cloglog"}, \code{"loglog"}, \code{"reciprocal"};
#' quotes are needed (default \code{"identity"}).
#'
#' @return The inverse link function applied to \code{x}.
#' If \code{link} is not in the above list of allowed  names, \code{NULL} will be returned.
#'
#' @export
#'
inverse_link <- function(x, link) {
  switch(link,
         identity = x,
         logit = 1 / (1 + exp(-x)),
         probit = pnorm(x),
         cloglog = (1 - exp(-exp(x))),
         loglog = exp(-exp(-x)),
         sqrt = x ^ 2,
         log = exp(x),
         reciprocal = 1 /x
        )
}

Try the JOPS package in your browser

Any scripts or data that you put into this service are public.

JOPS documentation built on Sept. 8, 2023, 5:42 p.m.