density.bma {BMS}R Documentation

Coefficient Marginal Posterior Densities


Calculates the mixture marginal posterior densities for the coefficients from a BMA object and plots them


## S3 method for class 'bma'
  reg = NULL,
  addons = "lemsz",
  std.coefs = FALSE,
  n = 300,
  plot = TRUE,
  hnbsteps = 30,
  addons.lwd = 1.5,



A bma object (see bms) or a zlm object.


A scalar integer or character detailing which covariate's coefficient should be plotted. If reg=NULL (default), then all regressors are plotted one after the other, waiting for user interaction.


character. Specifies which additional information should be added to the plot via low-level commands (see 'Details' below).


logical. If TRUE then the posterior density is estimated for standardized coefficients (representing the case where all variables have mean zero and standard deviation 1) - default is FALSE.


numeric. the number of equally spaced points at which the density is to be estimated.


logical. If TRUE (default), the density is plotted; if FALSE then density.bma only returns the estimated posterior densities without plotting.


even integer, default 30. The number of numerical integration steps to be used in case of a hyper-g prior (cf. argument g in bms). Increase this number to increase accuracy.


scalar, default 1.5. Line width to be used for the low-level plotting commands specified by addons. Cf. argument lwd in par


Additional arguments for plot.default with sensible defaults


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, (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 gpriors, not with any user-defined priors.

See Also

quantile.coef.density for extracting quantiles, coef.bma for similar concepts, bms for creating bma objects

Check for additional help.




# plot the posterior density only for the very best model

#using the calculated density for other purposes...


#Note that the shown density is only the part that is not zero

 #this pip and the EV conform to what is done by the follwing command

[Package BMS version 0.3.5 Index]