View source: R/all_postprodn_fns.R
d_fitted | R Documentation |
Density and random deviates from an angmcmc object
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, ...)
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 |
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. |
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 η is estimated
by applying fn
on the MCMC samples (using the function pointest), yielding the (consistent) Bayes estimate \hat{η}.
Then the mixture density f(x|η) at any point x is (consistently) estimated by
f(x|\hat{η}). The random deviates are generated from the estimated mixture density f(x|\hat{η}).
If type == 'post-pred'
, posterior predictive samples and densities are returned. That
is, the average density S^{-1} ∑_{s = 1}^S f(x | η_s) is returned in d_fitted
,
where η_1, …, η_S is the set posterior MCMC samples obtained from object
. In
r_fitted
, first a random sub-sample η_{(1)}, …, η_{(n)} of size n
from the
set of posterior samples η_1, …, η_S is drawn (with replacement if n
> S). Then
the i-th posterior predictive data point is generated from the mixture density
f(x|η_{(i)}) for i = 1,..., n.
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.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.