density.bma {BMS} | R Documentation |
Calculates the mixture marginal posterior densities for the coefficients from a BMA object and plots them
## S3 method for class 'bma' density(x, reg = NULL, addons = "lemsz", std.coefs = FALSE, n = 300, plot = TRUE, hnbsteps = 30, addons.lwd = 1.5, ...) ## S3 method for class 'zlm' density(x, reg = NULL, addons = "lesz", std.coefs = FALSE, n = 300, plot = TRUE, hnbsteps = 30, addons.lwd = 1.5, ...)
x |
|
reg |
A scalar integer or character detailing which covariate's coefficient should be plotted. If |
addons |
character. Specifies which additional information should be added to the plot via low-level commands (see 'Details' below). |
std.coefs |
logical. If |
n |
numeric. the number of equally spaced points at which the density is to be estimated. |
plot |
logical. If |
hnbsteps |
even integer, default 30. The number of numerical integration steps to be used in case of a hyper-g prior (cf. argument |
addons.lwd |
scalar, default 1.5. Line width to be used for the low-level plotting commands specified by |
... |
Additional arguments for |
The argument addons
specifies what additional information should be added to the plot(s) via the low-level commands lines
and legend
:
"e"
for the posterior expected value (EV) of coefficients conditional on inclusion (see argument exact=TRUE
in coef.bma
),
"s"
for 2 times posterior standard deviation (SD) bounds,
"m"
for the posterior median,
"b"
for posterior expected values of the individual models whom the density is averaged over,
"E"
for posterior EV under MCMC frequencies (see argument exact=FALSE
in coef.bma
),
"S"
for the corresponding SD bounds (MCMC),
"p"
for plotting the Posterior Inclusion Probability above the density plot,
"l"
for including a legend
, "z"
for a zero line, "g"
for adding a grid
Any combination of these letters will give the desired result. Use addons=""
for not using any of these.
In case of density.zlm
, only the letters e
, s
, l
, z
, and g
will have an effect.
The function returns a list containing objects of the class density
detailing the marginal posterior densities for each coefficient provided in reg
.
In case of density.zlm
, simple marginal posterior coefficient densities are computed, while density.bma
calculates there mixtures over models according to posterior model probabilities.
These densities contain only the density points apart from the origin. (see 'Note' below)
As long as plot=TRUE
, the densities are plotted too.
Note that (for density.bma
) if the posterior inclusion probability of a covariate is zero, then it will not be plotted, and the returned density will be list(x=numeric(n),y=numeric(n))
.
The computed marginal posterior densities from density.bma
are a Bayesian Model Averaging mixture of the marginal posterior densities of the individual models.
The accuracy of the result therefore depends on the number of 'best' models contained in x
(cf. argument nmodel
in bms
).
The marginal posterior density can be interpreted as 'conditional on inclusion': If the posterior inclusion probability of a variable is smaller than one, then some of its posterior density is Dirac at zero. Therefore the integral of the returned density vector adds up to the posterior inclusion probability, i.e. the probability that the coefficient is not zero.
Correspondingly, the posterior EV and SD specified by addons="es"
are based on 'best' model likelihoods ('exact') and are conditional on inclusion.
They correspond to the results from command coef.bma(x,exact=TRUE,condi.coef=TRUE,order.by.pip=FALSE)
(cf. the example below).
The low-level commands enacted by the argument addons
rely on colors of the palette
: color 2 for "e"
and "s"
, color 3 for "m"
, color 8 for "b"
, color 4 for "E"
and "S"
. The default colors may be changed by a call to palette
.
Up to BMS version 0.3.0, density.bma
may only cope with built-in gprior
s, not with any user-defined priors.
Martin Feldkircher and Stefan Zeugner
quantile.coef.density
for extracting quantiles, coef.bma
for similar concepts, bms
for creating bma objects
Check http://bms.zeugner.eu for additional help.
data(datafls) mm=bms(datafls) density(mm,reg="SubSahara") density(mm,reg=7,addons="lbz") density(mm,1:9) density(mm,reg=2,addons="zgSE",addons.lwd=2,std.coefs=TRUE) # plot the posterior density only for the very best model density(mm[1],reg=1,addons="esz") #using the calculated density for other purposes... dd=density(mm,reg="SubSahara") plot(dd) dd_list=density(mm,reg=1:3,plot=FALSE,n=400) plot(dd_list[[1]]) #Note that the shown density is only the part that is not zero dd=density(mm,reg="Abslat",addons="esl") pip_Abslat=sum(dd$y)*diff(dd$x)[1] #this pip and the EV conform to what is done by the follwing command coef(mm,exact=TRUE,condi.coef=TRUE)["Abslat",]