MCpriorIntFun function

Generic Monte-Carlo integration of a function under the prior distribution

Generic Monte-Carlo integration of a function under the prior distribution

Simple Monte-Carlo sampler approximating the integral of FUN with respect to the prior distribution.

MCpriorIntFun( Nsim = 200, prior, Hpar, dimData, FUN = function(par, ...) { as.vector(par) }, store = TRUE, show.progress = floor(seq(1, Nsim, length.out = 20)), Nsim.min = Nsim, precision = 0, ... )

Arguments

  • Nsim: Maximum number of iterations

  • prior: The prior distribution: of type

    function(type=c("r","d"), n ,par, Hpar, log, dimData ), where dimData is the dimension of the sample space (e.g., for the two-dimensional simplex (triangle), dimData=3. Should return either a matrix with n rows containing a random parameter sample generated under the prior (if type == "d"), or the density of the parameter par (the logarithm of the density if log==TRUE. See prior.pb and prior.nl for templates.

  • Hpar: A list containing Hyper-parameters to be passed to prior.

  • dimData: The dimension of the model's sample space, on which the parameter's dimension may depend. Passed to prior inside MCintegrateFun

  • FUN: A function to be integrated. It may return a vector or an array.

  • store: Should the successive evaluations of FUN be stored ?

  • show.progress: same as in posteriorMCMC

  • Nsim.min: The minimum number of iterations to be performed.

  • precision: The desired relative precision ϵ\epsilon. See Details below.

  • ...: Additional arguments to be passed to FUN.

Returns

A list made of

  • stored.vals : A matrix with nsim rows and length(FUN(par)) columns.
  • elapsed : The time elapsed during the computation.
  • nsim : The number of iterations performed
  • emp.mean : The desired integral estimate: the empirical mean.
  • emp.stdev : The empirical standard deviation of the sample.
  • est.error : The estimated standard deviation of the estimate (i.e. emp.stdev/(nsim)emp.stdev/\sqrt(nsim)).
  • not.finite : The number of non-finite values obtained (and discarded) when evaluating FUN(par,...)

Details

The algorithm exits after nn iterations, based on the following stopping rule : nn is the minimum number of iteration, greater than Nsim.min, such that the relative error is less than the specified precision.

max(est.esterr(n)/est.mean(n))ϵ, max (est.esterr(n)/ |est.mean(n)| ) \le \epsilon ,

where est.mean(n)est.mean(n) is the estimated mean of FUN at time nn, est.err(n)est.err(n) is the estimated standard deviation of the estimate: est.err(n)=est.var(n)/(nsim1)est.err(n) = \sqrt{est.var(n)/(nsim-1)} . The empirical variance is computed component-wise and the maximum over the parameters' components is considered.

The algorithm exits in any case after Nsim iterations, if the above condition is not fulfilled before this time.

Author(s)

Anne Sabourin

  • Maintainer: Leo Belzile
  • License: GPL (>= 2)
  • Last published: 2023-04-21

Useful links