Learn R Programming

BayesVarSel (version 2.4.5)

predict.Bvs: Bayesian Model Averaged predictions

Description

Samples of the model averaged objective predictive distribution

Usage

# S3 method for Bvs
predict(object, newdata, n.sim = 10000, ...)

Value

predict returns a matrix with n.sim rows with the simulations. Each column of the matrix corresponds to each of the configurations for the covariates defined in newdata.

Arguments

object

An object of class Bvs

newdata

A data frame in which to look for variables with which to predict

n.sim

Number of simulations to be produced

...

Further arguments to be passed (currently none implemented).

Author

Gonzalo Garcia-Donato and Anabel Forte

Maintainer: <anabel.forte@uv.es>

Details

The distribution that is sampled from is the discrete mixture of the (objective) predictive distribution with weights proportional to the posterior probabilities of each model. That is, from

\(latex\)

The models used in the mixture above are the retained best models (see the argument n.keep in Bvs) if x was generated with Bvs and the sampled models with the associated frequencies if x was generated with GibbsBvs. The formula for the objective predictive distribution within each model \(latex\) is taken from Bernardo and Smith (1994) page 442.

References

Bernardo, J. M. and Smith, A. F. M. (1994)<DOI:10.1002/9780470316870> Bayesian Theory. Chichester: Wiley.

See Also

See Bvs and GibbsBvs for creating objects of the class Bvs.

Examples

Run this code

if (FALSE) {

#Analysis of Crime Data
#load data
data(UScrime)

crime.Bvs<- Bvs(formula= y ~ ., data=UScrime, n.keep=1000)
#predict a future observation associated with the first two sets of covariates
crime.Bvs.predict<- predict(crime.Bvs, newdata=UScrime[1:2,], n.sim=10000)
#(Notice the best 1000 models are used in the mixture)

#Here you can use standard summaries to describe the underlying predictive distribution
#summary(crime.Bvs.predict)
#
#To study more in deep the first set:
plot(density(crime.Bvs.predict[,1]))
#Point prediction
median(crime.Bvs.predict[,1])
#A credible 95% interval for the prediction:
#lower bound:
quantile(crime.Bvs.predict[,1], probs=0.025)
#upper bound:
quantile(crime.Bvs.predict[,1], probs=0.975)

}

Run the code above in your browser using DataLab