## Not run:
#
# ##########################################################
# # Simulate data from a mixture of two normal densities
# ##########################################################
# nobs <- 500
# y1 <-rnorm(nobs, 3,.8)
#
# ## y2 = 0.6
# y21 <- rnorm(nobs,1.5, 0.8)
# y22 <- rnorm(nobs,4.0, 0.6)
# u <- runif(nobs)
# y2 <- ifelse(u<0.6,y21,y22)
# y <- c(y1,y2)
#
# ## design matrix including a single factor
# trt <- c(rep(0,nobs),rep(1,nobs))
#
# ## design matrix for posterior predictive
# zpred <- rbind(c(1,0),c(1,1))
#
# # Prior information
#
# S0 <- diag(100,2)
# m0 <- rep(0,2)
# psiinv <- diag(1,2)
#
# prior <- list(a0=10,
# b0=1,
# nu=4,
# m0=m0,
# S0=S0,
# psiinv=psiinv,
# tau1=6.01,
# taus1=6.01,
# taus2=2.01)
#
# # Initial state
# state <- NULL
#
# # MCMC parameters
#
# nburn <- 5000
# nsave <- 5000
# nskip <- 3
# ndisplay <- 100
# mcmc <- list(nburn=nburn,
# nsave=nsave,
# nskip=nskip,
# ndisplay=ndisplay)
#
# # Fit the model
# fit1 <- LDDPdensity(y~trt,prior=prior,mcmc=mcmc,
# state=state,status=TRUE,
# ngrid=200,zpred=zpred,
# compute.band=TRUE,type.band="PD")
#
#
# # Plot posterior density estimate
# # with design vector x0=(1,0)
#
# plot(fit1$grid,fit1$densp.h[1,],type="l",xlab="Y",
# ylab="density",lty=2,lwd=2)
# lines(fit1$grid,fit1$densp.l[1,],lty=2,lwd=2)
# lines(fit1$grid,fit1$densp.m[1,],lty=1,lwd=3)
#
# # add true density to the plot
# p1 <- dnorm(fit1$grid, 3.0, 0.8)
# lines(fit1$grid,p1,lwd=2,lty=1, col="red")
#
# # Plot posterior density estimate
# # with design vector x0=(1,1)
#
# plot(fit1$grid,fit1$densp.h[2,],type="l",xlab="Y",
# ylab="density",lty=2,lwd=2)
# lines(fit1$grid,fit1$densp.l[2,],lty=2,lwd=2)
# lines(fit1$grid,fit1$densp.m[2,],lty=1,lwd=3)
#
# # add true density to the plot
# p2 <- 0.6*dnorm(fit1$grid, 1.5, 0.8) +
# 0.4*dnorm(fit1$grid, 4.0, 0.6)
# lines(fit1$grid,p2,lwd=2,lty=1, col="red")
#
#
# # Plot posterior CDF estimate
# # with design vector x0=(1,0)
#
# plot(fit1$grid,fit1$cdfp.h[1,],type="l",xlab="Y",
# ylab="density",lty=2,lwd=2)
# lines(fit1$grid,fit1$cdfp.l[1,],lty=2,lwd=2)
# lines(fit1$grid,fit1$cdfp.m[1,],lty=1,lwd=3)
#
# # add true CDF to the plot
# p1 <- pnorm(fit1$grid, 3.0, 0.8)
# lines(fit1$grid,p1,lwd=2,lty=1, col="red")
#
# # Plot posterior CDF estimate
# # with design vector x0=(1,1)
#
# plot(fit1$grid,fit1$cdfp.h[2,],type="l",xlab="Y",
# ylab="density",lty=2,lwd=2)
# lines(fit1$grid,fit1$cdfp.l[2,],lty=2,lwd=2)
# lines(fit1$grid,fit1$cdfp.m[2,],lty=1,lwd=3)
#
# # add true density to the plot
# p2 <- 0.6*pnorm(fit1$grid, 1.5, 0.8) +
# 0.4*pnorm(fit1$grid, 4.0, 0.6)
# lines(fit1$grid,p2,lwd=2,lty=1, col="red")
#
# ## End(Not run)
Run the code above in your browser using DataLab