Description Usage Arguments Details Value Author(s) References See Also Examples
This function generates a posterior density sample for a Dirichlet process mixture of normals model.
1 2 3 |
y |
a vector or matrix giving the data from which the density estimate is to be computed. |
ngrid |
number of grid points where the density estimate is
evaluated. This is only used if dimension of |
grid |
matrix of dimension ngrid*nvar of grid points where the density estimate is
evaluated. This is only used if dimension of |
prior |
a list giving the prior information. The list includes the following
parameter: |
mcmc |
a list giving the MCMC parameters. The list must include
the following integers: |
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 ( |
method |
the method to be used. See |
data |
data frame. |
na.action |
a function that indicates what should happen when the data
contain |
This generic function fits a Dirichlet process mixture of normal model for density estimation (Escobar and West, 1995):
yi | mui, Sigmai ~ N(mui,Sigmai), i=1,…,n
(mui,Sigmai) | G ~ G
G | alpha, G0 ~ DP(alpha G0)
where, the baseline distribution is the conjugate normal-inverted-Wishart,
G0 = N(mu| m1, (1/k0) Sigma) IW (Sigma | nu1, psi1)
To complete the model specification, independent hyperpriors are assumed (optional),
alpha | a0, b0 ~ Gamma(a0,b0)
m1 | m2, s2 ~ N(m2,s2)
k0 | tau1, tau2 ~ Gamma(tau1/2,tau2/2)
psi1 | nu2, psi2 ~ IW(nu2,psi2)
Note that the inverted-Wishart prior is parametrized such that if A ~ IWq(nu, psi) then E(A)= psiinv/(nu-q-1).
To let part of the baseline distribution fixed at a particular value, set the corresponding hyperparameters of the prior distributions to NULL in the hyperprior specification of the model.
Although the baseline distribution, G0, is a conjugate prior in
this model specification, the algorithms with auxiliary parameters
described in MacEachern and Muller (1998) and Neal (2000) are
adopted. Specifically, the no-gaps algorithm of
MacEachern and Muller (1998), "no-gaps"
, and the algorithm 8 with m=1
of Neal (2000), "neal"
, are considered in the DPdensity
function.
The default method is the algorithm 8 of Neal.
An object of class DPdensity
representing the DP mixture of normals
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 function DPrandom
can be used to extract the posterior mean of the
subject-specific means and covariance matrices.
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:
ncluster |
an integer giving the number of clusters. |
muclus |
a matrix of dimension (nobservations+100)*(nvariables) giving the means of the clusters
(only the first |
sigmaclus |
a matrix of dimension (nobservations+100)*( (nvariables)*((nvariables)+1)/2) giving
the lower matrix of the covariance matrix of the clusters (only the first |
ss |
an interger vector defining to which of the |
alpha |
giving the value of the precision parameter. |
m1 |
giving the mean of the normal components of the baseline distribution. |
k0 |
giving the scale parameter of the normal part of the baseline distribution. |
psi1 |
giving the scale matrix of the inverted-Wishart part of the baseline distribution. |
Alejandro Jara <atjara@uc.cl>
Escobar, M.D. and West, M. (1995) Bayesian Density Estimation and Inference Using Mixtures. Journal of the American Statistical Association, 90: 577-588.
MacEachern, S. N. and Muller, P. (1998) Estimating mixture of Dirichlet Process Models. Journal of Computational and Graphical Statistics, 7 (2): 223-338.
Neal, R. M. (2000). Markov Chain sampling methods for Dirichlet process mixture models. Journal of Computational and Graphical Statistics, 9: 249-265.
DPrandom
, PTdensity
, BDPdensity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | ## Not run:
####################################
# Univariate example
####################################
# 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)
# Example of Prior information 1
# Fixing alpha, m1, and Psi1
prior1 <- list(alpha=1,m1=rep(0,1),psiinv1=diag(0.5,1),nu1=4,
tau1=1,tau2=100)
# Example of Prior information 2
# Fixing alpha and m1
prior2 <- list(alpha=1,m1=rep(0,1),psiinv2=solve(diag(0.5,1)),
nu1=4,nu2=4,tau1=1,tau2=100)
# Example of Prior information 3
# Fixing only alpha
prior3 <- list(alpha=1,m2=rep(0,1),s2=diag(100000,1),
psiinv2=solve(diag(0.5,1)),
nu1=4,nu2=4,tau1=1,tau2=100)
# Example of Prior information 4
# Everything is random
prior4 <- list(a0=2,b0=1,m2=rep(0,1),s2=diag(100000,1),
psiinv2=solve(diag(0.5,1)),
nu1=4,nu2=4,tau1=1,tau2=100)
# Fit the models
fit1.1 <- DPdensity(y=speeds,prior=prior1,mcmc=mcmc,
state=state,status=TRUE)
fit1.2 <- DPdensity(y=speeds,prior=prior2,mcmc=mcmc,
state=state,status=TRUE)
fit1.3 <- DPdensity(y=speeds,prior=prior3,mcmc=mcmc,
state=state,status=TRUE)
fit1.4 <- DPdensity(y=speeds,prior=prior4,mcmc=mcmc,
state=state,status=TRUE)
# Posterior means
fit1.1
fit1.2
fit1.3
fit1.4
# Plot the estimated density
plot(fit1.1,ask=FALSE)
plot(fit1.2,ask=FALSE)
plot(fit1.3,ask=FALSE)
plot(fit1.4,ask=FALSE)
# Extracting the density estimate
cbind(fit1.1$x1,fit1.1$dens)
cbind(fit1.2$x1,fit1.2$dens)
cbind(fit1.3$x1,fit1.3$dens)
cbind(fit1.4$x1,fit1.4$dens)
# Plot the parameters (only prior 2 for illustration)
# (to see the plots gradually set ask=TRUE)
plot(fit1.2,ask=FALSE,output="param")
# Plot the a specific parameters
# (to see the plots gradually set ask=TRUE)
plot(fit1.2,ask=FALSE,output="param",param="psi1-speeds",
nfigr=1,nfigc=2)
# Extracting the posterior mean of the specific
# means and covariance matrices
# (only prior 2 for illustration)
DPrandom(fit1.2)
# Ploting predictive information about the specific
# means and covariance matrices
# with HPD and Credibility intervals
# (only prior 2 for illustration)
# (to see the plots gradually set ask=TRUE)
plot(DPrandom(fit1.2,predictive=TRUE),ask=FALSE)
plot(DPrandom(fit1.2,predictive=TRUE),ask=FALSE,hpd=FALSE)
# Ploting information about all the specific means
# and covariance matrices
# with HPD and Credibility intervals
# (only prior 2 for illustration)
# (to see the plots gradually set ask=TRUE)
plot(DPrandom(fit1.2),ask=FALSE,hpd=FALSE)
####################################
# Bivariate example
####################################
# Data
data(airquality)
attach(airquality)
ozone <- Ozone**(1/3)
radiation <- Solar.R
# Prior information
s2 <- matrix(c(10000,0,0,1),ncol=2)
m2 <- c(180,3)
psiinv2 <- solve(matrix(c(10000,0,0,1),ncol=2))
prior <- list(a0=1,b0=1/5,nu1=4,nu2=4,s2=s2,
m2=m2,psiinv2=psiinv2,tau1=0.01,tau2=0.01)
# Initial state
state <- NULL
# MCMC parameters
nburn <- 5000
nsave <- 10000
nskip <- 10
ndisplay <- 1000
mcmc <- list(nburn=nburn,nsave=nsave,nskip=nskip,ndisplay=ndisplay)
# Fit the model
fit1 <- DPdensity(y=cbind(radiation,ozone),prior=prior,mcmc=mcmc,
state=state,status=TRUE,na.action=na.omit)
# Plot the estimated density
plot(fit1)
# Extracting the density estimate
fit1$x1
fit1$x2
fit1$dens
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.