Learn R Programming

BoomSpikeSlab (version 0.5.2)

predict.lm.spike: Predictions using spike-and-slab regression.

Description

Generate draws from the posterior predictive distribution of a spike and slab regression.

Usage

## S3 method for class 'lm.spike':
predict(object, newdata, burn = 0,
    na.action = na.pass, ...)

## S3 method for class 'logit.spike': predict(object, newdata, burn = 0, type = c("prob", "logit", "link", "response"), na.action = na.pass, ...)

## S3 method for class 'poisson.spike': predict(object, newdata, burn = 0, type = c("mean", "log", "link", "response"), na.action = na.pass, ...)

Arguments

object
An object of class lm.spike.
newdata
A data frame, matrix, or vector containing the predictors needed to make the prediction. If newdata is a data.frame it must contain variables with the same names as the data frame used to fit object. If
burn
The number of MCMC iterations in the object to be discarded as burn-in.
na.action
a function which indicates what should happen when the data contain NA's. The default is set by the na.action setting of options, and is
type
The type of prediction desired.

For logit.spike, prob means the prediction is returned on the probability scale, while logit returns the scale of the linear predictor.

For poisson.spike

...
Unused, but present for compatibility with generic predict().

Value

  • Returns a matrix of predictions, with each row corresponding to a row in newdata, and each column to an MCMC iteration.

See Also

lm.spike SpikeSlabPrior summary.lm.spike plot.lm.spike

Examples

Run this code
niter <- 1000
  n <- 100
  p <- 10
  ngood <- 3

  x <- cbind(1, matrix(rnorm(n * (p-1)), nrow=n))
  beta <- rep(0, p)
  good <- sample(1:p, ngood)
  beta[good] <- rnorm(ngood)
  sigma <- 1

  y <- rnorm(n, x %*% beta, sigma)
  model <- lm.spike(y ~ x - 1, niter=niter)
  plot(model)
  plot.ts(model$beta)
  hist(model$sigma)  ## should be near true value

  new.x <- cbind(1, matrix(rnorm(100 * (p-1)), ncol = (p-1)))
  pred <- predict(model, newdata = new.x, burn = 100)

Run the code above in your browser using DataLab