## Not run:
# ####################################
# # A simulated Data Set
# ####################################
# nsubject <- 200
# nitem <- 40
#
# y <- matrix(0,nrow=nsubject,ncol=nitem)
# dimnames(y) <- list(paste("id",seq(1:nsubject)),
# paste("item",seq(1,nitem)))
#
#
# ind <- rbinom(nsubject,1,0.5)
# theta <- ind*rnorm(nsubject,1,0.25)+(1-ind)*rnorm(nsubject,3,0.25)
# beta <- c(0,seq(-1,3,length=nitem-1))
# true.cdf <- function(grid)
# {
# 0.5*pnorm(grid,1,0.25)+0.5*pnorm(grid,3,0.25)
# }
# for(i in 1:nsubject)
# {
# for(j in 1:nitem)
# {
# eta<-theta[i]-beta[j]
# mean<-exp(eta)/(1+exp(eta))
# y[i,j]<-rbinom(1,1,mean)
# }
# }
#
# # Prior information
#
# beta0 <- rep(0,nitem-1)
# Sbeta0 <- diag(1000,nitem-1)
#
# prior <- list(alpha=1,
# tau1=6.02,
# tau2=2.02,
# mub=0,
# Sb=100,
# beta0=beta0,
# Sbeta0=Sbeta0)
#
# # Initial state
# state <- NULL
#
# # MCMC parameters
#
# nburn <- 5000
# nsave <- 5000
# nskip <- 0
# ndisplay<- 1000
# mcmc <- list(nburn=nburn,
# nsave=nsave,
# nskip=nskip,
# ndisplay=ndisplay)
#
# # Fit the model
# fit1 <- DPrasch(y=y,prior=prior,mcmc=mcmc,
# state=state,status=TRUE,grid=seq(-1,5,0.01),
# compute.band=TRUE)
#
# # CDF estimate and truth
# plot(fit1$grid,true.cdf(fit1$grid),type="l",lwd=2,col="red",
# xlab=expression(theta),ylab="CDF")
# lines(fit1$grid,fit1$cdf,lwd=2,col="blue")
# lines(fit1$grid,fit1$cdf.l,lwd=2,col="blue",lty=2)
# lines(fit1$grid,fit1$cdf.u,lwd=2,col="blue",lty=2)
#
# # Summary with HPD and Credibility intervals
# summary(fit1)
# summary(fit1,hpd=FALSE)
#
# # Plot model parameters
# # (to see the plots gradually set ask=TRUE)
# plot(fit1,ask=FALSE)
# plot(fit1,ask=FALSE,nfigr=2,nfigc=2)
#
# # Extract random effects
#
# DPrandom(fit1)
# plot(DPrandom(fit1))
# DPcaterpillar(DPrandom(fit1))
# ## End(Not run)
Run the code above in your browser using DataLab