R2BayesX (version 1.1-1)

predict.bayesx: Prediction from fitted BayesX objects

Description

Takes a fitted "bayesx" object returned from bayesx and produces predictions by refitting the initial model with weights set to zero for new observations.

Usage

# S3 method for bayesx
predict(object, newdata, model = NULL,
  type = c("response", "link", "terms", "model"),
  na.action = na.pass, digits = 5, ...)

Arguments

object

an object of class "bayesx" or "bayesx.hpc".

newdata

a data frame or list containing the values of the model covariates at which predictions are required. If missing newdata is the model.frame of the provided model.

model

for which model should predictions be calculated, either an integer or a character, e.g. model = "mcmc.model". Note that exactly one model must be selected within argument model to compute predicted values!

type

when type = "response", the default, predictions on the scale of the response are returned, "link" returns the linear predictor. When type = "terms", each component of the linear predictor is returned, but excludes any offset and intercept. If type = "model", the full model returned from updating the initial model with weights, that is used for computing predictions, is returned.

na.action

function determining what should be done with missing values in newdata.

digits

predictions should usually be based on the new values provided in argument newdata. However, since this prediction method uses refitting of the model with weights, predictions for model terms need to be matched with the new observations. BayesX returns values with a lower precision than R, therefore argument digits is used to round values when type = "terms", to find matching newdata pairs in the fitted objects returned from the refitted model and the new data. Note that this is a workaround and not 100% bulletproof. It is recommended to compute predictions for type = "response" or type = "link".

not used.

Value

Depending on the specifications of argument type.

See Also

fitted.bayesx, bayesx.

Examples

Run this code
# NOT RUN {
## generate some data
set.seed(121)
n <- 500

## regressors
dat <- data.frame(x = runif(n, -3, 3), z = runif(n, 0, 1),
  w = runif(n, 0, 3))

## generate response 
dat$y <- with(dat, 1.5 + sin(x) + z -3 * w + rnorm(n, sd = 0.6))

## estimate model
b <- bayesx(y ~ sx(x) + z + w, data = dat)

## create some data for which predictions are required
nd <- data.frame(x = seq(2, 5, length = 100), z = 1, w = 0)

## prediction model from refitting with weights
nd$fit <- predict(b, newdata = nd)
plot(fit ~ x, type = "l", data = nd)
# }

Run the code above in your browser using DataLab