Learn R Programming

bsamGP (version 1.2.6)

predict.bsam: Predict method for a bsam object

Description

Computes the predicted values of Bayesian spectral analysis models.

Usage

# S3 method for bsam
predict(object, newp, newnp, alpha = 0.05, HPD = TRUE, type = "response", ...)

Value

A list object of class predict.bsam containing posterior means and \(100(1-\alpha)\)% credible intervals.

The output list includes the following objects:

fxobs

posterior estimates for unknown functions over observation.

wbeta

posterior estimates for parametric part.

yhat

posterior estimates for fitted values of either response or expectation of response. For gbsar, it gives posterior estimates for expectation of response.

fxResid

posterior estimates for fitted parametric residuals. Not applicable for gbsar.

Arguments

object

a bsam object

newp

an optional data of parametric components with which to predict. If omitted, the fitted values are returned.

newnp

an optional data of nonparametric components with which to predict. If omitted, the fitted values are returned.

alpha

a numeric scalar in the interval (0,1) giving the \(100(1-\alpha)\)% credible intervals.

HPD

a logical variable indicating whether the \(100(1-\alpha)\)% Highest Posterior Density (HPD) intervals are calculated. If HPD=FALSE, the \(100(1-\alpha)\)% equal-tail credible intervals are calculated. The default is TRUE.

type

the type of prediction required. type = "response" gives the posterior predictive samples as default. The "mean" option returns expectation of the posterior estimates.

...

not used

Details

None.

See Also

bsaq, bsar, gbsar

Examples

Run this code
if (FALSE) {

##########################################
# Increasing Convex to Concave (S-shape) #
##########################################

# simulate data
f <- function(x) 5*exp(-10*(x - 1)^4) + 5*x^2

set.seed(1)

n <- 100
x <- runif(n)
y <- f(x) + rnorm(n, sd = 1)

# Number of cosine basis functions
nbasis <- 50

# Fit the model with default priors and mcmc parameters
fout <- bsar(y ~ fs(x), nbasis = nbasis, shape = 'IncreasingConvex',
             spm.adequacy = TRUE)

# Prediction
xnew <- runif(n)
predict(fout, newnp = xnew)
}

Run the code above in your browser using DataLab