R/inv_link.R

Defines functions inv_link

Documented in inv_link

#' Inverse of the link functions
#'
#' @description Computes the inverse of the link function according to the
#' distribution family specified in the \code{"family"} parameter.
#' @author Ines Ortega-Fernandez, Marta Sestelo.
#' @param family A description of the link function used in the model:
#' \code{"gaussian"} or \code{"binomial"}
#' @param muhat fitted values
#' @return the inverse link function specified by the \code{"family"}
#' distribution for the given fitted values
#' @keywords internal
inv_link <- function(family, muhat) {

  if (missing(muhat)) {
    stop("Argument \"muhat\" is missing, with no default")
  }

  if (missing(family)) {
    stop("Argument \"family\" is missing, with no default")
  }

  if (family != "gaussian" & family != "binomial") {
    stop("Unsupported distribution family. Supported values are \"gaussian\" and \"binomial\"")
  }


  if (family == "gaussian") {
    out <- muhat
  }
  if (family == "binomial") {
    d <- 1 - muhat
    d[d <= 0.001] <- 0.001
    d[d >= 0.999] <- 0.999
    out <- log(muhat / d)
  }

  return(out)
}

Try the neuralGAM package in your browser

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

neuralGAM documentation built on June 22, 2024, 6:55 p.m.