Learn R Programming

BoomSpikeSlab (version 1.2.6)

PlotModelSize: Plot a distribution of model size

Description

Produces a histogram of number of nonzero coefficients in a spike-and-slab regression.

Usage

PlotModelSize(beta, burn = 0, xlab= "Number of nonzero coefficients", ...)

Value

Invisibly returns the vector of MCMC draws of model sizes.

Arguments

beta

A matrix of model coefficients. Each row represents an MCMC draw. Each column represents a coefficient for a variable.

burn

The number of MCMC iterations to be discarded as burn-in.

xlab

Label for the horizontal axis.

...

Additional arguments to be passed to hist

Author

Steven L. Scott

See Also

lm.spike plot.lm.spike

Examples

Run this code
simulate.lm.spike <- function(n = 100, p = 10, ngood = 3, niter=1000, sigma = 8){
  x <- cbind(matrix(rnorm(n * (p-1)), nrow=n))
  beta <- c(rnorm(ngood), rep(0, p - ngood))
  y <- rnorm(n, beta[1] + x %*% beta[-1], sigma)
  draws <- lm.spike(y ~ x, niter=niter)
  return(invisible(draws))
}
model <- simulate.lm.spike(n = 1000, p = 50, sigma = .3)

# To get the plot of model size directly.
PlotModelSize(model$beta, burn = 10)

# Another way to get the same plot.
plot(model, "size", burn = 10)

Run the code above in your browser using DataLab