Learn R Programming

DPpackage (version 1.1-0)

DPbetabinom: Bayesian Semiparametric Beta-Binomial Model using a DP prior

Description

This function generates a posterior density sample for a semiparametric version of the Beta-Binomial model using a Dirichlet process prior for the mixing distribution.

Usage

DPbetabinom(y,ngrid,prior,mcmc,state,status,
           data=sys.frame(sys.parent()),work.dir=NULL)

Arguments

y
a matrix giving the binomial data. The first column must include the number of sucess and the second column the number of trials.
ngrid
number of grid points where the predictive density estimate is evaluated.
prior
a list giving the prior information. The list includes the following parameter: a0 and b0 giving the hyperparameters for prior distribution of the precision parameter of the Dirichlet p
mcmc
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
state
a list giving the current value of the parameters. This list is used if the current analysis is the continuation of a previous analysis.
status
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 specifie
data
data frame.
work.dir
working directory.

Value

  • An object of class DPbetabinom representing the DP Beta-Binomial model fit. Generic functions such as print, summary, and plot have methods to show the results of the fit. The results include the baseline parameters, alpha, and the number of clusters. The MCMC samples of the parameters in the model are stored in the object thetasave. The object is included in the list save.state and are matrices which can be analyzed directly by functions provided by the coda package. The subject-specific binomial probabilities are stored in the object randsave. 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:
  • nclusteran integer giving the number of clusters.
  • pa vector of dimension (no. observations+1) giving the current value of the binomial probabilities.
  • ssan interger vector defining to which of the ncluster clusters each observation belongs.
  • alphagiving the value of the precision parameter.

Details

This generic function fits a semiparametric version of the Beta-Binomial model (Liu, 1996): $$y_i | n_i, p_i \sim Binom(n_i,p_i), i=1,\ldots,n$$ $$p_i | G \sim G$$ $$G | \alpha, G_0 \sim DP(\alpha G_0)$$ where, the baseline distribution is the beta distribution, $$G_0 = Beta(a_1,b_1)$$ To complete the model specification, the following hyperprior can be assumed for the total mass parameter: $$\alpha | a_0, b_0 \sim Gamma(a_0,b_0)$$ Notice that the baseline distribution, $G_0$, is a conjugate prior in this model specification. Therefore, standard algorihtms for conjugate DP models are used (see, e.g., Escobar and West, 1995; MacEachern, 1998).

References

Escobar, M.D. and West, M. (1995) Bayesian Density Estimation and Inference Using Mixtures. Journal of the American Statistical Association, 90: 577-588. Liu, J.S. (1996). Nonparametric Hierarchical Bayes via Sequential Imputations. The Annals of Statistics, 24: 911-930. MacEachern, S.N. (1998) Computational Methods for Mixture of Dirichlet Process Models, in Practical Nonparametric and Semiparametric Bayesian Statistics, eds: D. Dey, P. Muller, D. Sinha, New York: Springer-Verlag, pp. 1-22.

Examples

Run this code
# Data
      data(rolling)
      y <- cbind(rolling$y1,rolling$y2)


    # Prior information

      prior<-list(alpha=1,
                  a1=1,
                  b1=1)

    # Initial state
      state <- NULL

    # MCMC parameters

      mcmc <- list(nburn=5000,
                   nsave=10000,
                   nskip=3,
                   ndisplay=100)

    # Fitting the model

      fit <- DPbetabinom(y=y,ngrid=100, 
                         prior=prior, 
                         mcmc=mcmc, 
                         state=state, 
                         status=TRUE)

      fit
      summary(fit)

    # density estimate
      plot(fit,output="density")

    # parameters
      plot(fit,output="param")

Run the code above in your browser using DataLab