Title: | Multivariate Extremes: Bayesian Estimation of the Spectral Measure |
---|---|
Description: | Toolkit for Bayesian estimation of the dependence structure in multivariate extreme value parametric models, following Sabourin and Naveau (2014) <doi:10.1016/j.csda.2013.04.021> and Sabourin, Naveau and Fougeres (2013) <doi:10.1007/s10687-012-0163-0>. |
Authors: | Leo Belzile [cre] |
Maintainer: | Leo Belzile <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.5 |
Built: | 2025-02-04 03:38:32 UTC |
Source: | https://github.com/lbelzile/bmamevt |
Toolkit for Bayesian estimation of the dependence structure
in Multivariate Extreme Value parametric models, with possible use of Bayesian model Averaging techniques
Includes a Generic MCMC sampler. Estimation of the marginal
distributions is a prerequisite, e.g. using one of the
packages
ismev
, evd
, evdbayes
or POT
. This package handles data sets which are assumed
to be marginally unit-Frechet distributed.
Anne Sabourin
evdbayes
Adds graphical elements to the current plot (on the two-dimensional simplex).
add.frame( equi = FALSE, lab1 = "w1", lab2 = "w2", lab3 = "w3", npoints = 60, col.polygon = "black", axes = TRUE )
add.frame( equi = FALSE, lab1 = "w1", lab2 = "w2", lab3 = "w3", npoints = 60, col.polygon = "black", axes = TRUE )
equi |
logical. Is the simplex represented as an equilateral triangle (if |
lab1 |
Character string: label for first component. |
lab2 |
Character string: label for second component. |
lab3 |
Character string: label for third component. |
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
col.polygon |
The background color outside the simplex. |
axes |
logical. Should axes be added ? |
Generic graphical tool for obtaining nice plots of the two-dimensional simplex
plot.new() add.frame() plot.new() mult.x=sqrt(2); mult.y=sqrt(3/2) plot.window( xlim=c(0,mult.x),ylim=c(0,mult.y), asp=1,bty ="n") add.frame(equi=TRUE)
plot.new() add.frame() plot.new() mult.x=sqrt(2); mult.y=sqrt(3/2) plot.window( xlim=c(0,mult.x),ylim=c(0,mult.y), asp=1,bty ="n") add.frame(equi=TRUE)
Builds an angular data set, retaining the points with largest radial component.
cons.angular.dat( coordinates = c(1, 2, 3), frechetDat = get("frechetdat"), n = 100, displ = TRUE, invisible = TRUE, add = FALSE, lab1 = "w1", lab2 = "w2", lab3 = "w3", npoints = 60, col.polygon = "white", ... )
cons.angular.dat( coordinates = c(1, 2, 3), frechetDat = get("frechetdat"), n = 100, displ = TRUE, invisible = TRUE, add = FALSE, lab1 = "w1", lab2 = "w2", lab3 = "w3", npoints = 60, col.polygon = "white", ... )
coordinates |
Index vector of the columns in |
frechetDat |
The data set. A matrix: each row is a multivariate record. May contain NA's. |
n |
The number of desired observations in the final angular data set. Should be less than |
displ |
logical. Should the angular data set be plotted ? |
invisible |
logical. Should the result be returned as invisible ? |
add |
logical. Only used when |
lab1 |
Character string: label for first component. |
lab2 |
Character string: label for second component. |
lab3 |
Character string: label for third component. |
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
col.polygon |
The background color outside the simplex. |
... |
Additional graphical parameters and arguments to be passed to function |
The data set frechetDat
is assumed to be marginally unit Frechet distributed.
The angular data set: A n*length(coordinates)
matrix, containing values between zero and one, which rows sum to one: Each row is thus a point on the unit simplex of dimension length(coordinates)-1
. Returned as invisible if invisible==TRUE
.
## Not run: cons.angular.dat()
## Not run: cons.angular.dat()
Likelihood function (spectral density on the simplex) and angular data sampler in the Dirichlet mixture model.
ddirimix( x = c(0.1, 0.2, 0.7), par, wei = par$wei, Mu = par$Mu, lnu = par$lnu, log = FALSE, vectorial = FALSE ) rdirimix( n = 10, par = get("dm.expar.D3k3"), wei = par$wei, Mu = par$Mu, lnu = par$lnu )
ddirimix( x = c(0.1, 0.2, 0.7), par, wei = par$wei, Mu = par$Mu, lnu = par$lnu, log = FALSE, vectorial = FALSE ) rdirimix( n = 10, par = get("dm.expar.D3k3"), wei = par$wei, Mu = par$Mu, lnu = par$lnu )
x |
An angular data set which may be reduced to a single point:
A |
par |
The parameter list for the Dirichlet mixture model. |
wei |
Optional. If present, overrides the value of
|
Mu |
Optional. If present, overrides the value of
|
lnu |
Optional. If present, overrides the value of
|
log |
Logical: should the density or the likelihood be returned on the log-scale ? |
vectorial |
Logical: Should a vector of size |
n |
The number of angular points to be generated |
The spectral probability measure defined on the simplex
characterizes the
dependence structure of multivariate extreme value models.
The parameter list for a mixture
with components, is made of
The density kernel centers
:
A
matrix,
which columns sum to one, and such that
Mu %*% wei=1
,
for the moments constraint to be satisfied.
Each column is a Dirichlet kernel center.
The weights vector for the kernel densities:
A vector of positive numbers summing to one.
The logarithms of the shape parameters
for the density kernels:
a vector of size
.
The moments constraint imposes that the barycenter of the columns in
Mu
, with weights wei
, be the center of the simplex.
ddirimix
returns the likelihood as a single number if
vectorial ==FALSE
, or as a vector of size
nrow(x)
containing the likelihood of each angular data point.
If log == TRUE
, the log-likelihood is returned instead.
rdirimix
returns a matrix with n
points and
p=nrow(Mu)
columns.
Only valid in the tri-variate case
ddirimix.grid( par = get("dm.expar.D3k3"), wei = par$wei, Mu = par$Mu, lnu = par$lnu, npoints = 30, eps = 10^(-3), equi = TRUE, marginal = TRUE, coord = c(1, 2, 3), invisible = TRUE, displ = TRUE, ... )
ddirimix.grid( par = get("dm.expar.D3k3"), wei = par$wei, Mu = par$Mu, lnu = par$lnu, npoints = 30, eps = 10^(-3), equi = TRUE, marginal = TRUE, coord = c(1, 2, 3), invisible = TRUE, displ = TRUE, ... )
par |
The parameter list for the Dirichlet mixture model. |
wei |
Optional. If present, overrides the value of
|
Mu |
Optional. If present, overrides the value of
|
lnu |
Optional. If present, overrides the value of
|
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
marginal |
logical. If |
coord |
A vector of size 3: the indices of the coordinates upon which the marginalization is to be done. |
invisible |
Logical: should the result be returned as invisible ? |
displ |
Logical: should a plot be issued ? |
... |
Additional arguments to be passed to
|
The discretized density
[0,1]
Plots a univariate Dirichlet mixture (in other words, a Beta mixture) angular density for extreme bi-variate data.
ddirimix.grid1D( par = get("dm.expar.D2k4"), wei = par$wei, Mu = par$Mu, lnu = par$lnu, npoints = 30, eps = 10^(-3), coord = c(1, 2), marginal = TRUE, invisible = TRUE, displ = TRUE, add = FALSE, ... )
ddirimix.grid1D( par = get("dm.expar.D2k4"), wei = par$wei, Mu = par$Mu, lnu = par$lnu, npoints = 30, eps = 10^(-3), coord = c(1, 2), marginal = TRUE, invisible = TRUE, displ = TRUE, add = FALSE, ... )
par |
The parameter list for the Dirichlet mixture model. |
wei |
Optional. If present, overrides the value of
|
Mu |
Optional. If present, overrides the value of
|
lnu |
Optional. If present, overrides the value of
|
npoints |
number of points on the 1D discretization grid. |
eps |
the minimum value ( = 1- the maximum value) of the grid points. |
coord |
A vector of size 2: the indices of the coordinates upon which the marginalization or projection is to be done if the dimension of the sample space is greater than two. |
marginal |
logical. If |
invisible |
Logical: should the result be returned as invisible ? |
displ |
Logical: should a plot be issued ? |
add |
Logical: should the density be added to the currently active plot ? |
... |
Additional arguments to be passed to |
The discretized density on [eps, 1-eps]
(included in [0,1])
Plots contours or gray-scale level sets of a spectral density on the two-dimensional simplex.
dgridplot( density = matrix(5 * sin(1/73 * (1:(40 * 40)))^2, ncol = 40, nrow = 40), eps = 10^(-3), equi = TRUE, add = FALSE, breaks = seq(-0.01, 5.1, length.out = 1000), levels = seq(0, 6, length.out = 13), col.lines = "black", labcex = 0.8, background = FALSE, col.polygon = gray(0.5), lab1 = "w1", lab2 = "w2", lab3 = "w3", ... )
dgridplot( density = matrix(5 * sin(1/73 * (1:(40 * 40)))^2, ncol = 40, nrow = 40), eps = 10^(-3), equi = TRUE, add = FALSE, breaks = seq(-0.01, 5.1, length.out = 1000), levels = seq(0, 6, length.out = 13), col.lines = "black", labcex = 0.8, background = FALSE, col.polygon = gray(0.5), lab1 = "w1", lab2 = "w2", lab3 = "w3", ... )
density |
A |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
add |
Logical. Should the contours be added to a currently active plot ? |
breaks |
Set of breakpoints for the gray scale colors.
See |
levels |
Levels to which plot the contour lines. See |
col.lines |
The color to be used for the contour lines. |
labcex |
|
background |
Logical. Should a the background be filled
inside the simplex via a call to
|
col.polygon |
The background color outside the simplex. |
lab1 |
Character string: label for first component. |
lab2 |
Character string: label for second component. |
lab3 |
Character string: label for third component. |
... |
Additional graphical parameters and arguments to be passed
to |
The function interprets the density
matrix as
contour
does, i.e. as a table of
f(X[i], Y[j])
values, with column 1 at the bottom,
where X
and Y
are
returned by discretize
and f
is the
density function.
wrapper <- function(x, y, my.fun,...) { sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i],...)) } grid <- discretize(npoints=40,eps=1e-3,equi=FALSE) Density <- outer(grid$X,grid$Y,FUN=wrapper, my.fun=function(x,y){10*((x/2)^2+y^2)*((x+y)<1)}) dgridplot(density= Density,npoints=40, equi=FALSE)
wrapper <- function(x, y, my.fun,...) { sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i],...)) } grid <- discretize(npoints=40,eps=1e-3,equi=FALSE) Density <- outer(grid$X,grid$Y,FUN=wrapper, my.fun=function(x,y){10*((x/2)^2+y^2)*((x+y)<1)}) dgridplot(density= Density,npoints=40, equi=FALSE)
The method issues several convergence diagnostics, in the particular case when the PB or the NL model is used. The code may be easily modified for other angular models.
diagnose(obj, ...) ## S3 method for class 'PBNLpostsample' diagnose( obj, true.par = NULL, from = NULL, to = NULL, autocor.max = 0.2, default.thin = 50, xlim.density = c(-4, 4), ylim.density = NULL, plot = TRUE, predictive = FALSE, save = TRUE, ... )
diagnose(obj, ...) ## S3 method for class 'PBNLpostsample' diagnose( obj, true.par = NULL, from = NULL, to = NULL, autocor.max = 0.2, default.thin = 50, xlim.density = c(-4, 4), ylim.density = NULL, plot = TRUE, predictive = FALSE, save = TRUE, ... )
obj |
an object of class |
... |
Additional parameters to be passed to the functions
|
true.par |
The true parameter. If |
from |
Integer or |
to |
Integer or |
autocor.max |
The maximum accepted auto-correlation for two successive parameters in the thinned sample. |
default.thin |
The default thinning interval if the above condition cannot be satisfied. |
xlim.density |
The |
ylim.density |
the |
plot |
Logical. Should plots be issued ? |
predictive |
Logical. Should the predictive density be plotted ? |
save |
Logical: should the result be saved ? Only used if the posterior sample has been saved itself (i.e. if it contains |
A list made of
The posterior predictive, or 0
if predictive=FALSE
the effective sample size of each component
The first part of the Heidelberger and Welch test (stationarity test). The first row indicates “success” (1) or rejection(0), the second line shows the number of iterations to be discarded, the third line is the p-value of the test statistic.
The test statistics from the Geweke stationarity test.
The p-values for the above test statistics
The thinning interval retained
The maximum auto-correlation for a lag equal to thin
The posterior mean of the transformed parameter (on the real line)
The standard deviation of the transformed parameters
The posterior mean of the original parameters, as they appears in the expression of the likelihood
the posterior standard deviation of the original parameters
Builds a discretization grid covering the two-dimensional unit simplex, with specified number of points and minimal distance from the boundary.
discretize(npoints = 40, eps = 0.001, equi = FALSE)
discretize(npoints = 40, eps = 0.001, equi = FALSE)
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
The npoints*npoints
grid covers either
the equilateral representation of
the simplex, or the right angled one.
In any case, the grid is
rectangular: some nodes lie outside the triangle.
Density computations on such a grid should handle the case when
the point passed as argument is outside the simplex (typically,
the function should return zero in such a case).
A list containing two elements: X
and Y
, vectors of size npoints
, the Cartesian coordinates of the grid nodes.
In case equi==TRUE
, epsilon
is the minimum
distance from any node inside the simplex to the simplex boundary,
after transformation to the right-angled representation.
The Dirichlet mixture density has three components, the center of mass of the three columns of Mu
, with weights wei
is : the centroid of the two dimensional unit simplex.
A list made of
A matrix, which rows sum to one, such that the
center of mass of the three column vectors (weighted with
wei
) is the centroid of the simplex: each column is the center of a Dirichlet mixture component.
A vector of length three, summing to one: the mixture weights
A vector of length three: the logarithm of the concentration parameters.
Likelihood function (spectral density) and random generator in the Pairwise Beta and NL models.
dnestlog( x = rbind(c(0.1, 0.3, 0.6), c(0.3, 0.3, 0.4)), par = c(0.5, 0.5, 0.2, 0.3), log = FALSE, vectorial = TRUE ) dpairbeta( x, par = c(1, rep(2, choose(4, 2) + 1)), log = FALSE, vectorial = TRUE ) rnestlog( n = 5, par = c(0.2, 0.3, 0.4, 0.5), threshold = 1000, return.points = FALSE ) rpairbeta(n = 1, dimData = 3, par = c(1, rep(1, 3)))
dnestlog( x = rbind(c(0.1, 0.3, 0.6), c(0.3, 0.3, 0.4)), par = c(0.5, 0.5, 0.2, 0.3), log = FALSE, vectorial = TRUE ) dpairbeta( x, par = c(1, rep(2, choose(4, 2) + 1)), log = FALSE, vectorial = TRUE ) rnestlog( n = 5, par = c(0.2, 0.3, 0.4, 0.5), threshold = 1000, return.points = FALSE ) rpairbeta(n = 1, dimData = 3, par = c(1, rep(1, 3)))
x |
An angular data set (may be reduced to a single point).
A |
par |
The parameter for the Pairwise Beta or the Nested Logistic density.
|
log |
Logical. Should the density be returned on the log scale ? |
vectorial |
Logical. Should a vector or a single value be returned ? |
n |
The number of points on the simplex to be generated. |
threshold |
The radial threshold
to hold. |
return.points |
logical: should the censored vectorial dataset corresponding to the angular one be returned ? |
dimData |
the dimension of the sample space, which is |
Applies to angular data sets. The density is given with respect to the Lebesgue measure on , where
p
is the number of columns in x
(or the length of x
, if the latter is a single point).
The value returned by the likelihood function is imposed (see
e.g. posteriorMCMC
.
In contrast, the random variable have unconstrained output format.
dpairbeta
returns the likelihood as a single number if vectorial ==FALSE
, or as a vector of size nrow(x)
containing the likelihood of each angular data point. If log == TRUE
, the log-likelihood is returned instead.
rpairbeta
returns a matrix with n
rows and dimData
columns.
dnestlog
returns the likelihood as a single number if vectorial ==FALSE
, or as a vector of size nrow(x)
containing the likelihood of each angular data point. If log == TRUE
, the log-likelihood is returned instead.
rnestlog
returns a matrix with n
rows and dimData
columns if return.points==FALSE
(the default). Otherwise,
a list is returned, with two elements:
Angles
: The angular data set
Points
: The full tri-variate data set above
threshold
(i.e. Angles
multiplied by the radial components)
The two functions compute respectively the NL and PB spectral densities, in the three-dimensional case, on a discretization grid. A plot is issued (optional).
dnestlog.grid( par, npoints = 50, eps = 0.001, equi = TRUE, displ = TRUE, invisible = TRUE, ... ) dpairbeta.grid( par, npoints = 50, eps = 0.001, equi = TRUE, displ = TRUE, invisible = TRUE, ... )
dnestlog.grid( par, npoints = 50, eps = 0.001, equi = TRUE, displ = TRUE, invisible = TRUE, ... ) dpairbeta.grid( par, npoints = 50, eps = 0.001, equi = TRUE, displ = TRUE, invisible = TRUE, ... )
par |
The parameter for the Pairwise Beta or the Nested Logistic density.
|
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
displ |
logical. Should a plot be produced ? |
invisible |
logical. If |
... |
Additional arguments to be passed to |
A npoints*npoints
matrix containing the
considered density's values on the grid.
The row (resp. column) indices increase
with the first (resp. second) coordinate on the simplex.
If equi==TRUE
, the density is relative to the Hausdorff
measure on the simplex itself: the values obtained with
equi = FALSE
are thus divided by
.
dpairbeta.grid(par=c( 0.8, 8, 5, 2), npoints=70, eps = 1e-3, equi = TRUE, displ = TRUE, invisible=TRUE) ## or ... Dens <- dpairbeta.grid(par=c(0.8, 8, 5, 2), npoints=70, eps = 1e-3, equi = TRUE, displ = FALSE) Grid=discretize(npoints=70,eps=1e-3,equi=TRUE) dev.new() image(Grid$X, Grid$Y, Dens) contour(Grid$X, Grid$Y, Dens, add=TRUE) add.frame(equi=TRUE, npoints=70, axes=FALSE)
dpairbeta.grid(par=c( 0.8, 8, 5, 2), npoints=70, eps = 1e-3, equi = TRUE, displ = TRUE, invisible=TRUE) ## or ... Dens <- dpairbeta.grid(par=c(0.8, 8, 5, 2), npoints=70, eps = 1e-3, equi = TRUE, displ = FALSE) Grid=discretize(npoints=70,eps=1e-3,equi=TRUE) dev.new() image(Grid$X, Grid$Y, Dens) contour(Grid$X, Grid$Y, Dens, add=TRUE) add.frame(equi=TRUE, npoints=70, axes=FALSE)
simple MC integration on the simplex.
excessProb.condit.dm( N = 100, par = get("dm.expar.D3k3"), thres = rep(100, 3), plot = FALSE, add = FALSE )
excessProb.condit.dm( N = 100, par = get("dm.expar.D3k3"), thres = rep(100, 3), plot = FALSE, add = FALSE )
N |
The number of MC iterations to be performed |
par |
the DM parameter, as a list |
thres |
the multivariate threshold |
plot |
logical: should convergence diagnostic plots be issued ? |
add |
logical: should the plot be added to a current one ? |
a list made of
the mean estimate from the MC sample
the estimated standard deviation of the estimator
The estimated standard deviation of the MC sample
Probability of joint threshold excess in the NL model
excessProb.condit.nl(par = c(0.3, 0.4, 0.5, 0.6), thres = rep(100, 3))
excessProb.condit.nl(par = c(0.3, 0.4, 0.5, 0.6), thres = rep(100, 3))
par |
The Nested logistic parameter: of length four. |
thres |
a positive vector of size three. |
The approximate probability of joint excess, valid when at least one coordinate of thres
is large
Posterior distribution the probability of joint threshold excess, in the NL model.
excessProb.nl( post.sample, from = NULL, to = NULL, thin = 100, thres = rep(100, 3), known.par = FALSE, true.par, displ = FALSE )
excessProb.nl( post.sample, from = NULL, to = NULL, thin = 100, thres = rep(100, 3), known.par = FALSE, true.par, displ = FALSE )
post.sample |
The posterior sample, as returned by |
from |
Integer or |
to |
Integer or |
thin |
Thinning interval. |
thres |
a positive vector of size three. |
known.par |
logical. Is the true parameter known ? |
true.par |
The true parameter, only used if |
displ |
logical. Should a plot be produced ? |
A list made of
The output of posteriorMean
called with FUN=excessProb.condit.nl
.
The posterior mean of the excess probability
The standard deviation of the mean estimator
The standard deviation of the excess probability, in the posterior sample.
The lower 0.1 quantile of the empirical posterior distribution of the excess probability
The upper 0.1 quantile of the empirical posterior distribution of the excess probability
NULL
if known.par=FALSE
, otherwise the excess probability in the true model.
Double Monte-Carlo integration.
excessProb.pb( post.sample, Nmin.intern = 100, precision = 0.05, from = NULL, to = NULL, thin = 100, displ = FALSE, thres = rep(500, 5), known.par = FALSE, true.par )
excessProb.pb( post.sample, Nmin.intern = 100, precision = 0.05, from = NULL, to = NULL, thin = 100, displ = FALSE, thres = rep(500, 5), known.par = FALSE, true.par )
post.sample |
The posterior sample. |
Nmin.intern |
The minimum number of MC iteration in the internal loop (excess probability, conditional to a parameter). |
precision |
The desired precision for the internal MC estimate |
from |
Integer or |
to |
Integer or |
thin |
Thinning interval. |
displ |
logical. Should a plot be produced ? |
thres |
A multivariate threshold |
known.par |
Logical |
true.par |
The true parameter from which the data are issued. |
A list made of
A vector of estimated excess probabilities, one for each element of the thinned posterior sample.
the estimated threshold excess probability: mean estimate.
The estimated standard deviation of the mean estimate (where the Monte-Carlo error is neglected)
The estimated standard deviation of the posterior sample (where the Monte-Carlo error is neglected)
The three lower quantiles of, respectively, the conditional mean estimates and of the upper and lower bounds of the Gaussian (centered)
% confidence intervals around the conditional estimates.
The three upper quantiles
the mean estimate conditional to the true parameter: a vector of size three: the mean estimate , and the latter +/- the standard deviation of the estimate
The exponent function for a max-stable variable
is such that
expfunction.nl(par = c(0.3, 0.4, 0.5, 0.6), x = 10 * rep(1, 3))
expfunction.nl(par = c(0.3, 0.4, 0.5, 0.6), x = 10 * rep(1, 3))
par |
The parameter for the NL distribution, respectively of length two or four. |
x |
A vector of three extended positive real numbers |
the value of for
.
Five-variate dataset which margins follow unit-Frechet distributions,
obtained from winterdat
by probability integral
transform.
Marginal estimation was performed by maximum likelihood estimation of a Generalized Pareto distribution over marginal thresholds corresponding to quantiles, following
Cooley et.al. (see reference below). The “non extreme” part of the marginal distributions was approximated by the empirical distribution function.
A - matrix:
COOLEY, D., DAVIS, R. and NAVEAU, P. (2010). The pairwise beta distribution: A flexible parametric multivariate model for extremes. Journal of Multivariate Analysis 101, 2103-2117.
Inverse transformation of the logit
function.
invlogit(x)
invlogit(x)
x |
A real number |
A number between and
.
Approximation of a model marginal likelihood by Laplace method.
laplace.evt( mode = NULL, npar = 4, likelihood, prior, Hpar, data, link, unlink, method = "L-BFGS-B" )
laplace.evt( mode = NULL, npar = 4, likelihood, prior, Hpar, data, link, unlink, method = "L-BFGS-B" )
mode |
The parameter vector (on the “unlinked” scale, i.e. before transformation to the real line)
which maximizes the posterior density, or |
npar |
The size of the parameter vector. Default to four. |
likelihood |
|
prior |
The prior density (takes an “unlinked” parameter as argument and returns the density of the |
Hpar |
The prior hyper parameter list. |
data |
The angular dataset |
link |
The link function, from the “classical” or “unlinked” parametrization onto the real line. (e.g. |
unlink |
The inverse link function (e.g. |
method |
The optimization method to be used. Default to |
The posterior mode is either supplied, or approximated by numerical optimization. For an introduction about Laplace's method, see e.g. Kass and Raftery, 1995 and the references therein.
A list made of
the parameter (on the unlinked scale) deemed to maximize the posterior density. This is equal to the argument if the latter is not null.
The value of the posterior, evaluated at mode
.
The logarithm of the estimated marginal likelihood
The inverse of the estimated hessian matrix at mode
KASS, R.E. and RAFTERY, A.E. (1995). Bayes Factors. Journal of the American Statistical Association, Vol. 90, No.430
The data set is constructed from coordinates (columns) of
frechetdat
.
It contains 100 angular points corresponding to the tri-variate vectors with largest
norm (
). The angular points are obtained by ‘normalizing’: e.g.,
. Thus,
each row in
Leeds
is a point on the two-dimensional simplex : .
A - matrix.
COOLEY, D., DAVIS, R. and NAVEAU, P. (2010). The pairwise beta distribution: A flexible parametric multivariate model for extremes. Journal of Multivariate Analysis 101, 2103-2117
RESNICK, S. (1987). Extreme values, regular variation, and point processes, Applied Probability. A, vol. 4, Series of the Applied Probability Trust. Springer-Verlag, New York.
The data set contains 590 (transformed) daily maxima of five air pollutants recorded in Leeds (U.K.) during five winter seasons (1994-1998). Contains NA's. Marginal transformation to unit Frechet was performed by Cooley et.al. (see reference below).##' . Thus,
A - matrix:
COOLEY, D., DAVIS, R. and NAVEAU, P. (2010). The pairwise beta distribution: A flexible parametric multivariate model for extremes. Journal of Multivariate Analysis 101, 2103-2117
Bijective Transformation from to the real line, defined
by
.
logit(p)
logit(p)
p |
A real number in |
A real number
Estimates the marginal likelihood of a model, proceeding by simple Monte-Carlo integration under the prior distribution.
marginal.lkl( dat, likelihood, prior, Nsim = 300, displ = TRUE, Hpar, Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) )
marginal.lkl( dat, likelihood, prior, Nsim = 300, displ = TRUE, Hpar, Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) )
dat |
The angular data set relative to which the marginal model likelihood is to be computed |
likelihood |
The likelihood function of the model.
See |
prior |
The prior distribution: of type |
Nsim |
Total number of iterations to perform. |
displ |
logical. If |
Hpar |
A list containing Hyper-parameters to be passed to
|
Nsim.min |
The minimum number of iterations to be performed. |
precision |
the desired relative precision. See
|
show.progress |
An vector of integers containing the times (iteration numbers) at which a message showing progression will be printed on the standard output. |
The function is a wrapper calling MCpriorIntFun
with parameter FUN
set to likelihood
.
The list returned by MCpriorIntFun
. The estimate is the list's element named emp.mean
.
The estimated standard deviations of the estimates produced by this function should be handled with care:For "larger" models than the Pairwise Beta or the NL models, the likelihood may have infinite second moment under the prior distribution. In such a case, it is recommended to resort to more sophisticated integration methods, e.g. by sampling from a mixture of the prior and the posterior distributions. See the reference below for more details.
KASS, R. and RAFTERY, A. (1995). Bayes factors. Journal of the american statistical association , 773-795.
marginal.lkl.pb
, marginal.lkl.nl
for direct use with the implemented models.
## Not run: lklNL= marginal.lkl(dat=Leeds, likelihood=dnestlog, prior=prior.nl, Nsim=20e+3, displ=TRUE, Hpar=nl.Hpar, ) ## End(Not run)
## Not run: lklNL= marginal.lkl(dat=Leeds, likelihood=dnestlog, prior=prior.nl, Nsim=20e+3, displ=TRUE, Hpar=nl.Hpar, ) ## End(Not run)
Wrappers for marginal.lkl
, in the specific cases of the PB and NL models,
with parameter likelihood
set to dpairbeta
or
dnestlog
, and prior
set to prior.pb
or
prior.nl
. See MCpriorIntFun
for more details.
marginal.lkl.nl( dat, Nsim = 10000, displ = TRUE, Hpar = get("nl.Hpar"), Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) ) marginal.lkl.pb( dat, Nsim = 10000, displ = TRUE, Hpar = get("pb.Hpar"), Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) )
marginal.lkl.nl( dat, Nsim = 10000, displ = TRUE, Hpar = get("nl.Hpar"), Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) ) marginal.lkl.pb( dat, Nsim = 10000, displ = TRUE, Hpar = get("pb.Hpar"), Nsim.min = Nsim, precision = 0, show.progress = floor(seq(1, Nsim, length.out = 20)) )
dat |
The angular data set relative to which the marginal model likelihood is to be computed |
Nsim |
Total number of iterations to perform. |
displ |
logical. If |
Hpar |
A list containing Hyper-parameters to be passed to
|
Nsim.min |
The minimum number of iterations to be performed. |
precision |
the desired relative precision. See
|
show.progress |
An vector of integers containing the times (iteration numbers) at which a message showing progression will be printed on the standard output. |
The list returned by
marginal.lkl
, i.e., the one returned by MCpriorIntFun
## Not run: marginal.lkl.pb(dat=Leeds , Nsim=20e+3 , displ=TRUE, Hpar = get("pb.Hpar") , ) marginal.lkl.nl(dat=Leeds , Nsim=10e+3 , displ=TRUE, Hpar = get("nl.Hpar") , ) ## End(Not run)
## Not run: marginal.lkl.pb(dat=Leeds , Nsim=20e+3 , displ=TRUE, Hpar = get("pb.Hpar") , ) marginal.lkl.nl(dat=Leeds , Nsim=10e+3 , displ=TRUE, Hpar = get("nl.Hpar") , ) ## End(Not run)
Maximum likelihood optimization
maxLikelihood( data, model, init = NULL, maxit = 500, method = "L-BFGS-B", hess = T, link, unlink )
maxLikelihood( data, model, init = NULL, maxit = 500, method = "L-BFGS-B", hess = T, link, unlink )
data |
The angular data to be used for inference |
model |
A list made of
.
|
init |
NULL or a real vector of size |
maxit |
maximum number of iterations to be performed by
function |
method |
The method to be used by |
hess |
logical: should an approximation of the hessian be performed ? |
link |
the link function from the natural marginal parameter spaces to the real line. |
unlink |
the inverse link function. If |
The list returned by optim
and the AIC and BIC criteria
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, ... )
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, ... )
Nsim |
Maximum number of iterations |
prior |
The prior distribution: of type |
Hpar |
A list containing Hyper-parameters to be passed to
|
dimData |
The dimension of the model's sample space,
on which the parameter's dimension may depend.
Passed to |
FUN |
A function to be integrated. It may return a vector or an array. |
store |
Should the successive evaluations of |
show.progress |
same as in |
Nsim.min |
The minimum number of iterations to be performed. |
precision |
The desired relative precision |
... |
Additional arguments to be passed to |
The algorithm exits after iterations,
based on the following stopping rule :
is the minimum number of iteration, greater than
Nsim.min
, such that the relative
error is less than the specified precision
.
where
is the estimated mean of
FUN
at time
,
is the estimated standard
deviation of the estimate:
.
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.
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. ).
not.finite
: The number of non-finite values obtained (and discarded) when evaluating FUN(par,...)
Anne Sabourin
Wrappers for MCpriorIntFun
with argument
prior=prior.pb
or prior=prior.nl
MCpriorIntFun.nl( Nsim = 200, FUN = function(par, ...) { par }, store = TRUE, Hpar = get("nl.Hpar"), show.progress = floor(seq(1, Nsim, length.out = 20)), Nsim.min = Nsim, precision = 0, ... ) MCpriorIntFun.pb( Nsim = 200, Hpar = get("pb.Hpar"), dimData = 3, FUN = function(par, ...) { as.vector(par) }, store = TRUE, show.progress = floor(seq(1, Nsim, length.out = 20)), Nsim.min = Nsim, precision = 0, ... )
MCpriorIntFun.nl( Nsim = 200, FUN = function(par, ...) { par }, store = TRUE, Hpar = get("nl.Hpar"), show.progress = floor(seq(1, Nsim, length.out = 20)), Nsim.min = Nsim, precision = 0, ... ) MCpriorIntFun.pb( Nsim = 200, Hpar = get("pb.Hpar"), dimData = 3, FUN = function(par, ...) { as.vector(par) }, store = TRUE, show.progress = floor(seq(1, Nsim, length.out = 20)), Nsim.min = Nsim, precision = 0, ... )
Nsim |
Maximum number of iterations |
FUN |
A function to be integrated. It may return a vector or an array. |
store |
Should the successive evaluations of |
Hpar |
Hyper-parameters for the PB prior (in |
show.progress |
same as in |
Nsim.min |
The minimum number of iterations to be performed. |
precision |
The desired relative precision |
... |
Additional arguments to be passed to |
dimData |
Only for the PB model: The dimension of model's sample space. The PB parameter space is of dimension |
The list returned by function
MCpriorIntFun
.
The logit-transformed parameters for the NL model are a priori
Gaussian. The list has the same format as pb.Hpar
.
A list of four parameters:
Mean and standard deviation of the normal prior distribution for the logit-transformed global dependence parameter .
Default to
.
Idem for the pairwise dependence parameters.
The proposals (on the logit-scale) are Gaussian, centered aroud the current value.
A list made of a single element: sd
. The standard deviation of the normal proposition kernel centered at the (logit-transformed)
current state. Default to .
The log-transformed dependence parameters are a priori independent, Gausian. This list contains the means and standard deviation for the prior distributions.
A list of four parameters:
Mean of the log-transformed global dependence parameter. Default to )
Standard deviation of the log-transformed global dependence parameter. Default to .
Mean of each of the log-transformed pairwise dependence parameters.
Default to )
Standard deviation of each of the log-transformed
pairwise dependence parameters. Default to .
The proposal for the log-transformed parameters are Gaussian, centered at the current value.
A list made of a single element: sd
,
the standard deviation of the normal proposition kernel (on the log-transformed parameter). Default to
.
Wrappers for posterior.predictive3D
in the PB and NL models.
posterior.predictive.nl( post.sample, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 50, npoints = 40, eps = 0.001, equi = T, displ = T, ... ) posterior.predictive.pb( post.sample, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 50, npoints = 40, eps = 10^(-3), equi = T, displ = T, ... )
posterior.predictive.nl( post.sample, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 50, npoints = 40, eps = 0.001, equi = T, displ = T, ... ) posterior.predictive.pb( post.sample, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 50, npoints = 40, eps = 10^(-3), equi = T, displ = T, ... )
post.sample |
A posterior sample as returned by |
from |
Integer or |
to |
Integer or |
thin |
Thinning interval. |
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
displ |
logical. Should a plot be produced ? |
... |
Additional graphical parameters and arguments to be passed
to |
The posterior predictive density is approximated by averaging the densities corresponding to the parameters stored in post.sample
. See
posterior.predictive3D
for details.
A npoints*npoints
matrix: the posterior predictive density.
posterior.predictive3D
, posteriorMCMC.pb
.
Computes an approximation of the predictive density based on a posterior parameters sample. Only allowed in the three-dimensional case.
posterior.predictive3D( post.sample, densityGrid, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 40, npoints = 40, eps = 10^(-3), equi = T, displ = T, ... )
posterior.predictive3D( post.sample, densityGrid, from = post.sample$Nbin + 1, to = post.sample$Nsim, thin = 40, npoints = 40, eps = 10^(-3), equi = T, displ = T, ... )
post.sample |
A posterior sample as returned by |
densityGrid |
A function returning a |
from |
Integer or |
to |
Integer or |
thin |
Thinning interval. |
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
equi |
logical. Is the simplex represented as an equilateral triangle (if |
displ |
logical. Should a plot be produced ? |
... |
Additional graphical parameters and arguments to be passed
to |
The posterior predictive density is approximated by averaging the
densities produced by the function
densityGrid(par, npoints, eps, equi, displ,invisible, ...)
for
par
in a subset of the parameters sample stored in
post.sample
. The arguments of densityGrid
must be
par
: A vector containing the parameters.
npoints, eps, equi
: Discretization parameters
to be passed to dgridplot
.
displ
: logical. Should a plot be produced ?
invisible
: logical. Should the result be returned as invisible
?
...
additional arguments to be passed to
dgridplot
Only a sub-sample is used: one out of thin
parameters is used
(thinning). Further, only the parameters produced between time
from
and time to
(included) are kept.
A npoints*npoints
matrix: the posterior predictive density.
The computational burden may be high: it is proportional to
npoints^2
. Therefore, the function assigned to
densityGridplot
should be
optimized, typically by calling .C
with an internal,
user defined C
function.
Anne Sabourin
Builds an empirical distribution defined as a sum of weighted Dirac masses from posterior samples in individual models.
posteriorDistr.bma(postweights = c(0.5, 0.5), post.distrs = list())
posteriorDistr.bma(postweights = c(0.5, 0.5), post.distrs = list())
postweights |
a vector of positive real numbers, summing to one: the posterior weights (in the same order as the elements of |
post.distrs |
A list of same length as |
A matrix with two rows and as many columns as the sum of the lengths of the elements of post.distrs
. The second line contains the weighted posterior sample in the BMA; the first line contains the weights to be assigned to each corresponding value on the second one.
Generates a posterior parameters sample, and computes the posterior mean and component-wise variance on-line.
posteriorMCMC( prior = function(type = c("r", "d"), n, par, Hpar, log, dimData) { NULL }, proposal = function(type = c("r", "d"), cur.par, prop.par, MCpar, log) { NULL }, likelihood = function(x, par, log, vectorial) { NULL }, Nsim, dat, Hpar, MCpar, Nbin = 0, par.start = NULL, show.progress = floor(seq(1, Nsim, length.out = 20)), seed = NULL, kind = "Mersenne-Twister", save = FALSE, class = NULL, name.save = NULL, save.directory = "~", name.dat = "", name.model = "" )
posteriorMCMC( prior = function(type = c("r", "d"), n, par, Hpar, log, dimData) { NULL }, proposal = function(type = c("r", "d"), cur.par, prop.par, MCpar, log) { NULL }, likelihood = function(x, par, log, vectorial) { NULL }, Nsim, dat, Hpar, MCpar, Nbin = 0, par.start = NULL, show.progress = floor(seq(1, Nsim, length.out = 20)), seed = NULL, kind = "Mersenne-Twister", save = FALSE, class = NULL, name.save = NULL, save.directory = "~", name.dat = "", name.model = "" )
prior |
The prior distribution: of type |
proposal |
The proposal function: of type |
likelihood |
The likelihood function.
Should be of type |
Nsim |
Total number of iterations to perform. |
dat |
An angular data set, e.g., constructed by
|
Hpar |
A list containing Hyper-parameters to be passed to
|
MCpar |
A list containing MCMC tuning parameters to be
passed to |
Nbin |
Length of the burn-in period. |
par.start |
Starting point for the MCMC sampler. |
show.progress |
An vector of integers containing the times (iteration numbers) at which a message showing progression will be printed on the standard output. |
seed |
The seed to be set via
|
kind |
The kind of random numbers generator. Default to
"Mersenne-Twister". See |
save |
Logical. Should the result be saved ? |
class |
Optional character string: additional class attribute to be assigned to the result. A predefined class |
name.save |
A character string giving the name under which
the result is to be saved. If |
save.directory |
A character string giving the directory where the result is to be saved (without trailing slash). |
name.dat |
A character string naming the data set used for inference. Default to |
name.model |
A character string naming the model. Default to |
A list made of
stored.vals
: A (Nsim-Nbin)*d
matrix, where
d
is the dimension of the parameter space.
llh
A vector of size (Nsim-Nbin)
containing the loglikelihoods evaluated at each parameter of the posterior sample.
lprior
A vector of size (Nsim-Nbin)
containing the logarithm of the prior densities evaluated at each parameter of the posterior sample.
elapsed
: The time elapsed, as given by
proc.time
between the start and the end of the run.
Nsim
: The same as the passed argument
Nbin
: idem.
n.accept
: The total number of accepted proposals.
n.accept.kept
: The number of accepted proposals after the burn-in period.
emp.mean
The estimated posterior parameters mean
emp.sd
The empirical posterior sample standard deviation.
posteriorMCMC.pb
,
posteriorMCMC.pb
for specific uses
in the PB and the NL models.
data(Leeds) data(pb.Hpar) data(pb.MCpar) postsample1 <- posteriorMCMC(Nsim=1e+3,Nbin=500, dat= Leeds, prior = prior.pb, proposal = proposal.pb, likelihood = dpairbeta, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(postsample1[[1]]) postsample1[-1] ## Not run: ## a more realistic one: postsample2 <- posteriorMCMC(Nsim=50e+3,Nbin=15e+3, dat= Leeds, prior = prior.pb, proposal = proposal.pb, likelihood = dpairbeta, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(postsample2[[1]]) postsample2[-1] ## End(Not run)
data(Leeds) data(pb.Hpar) data(pb.MCpar) postsample1 <- posteriorMCMC(Nsim=1e+3,Nbin=500, dat= Leeds, prior = prior.pb, proposal = proposal.pb, likelihood = dpairbeta, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(postsample1[[1]]) postsample1[-1] ## Not run: ## a more realistic one: postsample2 <- posteriorMCMC(Nsim=50e+3,Nbin=15e+3, dat= Leeds, prior = prior.pb, proposal = proposal.pb, likelihood = dpairbeta, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(postsample2[[1]]) postsample2[-1] ## End(Not run)
The functions generate parameters samples approximating the posterior distribution in the PB model or the NL model.
posteriorMCMC.nl(Nsim, dat, Hpar, MCpar, ...) posteriorMCMC.pb(Nsim, dat, Hpar, MCpar, ...)
posteriorMCMC.nl(Nsim, dat, Hpar, MCpar, ...) posteriorMCMC.pb(Nsim, dat, Hpar, MCpar, ...)
Nsim |
Total number of iterations to perform. |
dat |
An angular data set, e.g., constructed by
|
Hpar |
A list containing Hyper-parameters to be passed to
|
MCpar |
A list containing MCMC tuning parameters to be
passed to |
... |
Additional arguments to be passed to
|
The two functions are wrappers simplifying the use of
posteriorMCMC
for the two models implemented in this package.
an object with class attributes "postsample"
and
"PBNLpostsample"
: The posterior sample and some statistics
as returned by function posteriorMCMC
For the Leeds data set, and for simulated data sets with
similar features, setting Nsim=50e+3
and Nbin=15e+3
is enough (possibly too much),
with respect to the Heidelberger and Welch tests implemented in
heidel.diag
.
## Not run: data(Leeds) data(pb.Hpar) data(pb.MCpar) data(nl.Hpar) data(nl.MCpar) pPB <- posteriorMCMC.pb(Nsim=5e+3, dat=Leeds, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(pPB[1]) pPB[-(1:3)] pNL <- posteriorMCMC.nl(Nsim=5e+3, dat=Leeds, Hpar=nl.Hpar, MCpar=nl.MCpar) dim(pNL[1]) pNL[-(1:3)] ## End(Not run)
## Not run: data(Leeds) data(pb.Hpar) data(pb.MCpar) data(nl.Hpar) data(nl.MCpar) pPB <- posteriorMCMC.pb(Nsim=5e+3, dat=Leeds, Hpar=pb.Hpar, MCpar=pb.MCpar) dim(pPB[1]) pPB[-(1:3)] pNL <- posteriorMCMC.nl(Nsim=5e+3, dat=Leeds, Hpar=nl.Hpar, MCpar=nl.MCpar) dim(pNL[1]) pNL[-(1:3)] ## End(Not run)
Computes an approximation of the posterior mean of a parameter functional, based on a posterior parameters sample.
posteriorMean( post.sample, FUN = function(par, ...) { par }, from = NULL, to = NULL, thin = 50, displ = TRUE, ... )
posteriorMean( post.sample, FUN = function(par, ...) { par }, from = NULL, to = NULL, thin = 50, displ = TRUE, ... )
post.sample |
A posterior sample as returned by |
FUN |
a parameter functional returning a vector. |
from |
Integer or |
to |
Integer or |
thin |
Thinning interval. |
displ |
logical. Should a plot be produced ? |
... |
Additional parameters to be passed to |
Only a sub-sample is used: one out of thin
parameters is used
(thinning). Further, only the parameters produced between time
from
and time to
(included) are kept.
A list made of
A matrix : each column is the result of FUN
applied to a parameter from the posterior sample.
The posterior mean
The posterior standard deviation
Approximates the models' posterior weights by simple Monte Carlo integration
posteriorWeights( dat, HparList = list(get("pb.Hpar"), get("nl.Hpar")), lklList = list(get("dpairbeta"), get("dnestlog")), priorList = list(get("prior.pb"), get("prior.nl")), priorweights = c(0.5, 0.5), Nsim = 20000, Nsim.min = 10000, precision = 0.05, seed = 1, kind = "Mersenne-Twister", show.progress = floor(seq(1, Nsim, length.out = 10)), displ = FALSE )
posteriorWeights( dat, HparList = list(get("pb.Hpar"), get("nl.Hpar")), lklList = list(get("dpairbeta"), get("dnestlog")), priorList = list(get("prior.pb"), get("prior.nl")), priorweights = c(0.5, 0.5), Nsim = 20000, Nsim.min = 10000, precision = 0.05, seed = 1, kind = "Mersenne-Twister", show.progress = floor(seq(1, Nsim, length.out = 10)), displ = FALSE )
dat |
The angular data set relative to which the marginal model likelihood is to be computed |
HparList |
A list containing the hyper Parameter for the priors in each model. (list of lists). |
lklList |
A list containing the likelihood functions of each model |
priorList |
A list containing the prior definitions of each model. |
priorweights |
A vector of positive weights, summing to one: the prior marginal weights of each model. |
Nsim |
The maximum number of iterations to be performed. |
Nsim.min |
The minimum number of iterations to be performed. |
precision |
the desired relative precision. See
|
seed |
The seed to be set via
|
kind |
The kind of random numbers generator. Default to
"Mersenne-Twister". See |
show.progress |
An vector of integers containing the times (iteration numbers) at which a message showing progression will be printed on the standard output. |
displ |
Logical. Should convergence monitoring plots be issued ? |
if is the number of models, the posterior weights are given by
where stands for the Monte-Carlo estimate of the
marginal likelihood of model
and
is
the prior weight
defined in
priorweights[i]
. For more explanations, see the reference below
The confidence intervals are obtained by adding/subtracting two times the estimated standard errors of the marginal likelihood estimates.
The latter are only estimates, which interpretation may be misleading:
See the note in section marginal.lkl
A matrix of columns and
length(priorweights)
rows. The columns contain respectively the posterior model weights (in the same order as in priorweights
), the lower and the upper bound of the confidence interval (see Details), the marginal model weights, the estimated standard error of the marginal likelihood estimators, and the number of simulations performed.
HOETING, J., MADIGAN, D., RAFTERY, A. and VOLINSKY, C. (1999). Bayesian model averaging: A tutorial. Statistical science 14, 382-401.
data(pb.Hpar) data(nl.Hpar) set.seed(5) mixDat=rbind(rpairbeta(n=10,dimData=3, par=c(0.68,3.1,0.5,0.5)), rnestlog(n=10,par=c(0.68,0.78, 0.3,0.5))) posteriorWeights (dat=mixDat, HparList=list(get("pb.Hpar"),get("nl.Hpar")), lklList=list(get("dpairbeta"), get("dnestlog")), priorList=list(get("prior.pb"), get("prior.nl")), priorweights=c(0.5,0.5), Nsim=1e+3, Nsim.min=5e+2, precision=0.1, displ=FALSE) ## Not run: posteriorWeights (dat=mixDat, HparList=list(get("pb.Hpar"),get("nl.Hpar")), lklList=list(get("dpairbeta"), get("dnestlog")), priorList=list(get("prior.pb"), get("prior.nl")), priorweights=c(0.5,0.5), Nsim=20e+3, Nsim.min=10e+3, precision=0.05, displ=TRUE) ## End(Not run)
data(pb.Hpar) data(nl.Hpar) set.seed(5) mixDat=rbind(rpairbeta(n=10,dimData=3, par=c(0.68,3.1,0.5,0.5)), rnestlog(n=10,par=c(0.68,0.78, 0.3,0.5))) posteriorWeights (dat=mixDat, HparList=list(get("pb.Hpar"),get("nl.Hpar")), lklList=list(get("dpairbeta"), get("dnestlog")), priorList=list(get("prior.pb"), get("prior.nl")), priorweights=c(0.5,0.5), Nsim=1e+3, Nsim.min=5e+2, precision=0.1, displ=FALSE) ## Not run: posteriorWeights (dat=mixDat, HparList=list(get("pb.Hpar"),get("nl.Hpar")), lklList=list(get("dpairbeta"), get("dnestlog")), priorList=list(get("prior.pb"), get("prior.nl")), priorweights=c(0.5,0.5), Nsim=20e+3, Nsim.min=10e+3, precision=0.05, displ=TRUE) ## End(Not run)
Density and generating function of the prior distribution.
prior.nl(type = c("r", "d"), n, par, Hpar, log, dimData = 3)
prior.nl(type = c("r", "d"), n, par, Hpar, log, dimData = 3)
type |
One of the character strings |
n |
The number of parameters to be generated. Only used
if |
par |
A vector of length four, with component comprised
between In the NL model,
In the NL model,
|
Hpar |
list of Hyper-parameters : see |
log |
logical. Should the density be returned on the log scale ?
Only used if |
dimData |
The dimension of the sample space, equal to |
The four parameters are independent, the logit-transformed parameters follow a normal distribution.
Either a matrix with n
rows containing a random parameter sample generated under the prior (if type == "d"), or the (log)-density of the parameter par
.
Anne Sabourin
## Not run: prior.nl(type="r", n=5 ,Hpar=get("nl.Hpar")) ## Not run: prior.trinl(type="r", n=5 ,Hpar=get("nl.Hpar")) ## Not run: prior.pb(type="d", par=rep(0.5,2), Hpar=get("nl.Hpar"))
## Not run: prior.nl(type="r", n=5 ,Hpar=get("nl.Hpar")) ## Not run: prior.trinl(type="r", n=5 ,Hpar=get("nl.Hpar")) ## Not run: prior.pb(type="d", par=rep(0.5,2), Hpar=get("nl.Hpar"))
Density and generating function of the prior distribution.
prior.pb(type = c("r", "d"), n, par, Hpar, log, dimData)
prior.pb(type = c("r", "d"), n, par, Hpar, log, dimData)
type |
One of the character strings |
n |
The number of parameters to be generated. Only used
if |
par |
A vector with positive components:
The parameter where the density is to be taken.
Only used if |
Hpar |
list of Hyper-parameters : see |
log |
logical. Should the density be returned on the log scale ?
Only used if |
dimData |
The dimension of the sample space. (one more than the dimension of the simplex) |
The parameters components are independent, log-normal.
Either a matrix with n
rows containing a random parameter sample generated under the prior (if type == "d"), or the (log)-density of the parameter par
.
Anne Sabourin
## Not run: prior.pb(type="r", n=5 ,Hpar=get("pb.Hpar"), dimData=3 ) ## Not run: prior.pb(type="d", par=rep(1,choose(4,2), Hpar=get("pb.Hpar"), dimData=4 )
## Not run: prior.pb(type="r", n=5 ,Hpar=get("pb.Hpar"), dimData=3 ) ## Not run: prior.pb(type="d", par=rep(1,choose(4,2), Hpar=get("pb.Hpar"), dimData=4 )
Density of the proposal distribution q(cur.par,prop.par)
and random generator for MCMC algorithm in the NL3 model.
proposal.nl( type = c("r", "d"), cur.par, prop.par, MCpar = get("nl.MCpar"), log = TRUE )
proposal.nl( type = c("r", "d"), cur.par, prop.par, MCpar = get("nl.MCpar"), log = TRUE )
type |
One of the character strings |
cur.par |
Current state of the chain. |
prop.par |
Candidate parameter. |
MCpar |
A list made of a single element: MCMC parameter. Re-centering parameter for the proposal distribution. |
log |
Logical. Only used when |
The two components of proposal parameter
(alpha*, beta12*, beta13*, beta23*)
are generated independently, under a beta distribution with mode at the current parameter's value.
Let
MCpar$eps.recentre
. To generate alpha*
, given the current state alpha(t)
,
let be the mean
of the Beta proposal distribution and
(a scaling constant). Then
The betaij*
's are generated similarly.
Either the (log-)density of the proposal parameter prop.par
, given cur.par
(if type == "d"
), or a proposal parameter (a vector), if type =="r"
.
Density of the proposal distribution q(cur.par,prop.par)
and random generator for MCMC algorithm in the PB model.
proposal.pb(type = c("r", "d"), cur.par, prop.par, MCpar, log = TRUE)
proposal.pb(type = c("r", "d"), cur.par, prop.par, MCpar, log = TRUE)
type |
One of the character strings |
cur.par |
Current state of the chain |
prop.par |
Candidate parameter |
MCpar |
A list made of a single element: MCMC parameter for the standard deviation of the log-normal proposition, on the log scale. See |
log |
Logical. Only used when |
The components prop.par[i]
of the proposal parameter are generated independently, from the lognormal distribution:
prop.par = rlnorm(length(cur.par), meanlog=log(cur.par),
sdlog=rep(MCpar$sdlog,length(cur.par)))
Either the (log-)density of the proposal prop.par
, given cur.par
(if type == "d"
), or a proposal parameter (a vector), if type =="r"
.
## Not run: proposal.pb(type = "r", cur.par = rep(1,4), MCpar=get("pb.MCpar")) ## End(Not run) ## Not run: proposal.pb(type = "d", cur.par = rep(1,4), prop.par=rep(1.5,4), MCpar=get("pb.MCpar")) ## End(Not run)
## Not run: proposal.pb(type = "r", cur.par = rep(1,4), MCpar=get("pb.MCpar")) ## End(Not run) ## Not run: proposal.pb(type = "d", cur.par = rep(1,4), prop.par=rep(1.5,4), MCpar=get("pb.MCpar")) ## End(Not run)
Dirichlet distribution: random generator
rdirichlet(n = 1, alpha)
rdirichlet(n = 1, alpha)
n |
Number of draws |
alpha |
Dirichlet parameter: a vector of positive number |
A matrix with n
rows and length(alpha)
columns
The integral is approximated by a rectangular method, using the values stored in matrix density
.
rect.integrate(density, npoints, eps)
rect.integrate(density, npoints, eps)
density |
A |
npoints |
The number of grid nodes on the squared grid containing the desired triangle. |
eps |
Positive number: minimum distance from any node inside the simplex to the simplex boundary |
Integration is made with respect to the Lebesgue measure on the projection of the simplex onto the plane .
It is assumed that
density
has been constructed on a
grid obtained via function discretize
,
with argument equi
set to FALSE
and npoints
and eps
equal to those passed to rect.integrate
.
The value of the estimated integral of density
.
wrapper <- function(x, y, my.fun,...) { sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i],...)) } grid <- discretize(npoints=40,eps=1e-3,equi=FALSE) Density <- outer(grid$X,grid$Y,FUN=wrapper, my.fun=function(x,y){10*((x/2)^2+y^2)}) rect.integrate(Density,npoints=40,eps=1e-3)
wrapper <- function(x, y, my.fun,...) { sapply(seq_along(x), FUN = function(i) my.fun(x[i], y[i],...)) } grid <- discretize(npoints=40,eps=1e-3,equi=FALSE) Density <- outer(grid$X,grid$Y,FUN=wrapper, my.fun=function(x,y){10*((x/2)^2+y^2)}) rect.integrate(Density,npoints=40,eps=1e-3)
Random variable generator
rstable.posit(alpha = 0.5)
rstable.posit(alpha = 0.5)
alpha |
The parameter of the alpha-stable random variable |
An alpha-stable random variable with index
is
defined by its Laplace transform
. The algorithm used here is directly derived from Stephenson (2003).
A realization of the alpha-stable random variable.
STEPHENSON, A. (2003). Simulating multivariate extreme value distributions of logistic type. Extremes 6, 49-59.
distance between two densities on the simplex (trivariate case).Computes the Kullback-Leibler divergence and the distance between the "true" density (
true.dens
) and an estimated density (est.dens
).
scores3D(true.dens, est.dens, npoints, eps)
scores3D(true.dens, est.dens, npoints, eps)
true.dens |
A |
est.dens |
The estimated density: of the same type as |
npoints |
Number of grid points used to construct the density matrices (see |
eps |
Minimum distance from a grid point to the simplex boundary (see |
The integration is made via rect.integrate
: The discretization grid corresponding to the two matrices must be constructed
with discretize(npoints, eps, equi=FALSE)
.
A list made of
check.true
: The result of the rectangular integration of
true.dens
. It should be equal to one. If not, re size the grid.
check.true
:
Idem, replacing true.dens
with est.dens
.
L2score
: The estimated distance.
KLscore
: The estimated Kullback-Leibler divergence between the two re-normalized densities, using check.true
and check.est
as normalizing constants (this ensures that the divergence is always positive).
dens1=dpairbeta.grid(par=c(0.8,2,5,8),npoints=150,eps=1e-3, equi=FALSE) dens2=dnestlog.grid(par=c(0.5,0.8,0.4,0.6),npoints=150,eps=1e-3, equi=FALSE) scores3D(true.dens=dens1, est.dens=dens2, npoints=150, eps=1e-4)
dens1=dpairbeta.grid(par=c(0.8,2,5,8),npoints=150,eps=1e-3, equi=FALSE) dens2=dnestlog.grid(par=c(0.5,0.8,0.4,0.6),npoints=150,eps=1e-3, equi=FALSE) scores3D(true.dens=dens1, est.dens=dens2, npoints=150, eps=1e-4)
Switching coordinates system between equilateral and right-angled representation of the two-dimensional simplex.
transf.to.equi(vect) transf.to.rect(vect)
transf.to.equi(vect) transf.to.rect(vect)
vect |
a bi-variate vector, giving the first two coordinates of the angular point to be transformed. |
If transf.to.rect
, is called, vect
must belongs to the triangle
and the result lies in
.
transf.to.equi
is the reciprocal.
The vector obtained by linear transformation.
Anne Sabourin
## Not run: transf.to.equi(c(sqrt(2)/2, sqrt(3/8) ) )
## Not run: transf.to.equi(c(sqrt(2)/2, sqrt(3/8) ) )
Contains 590 daily maxima of five air pollutants (respectively PM10, N0, NO2, 03, S02) recorded in Leeds (U.K.) during five winter seasons (1994-1998, November-February included). Contains NA's.
A matrix.