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 = "pointest", fn = mean, log = FALSE, chain.no, ...)
r_fitted(n = 1, object, type = "pointest", fn = mean, chain.no, ...)
Arguments
x 
vector, if univariate or a two column matrix, if bivariate, with each row a 2D 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 
type 
Method of estimating density/generating random deviates. Possible choices are

fn 
function, or a single character string specifying its name, to evaluate on MCMC samples to estimate
parameters. Defaults to 
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 = 'pointest'
, 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 == 'postpred'
, 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 subsample \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 ith 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 2D 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 = "postpred")
d_fitted(c(0,0), fit.vmsin.20, type = "pointest")
r_fitted(10, fit.vmsin.20, type = "postpred")
r_fitted(10, fit.vmsin.20, type = "pointest")