|
| 1 | +#' Estimate parameters of the Generalized Pareto distribution |
| 2 | +#' |
| 3 | +#' Given a sample \eqn{x}, Estimate the parameters \eqn{k} and \eqn{\sigma} of |
| 4 | +#' the generalized Pareto distribution (GPD), assuming the location parameter is |
| 5 | +#' 0. By default the fit uses a prior for \eqn{k}, which will stabilize |
| 6 | +#' estimates for very small sample sizes (and low effective sample sizes in the |
| 7 | +#' case of MCMC samples). The weakly informative prior is a Gaussian prior |
| 8 | +#' centered at 0.5. |
| 9 | +#' |
| 10 | +#' @export |
| 11 | +#' @param x A numeric vector. The sample from which to estimate the parameters. |
| 12 | +#' @param wip Logical indicating whether to adjust \eqn{k} based on a weakly |
| 13 | +#' informative Gaussian prior centered on 0.5. Defaults to `TRUE`. |
| 14 | +#' @param min_grid_pts The minimum number of grid points used in the fitting |
| 15 | +#' algorithm. The actual number used is `min_grid_pts + floor(sqrt(length(x)))`. |
| 16 | +#' @param sort_x If `TRUE` (the default), the first step in the fitting |
| 17 | +#' algorithm is to sort the elements of `x`. If `x` is already |
| 18 | +#' sorted in ascending order then `sort_x` can be set to `FALSE` to |
| 19 | +#' skip the initial sorting step. |
| 20 | +#' @return A named list with components `k` and `sigma`. |
| 21 | +#' |
| 22 | +#' @details Here the parameter \eqn{k} is the negative of \eqn{k} in Zhang & |
| 23 | +#' Stephens (2009). |
| 24 | +#' |
| 25 | +#' @seealso [psis()], [pareto-k-diagnostic] |
| 26 | +#' |
| 27 | +#' @references |
| 28 | +#' Zhang, J., and Stephens, M. A. (2009). A new and efficient estimation method |
| 29 | +#' for the generalized Pareto distribution. *Technometrics* **51**, 316-325. |
| 30 | +#' |
| 31 | +gpdfit <- function(x, wip = TRUE, min_grid_pts = 30, sort_x = TRUE) { |
| 32 | + posterior::gpdfit( |
| 33 | + x = x, |
| 34 | + wip = wip, |
| 35 | + min_grid_pts = min_grid_pts, |
| 36 | + sort_x = sort_x |
| 37 | + ) |
| 38 | +} |
0 commit comments