predict.lm.spike {BoomSpikeSlab}R Documentation

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 = NULL, burn = 0,
    na.action = na.pass, mean.only = FALSE, ...)

## 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 = NULL,
    exposure = NULL, burn = 0,
    type = c("mean", "log", "link", "response"),
    na.action = na.pass, ...)

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

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

## S3 method for class 'BayesNnet'
predict(object, newdata = NULL, burn = 0,
    na.action = na.pass, mean.only = FALSE, seed = NULL, ...)

Arguments

object

A model object of class lm.spike, logit.spike, etc.

newdata

Either NULL, or else a data frame, matrix, or vector containing the predictors needed to make the prediction.

If newdata is NULL then the predictors are taken from the training data used to create the model object. Note that object does not store its training data, so the data objects used to fit the model must be present for the training data to be recreated.

If newdata is a data.frame it must contain variables with the same names as the data frame used to fit object. If it is a matrix, it must have the same number of columns as object$beta. An intercept term will be implicitly added if the number of columns is too small by one. If the dimension of object$beta is 1 or 2, then newdata can be a vector.

exposure

A vector of positive real numbers the same size as newdata, or NULL. If both newdata and exposure are NULL then exposure is taken to be the exposure from the training data. If newdata is supplied and exposure is NULL then exposure is taken to be 1 for all observations.

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 na.fail if that is unset. The "factory-fresh" default is na.omit. Another possible value is NULL, no action. Value na.exclude can be useful.

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. Probits work similarly to logits.

For poisson.spike, mean means the prediction is returned on the scale of the data, while log means it is on the scale of the linear predictor.

Both cases also accept link and response for compatibility with predict.glm.

mean.only

Logical. If TRUE then return the posterior mean of the predictive distribution. If FALSE then return the entire distribution.

seed

Random seed for the C++ random number generator. This is only needed for models that require C++ to implement their predict method.

...

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.

Author(s)

Steven L. Scott

See Also

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

Examples

  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)

[Package BoomSpikeSlab version 1.2.4 Index]