| rhierBinLogit {bayesm} | R Documentation |
rhierBinLogit implements an MCMC algorithm for hierarchical binary logits with
a normal heterogeneity distribution. This is a hybrid sampler with a RW Metropolis step
for unit-level logit parameters.
rhierBinLogit is designed for use on choice-based conjoint data with partial profiles.
The Design matrix is based on differences of characteristics between two alternatives. See
Appendix A of Bayesian Statistics and Marketing for details.
rhierBinLogit(Data, Prior, Mcmc)
Data |
list(lgtdata,Z) (note: Z is optional) |
Prior |
list(Deltabar,ADelta,nu,V) (note: all are optional) |
Mcmc |
list(sbeta,R,keep) (note: all but R are optional) |
Model:
y_{hi} = 1 with pr=exp(x_{hi}'beta_h)/(1+exp(x_{hi}'beta_h). beta_h is nvar x 1.
h=1,...,length(lgtdata) units or "respondents" for survey data.
beta_h= ZDelta[h,] + u_h.
Note: here ZDelta refers to Z%*%Delta, ZDelta[h,] is hth row of this product.
Delta is an nz x nvar array.
u_h ~ N(0,V_{beta}).
Priors:
delta= vec(Delta) ~ N(vec(Deltabar),V_{beta} (x) ADelta^{-1})
V_{beta} ~ IW(nu,V)
Lists contain:
lgtdatalgtdata[[h]]$ylgtdata[[h]]$XDeltabarADeltanuVsbetaRkeepa list containing:
Deltadraw |
R/keep x nz*nvar matrix of draws of Delta |
betadraw |
nlgt x nvar x R/keep array of draws of betas |
Vbetadraw |
R/keep x nvar*nvar matrix of draws of Vbeta |
llike |
R/keep vector of log-like values |
reject |
R/keep vector of reject rates over nlgt units |
Some experimentation with the Metropolis scaling paramter (sbeta) may be required.
Peter Rossi, Graduate School of Business, University of Chicago, Peter.Rossi@ChicagoGsb.edu.
For further discussion, see Bayesian Statistics and Marketing
by Rossi, Allenby and McCulloch, Chapter 5.
http://faculty.chicagogsb.edu/peter.rossi/research/bsm.html
##
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=10000} else {R=10}
set.seed(66)
nvar=5 ## number of coefficients
nlgt=1000 ## number of cross-sectional units
nobs=10 ## number of observations per unit
nz=2 ## number of regressors in mixing distribution
## set hyper-parameters
## B=ZDelta + U
Z=matrix(c(rep(1,nlgt),runif(nlgt,min=-1,max=1)),nrow=nlgt,ncol=nz)
Delta=matrix(c(-2,-1,0,1,2,-1,1,-.5,.5,0),nrow=nz,ncol=nvar)
iota=matrix(1,nrow=nvar,ncol=1)
Vbeta=diag(nvar)+.5*iota%*%t(iota)
## simulate data
lgtdata=NULL
for (i in 1:nlgt)
{ beta=t(Delta)%*%Z[i,]+as.vector(t(chol(Vbeta))%*%rnorm(nvar))
X=matrix(runif(nobs*nvar),nrow=nobs,ncol=nvar)
prob=exp(X%*%beta)/(1+exp(X%*%beta))
unif=runif(nobs,0,1)
y=ifelse(unif<prob,1,0)
lgtdata[[i]]=list(y=y,X=X,beta=beta)
}
out=rhierBinLogit(Data=list(lgtdata=lgtdata,Z=Z),Mcmc=list(R=R))
cat("Summary of Delta draws",fill=TRUE)
summary(out$Deltadraw,tvalues=as.vector(Delta))
cat("Summary of Vbeta draws",fill=TRUE)
summary(out$Vbetadraw,tvalues=as.vector(Vbeta[upper.tri(Vbeta,diag=TRUE)]))
if(0){
## plotting examples
plot(out$Deltadraw,tvalues=as.vector(Delta))
plot(out$betadraw)
plot(out$Vbetadraw,tvalues=as.vector(Vbeta[upper.tri(Vbeta,diag=TRUE)]))
}