predict.bamlss {bamlss}R Documentation

BAMLSS Prediction


Takes a fitted bamlss object and computes predictions. Predictions can be based on estimated parameters of optimizer functions or on samples returned from sampler functions. It is possible to compute predictions on multiple cores using the parallel and to chunk predictions to save computation time and memory storage. Predictions can be computed for full distributional parameters or specific model terms. If a link{bamlss} model was fitted on multiple cores, i.e., the samples are provided as link{mcmc.list} where each list entry represents samples from one core, function predict.bamlss() computes combined predictions based on samples of all cores.


## S3 method for class 'bamlss'
predict(object, newdata, model = NULL, term = NULL,
  match.names = TRUE, intercept = TRUE, type = c("link", "parameter"),
  FUN = function(x) { mean(x, na.rm = TRUE) }, trans = NULL,
  what = c("samples", "parameters"), nsamps = NULL,
  verbose = FALSE, drop = TRUE,
  cores = NULL, chunks = 1, ...)



An object of class "bamlss"


A data frame or list containing the values of the model covariates at which predictions are required. Note that depending on argument term, only covariates that are needed by the corresponding model terms need to be supplied.


Character or integer, specifies the model for which predictions should be computed.


Character or integer, specifies the model terms for which predictions are required. Note that, e.g., term = c("s(x1)", "x2") will compute the combined prediction s(x1) + x2.


Should partial string matching be used to select the terms for prediction. Note that, e.g., term = "x1" will select all terms including "x1" if match.names = TRUE.


Should the intercept be included?


If type = "link" the predictor of the corresponding model is returned. If type = "parameter" predictions on the distributional parameter scale are returned.


A function that should be applied on the samples of predictors or parameters, depending on argument type.


A transformer function or named list of transformer functions that computes transformed predictions. If trans is a list, the list names must match the names of the parameters of the


Predictions can be computed from samples or estimated parameters of optimizer functions. If no samples are available the default is to use estimated parameters.


If the fitted bamlss object contains samples of parameters, computing predictions may take quite some time. Therefore, to get a first feeling it can be useful to compute predictions only based on nsamps samples, i.e., nsamps specifies the number of samples which are extracted on equidistant intervals.


If predictions are chunked, information on the prediction process can be printed.


If predictions for only one model are returned, the list structure is dropped.


Specifies the number of cores that should be used for prediction. Note that this functionality is based on the parallel package.


Should computations be split into chunks? Prediction is then processed sequentially.


Arguments passed to prediction functions that are part of a object, i.e., the objects has a $predict() function that should be used instead.


Depending on arguments model, FUN and the structure of the bamlss model, a list of predictions or simple vectors or matrices of predictions.

See Also

link{bamlss}, fitted.bamlss.


## Not run: ## Generate some data.
d <- GAMart()

## Model formula.
f <- list(
  num ~ s(x1) + s(x2) + s(x3) + te(lon,lat),
  sigma ~ s(x1) + s(x2) + s(x3) + te(lon,lat)

## Estimate model.
b <- bamlss(f, data = d)

## Predictions.
p <- predict(b)

## Prediction for "mu" model and term "s(x2)".
p <- predict(b, model = "mu", term = "s(x2)")

## Plot effect
plot2d(p ~ x2, data = d)

## Same for "sigma" model.
p <- predict(b, model = "sigma", term = "s(x2)")
plot2d(p ~ x2, data = d)

## Prediction for "mu" model and term "s(x1)" + "s(x2)"
## without intercept.
p <- predict(b, model = "mu", term = c("s(x1)", "s(x2)"),
  intercept = FALSE)

## Prediction based on quantiles.
p <- predict(b, model = "mu", term = "s(x2)", FUN = c95)
plot2d(p ~ x2, data = d)

## Extract samples of predictor for "s(x2)".
p <- predict(b, model = "mu", term = "s(x2)",
  intercept = FALSE, FUN = function(x) { x })
plot2d(p ~ x2, data = d, col.lines = rgb(0.1, 0.1, 0.1, alpha = 0.1))

## Or using specific combinations of terms.
p <- predict(b, model = "mu", term = c("s(x2)", "te(lon,lat)"),
  intercept = FALSE, FUN = function(x) { x })

## Prediction using new data.
## Only need x3 data when predicting
## for s(x3).
nd <- data.frame("x3" = seq(0, 1, length = 100))
nd <- cbind(nd, predict(b, newdata = nd, term = "s(x3)"))
plot2d(mu ~ x3, data = nd)
plot2d(sigma ~ x3, data = nd)

## End(Not run)

[Package bamlss version 1.2-3 Index]