d_fitted {BAMBI}R Documentation

Density and random deviates from an angmcmc object

Description

Density and random deviates from an angmcmc object

Usage

d_fitted(x, object, type = "point-est", fn = mean, log = FALSE, chain.no, ...)

r_fitted(n = 1, object, type = "point-est", fn = mean, chain.no, ...)

Arguments

x

vector, if univariate or a two column matrix, if bivariate, with each row a 2-D vector, (can also be a data frame of similar dimensions) of points where the densities are to be computed.

object

angular MCMC object. The dimension of the model must match with x.

type

Method of estimating density/generating random deviates. Possible choices are "post-pred" and "point-est". See details. Defaults to "point-est".

fn

function, or a single character string specifying its name, to evaluate on MCMC samples to estimate parameters. Defaults to mean, which computes the estimated posterior mean. Note that if fn = "MODE" (warning: not "mode") or fn = "MAP", then the maximum aposteriori estimate (MAP) is calculated.

log

logical. Should the log density be returned instead?

chain.no

vector of chain numbers whose samples are to be be used. in the estimation. By default all chains are used.

...

additional arguments to be passed to the function.

n

number of observations to be generated.

Details

If type = 'point-est', density is evaluated/random samples are generated at a point estimate of the parameter values. To estimate the mixture density, first the parameter vector \eta is estimated by applying fn on the MCMC samples (using the function pointest), yielding the (consistent) Bayes estimate \hat{\eta}. Then the mixture density f(x|\eta) at any point x is (consistently) estimated by f(x|\hat{\eta}). The random deviates are generated from the estimated mixture density f(x|\hat{\eta}).

If type == 'post-pred', posterior predictive samples and densities are returned. That is, the average density S^{-1} \sum_{s = 1}^S f(x | \eta_s) is returned in d_fitted, where \eta_1, \dots, \eta_S is the set posterior MCMC samples obtained from object. In r_fitted, first a random sub-sample \eta_{(1)}, \dots, \eta_{(n)} of size n from the set of posterior samples \eta_1, \dots, \eta_S is drawn (with replacement if n > S). Then the i-th posterior predictive data point is generated from the mixture density f(x|\eta_{(i)}) for i = 1,..., n.

Value

d_fitted gives a vector the densities computed at the given points and r_fitted creates a vector (if univariate) or a matrix (if bivariate) with each row being a 2-D point, of random deviates.

Examples

set.seed(1)
# illustration only - more iterations needed for convergence
fit.vmsin.20 <- fit_vmsinmix(tim8, ncomp = 3, n.iter =  20,
                             n.chains = 1)
d_fitted(c(0,0), fit.vmsin.20, type = "post-pred")
d_fitted(c(0,0), fit.vmsin.20, type = "point-est")

r_fitted(10, fit.vmsin.20, type = "post-pred")
r_fitted(10, fit.vmsin.20, type = "point-est")

[Package BAMBI version 2.3.5 Index]