Gibbs Sampler for Ordered Probit
rordprobitGibbs
implements a Gibbs Sampler for the ordered probit model with a RW Metropolis step for the cut-offs.
rordprobitGibbs(Data, Prior, Mcmc)
Data
: list(y, X, k)Prior
: list(betabar, A, dstarbar, Ad)Mcmc
: list(R, keep, nprint, s)with
if c[k] c[k+1] with
cutoffs = {c[1], , c[k+1]}
Be careful in assessing prior parameter Ad
: 0.1 is too small for many applications.
Data = list(y, X, k)
y: | vector of observations, ( ) |
X: | Design Matrix |
k: | the largest possible value of y |
Prior = list(betabar, A, dstarbar, Ad)
[optional]
betabar: | prior mean (def: 0) |
A: | prior precision matrix (def: 0.01*I) |
dstarbar: | prior mean, where (def: 0) |
Ad: | prior precision matrix (def: I) |
Mcmc = list(R, keep, nprint, s)
[only R
required]
R: | number of MCMC draws |
keep: | MCMC thinning parameter -- keep every keep th draw (def: 1) |
nprint: | print the estimated time remaining for every nprint 'th draw (def: 100, set to 0 for no print) |
s: | scaling parameter for RW Metropolis (def: 2.93/ sqrt(p) ) |
A list containing: - betadraw: matrix of betadraws
cutdraw: matrix of cutdraws
dstardraw: matrix of dstardraws
accept: acceptance rate of Metropolis draws for cut-offs
set c[1] = -100 and c[k+1] = 100. c[2] is set to 0 for identification.
The relationship between cut-offs and dstar is:
c[3] = exp(dstar[1]),
c[4] = c[3] + exp(dstar[2]), ...,
c[k] = c[k-1] + exp(dstar[k-2])
Bayesian Statistics and Marketing by Rossi, Allenby, and McCulloch.
Peter Rossi, Anderson School, UCLA, perossichi@gmail.com .
rbprobitGibbs
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=2000} else {R=10} set.seed(66) ## simulate data for ordered probit model simordprobit=function(X, betas, cutoff){ z = X%*%betas + rnorm(nobs) y = cut(z, br = cutoff, right=TRUE, include.lowest = TRUE, labels = FALSE) return(list(y = y, X = X, k=(length(cutoff)-1), betas= betas, cutoff=cutoff )) } nobs = 300 X = cbind(rep(1,nobs),runif(nobs, min=0, max=5),runif(nobs,min=0, max=5)) k = 5 betas = c(0.5, 1, -0.5) cutoff = c(-100, 0, 1.0, 1.8, 3.2, 100) simout = simordprobit(X, betas, cutoff) Data=list(X=simout$X, y=simout$y, k=k) ## set Mcmc for ordered probit model Mcmc = list(R=R) out = rordprobitGibbs(Data=Data, Mcmc=Mcmc) cat(" ", fill=TRUE) cat("acceptance rate= ", accept=out$accept, fill=TRUE) ## outputs of betadraw and cut-off draws cat(" Summary of betadraws", fill=TRUE) summary(out$betadraw, tvalues=betas) cat(" Summary of cut-off draws", fill=TRUE) summary(out$cutdraw, tvalues=cutoff[2:k]) ## plotting examples if(0){plot(out$cutdraw)}
Useful links