Title: | Ratio-of-Uniforms Sampling for Bayesian Extreme Value Analysis |
---|---|
Description: | Provides functions for the Bayesian analysis of extreme value models. The 'rust' package <https://cran.r-project.org/package=rust> is used to simulate a random sample from the required posterior distribution. The functionality of 'revdbayes' is similar to the 'evdbayes' package <https://cran.r-project.org/package=evdbayes>, which uses Markov Chain Monte Carlo ('MCMC') methods for posterior simulation. In addition, there are functions for making inferences about the extremal index, using the models for threshold inter-exceedance times of Suveges and Davison (2010) <doi:10.1214/09-AOAS292> and Holesovsky and Fusek (2020) <doi:10.1007/s10687-020-00374-3>. Also provided are d,p,q,r functions for the Generalised Extreme Value ('GEV') and Generalised Pareto ('GP') distributions that deal appropriately with cases where the shape parameter is very close to zero. |
Authors: | Paul J. Northrop [aut, cre, cph], Scott D. Grimshaw [ctb] |
Maintainer: | Paul J. Northrop <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.5.5 |
Built: | 2024-11-21 02:51:36 UTC |
Source: | https://github.com/paulnorthrop/revdbayes |
Uses the multivariate generalized ratio-of-uniforms method to simulate random samples from the posterior distributions commonly encountered in Bayesian extreme value analyses.
The main functions in the revdbayes package are rpost
and rpost_rcpp
, which simulate random samples from the
posterior distribution of extreme value model parameters using the
functions ru
and ru_rcpp
from the rust package, respectively. The user chooses the extreme value
model, the prior density for the parameters and provides the data.
There are options to improve the probability of acceptance of the
ratio-of-uniforms algorithm by working with transformation of the model
parameters.
The functions kgaps_post
and dgaps_post
simulate from the posterior distribution of the extremal index
based on the K-gaps model for threshold interexceedance
times of Suveges and Davison (2010) and the similar D-gaps model of
Holesovsky and Fusek (2020). See also Attalides (2015).
See vignette("revdbayes-a-vignette", package = "revdbayes")
for an
overview of the package and
vignette("revdbayes-b-using-rcpp-vignette", package = "revdbayes")
for an illustration of the improvements in efficiency produced using
the Rcpp package.
See
vignette("revdbayes-c-predictive-vignette", package = "revdbayes")
for an outline of how to use revdbayes to perform posterior predictive
extreme value inference and
vignette("revdbayes-d-kgaps-vignette", package = "revdbayes")
considers Bayesian inference for the extremal index
using threshold inter-exceedance times.
Maintainer: Paul J. Northrop [email protected] [copyright holder]
Other contributors:
Scott D. Grimshaw [contributor]
Holesovsky, J. and Fusek, M. Estimation of the extremal index using censored distributions. Extremes 23, 197-213 (2020). doi:10.1007/s10687-020-00374-3
Northrop, P. J. (2016). rust: Ratio-of-Uniforms Simulation with Transformation. R package version 1.2.2. https://cran.r-project.org/package=rust.
Suveges, M. and Davison, A. C. (2010) Model misspecification in peaks over threshold analysis, The Annals of Applied Statistics, 4(1), 203-221. doi:10.1214/09-AOAS292
Attalides, N. (2015) Threshold-based extreme value modelling, PhD thesis, University College London. https://discovery.ucl.ac.uk/1471121/1/Nicolas_Attalides_Thesis.pdf
set_prior
to set a prior density for extreme value
parameters.
rpost
and rpost_rcpp
to perform
ratio-of-uniforms sampling from an extreme value posterior distribution.
kgaps_post
and dgaps_post
to sample
from a posterior distribution for the extremal index based on
inter-exceedance times.
The ru
and ru_rcpp
functions in the rust
package for details of the arguments
that can be passed to ru
via rpost
and for the form of the
object (of class "evpost"
) returned from rpost
, which has the same
structure as an object (of class "ru"
) returned by ru
and
ru_rcpp
.
Samples from the posterior distribution of the probability
of a binomial distribution.
binpost(n, prior, ds_bin, param = c("logit", "p"))
binpost(n, prior, ds_bin, param = c("logit", "p"))
n |
A numeric scalar. The size of posterior sample required. |
prior |
A function to evaluate the prior, created by
|
ds_bin |
A numeric list. Sufficient statistics for inference
about a binomial probability
|
param |
A character scalar. Only relevant if If If The latter tends to make the optimizations involved in the ratio-of-uniforms algorithm more stable and to increase the probability of acceptance, but at the expense of slower function evaluations. |
If prior$prior == "bin_beta"
then the posterior for
is a beta distribution so
rbeta
is used to
sample from the posterior.
If prior$prior == "bin_mdi"
then
rejection sampling is used to sample from the posterior with an envelope
function equal to the density of a
beta(ds$m
+ 1, ds$n_raw - ds$m
+ 1) density.
If prior$prior == "bin_northrop"
then
rejection sampling is used to sample from the posterior with an envelope
function equal to the posterior density that results from using a
Haldane prior.
If prior$prior
is a (user-supplied) R function then
ru
is used to sample from the posterior using the
generalised ratio-of-uniforms method.
An object (list) of class "binpost"
with components
bin_sim_vals: |
An |
bin_logf: |
A function returning the log-posterior for
|
bin_logf_args: |
A list of arguments to |
If prior$prior
is a (user-supplied) R function then this list
also contains ru_object
the object of class "ru"
returned by ru
.
set_bin_prior
for setting a prior distribution
for the binomial probability .
u <- quantile(gom, probs = 0.65) ds_bin <- list() ds_bin$n_raw <- length(gom) ds_bin$m <- sum(gom > u) bp <- set_bin_prior(prior = "jeffreys") temp <- binpost(n = 1000, prior = bp, ds_bin = ds_bin) graphics::hist(temp$bin_sim_vals, prob = TRUE) # Setting a beta prior (Jeffreys in this case) by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) temp <- binpost(n = 1000, prior = jeffreys, ds_bin = ds_bin)
u <- quantile(gom, probs = 0.65) ds_bin <- list() ds_bin$n_raw <- length(gom) ds_bin$m <- sum(gom > u) bp <- set_bin_prior(prior = "jeffreys") temp <- binpost(n = 1000, prior = bp, ds_bin = ds_bin) graphics::hist(temp$bin_sim_vals, prob = TRUE) # Setting a beta prior (Jeffreys in this case) by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) temp <- binpost(n = 1000, prior = jeffreys, ds_bin = ds_bin)
This function provides an example of a way in which a user can specify
their own prior density to rpost_rcpp
.
More specifically, a function like this (the user will need to create
an edited version tailored to their own C++ function(s)) can be used to
generate an external pointer to a compiled C++ function that evaluates
the log-prior density. Please see the vignette
"Faster simulation using revdbayes" for more information.
create_prior_xptr(fstr)
create_prior_xptr(fstr)
fstr |
A string indicating the C++ function required. |
Suppose that the user's C++ functions are in a file called "user_fns.cpp".
These functions must be compiled and made available to R before the
pointer is created. This can be achieved using the function
sourceCpp
in the Rcpp package
or using RStudio's Source button on the editor toolbar.
For details see the examples in the documentation of the functions
rpost_rcpp
and set_prior
,
the vignette "Faster simulation using revdbayes"
and the vignette "Rusting Faster: Simulation using Rcpp" in the package
rust.
An external pointer.
set_prior
to specify a prior distribution using
an external pointer returned by create_prior_xptr
and for
details of in-built named prior distributions.
The examples in the documentation of rpost_rcpp
.
ptr_gp_flat <- create_prior_xptr("gp_flat") prior_cfn <- set_prior(prior = ptr_gp_flat, model = "gp", min_xi = -1) ptr_gev_flat <- create_prior_xptr("gev_flat") prior_cfn <- set_prior(prior = ptr_gev_flat, model = "gev", min_xi = -1, max_xi = Inf) mat <- diag(c(10000, 10000, 100)) ptr_gev_norm <- create_prior_xptr("gev_norm") pn_u <- set_prior(prior = ptr_gev_norm, model = "gev", mean = c(0,0,0), icov = solve(mat))
ptr_gp_flat <- create_prior_xptr("gp_flat") prior_cfn <- set_prior(prior = ptr_gp_flat, model = "gp", min_xi = -1) ptr_gev_flat <- create_prior_xptr("gev_flat") prior_cfn <- set_prior(prior = ptr_gev_flat, model = "gev", min_xi = -1, max_xi = Inf) mat <- diag(c(10000, 10000, 100)) ptr_gev_norm <- create_prior_xptr("gev_norm") pn_u <- set_prior(prior = ptr_gev_norm, model = "gev", mean = c(0,0,0), icov = solve(mat))
Uses the rust
package to simulate from the posterior
distribution of the extremal index based on the D-gaps model
for threshold interexceedance times of Holesovsky and Fusek (2020). We refer
to this as the
-gaps model, because it uses a tuning parameter
, whereas the related
-gaps model of Suveges and Davison
(2010) has a tuning parameter
.
dgaps_post( data, thresh, D = 1, n = 1000, inc_cens = TRUE, alpha = 1, beta = 1, param = c("logit", "theta"), use_rcpp = TRUE )
dgaps_post( data, thresh, D = 1, n = 1000, inc_cens = TRUE, alpha = 1, beta = 1, param = c("logit", "theta"), use_rcpp = TRUE )
data |
A numeric vector or numeric matrix of raw data. If If |
thresh |
A numeric scalar. Extreme value threshold applied to data. |
D |
A numeric scalar. The censoring parameter |
n |
A numeric scalar. The size of posterior sample required. |
inc_cens |
A logical scalar indicating whether or not to include
contributions from right-censored inter-exceedance times, relating to the
first and last observations. It is known that these times are greater
than or equal to the time observed.
If |
alpha , beta
|
Positive numeric scalars. Parameters of a
beta( |
param |
A character scalar. If |
use_rcpp |
A logical scalar. If |
A beta(,
) prior distribution is used for
so that the posterior from which values are simulated is
proportional to
See dgaps_stat
for a description of the variables
involved in the contribution of the likelihood to this expression.
The ru
function in the rust
package simulates from this posterior distribution using the
generalised ratio-of-uniforms distribution. To improve the probability
of acceptance, and to ensure that the simulation will work even in
extreme cases where the posterior density of is unbounded as
approaches 0 or 1, we simulate from the posterior
distribution of
and then transform back to the
-scale.
An object (list) of class "evpost"
, which has the same
structure as an object of class "ru"
returned from
ru
.
In addition this list contains
call
: The call to dgaps()
.
model
: The character scalar "dgaps"
.
thresh
: The argument thresh
.
ss
: The sufficient statistics for the D-gaps likelihood,
as calculated by dgaps_stat
.
Holesovsky, J. and Fusek, M. Estimation of the extremal index using censored distributions. Extremes 23, 197-213 (2020). doi:10.1007/s10687-020-00374-3
Suveges, M. and Davison, A. C. (2010) Model misspecification in peaks over threshold analysis, The Annals of Applied Statistics, 4(1), 203-221. doi:10.1214/09-AOAS292
ru
for the form of the object returned by
dgaps_post
.
kgaps_post
for Bayesian inference about the
extremal index using the
-gaps model.
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) d_postsim <- dgaps_post(newlyn, thresh) plot(d_postsim) ### Cheeseboro wind gusts d_postsim <- dgaps_post(exdex::cheeseboro, thresh = 45, D = 3) plot(d_postsim)
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) d_postsim <- dgaps_post(newlyn, thresh) plot(d_postsim) ### Cheeseboro wind gusts d_postsim <- dgaps_post(exdex::cheeseboro, thresh = 45, D = 3) plot(d_postsim)
Density function, distribution function, quantile function and random generation for the generalised extreme value (GEV) distribution.
dgev(x, loc = 0, scale = 1, shape = 0, log = FALSE, m = 1) pgev(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE, m = 1) qgev(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE, m = 1) rgev(n, loc = 0, scale = 1, shape = 0, m = 1)
dgev(x, loc = 0, scale = 1, shape = 0, log = FALSE, m = 1) pgev(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE, m = 1) qgev(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE, m = 1) rgev(n, loc = 0, scale = 1, shape = 0, m = 1)
x , q
|
Numeric vectors of quantiles. |
loc , scale , shape
|
Numeric vectors.
Location, scale and shape parameters.
All elements of |
log , log.p
|
A logical scalar; if TRUE, probabilities p are given as log(p). |
m |
A numeric scalar. The distribution is reparameterised by working
with the GEV( |
lower.tail |
A logical scalar. If TRUE (default), probabilities
are |
p |
A numeric vector of probabilities in [0,1]. |
n |
Numeric scalar. The number of observations to be simulated.
If |
The distribution function of a GEV distribution with parameters
loc
= ,
scale
= and
shape
= is
for . If
the
distribution function is defined as the limit as
tends to zero.
The support of the distribution depends on
: it is
for
;
for
;
and
is unbounded for
.
Note that if
the GEV density function becomes infinite
as
approaches
from below.
If lower.tail = TRUE
then if p = 0
(p = 1
) then
the lower (upper) limit of the distribution is returned, which is
-Inf
or Inf
in some cases. Similarly, but reversed,
if lower.tail = FALSE
.
See https://en.wikipedia.org/wiki/Generalized_extreme_value_distribution for further information.
The effect of m
is to change the location, scale and shape
parameters to
if
and
.
For integer
m
we can think of this as working with the
maximum of m
independent copies of the original
GEV(loc, scale, shape
) variable.
dgev
gives the density function, pgev
gives the
distribution function, qgev
gives the quantile function,
and rgev
generates random deviates.
The length of the result is determined by n
for rgev
,
and is the maximum of the lengths of the numerical arguments for the
other functions.
The numerical arguments other than n
are recycled to the length
of the result.
Jenkinson, A. F. (1955) The frequency distribution of the annual maximum (or minimum) of meteorological elements. Quart. J. R. Met. Soc., 81, 158-171. doi:10.1002/qj.49708134804
Coles, S. G. (2001) An Introduction to Statistical Modeling of Extreme Values, Springer-Verlag, London. Chapter 3: doi:10.1007/978-1-4471-3675-0_3
dgev(-1:4, 1, 0.5, 0.8) dgev(1:6, 1, 0.5, -0.2, log = TRUE) dgev(1, shape = c(-0.2, 0.4)) pgev(-1:4, 1, 0.5, 0.8) pgev(1:6, 1, 0.5, -0.2) pgev(1, c(1, 2), c(1, 2), c(-0.2, 0.4)) pgev(-3, c(1, 2), c(1, 2), c(-0.2, 0.4)) pgev(7, 1, 1, c(-0.2, 0.4)) qgev((1:9)/10, 2, 0.5, 0.8) qgev(0.5, c(1,2), c(0.5, 1), c(-0.5, 0.5)) p <- (1:9)/10 pgev(qgev(p, 1, 2, 0.8), 1, 2, 0.8) rgev(6, 1, 0.5, 0.8)
dgev(-1:4, 1, 0.5, 0.8) dgev(1:6, 1, 0.5, -0.2, log = TRUE) dgev(1, shape = c(-0.2, 0.4)) pgev(-1:4, 1, 0.5, 0.8) pgev(1:6, 1, 0.5, -0.2) pgev(1, c(1, 2), c(1, 2), c(-0.2, 0.4)) pgev(-3, c(1, 2), c(1, 2), c(-0.2, 0.4)) pgev(7, 1, 1, c(-0.2, 0.4)) qgev((1:9)/10, 2, 0.5, 0.8) qgev(0.5, c(1,2), c(0.5, 1), c(-0.5, 0.5)) p <- (1:9)/10 pgev(qgev(p, 1, 2, 0.8), 1, 2, 0.8) rgev(6, 1, 0.5, 0.8)
For information about this and other priors see set_prior
.
gev_beta(pars, min_xi = -1/2, max_xi = 1/2, pq = c(6, 9), trendsd = 0)
gev_beta(pars, min_xi = -1/2, max_xi = 1/2, pq = c(6, 9), trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
pq |
A numeric vector of length 2.
See |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gev_flat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_flat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gev_flatflat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_flatflat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gev_loglognorm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_loglognorm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
mean |
A numeric vector of length 3. Prior mean. |
icov |
A 3x3 numeric matrix. The inverse of the prior covariance matrix. |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gev_mdi(pars, a = 0.577215664901532, min_xi = -1, max_xi = Inf, trendsd = 0)
gev_mdi(pars, a = 0.577215664901532, min_xi = -1, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
a |
A numeric scalar. The default value, Euler's constant, gives the MDI prior. |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gev_norm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_norm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
mean |
A numeric vector of length 3. Prior mean. |
icov |
A 3x3 numeric matrix. The inverse of the prior covariance matrix. |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
Constructs an informative prior for GEV parameters (),
constructed on the probability scale. For information about how to set this
prior see
set_prior
.
gev_prob(pars, quant, alpha, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_prob(pars, quant, alpha, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
quant |
A numeric vector of length 3 containing quantiles
( |
alpha |
A numeric vector of length 4. Parameters specifying a
prior distribution for probabilities related to the quantiles in
|
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
A prior for GEV parameters ,
based on Crowder (1992). This construction is typically used to set
an informative prior, based on specified quantiles
.
There are two interpretations of the parameter vector
alpha
= :
as the parameters of beta distributions for ratio of exceedance
probabilities (Stephenson, 2016) and as the parameters of a Dirichlet
distribution for differences between non-exceedance probabilities
(Northrop et al., 2017). See these publications for details.
The log of the prior density.
Crowder, M. (1992) Bayesian priors based on parameter transformation using the distribution function Ann. Inst. Statist. Math., 44, 405-416. https://link.springer.com/article/10.1007/BF00050695.
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Stephenson, A. (2016) Bayesian inference for extreme value modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications (eds D. K. Dey and J. Yan), 257-280, Chapman and Hall, London. doi:10.1201/b19721.
set_prior
for setting a prior distribution.
rpost
and rpost_rcpp
for sampling
from an extreme value posterior distribution.
Sets the same prior as the function
prior.prob
in the evdbayes package.
Informative GEV prior for GEV parameters ()
constructed on the quantile scale. For information about how to set this
prior see
set_prior
.
gev_quant(pars, prob, shape, scale, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gev_quant(pars, prob, shape, scale, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 3.
GEV parameters ( |
prob |
A numeric vector of length 3 containing exceedance
probabilities ( |
shape , scale
|
Numeric vectors of length 3. Shape and scale
parameters specifying (independent) gamma prior distributions placed
on the differences between the quantiles corresponding to the
probabilities given in |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
See Coles and Tawn (1996) and/or Stephenson (2016) for details.
Note that the lower end point of the distribution of the distribution of the variable in question is assumed to be equal to zero. If this is not the case then the user should shift the data to ensure that this is true.
The log of the prior density.
Coles, S. G. and Tawn, J. A. (1996) A Bayesian analysis of extreme rainfall data. Appl. Statist., 45, 463-478.
Stephenson, A. (2016) Bayesian inference for extreme value modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications (eds D. K. Dey and J. Yan), 257-280, Chapman and Hall, London. doi:10.1201/b19721.
A numeric vector containing 315 hindcasts of storm peak significant wave heights, metres, from 1900 to 2005 at an unnamed location in the Gulf of Mexico.
gom
gom
A vector containing 315 observations.
Oceanweather Inc. (2005) GOMOS – Gulf of Mexico hindcast study.
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Density function, distribution function, quantile function and random generation for the generalised Pareto (GP) distribution.
dgp(x, loc = 0, scale = 1, shape = 0, log = FALSE) pgp(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) qgp(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) rgp(n, loc = 0, scale = 1, shape = 0)
dgp(x, loc = 0, scale = 1, shape = 0, log = FALSE) pgp(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) qgp(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) rgp(n, loc = 0, scale = 1, shape = 0)
x , q
|
Numeric vectors of quantiles. All elements of |
loc , scale , shape
|
Numeric vectors.
Location, scale and shape parameters.
All elements of |
log , log.p
|
A logical scalar; if TRUE, probabilities p are given as log(p). |
lower.tail |
A logical scalar. If TRUE (default), probabilities
are |
p |
A numeric vector of probabilities in [0,1]. |
n |
Numeric scalar. The number of observations to be simulated.
If |
The distribution function of a GP distribution with parameters
location
= ,
scale
= and
shape
= is
for . If
the
distribution function is defined as the limit as
tends to zero.
The support of the distribution depends on
: it is
for
; and
for
. Note that if
the GP density function
becomes infinite as
approaches
.
If lower.tail = TRUE
then if p = 0
(p = 1
) then
the lower (upper) limit of the distribution is returned.
The upper limit is Inf
if shape
is non-negative.
Similarly, but reversed, if lower.tail = FALSE
.
See https://en.wikipedia.org/wiki/Generalized_Pareto_distribution for further information.
dgp
gives the density function, pgp
gives the
distribution function, qgp
gives the quantile function,
and rgp
generates random deviates.
Pickands, J. (1975) Statistical inference using extreme order statistics. Annals of Statistics, 3, 119-131. doi:10.1214/aos/1176343003
Coles, S. G. (2001) An Introduction to Statistical Modeling of Extreme Values, Springer-Verlag, London. Chapter 4: doi:10.1007/978-1-4471-3675-0_4
dgp(0:4, scale = 0.5, shape = 0.8) dgp(1:6, scale = 0.5, shape = -0.2, log = TRUE) dgp(1, scale = 1, shape = c(-0.2, 0.4)) pgp(0:4, scale = 0.5, shape = 0.8) pgp(1:6, scale = 0.5, shape = -0.2) pgp(1, scale = c(1, 2), shape = c(-0.2, 0.4)) pgp(7, scale = 1, shape = c(-0.2, 0.4)) qgp((0:9)/10, scale = 0.5, shape = 0.8) qgp(0.5, scale = c(0.5, 1), shape = c(-0.5, 0.5)) p <- (1:9)/10 pgp(qgp(p, scale = 2, shape = 0.8), scale = 2, shape = 0.8) rgp(6, scale = 0.5, shape = 0.8)
dgp(0:4, scale = 0.5, shape = 0.8) dgp(1:6, scale = 0.5, shape = -0.2, log = TRUE) dgp(1, scale = 1, shape = c(-0.2, 0.4)) pgp(0:4, scale = 0.5, shape = 0.8) pgp(1:6, scale = 0.5, shape = -0.2) pgp(1, scale = c(1, 2), shape = c(-0.2, 0.4)) pgp(7, scale = 1, shape = c(-0.2, 0.4)) qgp((0:9)/10, scale = 0.5, shape = 0.8) qgp(0.5, scale = c(0.5, 1), shape = c(-0.5, 0.5)) p <- (1:9)/10 pgp(qgp(p, scale = 2, shape = 0.8), scale = 2, shape = 0.8) rgp(6, scale = 0.5, shape = 0.8)
For information about this and other priors see set_prior
.
gp_beta(pars, min_xi = -1/2, max_xi = 1/2, pq = c(6, 9), trendsd = 0)
gp_beta(pars, min_xi = -1/2, max_xi = 1/2, pq = c(6, 9), trendsd = 0)
pars |
A numeric vector of length 2.
GP parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
pq |
A numeric vector of length 2.
See |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gp_flat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gp_flat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 2.
GP parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gp_flatflat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0, upper = NULL)
gp_flatflat(pars, min_xi = -Inf, max_xi = Inf, trendsd = 0, upper = NULL)
pars |
A numeric vector of length 2.
GP parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
upper |
A positive numeric scalar. The upper endpoint of the GP distribution. |
The log of the prior density.
)For information about this and other priors see set_prior
.
gp_jeffreys(pars, min_xi = -1/2, max_xi = Inf, trendsd = 0)
gp_jeffreys(pars, min_xi = -1/2, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 2.
GP parameters ( |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
Uses the Linear Combinations of Ratios of Spacings (LRS) methodology of (Reiss and Thomas, 2007, page 134) to estimate the parameters of the generalised Pareto (GP) distribution, based on a sample of positive values.
gp_lrs(x)
gp_lrs(x)
x |
A numeric vector containing only positive values, assumed to be a random sample from a generalized Pareto distribution. |
A numeric vector of length 2. The estimates of the scale parameter
and the shape parameter
.
Reiss, R.-D., Thomas, M. (2007) Statistical Analysis of Extreme Values with Applications to Insurance, Finance, Hydrology and Other Fields.Birkhauser. doi:10.1007/978-3-7643-7399-3.
gp
for details of the parameterisation of the GP
distribution.
u <- quantile(gom, probs = 0.65) gp_lrs((gom - u)[gom > u])
u <- quantile(gom, probs = 0.65) gp_lrs((gom - u)[gom > u])
)For information about this and other priors see set_prior
.
gp_mdi(pars, a = 1, min_xi = -1, max_xi = Inf, trendsd = 0)
gp_mdi(pars, a = 1, min_xi = -1, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 2.
GP parameters ( |
a |
A numeric scalar. The default value of 1 gives the MDI prior. |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
Northrop, P.J. and Attalides, N. (2016) Posterior propriety in Bayesian extreme value analyses using reference priors Statistica Sinica, 26(2), 721–743 doi:10.5705/ss.2014.034.
)For information about this and other priors see set_prior
.
gp_norm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
gp_norm(pars, mean, icov, min_xi = -Inf, max_xi = Inf, trendsd = 0)
pars |
A numeric vector of length 2.
GP parameters ( |
mean |
A numeric vector of length 2. Prior mean. |
icov |
A 2x2 numeric matrix. The inverse of the prior covariance matrix. |
min_xi |
A numeric scalar. Prior lower bound on |
max_xi |
A numeric scalar. Prior upper bound on |
trendsd |
Has no function other than to achieve compatibility with function in the evdbayes package. |
The log of the prior density.
Uses the methodology of Hosking and Wallis (1987) to estimate the parameters of the generalised Pareto (GP) distribution.
gp_pwm(gp_data, u = 0)
gp_pwm(gp_data, u = 0)
gp_data |
A numeric vector of raw data, assumed to be a random sample from a probability distribution. |
u |
A numeric scalar. A threshold. The GP distribution is fitted to
the excesses of |
A list with components
est
: A numeric vector. PWM estimates of GP parameters
(scale) and
(shape).
se
: A numeric vector. Estimated standard errors of
and
.
cov
: A numeric matrix. Estimate covariance matrix of the
the PWM estimators of and
.
Hosking, J. R. M. and Wallis, J. R. (1987) Parameter and Quantile Estimation for the Generalized Pareto Distribution. Technometrics, 29(3), 339-349. doi:10.2307/1269343.
gp
for details of the parameterisation of the GP
distribution.
u <- quantile(gom, probs = 0.65) gp_pwm(gom, u)
u <- quantile(gom, probs = 0.65) gp_pwm(gom, u)
Uses the methodology of Grimshaw (1993) to find the MLEs of the parameters of the generalised Pareto distribution, based on a sample of positive values. The function is essentially the same as that made available with Grimshaw (1993), with only minor modifications.
grimshaw_gp_mle(x)
grimshaw_gp_mle(x)
x |
A numeric vector containing only positive values, assumed to be a random sample from a generalized Pareto distribution. |
A numeric vector of length 2. The estimates of the negated
shape parameter and the scale parameter
.
Grimshaw, S. D. (1993) Computing Maximum Likelihood Estimates for the Generalized Pareto Distribution. Technometrics, 35(2), 185-191. and Computing (1991) 1, 129-133. doi:10.1080/00401706.1993.10485040.
gp
for details of the parameterisation of the GP
distribution, in terms of and
.
u <- quantile(gom, probs = 0.65) grimshaw_gp_mle((gom - u)[gom > u])
u <- quantile(gom, probs = 0.65) grimshaw_gp_mle((gom - u)[gom > u])
Uses the rust
package to simulate from the posterior
distribution of the extremal index based on the K-gaps model
for threshold interexceedance times of Suveges and Davison (2010).
kgaps_post( data, thresh, k = 1, n = 1000, inc_cens = TRUE, alpha = 1, beta = 1, param = c("logit", "theta"), use_rcpp = TRUE )
kgaps_post( data, thresh, k = 1, n = 1000, inc_cens = TRUE, alpha = 1, beta = 1, param = c("logit", "theta"), use_rcpp = TRUE )
data |
A numeric vector or numeric matrix of raw data. If If |
thresh |
A numeric scalar. Extreme value threshold applied to data. |
k |
A numeric scalar. Run parameter |
n |
A numeric scalar. The size of posterior sample required. |
inc_cens |
A logical scalar indicating whether or not to include
contributions from right-censored inter-exceedance times, relating to the
first and last observations. It is known that these times are greater
than or equal to the time observed.
If |
alpha , beta
|
Positive numeric scalars. Parameters of a
beta( |
param |
A character scalar. If |
use_rcpp |
A logical scalar. If |
A beta(,
) prior distribution is used for
so that the posterior from which values are simulated is
proportional to
See kgaps_stat
for a description of the variables
involved in the contribution of the likelihood to this expression.
The ru
function in the rust
package simulates from this posterior distribution using the
generalised ratio-of-uniforms distribution. To improve the probability
of acceptance, and to ensure that the simulation will work even in
extreme cases where the posterior density of is unbounded as
approaches 0 or 1, we simulate from the posterior
distribution of
and then transform back to the
-scale.
An object (list) of class "evpost"
, which has the same
structure as an object of class "ru"
returned from
ru
.
In addition this list contains
call
: The call to kgaps()
.
model
: The character scalar "kgaps"
.
thresh
: The argument thresh
.
ss
: The sufficient statistics for the K-gaps likelihood,
as calculated by kgaps_stat
.
Suveges, M. and Davison, A. C. (2010) Model misspecification in peaks over threshold analysis, The Annals of Applied Statistics, 4(1), 203-221. doi:10.1214/09-AOAS292
ru
for the form of the object returned by
kgaps_post
.
dgaps_post
for Bayesian inference about the
extremal index using the
-gaps model.
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) k_postsim <- kgaps_post(newlyn, thresh) plot(k_postsim) ### Cheeseboro wind gusts k_postsim <- kgaps_post(exdex::cheeseboro, thresh = 45, k = 3) plot(k_postsim)
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) k_postsim <- kgaps_post(newlyn, thresh) plot(k_postsim) ### Cheeseboro wind gusts k_postsim <- kgaps_post(exdex::cheeseboro, thresh = 45, k = 3) plot(k_postsim)
The vector newlyn
contains 2894 maximum sea-surges measured at
Newlyn, Cornwall, UK over the period 1971-1976. The observations are
the maximum hourly sea-surge heights over contiguous 15-hour time
periods.
newlyn
newlyn
A vector of length 2894.
Coles, S.G. (1991) Modelling extreme multivariate events. PhD thesis, University of Sheffield, U.K.
Fawcett, L. and Walshaw, D. (2012) Estimating return levels from serially dependent extremes. Environmetrics, 23(3), 272-283. doi:10.1002/env.2133
Northrop, P. J. (2015) An efficient semiparametric maxima estimator of the extremal index. Extremes, 18, 585-603. doi:10.1007/s10687-015-0221-5
A numeric vector containing annual maximum temperatures, in degrees Fahrenheit, from 1901 to 1980 at Oxford, England.
oxford
oxford
A vector containing 80 observations.
Tabony, R. C. (1983) Extreme value analysis in meteorology. The Meteorological Magazine, 112, 77-98.
plot
method for class "evpost". For d = 1
a histogram of the
simulated values is plotted with a the density function superimposed.
The density is normalized crudely using the trapezium rule. For
d = 2
a scatter plot of the simulated values is produced with
density contours superimposed. For d > 2
pairwise plots of the
simulated values are produced.
An interface is also provided to the functions in the bayesplot
package that produce plots of Markov chain Monte Carlo (MCMC)
simulations. See MCMC-overview for details of these
functions.
## S3 method for class 'evpost' plot( x, y, ..., n = ifelse(x$d == 1, 1001, 101), prob = c(0.5, 0.1, 0.25, 0.75, 0.95, 0.99), ru_scale = FALSE, rows = NULL, xlabs = NULL, ylabs = NULL, points_par = list(col = 8), pu_only = FALSE, add_pu = FALSE, use_bayesplot = FALSE, fun_name = c("areas", "intervals", "dens", "hist", "scatter") )
## S3 method for class 'evpost' plot( x, y, ..., n = ifelse(x$d == 1, 1001, 101), prob = c(0.5, 0.1, 0.25, 0.75, 0.95, 0.99), ru_scale = FALSE, rows = NULL, xlabs = NULL, ylabs = NULL, points_par = list(col = 8), pu_only = FALSE, add_pu = FALSE, use_bayesplot = FALSE, fun_name = c("areas", "intervals", "dens", "hist", "scatter") )
x |
An object of class "evpost", a result of a call to
|
y |
Not used. |
... |
Additional arguments passed on to |
n |
A numeric scalar. Only relevant if
|
prob |
Numeric vector. Only relevant for d = 2. The contour lines are drawn such that the respective probabilities that the variable lies within the contour are approximately prob. |
ru_scale |
A logical scalar. Should we plot data and density on the scale used in the ratio-of-uniforms algorithm (TRUE) or on the original scale (FALSE)? |
rows |
A numeric scalar. When |
xlabs , ylabs
|
Numeric vectors. When |
points_par |
A list of arguments to pass to
|
pu_only |
Only produce a plot relating to the posterior distribution
for the threshold exceedance probability |
add_pu |
Before producing the plots add the threshold exceedance
probability |
use_bayesplot |
A logical scalar. If |
fun_name |
A character scalar. The name of the bayesplot function,
with the initial |
For details of the bayesplot functions available when
use_bayesplot = TRUE
see MCMC-overview and
the bayesplot vignette
Plotting MCMC draws.
Nothing is returned unless use_bayesplot = TRUE
when a
ggplot object, which can be further customized using the
ggplot2 package, is returned.
Jonah Gabry (2016). bayesplot: Plotting for Bayesian Models. R package version 1.1.0. https://CRAN.R-project.org/package=bayesplot
summary.evpost
for summaries of the simulated values
and properties of the ratio-of-uniforms algorithm.
MCMC-overview
,
MCMC-intervals
,
MCMC-distributions
.
## GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # Using the bayesplot package plot(gpg, use_bayesplot = TRUE) plot(gpg, use_bayesplot = TRUE, pars = "xi", prob = 0.95) plot(gpg, use_bayesplot = TRUE, fun_name = "intervals", pars = "xi") plot(gpg, use_bayesplot = TRUE, fun_name = "hist") plot(gpg, use_bayesplot = TRUE, fun_name = "dens") plot(gpg, use_bayesplot = TRUE, fun_name = "scatter") ## bin-GP posterior u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") npy_gom <- length(gom)/105 bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, npy = npy_gom) plot(bgpg) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Using the bayesplot package dimnames(bgpg$bin_sim_vals) plot(bgpg, use_bayesplot = TRUE) plot(bgpg, use_bayesplot = TRUE, fun_name = "hist") plot(bgpg, use_bayesplot = TRUE, pars = "p[u]")
## GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # Using the bayesplot package plot(gpg, use_bayesplot = TRUE) plot(gpg, use_bayesplot = TRUE, pars = "xi", prob = 0.95) plot(gpg, use_bayesplot = TRUE, fun_name = "intervals", pars = "xi") plot(gpg, use_bayesplot = TRUE, fun_name = "hist") plot(gpg, use_bayesplot = TRUE, fun_name = "dens") plot(gpg, use_bayesplot = TRUE, fun_name = "scatter") ## bin-GP posterior u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") npy_gom <- length(gom)/105 bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, npy = npy_gom) plot(bgpg) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Using the bayesplot package dimnames(bgpg$bin_sim_vals) plot(bgpg, use_bayesplot = TRUE) plot(bgpg, use_bayesplot = TRUE, fun_name = "hist") plot(bgpg, use_bayesplot = TRUE, pars = "p[u]")
plot
method for class "evpred". Plots summarising the predictive
distribution of the largest value to be observed in N years are produced.
The plot produced depends on x$type
.
If x$type = "d", "p"
or "q"
then
matplot
is used to produce a line plot of the
predictive density, distribution or quantile function, respectively,
with a line for each value of N in x$n_years
.
If x$type = "r"
then estimates of the predictive density
(from density
) are plotted with a line for each N.
If x$type = "i"
then lines representing estimated predictive
intervals are plotted, with the level of the interval indicated next to
the line.
## S3 method for class 'evpred' plot( x, ..., leg_pos = NULL, leg_text = NULL, which_int = c("long", "short", "both") )
## S3 method for class 'evpred' plot( x, ..., leg_pos = NULL, leg_text = NULL, which_int = c("long", "short", "both") )
x |
An object of class "evpost", a result of a call to
|
... |
Additional arguments passed on to |
leg_pos |
A character scalar. Keyword for the position of legend.
See |
leg_text |
A character or expression vector. Text for legend.
See |
which_int |
A character scalar. If |
Nothing is returned.
predict.evpost
for the S3 predict
method
for objects of class evpost
.
data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost(n = 1000, model = "gev", prior = pn, data = portpirie) # Predictive density function d_gevp <- predict(gevp, type = "d", n_years = c(100, 1000)) plot(d_gevp) # Predictive distribution function p_gevp <- predict(gevp, type = "p", n_years = c(100, 1000)) plot(p_gevp) # Predictive quantiles q_gevp <- predict(gevp, type = "q", n_years = c(100, 1000)) plot(q_gevp) # Predictive intervals i_gevp <- predict(gevp, type = "i", n_years = c(100, 1000), hpd = TRUE) plot(i_gevp, which_int = "both") # Sample from predictive distribution r_gevp <- predict(gevp, type = "r", n_years = c(100, 1000)) plot(r_gevp) plot(r_gevp, xlim = c(4, 10))
data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost(n = 1000, model = "gev", prior = pn, data = portpirie) # Predictive density function d_gevp <- predict(gevp, type = "d", n_years = c(100, 1000)) plot(d_gevp) # Predictive distribution function p_gevp <- predict(gevp, type = "p", n_years = c(100, 1000)) plot(p_gevp) # Predictive quantiles q_gevp <- predict(gevp, type = "q", n_years = c(100, 1000)) plot(q_gevp) # Predictive intervals i_gevp <- predict(gevp, type = "i", n_years = c(100, 1000), hpd = TRUE) plot(i_gevp, which_int = "both") # Sample from predictive distribution r_gevp <- predict(gevp, type = "r", n_years = c(100, 1000)) plot(r_gevp) plot(r_gevp, xlim = c(4, 10))
A numeric vector of length 65 containing annual maximum sea levels, in metres, from 1923 to 1987 at Port Pirie, South Australia.
portpirie
portpirie
A numeric vector containing 65 observations.
Coles, S. G. (2001) An Introduction to Statistical Modelling of Extreme Values. London: Springer. doi:10.1007/978-1-4471-3675-0
pp_check
method for class "evpost". This provides an interface
to the functions that perform posterior predictive checks in the
bayesplot package. See PPC-overview for
details of these functions.
## S3 method for class 'evpost' pp_check( object, ..., type = c("stat", "overlaid", "multiple", "intervals", "user"), subtype = NULL, stat = "median", nrep = 8, fun = NULL )
## S3 method for class 'evpost' pp_check( object, ..., type = c("stat", "overlaid", "multiple", "intervals", "user"), subtype = NULL, stat = "median", nrep = 8, fun = NULL )
object |
An object of class "evpost", a result of a call to
|
... |
Additional arguments passed on to bayesplot functions. |
type |
A character vector. The type of bayesplot plot required:
|
subtype |
A character scalar. Specifies the form of the plot(s)
produced. Could be one of
|
stat |
See PPC-test-statistics. |
nrep |
If |
fun |
The plotting function to call.
Only relevant if |
For details of these functions see PPC-overview. See also the vignette Posterior Predictive Extreme Value Inference and the bayesplot vignette Graphical posterior predictive checks.
The general idea is to compare the observed data object$data
with a matrix object$data_rep
in which each row is a
replication of the observed data simulated from the posterior predictive
distribution. For greater detail see Chapter 6 of Gelman et al. (2013).
The format of object$data
depends on the model:
model = "gev"
. A vector of block maxima.
model = "gp"
. Data that lie above the threshold,
i.e. threshold exceedances.
model = "bingp"
or model = "pp"
. The input data are
returned but any value lying below the threshold is set to
object$thresh
.
In all cases any missing values have been removed from the data.
If model = "bingp"
or "pp"
the rate of threshold exceedance
is part of the inference. Therefore, the number of values in
object$data_rep
that lie above the threshold varies between
predictive replications, with values below the threshold being
left-censored at the threshold. This limits a little the posterior
predictive checks that it is useful to perform. In the examples below
we have compared object$data
and object$data_rep
using
only their sample maxima.
A ggplot object that can be further customized using the ggplot2 package.
Jonah Gabry (2016). bayesplot: Plotting for Bayesian Models. R package version 1.1.0. https://CRAN.R-project.org/package=bayesplot
Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A., and Rubin, D. B. (2013). Bayesian Data Analysis. Chapman & Hall/CRC Press, London, third edition. (Chapter 6)
rpost
and rpost_rcpp
for sampling
from an extreme value posterior distribution.
bayesplot functions PPC-overview, PPC-distributions, PPC-test-statistics, PPC-intervals, pp_check.
# GEV model data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost(1000, model = "gev", prior = pn, data = portpirie, nrep = 50) # Posterior predictive test statistics pp_check(gevp) pp_check(gevp, stat = "min") pp_check(gevp, stat = c("min", "max")) iqr <- function(y) diff(quantile(y, c(0.25, 0.75))) pp_check(gevp, stat = "iqr") # Overlaid density and distributions functions pp_check(gevp, type = "overlaid") pp_check(gevp, type = "overlaid", subtype = "dens") # Multiple plots pp_check(gevp, type = "multiple") pp_check(gevp, type = "multiple", subtype = "hist") pp_check(gevp, type = "multiple", subtype = "boxplot") # Intervals pp_check(gevp, type = "intervals") pp_check(gevp, type = "intervals", subtype = "ribbon") # User-supplied bayesplot function # Equivalent to p_check(gevp, type = "overlaid") pp_check(gevp, type = "user", fun = "dens_overlay") # GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom, nrep = 50) pp_check(gpg) pp_check(gpg, type = "overlaid") # bin-GP model bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, nrep = 50) pp_check(bgpg, stat = "max") # PP model data(rainfall) rthresh <- 40 pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = rthresh, noy = 54, nrep = 50) pp_check(ppr, stat = "max")
# GEV model data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost(1000, model = "gev", prior = pn, data = portpirie, nrep = 50) # Posterior predictive test statistics pp_check(gevp) pp_check(gevp, stat = "min") pp_check(gevp, stat = c("min", "max")) iqr <- function(y) diff(quantile(y, c(0.25, 0.75))) pp_check(gevp, stat = "iqr") # Overlaid density and distributions functions pp_check(gevp, type = "overlaid") pp_check(gevp, type = "overlaid", subtype = "dens") # Multiple plots pp_check(gevp, type = "multiple") pp_check(gevp, type = "multiple", subtype = "hist") pp_check(gevp, type = "multiple", subtype = "boxplot") # Intervals pp_check(gevp, type = "intervals") pp_check(gevp, type = "intervals", subtype = "ribbon") # User-supplied bayesplot function # Equivalent to p_check(gevp, type = "overlaid") pp_check(gevp, type = "user", fun = "dens_overlay") # GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom, nrep = 50) pp_check(gpg) pp_check(gpg, type = "overlaid") # bin-GP model bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, nrep = 50) pp_check(bgpg, stat = "max") # PP model data(rainfall) rthresh <- 40 pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = rthresh, noy = 54, nrep = 50) pp_check(ppr, stat = "max")
years.predict
method for class "evpost". Performs predictive inference
about the largest value to be observed over a future time period of
years. Predictive inferences accounts for uncertainty in model
parameters and for uncertainty owing to the variability of future
observations.
## S3 method for class 'evpost' predict( object, type = c("i", "p", "d", "q", "r"), x = NULL, x_num = 100, n_years = 100, npy = NULL, level = 95, hpd = FALSE, lower_tail = TRUE, log = FALSE, big_q = 1000, ... )
## S3 method for class 'evpost' predict( object, type = c("i", "p", "d", "q", "r"), x = NULL, x_num = 100, n_years = 100, npy = NULL, level = 95, hpd = FALSE, lower_tail = TRUE, log = FALSE, big_q = 1000, ... )
object |
An object of class
|
type |
A character vector. Indicates which type of inference is required:
|
x |
A numeric vector or a matrix with
|
x_num |
A numeric scalar. If |
n_years |
A numeric vector. Values of |
npy |
A numeric scalar. The mean number of observations per year of data, after excluding any missing values, i.e. the number of non-missing observations divided by total number of years' worth of non-missing data. If Otherwise, a default value will be assumed if
If |
level |
A numeric vector of values in (0, 100).
Only relevant when |
hpd |
A logical scalar.
Only relevant when If If |
lower_tail |
A logical scalar.
Only relevant when |
log |
A logical scalar. Only relevant when |
big_q |
A numeric scalar. Only relevant when |
... |
Additional optional arguments. At present no optional arguments are used. |
Inferences about future extreme observations are integrated over the posterior distribution of the model parameters, thereby accounting for uncertainty in model parameters and uncertainty owing to the variability of future observations. In practice the integrals involved are estimated using an empirical mean over the posterior sample. See, for example, Coles (2001), Stephenson (2016) or Northrop et al. (2017) for details. See also the vignette Posterior Predictive Extreme Value Inference
GEV / OS / PP.
If model = "gev"
, model = "os"
or model = "pp"
in the call to rpost
or rpost_rcpp
we first calculate the number of blocks in
n_years
years.
To calculate the density function or distribution function of the maximum
over n_years
we call dgev
or pgev
with m
= .
type = "p"
. We calculate using pgev
the GEV distribution function at q
for each of the posterior
samples of the location, scale and shape parameters. Then we take
the mean of these values.
type = "d"
. We calculate using dgev
the GEV density function at x
for each of the posterior samples
of the location, scale and shape parameters. Then we take the
mean of these values.
type = "q"
. We solve numerically
predict.evpost(object, type = "p", x = q)
= p[i]
numerically for q
for each element p[i]
of p
.
type = "i"
. If hpd = FALSE
then the interval is
equi-tailed, equal to predict.evpost()
object, type ="q", x = p)
,
where p = c((1-level/100)/2,
(1+level/100)/2)
.
If hpd = TRUE
then, in addition, we perform a
numerical minimisation of the length of level% intervals, after
approximating the predictive quantile function using monotonic
cubic splines, to reduce computing time.
type = "r"
. For each simulated value of the GEV parameters
at the n_years
level of aggregation we simulate one value from
this GEV distribution using rgev
. Thus, each sample
from the predictive distribution is of a size equal to the size of
the posterior sample.
Binomial-GP. If model = "bingp"
in the call to
rpost
or rpost_rcpp
then we calculate the
mean number of observations in n_years
years, i.e.
npy * n_years
.
Following Northrop et al. (2017), let be the largest value
observed in
years,
=
npy * n_years
and the
threshold
object$thresh
used in the call to rpost
or rpost_rcpp
.
For fixed values of the distribution
function of
is given by
, for
, where
The distribution function of cannot be evaluated for
because no model has been supposed for observations below
the threshold.
type = "p"
. We calculate
at
q
for each of the posterior samples
. Then we take the mean of these values.
type = "d"
. We calculate the density of of , i.e.
the derivative of
with respect to
at
x
for each of the posterior samples . Then we take
the mean of these values.
type = "q"
and type = "i"
. We perform calculations
that are analogous to the GEV case above. If n_years
is very
small and/or level is very close to 100 then a predictive interval
may extend below the threshold. In such cases NA
s are returned
(see Value below).
type = "r"
. For each simulated value of the bin-GP
parameter we simulate from the distribution of using the
inversion method applied to the distribution function of
given
above. Occasionally a value below the threshold would need to be
simulated. If these instances a missing value code
NA
is
returned. Thus, each sample from the predictive distribution is of a
size equal to the size of the posterior sample, perhaps with a small
number os NA
s.
An object of class "evpred", a list containing a subset of the following components:
type |
The argument |
x |
A matrix containing the argument |
y |
The content of
|
long |
A |
short |
A matrix with the same structure as |
The arguments n_years, level, hpd, lower_tail, log
supplied
to predict.evpost
are also included, as is the argument npy
supplied to, or set within, predict.evpost
and
the arguments data
and model
from the original call to
rpost
or rpost_rcpp
.
Coles, S. G. (2001) An Introduction to Statistical Modeling of Extreme Values, Springer-Verlag, London. Chapter 9: doi:10.1007/978-1-4471-3675-0_9
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Stephenson, A. (2016). Bayesian Inference for Extreme Value Modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications, edited by D. K. Dey and J. Yan, 257-80. London: Chapman and Hall. doi:10.1201/b19721
plot.evpred
for the S3 plot
method for
objects of class evpred
.
rpost
or rpost_rcpp
for sampling
from an extreme value posterior distribution.
### GEV data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost_rcpp(n = 1000, model = "gev", prior = pn, data = portpirie) # Interval estimation predict(gevp)$long predict(gevp, hpd = TRUE)$short # Density function x <- 4:7 predict(gevp, type = "d", x = x)$y plot(predict(gevp, type = "d", n_years = c(100, 1000))) # Distribution function predict(gevp, type = "p", x = x)$y plot(predict(gevp, type = "p", n_years = c(100, 1000))) # Quantiles predict(gevp, type = "q", n_years = c(100, 1000))$y # Random generation plot(predict(gevp, type = "r")) ### Binomial-GP u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") npy_gom <- length(gom)/105 bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) # Setting npy in call to predict.evpost() predict(bgpg, npy = npy_gom)$long # Setting npy in call to rpost() or rpost_rcpp() bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, npy = npy_gom) # Interval estimation predict(bgpg)$long predict(bgpg, hpd = TRUE)$short # Density function plot(predict(bgpg, type = "d", n_years = c(100, 1000))) # Distribution function plot(predict(bgpg, type = "p", n_years = c(100, 1000))) # Quantiles predict(bgpg, type = "q", n_years = c(100, 1000))$y # Random generation plot(predict(bgpg, type = "r"))
### GEV data(portpirie) mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) gevp <- rpost_rcpp(n = 1000, model = "gev", prior = pn, data = portpirie) # Interval estimation predict(gevp)$long predict(gevp, hpd = TRUE)$short # Density function x <- 4:7 predict(gevp, type = "d", x = x)$y plot(predict(gevp, type = "d", n_years = c(100, 1000))) # Distribution function predict(gevp, type = "p", x = x)$y plot(predict(gevp, type = "p", n_years = c(100, 1000))) # Quantiles predict(gevp, type = "q", n_years = c(100, 1000))$y # Random generation plot(predict(gevp, type = "r")) ### Binomial-GP u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") npy_gom <- length(gom)/105 bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) # Setting npy in call to predict.evpost() predict(bgpg, npy = npy_gom)$long # Setting npy in call to rpost() or rpost_rcpp() bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp, npy = npy_gom) # Interval estimation predict(bgpg)$long predict(bgpg, hpd = TRUE)$short # Density function plot(predict(bgpg, type = "d", n_years = c(100, 1000))) # Distribution function plot(predict(bgpg, type = "p", n_years = c(100, 1000))) # Quantiles predict(bgpg, type = "q", n_years = c(100, 1000))$y # Random generation plot(predict(bgpg, type = "r"))
Print method for objects of class "evpost"
## S3 method for class 'evpost' print(x, ...)
## S3 method for class 'evpost' print(x, ...)
x |
An object of class "evpost", a result of a call to
|
... |
Further arguments. None are used. |
print.evpost
just prints the original function call, to
avoid printing a huge list.
The argument x
is returned, invisibly.
plot.evpost
for a diagnostic plot.
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) k_postsim <- kgaps_post(newlyn, thresh) k_postsim
# Newlyn sea surges thresh <- quantile(newlyn, probs = 0.90) k_postsim <- kgaps_post(newlyn, thresh) k_postsim
print
method for an object object
of class "summary.evpost".
## S3 method for class 'summary.evpost' print(x, ...)
## S3 method for class 'summary.evpost' print(x, ...)
x |
An object of class "summary.evpost", a result of a call to
|
... |
Additional arguments passed on to |
Prints
information about the ratio-of-uniforms bounding box, i.e.
object$box
an estimate of the probability of acceptance, i.e.
object$pa
a summary of the simulated values, via
summary(object$sim_vals)
ru
or ru_rcpp
for
descriptions of object$sim_vals
and $box
.
plot.evpost
for a diagnostic plot.
# GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) summary(gpg)
# GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) summary(gpg)
Three quantiles, that is, the value of quantile and their respective exceedance probabilities, are provided. This function attempts to find the location, scale and shape parameters of a GEV distribution that has these quantiles.
quantile_to_gev(quant, prob)
quantile_to_gev(quant, prob)
quant |
A numeric vector of length 3. Values of the quantiles.
The values should increase with the index of the vector.
If not, the values in |
prob |
A numeric vector of length 3. Exceedance probabilities
corresponding to the quantiles in |
Suppose that is the distribution function of
a GEV(
) distribution. This function attempts to
solve numerically the set of three non-linear equations
where are the quantiles in
quant
and
are the exceedance probabilities in
prob
.
This is reduced to a one-dimensional optimisation over the GEV
shape parameter.
A numeric vector of length 3 containing the GEV location, scale and shape parameters.
rprior_quant
for simulation of GEV parameters from
a prior constructed on the quantile scale.
my_q <- c(15, 20, 22.5) my_p <- 1-c(0.5, 0.9, 0.5^0.01) x <- quantile_to_gev(quant = my_q, prob = my_p) # Check qgev(p = 1 - my_p, loc = x[1], scale = x[2], shape = x[3])
my_q <- c(15, 20, 22.5) my_p <- 1-c(0.5, 0.9, 0.5^0.01) x <- quantile_to_gev(quant = my_q, prob = my_p) # Check qgev(p = 1 - my_p, loc = x[1], scale = x[2], shape = x[3])
A numeric vector of length 20820 containing daily aggregate rainfall observations, in millimetres, recorded at a rain gauge in England over a 57 year period, beginning on a leap year. Three of these years contain only missing values.
rainfall
rainfall
A vector containing 20820 observations.
Unknown
Simulates from a Dirichlet distribution with concentration parameter
vector = (
, ...,
).
rDir(n = 1, alpha = c(1, 1))
rDir(n = 1, alpha = c(1, 1))
n |
A numeric scalar. The size of sample required. |
alpha |
A numeric vector. Dirichlet concentration parameter. |
The simulation is based on the property that if
are independent,
has a
gamma(
, 1) distribution and
then
has a
Dirichlet(
, ...,
) distribution.
See https://en.wikipedia.org/wiki/Dirichlet_distribution#Gamma_distribution
An n
by length(alpha)
numeric matrix.
Kotz, S., Balakrishnan, N. and Johnson, N. L. (2000) Continuous Multivariate Distributions, vol. 1, Models and Applications, 2nd edn, ch. 49. New York: Wiley. doi:10.1002/0471722065
rprior_prob
for prior simulation of
GEV parameters - prior on probability scale.
rDir(n = 10, alpha = 1:4)
rDir(n = 10, alpha = 1:4)
Uses the ru
function in the rust
package to simulate from the posterior distribution of an extreme value
model.
rpost( n, model = c("gev", "gp", "bingp", "pp", "os"), data, prior, ..., nrep = NULL, thresh = NULL, noy = NULL, use_noy = TRUE, npy = NULL, ros = NULL, bin_prior = structure(list(prior = "bin_beta", ab = c(1/2, 1/2), class = "binprior")), bin_param = "logit", init_ests = NULL, mult = 2, use_phi_map = FALSE, weights = NULL )
rpost( n, model = c("gev", "gp", "bingp", "pp", "os"), data, prior, ..., nrep = NULL, thresh = NULL, noy = NULL, use_noy = TRUE, npy = NULL, ros = NULL, bin_prior = structure(list(prior = "bin_beta", ab = c(1/2, 1/2), class = "binprior")), bin_param = "logit", init_ests = NULL, mult = 2, use_phi_map = FALSE, weights = NULL )
n |
A numeric scalar. The size of posterior sample required. |
model |
A character string. Specifies the extreme value model. |
data |
Sample data, of a format appropriate to the value of
|
prior |
A list specifying the prior for the parameters of the extreme
value model, created by |
... |
Further arguments to be passed to |
nrep |
A numeric scalar. If |
thresh |
A numeric scalar. Extreme value threshold applied to data.
Only relevant when |
noy |
A numeric scalar. The number of blocks of observations,
excluding any missing values. A block is often a year.
Only relevant, and must be supplied, if |
use_noy |
A logical scalar. Only relevant if model is "pp".
If |
npy |
A numeric scalar. The mean number of observations per year of data, after excluding any missing values, i.e. the number of non-missing observations divided by total number of years' worth of non-missing data. The value of |
ros |
A numeric scalar. Only relevant when |
bin_prior |
A list specifying the prior for a binomial probability
|
bin_param |
A character scalar. The argument |
init_ests |
A numeric vector. Initial parameter estimates for search for the mode of the posterior distribution. |
mult |
A numeric scalar. The grid of values used to choose the Box-Cox transformation parameter lambda is based on the maximum a posteriori (MAP) estimate +/- mult x estimated posterior standard deviation. |
use_phi_map |
A logical scalar. If trans = "BC" then |
weights |
An optional numeric vector of weights by which to multiply
the observations when constructing the log-likelihood.
Currently only implemented for |
Generalised Pareto (GP): model = "gp"
. A model for threshold
excesses. Required arguments: n
, data
and prior
.
If thresh
is supplied then only the values in data
that
exceed thresh
are used and the GP distribution is fitted to the
amounts by which those values exceed thresh
.
If thresh
is not supplied then the GP distribution is fitted to
all values in data
, in effect thresh = 0
.
See also gp
.
Binomial-GP: model = "bingp"
. The GP model for threshold
excesses supplemented by a binomial(length(data)
, )
model for the number of threshold excesses. See Northrop et al. (2017)
for details. Currently, the GP and binomial parameters are assumed to
be independent a priori.
Generalised extreme value (GEV) model: model = "gev"
. A
model for block maxima. Required arguments: n
, data
,
prior
. See also gev
.
Point process (PP) model: model = "pp"
. A model for
occurrences of threshold exceedances and threshold excesses. Required
arguments: n
, data
, prior
, thresh
and
noy
.
r-largest order statistics (OS) model: model = "os"
.
A model for the largest order statistics within blocks of data.
Required arguments: n
, data
, prior
. All the values
in data
are used unless ros
is supplied.
Parameter transformation. The scalar logical arguments (to the
function ru
) trans
and rotate
determine,
respectively, whether or not Box-Cox transformation is used to reduce
asymmetry in the posterior distribution and rotation of parameter
axes is used to reduce posterior parameter dependence. The default
is trans = "none"
and rotate = TRUE
.
See the Introducing revdbayes vignette for further details and examples.
An object (list) of class "evpost"
, which has the same
structure as an object of class "ru"
returned from
ru
.
In addition this list contains
model: |
The argument |
data: |
The content depends on |
prior: |
The argument |
If nrep
is not NULL
then this list also contains
data_rep
, a numerical matrix with nrep
rows. Each
row contains a replication of the original data data
simulated from the posterior predictive distribution.
If model = "bingp"
or "pp"
then the rate of threshold
exceedance is part of the inference. Therefore, the number of values in
data_rep
that lie above the threshold varies between
predictive replications (different rows of data_rep
).
Values below the threshold are left-censored at the threshold, i.e. they
are set at the threshold.
If model == "pp"
then this list also contains the argument
noy
to rpost
detailed above.
If the argument npy
was supplied then this list also contains
npy
.
If model == "gp"
or model == "bingp"
then this list also
contains the argument thresh
to rpost
detailed above.
If model == "bingp"
then this list also contains
bin_sim_vals: |
An |
bin_logf: |
A function returning the log-posterior for
|
bin_logf_args: |
A list of arguments to |
Coles, S. G. and Powell, E. A. (1996) Bayesian methods in extreme value modelling: a review and new developments. Int. Statist. Rev., 64, 119-136.
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Stephenson, A. (2016) Bayesian Inference for Extreme Value Modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications, edited by D. K. Dey and J. Yan, 257-80. London: Chapman and Hall. doi:10.1201/b19721 value posterior using the evdbayes package.
Wadsworth, J. L., Tawn, J. A. and Jonathan, P. (2010) Accounting for choice of measurement scale in extreme value modeling. The Annals of Applied Statistics, 4(3), 1558-1578. doi:10.1214/10-AOAS333
set_prior
for setting a prior distribution.
rpost_rcpp
for faster posterior simulation using
the Rcpp package.
plot.evpost
, summary.evpost
and
predict.evpost
for the S3 plot
, summary
and predict
methods for objects of class evpost
.
ru
and ru_rcpp
in the
rust
package for details of the arguments that can
be passed to ru
and the form of the object returned by
rpost
.
find_lambda
and
find_lambda_rcpp
in the rust
package is used inside rpost
to set the Box-Cox transformation
parameter lambda when the trans = "BC"
argument is given.
# GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # Binomial-GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Setting the same binomial (Jeffreys) prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = jeffreys) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # GEV model mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) gevp <- rpost(n = 1000, model = "gev", prior = pn, data = portpirie) plot(gevp) # GEV model, informative prior constructed on the probability scale pip <- set_prior(quant = c(85, 88, 95), alpha = c(4, 2.5, 2.25, 0.25), model = "gev", prior = "prob") ox_post <- rpost(n = 1000, model = "gev", prior = pip, data = oxford) plot(ox_post) # PP model pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = 40, noy = 54) plot(ppr) # PP model, informative prior constructed on the quantile scale piq <- set_prior(prob = 10^-(1:3), shape = c(38.9, 7.1, 47), scale = c(1.5, 6.3, 2.6), model = "gev", prior = "quant") rn_post <- rpost(n = 1000, model = "pp", prior = piq, data = rainfall, thresh = 40, noy = 54) plot(rn_post) # OS model mat <- diag(c(10000, 10000, 100)) pv <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) osv <- rpost(n = 1000, model = "os", prior = pv, data = venice) plot(osv)
# GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # Binomial-GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Setting the same binomial (Jeffreys) prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) bgpg <- rpost(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = jeffreys) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # GEV model mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) gevp <- rpost(n = 1000, model = "gev", prior = pn, data = portpirie) plot(gevp) # GEV model, informative prior constructed on the probability scale pip <- set_prior(quant = c(85, 88, 95), alpha = c(4, 2.5, 2.25, 0.25), model = "gev", prior = "prob") ox_post <- rpost(n = 1000, model = "gev", prior = pip, data = oxford) plot(ox_post) # PP model pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = 40, noy = 54) plot(ppr) # PP model, informative prior constructed on the quantile scale piq <- set_prior(prob = 10^-(1:3), shape = c(38.9, 7.1, 47), scale = c(1.5, 6.3, 2.6), model = "gev", prior = "quant") rn_post <- rpost(n = 1000, model = "pp", prior = piq, data = rainfall, thresh = 40, noy = 54) plot(rn_post) # OS model mat <- diag(c(10000, 10000, 100)) pv <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) osv <- rpost(n = 1000, model = "os", prior = pv, data = venice) plot(osv)
Uses the ru_rcpp
function in the
rust
package to simulate from the posterior distribution
of an extreme value model.
rpost_rcpp( n, model = c("gev", "gp", "bingp", "pp", "os"), data, prior, ..., nrep = NULL, thresh = NULL, noy = NULL, use_noy = TRUE, npy = NULL, ros = NULL, bin_prior = structure(list(prior = "bin_beta", ab = c(1/2, 1/2), class = "binprior")), init_ests = NULL, mult = 2, use_phi_map = FALSE )
rpost_rcpp( n, model = c("gev", "gp", "bingp", "pp", "os"), data, prior, ..., nrep = NULL, thresh = NULL, noy = NULL, use_noy = TRUE, npy = NULL, ros = NULL, bin_prior = structure(list(prior = "bin_beta", ab = c(1/2, 1/2), class = "binprior")), init_ests = NULL, mult = 2, use_phi_map = FALSE )
n |
A numeric scalar. The size of posterior sample required. |
model |
A character string. Specifies the extreme value model. |
data |
Sample data, of a format appropriate to the value of
|
prior |
A list specifying the prior for the parameters of the extreme
value model, created by |
... |
Further arguments to be passed to |
nrep |
A numeric scalar. If |
thresh |
A numeric scalar. Extreme value threshold applied to data.
Only relevant when |
noy |
A numeric scalar. The number of blocks of observations,
excluding any missing values. A block is often a year.
Only relevant, and must be supplied, if |
use_noy |
A logical scalar. Only relevant if model is "pp".
If |
npy |
A numeric scalar. The mean number of observations per year of data, after excluding any missing values, i.e. the number of non-missing observations divided by total number of years' worth of non-missing data. The value of |
ros |
A numeric scalar. Only relevant when |
bin_prior |
A list specifying the prior for a binomial probability
|
init_ests |
A numeric vector. Initial parameter estimates for search for the mode of the posterior distribution. |
mult |
A numeric scalar. The grid of values used to choose the Box-Cox transformation parameter lambda is based on the maximum a posteriori (MAP) estimate +/- mult x estimated posterior standard deviation. |
use_phi_map |
A logical scalar. If trans = "BC" then |
Generalised Pareto (GP): model = "gp"
. A model for threshold
excesses. Required arguments: n
, data
and prior
.
If thresh
is supplied then only the values in data
that
exceed thresh
are used and the GP distribution is fitted to the
amounts by which those values exceed thresh
.
If thresh
is not supplied then the GP distribution is fitted to
all values in data
, in effect thresh = 0
.
See also gp
.
Binomial-GP: model = "bingp"
. The GP model for threshold
excesses supplemented by a binomial(length(data)
, )
model for the number of threshold excesses. See Northrop et al. (2017)
for details. Currently, the GP and binomial parameters are assumed to
be independent a priori.
Generalised extreme value (GEV) model: model = "gev"
. A
model for block maxima. Required arguments: n
, data
,
prior
. See also gev
.
Point process (PP) model: model = "pp"
. A model for
occurrences of threshold exceedances and threshold excesses. Required
arguments: n
, data
, prior
, thresh
and
noy
.
r-largest order statistics (OS) model: model = "os"
.
A model for the largest order statistics within blocks of data.
Required arguments: n
, data
, prior
. All the values
in data
are used unless ros
is supplied.
Parameter transformation. The scalar logical arguments (to the
function ru
) trans
and rotate
determine,
respectively, whether or not Box-Cox transformation is used to reduce
asymmetry in the posterior distribution and rotation of parameter
axes is used to reduce posterior parameter dependence. The default
is trans = "none"
and rotate = TRUE
.
See the Introducing revdbayes vignette for further details and examples.
An object (list) of class "evpost"
, which has the same
structure as an object of class "ru"
returned from
ru_rcpp
. In addition this list contains
model: |
The argument |
data: |
The content depends on |
prior: |
The argument |
logf_rho_args: |
A list of arguments to the (transformed) target log-density. |
If nrep
is not NULL
then this list also contains
data_rep
, a numerical matrix with nrep
rows. Each
row contains a replication of the original data data
simulated from the posterior predictive distribution.
If model = "bingp"
or "pp"
then the rate of threshold
exceedance is part of the inference. Therefore, the number of values in
data_rep
that lie above the threshold varies between
predictive replications (different rows of data_rep
).
Values below the threshold are left-censored at the threshold, i.e. they
are set at the threshold.
If model == "pp"
then this list also contains the argument
noy
to rpost
detailed above.
If the argument npy
was supplied then this list also contains
npy
.
If model == "gp"
or model == "bingp"
then this list also
contains the argument thresh
to rpost
detailed above.
If model == "bingp"
then this list also contains
bin_sim_vals: |
An |
bin_logf: |
A function returning the log-posterior for
|
bin_logf_args: |
A list of arguments to |
Coles, S. G. and Powell, E. A. (1996) Bayesian methods in extreme value modelling: a review and new developments. Int. Statist. Rev., 64, 119-136.
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Stephenson, A. (2016) Bayesian Inference for Extreme Value Modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications, edited by D. K. Dey and J. Yan, 257-80. London: Chapman and Hall. doi:10.1201/b19721 value posterior using the evdbayes package.
Wadsworth, J. L., Tawn, J. A. and Jonathan, P. (2010) Accounting for choice of measurement scale in extreme value modeling. The Annals of Applied Statistics, 4(3), 1558-1578. doi:10.1214/10-AOAS333
set_prior
for setting a prior distribution.
rpost
for posterior simulation without using
the Rcpp package.
plot.evpost
, summary.evpost
and
predict.evpost
for the S3 plot
, summary
and predict
methods for objects of class evpost
.
ru_rcpp
in the rust
package for details of the arguments that can be passed to
ru_rcpp
and the form of the object returned by rpost_rcpp
.
find_lambda
in the
rust
package is used inside rpost
to set the
Box-Cox transformation parameter lambda when the trans = "BC"
argument is given.
# GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # GP model, user-defined prior (same prior as the previous example) ptr_gp_flat <- create_prior_xptr("gp_flat") p_user <- set_prior(prior = ptr_gp_flat, model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = p_user, thresh = u, data = gom) plot(gpg) # Binomial-GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Setting the same binomial (Jeffreys) prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = jeffreys) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # GEV model mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) gevp <- rpost_rcpp(n = 1000, model = "gev", prior = pn, data = portpirie) plot(gevp) # GEV model, user-defined prior (same prior as the previous example) mat <- diag(c(10000, 10000, 100)) ptr_gev_norm <- create_prior_xptr("gev_norm") pn_u <- set_prior(prior = ptr_gev_norm, model = "gev", mean = c(0, 0, 0), icov = solve(mat)) gevu <- rpost_rcpp(n = 1000, model = "gev", prior = pn_u, data = portpirie) plot(gevu) # GEV model, informative prior constructed on the probability scale pip <- set_prior(quant = c(85, 88, 95), alpha = c(4, 2.5, 2.25, 0.25), model = "gev", prior = "prob") ox_post <- rpost_rcpp(n = 1000, model = "gev", prior = pip, data = oxford) plot(ox_post) # PP model pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost_rcpp(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = 40, noy = 54) plot(ppr) # PP model, user-defined prior (same prior as the previous example) ptr_gev_flat <- create_prior_xptr("gev_flat") pf_u <- set_prior(prior = ptr_gev_flat, model = "gev", min_xi = -1, max_xi = Inf) ppru <- rpost_rcpp(n = 1000, model = "pp", prior = pf_u, data = rainfall, thresh = 40, noy = 54) plot(ppru) # PP model, informative prior constructed on the quantile scale piq <- set_prior(prob = 10^-(1:3), shape = c(38.9, 7.1, 47), scale = c(1.5, 6.3, 2.6), model = "gev", prior = "quant") rn_post <- rpost_rcpp(n = 1000, model = "pp", prior = piq, data = rainfall, thresh = 40, noy = 54) plot(rn_post) # OS model mat <- diag(c(10000, 10000, 100)) pv <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) osv <- rpost_rcpp(n = 1000, model = "os", prior = pv, data = venice) plot(osv)
# GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) plot(gpg) # GP model, user-defined prior (same prior as the previous example) ptr_gp_flat <- create_prior_xptr("gp_flat") p_user <- set_prior(prior = ptr_gp_flat, model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = p_user, thresh = u, data = gom) plot(gpg) # Binomial-GP model u <- quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) bp <- set_bin_prior(prior = "jeffreys") bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = bp) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # Setting the same binomial (Jeffreys) prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2)) bgpg <- rpost_rcpp(n = 1000, model = "bingp", prior = fp, thresh = u, data = gom, bin_prior = jeffreys) plot(bgpg, pu_only = TRUE) plot(bgpg, add_pu = TRUE) # GEV model mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) gevp <- rpost_rcpp(n = 1000, model = "gev", prior = pn, data = portpirie) plot(gevp) # GEV model, user-defined prior (same prior as the previous example) mat <- diag(c(10000, 10000, 100)) ptr_gev_norm <- create_prior_xptr("gev_norm") pn_u <- set_prior(prior = ptr_gev_norm, model = "gev", mean = c(0, 0, 0), icov = solve(mat)) gevu <- rpost_rcpp(n = 1000, model = "gev", prior = pn_u, data = portpirie) plot(gevu) # GEV model, informative prior constructed on the probability scale pip <- set_prior(quant = c(85, 88, 95), alpha = c(4, 2.5, 2.25, 0.25), model = "gev", prior = "prob") ox_post <- rpost_rcpp(n = 1000, model = "gev", prior = pip, data = oxford) plot(ox_post) # PP model pf <- set_prior(prior = "flat", model = "gev", min_xi = -1) ppr <- rpost_rcpp(n = 1000, model = "pp", prior = pf, data = rainfall, thresh = 40, noy = 54) plot(ppr) # PP model, user-defined prior (same prior as the previous example) ptr_gev_flat <- create_prior_xptr("gev_flat") pf_u <- set_prior(prior = ptr_gev_flat, model = "gev", min_xi = -1, max_xi = Inf) ppru <- rpost_rcpp(n = 1000, model = "pp", prior = pf_u, data = rainfall, thresh = 40, noy = 54) plot(ppru) # PP model, informative prior constructed on the quantile scale piq <- set_prior(prob = 10^-(1:3), shape = c(38.9, 7.1, 47), scale = c(1.5, 6.3, 2.6), model = "gev", prior = "quant") rn_post <- rpost_rcpp(n = 1000, model = "pp", prior = piq, data = rainfall, thresh = 40, noy = 54) plot(rn_post) # OS model mat <- diag(c(10000, 10000, 100)) pv <- set_prior(prior = "norm", model = "gev", mean = c(0, 0, 0), cov = mat) osv <- rpost_rcpp(n = 1000, model = "os", prior = pv, data = venice) plot(osv)
Simulates from the prior distribution for GEV parameters based on Crowder (1992), in which independent beta priors are specified for ratios of probabilities (which is equivalent to a Dirichlet prior on differences between these probabilities).
rprior_prob(n, quant, alpha, exc = FALSE, lb = NULL, lb_prob = 0.001)
rprior_prob(n, quant, alpha, exc = FALSE, lb = NULL, lb_prob = 0.001)
n |
A numeric scalar. The size of sample required. |
quant |
A numeric vector of length 3. Contains quantiles
|
alpha |
A numeric vector of length 4. Parameters of the Dirichlet distribution for the exceedance probabilities. |
exc |
A logical scalar. Let |
lb |
A numeric scalar. If this is not |
lb_prob |
A numeric scalar. The non-exceedance probability involved
in the specification of |
The simulation is based on the way that the prior is constructed.
See Stephenson (1996) the evdbayes user guide or Northrop et al. (2017)
Northrop et al. (2017) for details of the construction of the prior.
First, differences between probabilities are simulated from a Dirichlet
distribution. Then the GEV location, scale and shape parameters that
correspond to these quantile values are found, by solving numerically a
set of three non-linear equations in which the GEV quantile function
evaluated at the simulated probabilities is equated to the quantiles in
quant
. This is reduced to a one-dimensional optimisation over the
GEV shape parameter.
An n
by 3 numeric matrix.
Crowder, M. (1992) Bayesian priors based on parameter transformation using the distribution function. Ann. Inst. Statist. Math., 44(3), 405-416. https://link.springer.com/article/10.1007/BF00050695
Stephenson, A. 2016. Bayesian Inference for Extreme Value Modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications, edited by D. K. Dey and J. Yan, 257-80. London: Chapman and Hall. doi:10.1201/b19721
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
rpost
and rpost_rcpp
for sampling
from an extreme value posterior distribution.
quant <- c(85, 88, 95) alpha <- c(4, 2.5, 2.25, 0.25) x <- rprior_prob(n = 1000, quant = quant, alpha = alpha, exc = TRUE) x <- rprior_prob(n = 1000, quant = quant, alpha = alpha, exc = TRUE, lb = 0)
quant <- c(85, 88, 95) alpha <- c(4, 2.5, 2.25, 0.25) x <- rprior_prob(n = 1000, quant = quant, alpha = alpha, exc = TRUE) x <- rprior_prob(n = 1000, quant = quant, alpha = alpha, exc = TRUE, lb = 0)
Simulates from the prior distribution for GEV parameters proposed in Coles and Tawn (1996), based on independent gamma priors for differences between quantiles.
rprior_quant(n, prob, shape, scale, lb = NULL, lb_prob = 0.001)
rprior_quant(n, prob, shape, scale, lb = NULL, lb_prob = 0.001)
n |
A numeric scalar. The size of sample required. |
prob |
A numeric vector of length 3. Exceedance probabilities
corresponding to the quantiles used to specify the prior distribution.
The values should decrease with the index of the vector.
If not, the values in |
shape |
A numeric vector of length 3. Respective shape parameters of the gamma priors for the quantile differences. |
scale |
A numeric vector of length 3. Respective scale parameters of the gamma priors for the quantile differences. |
lb |
A numeric scalar. If this is not |
lb_prob |
A numeric scalar. The non-exceedance probability involved
in the specification of |
The simulation is based on the way that the prior is constructed.
See Coles and Tawn (1996), Stephenson (2016) or the evdbayes user guide
for details of the construction of the prior. First, the quantile
differences are simulated from the specified gamma distributions.
Then the simulated quantiles are calculated. Then the GEV location,
scale and shape parameters that give these quantile values are found,
by solving numerically a set of three non-linear equations in which the
GEV quantile function evaluated at the values in prob
is equated
to the simulated quantiles. This is reduced to a one-dimensional
optimisation over the GEV shape parameter.
An n
by 3 numeric matrix.
Coles, S. G. and Tawn, J. A. (1996) A Bayesian analysis of extreme rainfall data. Appl. Statist., 45, 463-478.
Stephenson, A. 2016. Bayesian Inference for Extreme Value Modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications, edited by D. K. Dey and J. Yan, 257-80. London: Chapman and Hall. doi:10.1201/b19721
rpost
and rpost_rcpp
for sampling
from an extreme value posterior distribution.
pr <- 10 ^ -(1:3) sh <- c(38.9, 7.1, 47) sc <- c(1.5, 6.3, 2.6) x <- rprior_quant(n = 1000, prob = pr, shape = sh, scale = sc) x <- rprior_quant(n = 1000, prob = pr, shape = sh, scale = sc, lb = 0)
pr <- 10 ^ -(1:3) sh <- c(38.9, 7.1, 47) sc <- c(1.5, 6.3, 2.6) x <- rprior_quant(n = 1000, prob = pr, shape = sh, scale = sc) x <- rprior_quant(n = 1000, prob = pr, shape = sh, scale = sc, lb = 0)
Constructs a prior distribution for use as the argument bin_prior
in
rpost
or in binpost
. The user can choose
from a list of in-built priors or specify their own prior function,
returning the log of the prior density, using an R function
and arguments for hyperparameters.
set_bin_prior( prior = c("jeffreys", "laplace", "haldane", "beta", "mdi", "northrop"), ... )
set_bin_prior( prior = c("jeffreys", "laplace", "haldane", "beta", "mdi", "northrop"), ... )
prior |
Either
|
... |
Further arguments to be passed to the user-supplied or in-built
prior function. For the latter this is only relevant if
|
Binomial priors. The names of the binomial priors set using
bin_prior
are:
"jeffreys"
: the Jeffreys beta(1/2, 1/2) prior.
"laplace"
: the Bayes-Laplace beta(1, 1) prior.
"haldane"
: the Haldane beta(0, 0) prior.
"beta"
: a beta() prior. The argument
ab
is a vector containing c
().
The default is
ab = c(1, 1)
.
"mdi"
: the MDI prior
,
for
"northrop"
: the improper prior
,
for
Apart from the last two priors these are all beta distributions.
A list of class "binprior"
. The first component is the
name of the input prior. Apart from the MDI prior this will be "beta",
in which case the other component of the list is a vector of length two
giving the corresponding values of the beta parameters.
binpost
for sampling from a binomial posterior
distribution.
bp <- set_bin_prior(prior = "jeffreys") # Setting the Jeffreys prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2))
bp <- set_bin_prior(prior = "jeffreys") # Setting the Jeffreys prior by hand beta_prior_fn <- function(p, ab) { return(stats::dbeta(p, shape1 = ab[1], shape2 = ab[2], log = TRUE)) } jeffreys <- set_bin_prior(beta_prior_fn, ab = c(1 / 2, 1 / 2))
Constructs a prior distribution for use as the argument prior
in
rpost
and rpost_rcpp
. The user can either
specify their own prior function, returning the log of the prior
density, (using an R function or an external pointer to a compiled C++
function) and arguments for hyperparameters or choose from a list of
in-built model-specific priors. Note that the arguments
model = "gev"
, model = "pp"
and model =="os"
are
equivalent because a prior is specified is the GEV parameterisation in each
of these cases.
Note also that for model = "pp"
the prior GEV parameterisation
relates to the value of noy
subsequently supplied to
rpost
or rpost_rcpp
.
The argument model
is used for consistency with rpost
.
set_prior( prior = c("norm", "loglognorm", "mdi", "flat", "flatflat", "jeffreys", "beta", "prob", "quant"), model = c("gev", "gp", "pp", "os"), ... )
set_prior( prior = c("norm", "loglognorm", "mdi", "flat", "flatflat", "jeffreys", "beta", "prob", "quant"), model = c("gev", "gp", "pp", "os"), ... )
prior |
Either
|
model |
A character string. If |
... |
Further arguments to be passed to the user-supplied or
in-built prior function. For details of the latter see Details
and/or the relevant underlying function: |
Of the in-built named priors available in revdbayes only
those specified using prior = "prob"
(gev_prob
),
prior = "quant"
(gev_quant
)
prior = "norm"
(gev_norm
) or
prior = "loglognorm"
(gev_loglognorm
) are proper.
If model = "gev"
these priors are equivalent to priors available
in the evdbayes package, namely prior.prob
,
prior.quant
, prior.norm
and prior.loglognorm
.
The other in-built priors are improper, that is, the integral of the
prior function over its support is not finite. Such priors do not
necessarily result in a proper posterior distribution. Northrop and
Attalides (2016) consider the issue of posterior propriety in Bayesian
extreme value analyses. In most of improper priors below the prior for
the scale parameter is taken to be
,
i.e. a flat prior for
. Here we denote the
scale parameter of the GP distribution by
, whereas we use
in the revdbayes vignette.
For all in-built priors the arguments min_xi
and max_xi
may
be supplied by the user. The prior density is set to zero for any value
of the shape parameter that is outside
(
min_xi
, max_xi
). This will override the default values
of min_xi
and max_xi
in the named priors detailed above.
Extreme value priors. It is typical to use either
prior = "prob"
(gev_prob
) or
prior = "quant"
(gev_quant
) to set an informative
prior and one of the other prior (or a user-supplied function) otherwise.
The names of the in-built extreme value priors set using prior
and details of hyperparameters are:
"prob"
. A prior for GEV parameters
based on Crowder (1992). See
gev_prob
for details.
See also Northrop et al. (2017) and Stephenson (2016).
"quant"
. A prior for GEV parameters
based on Coles and Tawn (1996). See
gev_quant
for details.
"norm"
.
For model = "gp"
:
(), is bivariate normal
with mean
mean
(a numeric vector of length 2) and covariance
matrix cov
(a symmetric positive definite 2 by 2 matrix).
For model = "gev"
:
(), is trivariate
normal with mean
mean
(a numeric vector of length 3) and
covariance matrix cov
(a symmetric positive definite 3 by 3
matrix).
"loglognorm"
. For model = "gev"
only:
(), is
trivariate normal with mean
mean
(a numeric vector of length 3)
and covariance matrix cov
(a symmetric positive definite 3 by 3
matrix).
"mdi"
.
For model = "gp"
: (an extended version
of) the maximal data information (MDI) prior, that is,
The value of is set using the argument
a
. The default
value is , which gives the MDI prior.
For model = "gev"
: (an extended version
of) the maximal data information (MDI) prior, that is,
The value of is set using the argument
a
. The default
value is , where
is Euler's
constant, which gives the MDI prior.
For each of these cases must be is bounded below
a priori for the posterior to be proper
(Northrop and Attalides, 2016). An argument for the
bound
is that for
the
GP (GEV) likelihood is unbounded above as
(
)) approaches the sample maximum. In
maximum likelihood estimation of GP parameters (Grimshaw, 1993)
and GEV parameters a local maximum of the likelihood
is sought on the region
.
"flat"
.
For model = "gp"
: a flat prior for
(and for
):
For model = "gev"
: a flat prior for
(and for
and
):
"flatflat"
.
For model = "gp"
: flat priors for
and
:
For model = "gev"
: flat priors for ,
and
:
Therefore, the posterior is proportional to the likelihood.
"jeffreys"
. For model = "gp"
only: the Jeffreys
prior (Castellanos and Cabras, 2007):
In the GEV case the Jeffreys prior doesn't yield a proper posterior for any sample size. See Northrop and Attalides (2016) for details.
"beta"
.
For model = "gp"
: a beta-type(p, q)
prior is used for xi on the interval (min_xi
, max_xi
):
For model = "gev"
: similarly ...
The argument pq
is a vector containing c(p,q)
.
The default settings for this prior are p = 6, q = 9
and
min_xi = -1/2, max_xi = 1/2
, which corresponds to the
prior for proposed in Martins and Stedinger (2000, 2001).
A list with class "evprior"
. The first component is the
input prior, i.e. either the name of the prior or a user-supplied
function. The remaining components contain the numeric values of any
hyperparameters in the prior.
Castellanos, E. M. and Cabras, S. (2007) A default Bayesian procedure for the generalized Pareto distribution. Journal of Statistical Planning and Inference 137(2), 473-483. doi:10.1016/j.jspi.2006.01.006.
Coles, S. G. and Tawn, J. A. (1996) A Bayesian analysis of extreme rainfall data. Appl. Statist., 45, 463-478.
Crowder, M. (1992) Bayesian priors based on parameter transformation using the distribution function Ann. Inst. Statist. Math., 44, 405-416. https://link.springer.com/article/10.1007/BF00050695.
Grimshaw, S. D. (1993) Computing Maximum Likelihood Estimates for the Generalized Pareto Distribution. Technometrics, 35(2), 185-191. doi:10.1080/00401706.1993.10485040.
Hosking, J. R. M. and Wallis, J. R. (1987) Parameter and Quantile Estimation for the Generalized Pareto Distribution. Technometrics, 29(3), 339-349. doi:10.2307/1269343.
Martins, E. S. and Stedinger, J. R. (2000) Generalized maximum likelihood generalized extreme value quantile estimators for hydrologic data, Water Resources Research, 36(3), 737-744. doi:10.1029/1999WR900330.
Martins, E. S. and Stedinger, J. R. (2001) Generalized maximum likelihood Pareto-Poisson estimators for partial duration series, Water Resources Research, 37(10), 2551-2557. doi:10.1029/2001WR000367.
Northrop, P.J. and Attalides, N. (2016) Posterior propriety in Bayesian extreme value analyses using reference priors Statistica Sinica, 26(2), 721–743 doi:10.5705/ss.2014.034.
Northrop, P. J., Attalides, N. and Jonathan, P. (2017) Cross-validatory extreme value threshold selection and uncertainty with application to ocean storm severity. Journal of the Royal Statistical Society Series C: Applied Statistics, 66(1), 93-120. doi:10.1111/rssc.12159
Stephenson, A. (2016) Bayesian inference for extreme value modelling. In Extreme Value Modeling and Risk Analysis: Methods and Applications (eds D. K. Dey and J. Yan), 257-280, Chapman and Hall, London. doi:10.1201/b19721.
rpost
and rpost_rcpp
for sampling
from an extreme value posterior distribution.
create_prior_xptr
for creating an external
pointer to a C++ function to evaluate the log-prior density.
rprior_prob
and rprior_quant
for
sampling from informative prior distributions for GEV parameters.
gp_norm
, gp_mdi
,
gp_flat
, gp_flatflat
,
gp_jeffreys
, gp_beta
to see the arguments
for priors for GP parameters.
gev_norm
, gev_loglognorm
,
gev_mdi
, gev_flat
, gev_flatflat
,
gev_beta
, gev_prob
, gev_quant
to see the arguments for priors for GEV parameters.
# Normal prior for GEV parameters (mu, log(sigma), xi). mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) pn # Prior for GP parameters with flat prior for xi on (-1, infinity). fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) fp # A user-defined prior (see the vignette for details). u_prior_fn <- function(x, ab) { if (x[1] <= 0 | x[2] <= -1 | x[2] >= 1) { return(-Inf) } return(-log(x[1]) + (ab[1] - 1) * log(1 + x[2]) + (ab[2] - 1) * log(1 - x[2])) } up <- set_prior(prior = u_prior_fn, ab = c(2, 2), model = "gp") # A user-defined prior using a pointer to a C++ function ptr_gp_flat <- create_prior_xptr("gp_flat") u_prior_ptr <- set_prior(prior = ptr_gp_flat, model = "gp")
# Normal prior for GEV parameters (mu, log(sigma), xi). mat <- diag(c(10000, 10000, 100)) pn <- set_prior(prior = "norm", model = "gev", mean = c(0,0,0), cov = mat) pn # Prior for GP parameters with flat prior for xi on (-1, infinity). fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) fp # A user-defined prior (see the vignette for details). u_prior_fn <- function(x, ab) { if (x[1] <= 0 | x[2] <= -1 | x[2] >= 1) { return(-Inf) } return(-log(x[1]) + (ab[1] - 1) * log(1 + x[2]) + (ab[2] - 1) * log(1 - x[2])) } up <- set_prior(prior = u_prior_fn, ab = c(2, 2), model = "gp") # A user-defined prior using a pointer to a C++ function ptr_gp_flat <- create_prior_xptr("gp_flat") u_prior_ptr <- set_prior(prior = ptr_gp_flat, model = "gp")
summary
method for class "evpost"
## S3 method for class 'evpost' summary(object, add_pu = FALSE, ...)
## S3 method for class 'evpost' summary(object, add_pu = FALSE, ...)
object |
An object of class "evpost", a result of a call to
|
add_pu |
Includes in the summary of the simulated values the threshold
exceedance probability |
... |
Additional arguments passed on to |
Prints
information about the ratio-of-uniforms bounding box, i.e.
object$box
an estimate of the probability of acceptance, i.e.
object$pa
a summary of the simulated values, via
summary(object$sim_vals)
ru
or ru_rcpp
for
descriptions of object$sim_vals
and object$box
.
plot.evpost
for a diagnostic plot.
# GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) summary(gpg)
# GP posterior u <- stats::quantile(gom, probs = 0.65) fp <- set_prior(prior = "flat", model = "gp", min_xi = -1) gpg <- rpost_rcpp(n = 1000, model = "gp", prior = fp, thresh = u, data = gom) summary(gpg)
The venice
data frame has 51 rows and 10 columns. The jth column
contains the jth largest sea levels in Venice, for the years 1931-1981. Only
the largest six measurements are available for the year 1935; the
corresponding row contains four missing values. The years for each set of
measurements are given as row names.
venice
venice
A data frame with 51 rows and 10 columns.
Smith, R. L. (1986) Extreme value theory based on the r largest annual events. Journal of Hydrology, 86, 27-43. doi:10.1016/0022-1694(86)90004-1
Coles, S. G. (2001) An Introduction to Statistical Modelling of Extreme Values. London: Springer. doi:10.1007/978-1-4471-3675-0
Samples from the posterior distribution of the probability
of a binomial distribution. User-supplied weights are applied to each
observation when constructing the log-likelihood.
wbinpost(n, prior, ds_bin)
wbinpost(n, prior, ds_bin)
n |
A numeric scalar. The size of posterior sample required. |
prior |
A function to evaluate the prior, created by
|
ds_bin |
A numeric list. Sufficient statistics for inference
about the binomial probability
|
For prior$prior == "bin_beta"
the posterior for
is a beta distribution so
rbeta
is used to
sample from the posterior.
An object (list) of class "binpost"
with components
bin_sim_vals: |
An |
bin_logf: |
A function returning the log-posterior for
|
bin_logf_args: |
A list of arguments to |
set_bin_prior
for setting a prior distribution
for the binomial probability .
u <- quantile(gom, probs = 0.65) ds_bin <- list(sf = gom > u, w = rep(1, length(gom))) bp <- set_bin_prior(prior = "jeffreys") temp <- wbinpost(n = 1000, prior = bp, ds_bin = ds_bin) graphics::hist(temp$bin_sim_vals, prob = TRUE)
u <- quantile(gom, probs = 0.65) ds_bin <- list(sf = gom > u, w = rep(1, length(gom))) bp <- set_bin_prior(prior = "jeffreys") temp <- wbinpost(n = 1000, prior = bp, ds_bin = ds_bin) graphics::hist(temp$bin_sim_vals, prob = TRUE)