pred.density {BMS}R Documentation

Predictive Densities for bma Objects

Description

Predictive densities for conditional forecasts

Usage

 pred.density(object, newdata = NULL, n = 300, hnbsteps = 30, ...)
 

Arguments

object

a bma object - see bms, alternativel a zlm object

newdata

A data.frame, matrix or vector containing variables with which to predict.

n

The integer number of equally spaced points at which the density is to be estimated.

hnbsteps

The number of numerical integration steps to be used in case of a hyper-g prior (cf. argument g in bms). Increase this number to increase accuracy. Must be an even integer.

...

arguments to be passed on to plot.density.

Details

The predictive density is a mixture density based on the nmodels best models in a bma object (cf. nmodel in bms).
The number of 'best models' to retain is therefore vital and should be set quite high for accuracy.

Value

pred.density returns a list of class pred.density with the following elements

densities()

a list whose elements each contain the estimated density for each forecasted observation

fit

a vector with the expected values of the predictions (the 'point forecasts')

std.err

a vector with the standard deviations of the predictions (the 'standard errors')

dyf(realized.y, predict_index=NULL)

Returns the densities of realized response variables provided in realized.y.
If realized.y is a matrix, then each row corresponds to a forecast obeservation in newdata
if not left empty, predict.index specifies to which observations in newdata the realized.y should apply

lps(realized.y, predict_index=NULL)

Computes the log predictive score for the response varaible provided in realized.y (cf. lps.bma) -
Note that the LPS equals minus the mean of the logarithmized results from dyf)

plot((x, predict_index = NULL, addons = "eslz", realized.y = NULL, addons.lwd = 1.5, ...)

the same as plot.pred.density

n

The number of equally spaced points for which the density (under densities() was computed.

nmodel

The number of best models predictive densities are based upon.

call

the call that created this pred.density object

Note

In BMS version 0.3.0, pred.density may only cope with built-in gpriors, not with any user-defined priors.

Author(s)

Martin Feldkircher and Stefan Zeugner

See Also

predict.bma for simple point forecasts, plot.pred.density for plotting predictive densities, lps.bma for calculating the log predictive score independently, quantile.pred.density for extracting quantiles

Check http://bms.zeugner.eu for additional help.

Examples

 data(datafls)
 mm=bms(datafls,user.int=FALSE)
 
 #predictive densityfor two 'new' data points
 pd=pred.density(mm,newdata=datafls[1:2,]) 
 
 
 #fitted values based on best models, same as predict(mm, exact=TRUE)
 pd$fit
 
 #plot the density for the first forecast observation
 plot(pd,1)  
 
 # the same plot ' naked'
 plot(pd$densities()[[1]])
 
 
 #predict density for the first forecast observation if the dep. variable is 0
 pd$dyf(0,1) 
 
 #predict densities for both forecasts for the realizations 0 and 0.5
 pd$dyf(rbind(c(0,.5),c(0,.5)))
 
 # calc. Log Predictive Score if both forecasts are realized at 0:
 lps.bma(pd,c(0,0))
 
 

[Package BMS version 0.3.1 Index]