This function generates a posterior density sample for a Bernstein-Dirichlet model.
BDPdensity(y,support=3,ngrid=1000,grid=NULL,prior,mcmc,state,status,
data=sys.frame(sys.parent()),na.action=na.fail)
a vector giving the data from which the density estimate is to be computed.
an integer number giving the support of the random density, 1=[0,1], 2=(0, +Inf], and 3=(-In,+Inf). Depending on this, the data is transformed to lie in the [0,1] interval.
number of grid points where the density estimate is
evaluated. This is only used if dimension of y
is lower or equal than 2. The default value is 1000.
vector of grid points where the density estimate is evaluated. The default value is NULL and the grid is chosen according to the range of the data.
a list giving the prior information. The list includes the following
parameter: aa0
and ab0
giving the hyperparameters for
prior distribution of the precision parameter of the Dirichlet process
prior, alpha
giving the value of the precision parameter (it
must be specified if aa0
is missing, see details
below), a0
and b0
giving the parameters of the
beta centering distribution of the DP prior, and
kmax
giving the maximum value of the discrete uniform
prior for the degree of the Bernstein polynomial.
a list giving the MCMC parameters. The list must include
the following integers: nburn
giving the number of burn-in
scans, nskip
giving the thinning interval, nsave
giving
the total number of scans to be saved, and ndisplay
giving
the number of saved scans to be displayed on screen (the function reports
on the screen when every ndisplay
iterations have been carried
out).
a list giving the current value of the parameters. This list is used if the current analysis is the continuation of a previous analysis.
a logical variable indicating whether this run is new (TRUE
) or the
continuation of a previous analysis (FALSE
). In the latter case
the current value of the parameters must be specified in the
object state
.
data frame.
a function that indicates what should happen when the data
contain NA
s. The default action (na.fail
) causes
BDPdensity
to print an error message and terminate if there are any
incomplete observations.
An object of class BDPdensity
representing the Bernstein-Dirichlet
model fit. Generic functions such as print
, summary
, and plot
have methods to
show the results of the fit. The results include the degree of the polynomial k
, alpha
, and the
number of clusters.
The MCMC samples of the parameters and the errors in the model are stored in the object
thetasave
and randsave
, respectively. Both objects are included in the
list save.state
and are matrices which can be analyzed directly by functions
provided by the coda package.
The list state
in the output object contains the current value of the parameters
necessary to restart the analysis. If you want to specify different starting values
to run multiple chains set status=TRUE
and create the list state based on
this starting values. In this case the list state
must include the following objects:
an integer giving the number of clusters.
a real vector giving the y
latent variables of the clusters (only the first ncluster
are
considered to start the chain).
an interger vector defining to which of the ncluster
clusters each observation belongs.
giving the value of the precision parameter.
giving the degree of the Bernstein polynomial.
This generic function fits a Bernstein-Dirichlet model for density estimation (Petrone, 1999a, 1999b; Petrone and Waserman, 2002): $$y_i | G \sim G, i=1,\ldots,n$$ $$G | kmax, \alpha, G_0 \sim BDP(kmax,\alpha G_0)$$
where, \(y_i\) is the transformed data to lie in [0,1], kmax
is the upper limit of the discrete uniform prior for the degree of the Bernstein
polynomial, \(\alpha\) is the total mass parameter of the Dirichlet process component,
and \(G_0\) is the centering distribution of the DP. The centering distribution corresponds
to a \(G_0=Beta(a_0,b_0)\) distribution.
The precision or total mass parameter, \(\alpha\), of the DP
prior
can be considered as random, having a gamma
distribution, \(Gamma(a_0,b_0)\),
or fixed at some particular value. When \(\alpha\) is random the method described by
Escobar and West (1995) is used. To let \(\alpha\) to be fixed at a particular
value, set \(a_0\) to NULL in the prior specification.
Escobar, M.D. and West, M. (1995) Bayesian Density Estimation and Inference Using Mixtures. Journal of the American Statistical Association, 90: 577-588.
Petrone, S. (1999a) Random Bernstein Polynomials. Scandinavian Journal of Statistics, 26: 373-393.
Petrone, S. (1999b) Bayesian density estimation using Bernstein polynomials. The Canadian Journal of Statistics, 27: 105-126.
Petrone, S. and Waserman, L. (2002) Consistency of Bernstein polynomial posterior. Journal of the Royal Statistical Society, Series B, 64: 79-100.
# NOT RUN {
# Data
data(galaxy)
galaxy<-data.frame(galaxy,speeds=galaxy$speed/1000)
attach(galaxy)
# Initial state
state <- NULL
# MCMC parameters
nburn<-1000
nsave<-10000
nskip<-10
ndisplay<-100
mcmc <- list(nburn=nburn,nsave=nsave,nskip=nskip,ndisplay=ndisplay)
# Prior
prior<-list(aa0=2.01,
ab0=0.01,
kmax=1000,
a0=1,
b0=1)
# Fitting the model
fit <- BDPdensity(y=speeds,prior=prior,mcmc=mcmc,
state=state,status=TRUE)
plot(fit)
# }
Run the code above in your browser using DataLab