PlotModelSize | R Documentation |
Produces a histogram of number of nonzero coefficients in a spike-and-slab regression.
PlotModelSize(beta, burn = 0, xlab= "Number of nonzero coefficients", ...)
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 |
Invisibly returns the vector of MCMC draws of model sizes.
Steven L. Scott
lm.spike
plot.lm.spike
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.