BMS (version 0.3.4)

density.bma: Coefficient Marginal Posterior Densities

Description

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

Usage

## 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, ...)

Arguments

x
A bma object (see bms) or a zlm object.
reg
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.
addons
character. Specifies which additional information should be added to the plot via low-level commands (see 'Details' below).
std.coefs
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.
n
numeric. the number of equally spaced points at which the density is to be estimated.
plot
logical. If TRUE (default), the density is plotted; if FALSE then density.bma only returns the estimated posterior densities without plotting.
hnbsteps
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.
addons.lwd
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

Value

  • 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)).

Details

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.

See Also

quantile.coef.density for extracting quantiles, coef.bma for similar concepts, bms for creating bma objects Check http://bms.zeugner.eu for additional help.

Examples

Run this code
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",]

Run the code above in your browser using DataLab