R/qgev.R

Defines functions qgev

Documented in qgev

#' @rdname dgev
#' @export
qgev <- function(p, mu, sigma, xi, lower.tail=TRUE, log.p=FALSE){
  ## this code is trickier than it looks.

  ## we use G ~ (exp(-xi log E) - 1) / xi

  ## there's no argument checking in qexp, so we do this to match the
  ## existing behaviour

  if (length(log.p) > 1){
    stop("log.p must have length 1")
  } else if ((!log.p)){
    if (any((p < 0) | any(p > 1))) {
      stop("p must lie between 0 and 1 if log.p=FALSE")
    }
  }

  ## get the quantiles of the standard exponential
  ## change the sense of lower tail (the minus sign above)

  neg.exp.quantiles <- -log(qexp(p, lower.tail=!lower.tail,
                                 log.p=log.p))
  standard.gev <- .exprel(neg.exp.quantiles * xi) * neg.exp.quantiles

  ## and now shift and scale
  mu + sigma * standard.gev
}

Try the texmex package in your browser

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

texmex documentation built on June 22, 2024, 12:26 p.m.