Code Monkey home page Code Monkey logo

revdbayes's Introduction

revdbayes

AppVeyor Build Status R-CMD-check Coverage Status CRAN_Status_Badge Downloads (monthly) Downloads (total)

Ratio-of-uniforms Sampling for Bayesian Extreme Value Analysis

What does revdbayes do?

The revdbayes package uses the ratio-of-uniforms method to produce random samples from the posterior distributions that occur in some relatively simple Bayesian extreme value analyses. The functionality of revdbayes is similar to the evdbayes package, which uses Markov Chain Monte Carlo (MCMC) methods for posterior simulation. Advantages of the ratio-of-uniforms method over MCMC in this context are that the user is not required to set tuning parameters nor to monitor convergence and a random posterior sample is produced. Use of the Rcpp package enables revdbayes to be faster than evdbayes. Also provided are functions for making inferences about the extremal index, using the K-gaps model of Suveges and Davison (2010) and the D-gaps model of Holesovsky and Fusek (2020).

A simple example

The two main functions in revdbayes are set_prior and rpost. set_prior sets a prior for extreme value parameters. rpost samples from the posterior produced by updating this prior using the likelihood of observed data under an extreme value model. The following code sets a prior for Generalised Extreme Value (GEV) parameters based on a multivariate normal distribution and then simulates a random sample of size 1000 from the posterior distribution based on a dataset of annual maximum sea levels.

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)
plot(gevp)

From version 1.2.0 onwards the faster function rpost_rcpp can be used.
See the vignette “Faster simulation using revdbayes and Rcpp” for details. The functions rpost and post_rcpp have the same syntax. For example:

gevp_rcpp  <- rpost_rcpp(n = 1000, model = "gev", prior = pn, data = portpirie)

Installation

To get the current released version from CRAN:

install.packages("revdbayes")

Vignettes

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. Inference for the extremal index using threshold inter-exceedance times is described in vignette("revdbayes-d-kgaps-vignette", package = "revdbayes")

revdbayes's People

Contributors

paulnorthrop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

revdbayes's Issues

Failure with dev testthat

I see

── ERROR (test-bingp.R:37:3): (code run outside of `test_that()`) ──────────────
Error: `desc` must be a string
Backtrace:
    █
 1. └─revdbayes:::test_function(x, test_string) test-bingp.R:37:2
 2.   └─testthat::test_that(...) test-bingp.R:22:2

── ERROR (test-gev.R:35:3): (code run outside of `test_that()`) ────────────────
Error: `desc` must be a string
Backtrace:
    █
 1. └─revdbayes:::test_function(x, test_string) test-gev.R:35:2
 2.   └─testthat::test_that(...) test-gev.R:21:2

── ERROR (test-gp.R:35:3): (code run outside of `test_that()`) ─────────────────
Error: `desc` must be a string
Backtrace:
    █
 1. └─revdbayes:::test_function(x, test_string) test-gp.R:35:2
 2.   └─testthat::test_that(...) test-gp.R:21:2

Because testthat now checks that the first argument is a string.

I'm planning to submit testthat to CRAN in about a month.

Confusing documentation for MDI prior

Lines 434-437 of priors.R, the documentation for the MDI prior for the generalized Pareto model states the following:

#' @param pars A numeric vector of length 3.
#'   GP parameters (\eqn{\sigma, \xi}).
#' @param a A numeric scalar.  The default value, **Euler's constant**, gives the
#'   MDI prior.

The parameter vector is of length 2. The default value for a is 1, as the function is parametrized so that $$\frac{1}{\sigma}\exp(-a\xi).$$

Revert commit 09b9934

If the data consist of exceedances above the threshold (e.g., when thresh = NULL with model = "gp"), this throws an unwanted error.
The documentation for rpost_rcpp states (argument thresh):

If model = "gp" and thresh is not supplied then thresh = 0 is used and data should contain threshold excesses.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.