Bayesian Analysis of Choice Data
Simon Jackman
Stanford University http://jackman.stanford.edu/BASS
February 3, 2012
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 1 / 1
Bayesian Analysis of Choice Data Simon Jackman Stanford University - - PowerPoint PPT Presentation
Bayesian Analysis of Choice Data Simon Jackman Stanford University http://jackman.stanford.edu/BASS February 3, 2012 Simon Jackman ( Stanford ) Bayesian Analysis of Choice Data February 3, 2012 1 / 1 Discrete Choice binary (e.g., probit
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 1 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 2 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 2 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 2 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 2 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 3 / 1
JAGS code 1 model{ 2 for (i in 1:N){ ## loop over observations 3 y[i] ~ dbern(p[i]) ## binary outcome 4 logit(p[i]) <- ystar[i] ## logit link 5 ystar[i] <- beta[1] ## regression structure for covariates 6 + beta[2]*educ[i] 7 + beta[3]*(educ[i]*educ[i]) 8 + beta[4]*age[i] 9 + beta[5]*(age[i]*age[i]) 10 + beta[6]*south[i] 11 + beta[7]*govelec[i] 12 + beta[8]*closing[i] 13 + beta[9]*(closing[i]*educ[i]) 14 + beta[10]*(educ[i]*educ[i]*closing[i]) 15 } 16 17 ## priors 18 beta[1:10] ~ dmnorm(mu[] , B[ , ]) # diffuse multivariate Normal prior 19 # see data file 20 } Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 4 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 5 / 1
R code 1 ## collapse by covariate classes 2 X <- cbind(nagler$age,nagler$educYrs) 3 X <- apply(X,1,paste,collapse=":") 4 covClasses <- match(X,unique(X)) 5 covX <- matrix(unlist(strsplit(unique(X),":")),ncol=2,byrow=TRUE) 6 r <- tapply(nagler$turnout,covClasses,sum) 7 n <- tapply(nagler$turnout,covClasses,length) 8 groupedData <- list(n=n,r=r, 9 age=as.numeric(covX[,1]), 10 educYrs=as.numeric(covX[,2]), 11 NOBS=length(n)) Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 6 / 1
JAGS code 1 model{ 2 for (i in 1:NOBS){ 3 logit(p[i]) <- beta[1] + age[i]*beta[2] 4 + pow(age[i],2)*beta[3] 5 + educYrs[i]*beta[4] 6 + pow(educYrs[i],2)*beta[5] 7 r[i] ~ dbin(p[i],n[i]) ## binomial model for each covariate class 8 } 9 10 11 beta[1:5] ~ dmnorm(b0[],B0[,]) 12 } 13 Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 7 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 8 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 9 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 10 / 1
JAGS code 1 for(j in 1:4){ 2 tau0[j] ~ dnorm(0,.01) 3 } 4 tau[1:4] <- sort(tau0) ## JAGS only, not in WinBUGS!
BUGS code 1 tau[1] ~ dnorm(0,.01) 2 for(j in 1:3){ 3 delta[j] ~ dexp(2) 4 tau[j+1] <- tau[j] + delta[j] 5 } Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 11 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 12 / 1
JAGS code 1 model{ 2 for(i in 1:N){ ## loop over observations 3 ## form the linear predictor (no intercept) 4 mu[i] <- x[i,1]*beta[1] + 5 x[i,2]*beta[2] + 6 x[i,3]*beta[3] + 7 x[i,4]*beta[4] + 8 x[i,5]*beta[5] + 9 x[i,6]*beta[6] 10 11 ## cumulative logistic probabilities 12 logit(Q[i,1]) <- tau[1]-mu[i] 13 p[i,1] <- Q[i,1] 14 for(j in 2:4){ 15 logit(Q[i,j]) <- tau[j]-mu[i] 16 ## trick to get slice of the cdf we need 17 p[i,j] <- Q[i,j] - Q[i,j-1] 18 } 19 p[i,5] <- 1 - Q[i,4] 20 y[i] ~ dcat(p[i,1:5]) ## p[i,] sums to 1 for each i 21 } 22 23 ## priors over betas 24 beta[1:6] ~ dmnorm(b0[],B0[,]) 25 26 ## thresholds 27 for(j in 1:4){ 28 tau0[j] ~ dnorm(0, .01) 29 } 30 tau[1:4] <- sort(tau0) ## JAGS only not in BUGS! 31 } Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 13 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 14 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 15 / 1
JAGS code 1 model{ 2 for(i in 1:N){ ## loop over observations 3 ## form the linear predictor 4 mu[i] <- x[i,1]*beta[1] + x[i,2]*beta[2] + x[i,3]*beta[3] + 5 x[i,4]*beta[4] + x[i,5]*beta[5] + x[i,6]*beta[6] + eta[id[i]] 6 7 ## cumulative logistic probabilities 8 logit(Q[i,1]) <- tau[1]-mu[i] 9 p[i,1] <- Q[i,1] 10 for(j in 2:4){ 11 logit(Q[i,j]) <- tau[j]-mu[i] 12 p[i,j] <- Q[i,j] - Q[i,j-1] 13 } 14 p[i,5] <- 1 - Q[i,4] 15 y[i] ~ dcat(p[i,1:5]) ## p[i,] sums to 1 for each i 16 } 17 ## priors over betas 18 beta[1:6] ~ dmnorm(b0[],B0[,]) 19 ## hierarchical model over etas, note zero mean restriction 20 for(k in 1:NID){ 21 eta[k] ~ dnorm(0.0,eta.tau) 22 } 23 eta.tau <- 1/pow(sigma,2) ## convert stddev to precision 24 sigma ~ dunif(0,2) 25 ## priors over thresholds 26 for(j in 1:4){ 27 tau0[j] ~ dnorm(0,.01) 28 } 29 tau[1:4] <- sort(tau0) ## JAGS only, not in WinBUGS! 30 } Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 16 / 1
σ Density 0.0 0.5 1.0 1.5 2.0 1 2 3 4 5
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 17 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 18 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 19 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 20 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 21 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 22 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 23 / 1
JAGS code 1 model{ 2 for(i in 1:NOBS){ 3 for(j in 1:3){ ## loop over choices 4 mu[i,j] <- beta[j,1] 5 + beta[j,2]*dem[i] 6 + beta[j,3]*ind[i] 7 + beta[j,4]*rep[i] 8 + beta[j,5]*female[i] 9 + beta[j,6]*natlecon[i] 10 + gamma*dist[i,j] 11 emu[i,j] <- exp(mu[i,j]) 12 p[i,j] <- emu[i,j]/sum(emu[i,1:3]) 13 } 14 y[i] ~ dcat(p[i,1:3]) 15 } 16 17 ## priors 18 for(k in 1:6){ 19 beta[1,k] <- 0 ## identifying restriction 20 } 21 for(j in 2:3){ 22 beta[j,1:6] ~ dmnorm(b0,B0) ## b0, B0 passed as data from R 23 } 24 gamma ~ dnorm(0,.01) 25 26 ## plus code for mapping to identified parameters, see book 27 } Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 24 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 25 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 26 / 1
1
2
3
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 27 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 28 / 1
σ σ22
10 20 30 40 50 60
Lag
200 400 600 800 1000 0.2 0.4 0.6 0.8 1.0
Autocorrelations : σ22
Effective sample size: 2,412
σ σ12
−4 −2 2 4 6
Lag
200 400 600 800 1000 0.0 0.2 0.4 0.6 0.8 1.0
Autocorrelations : σ12
Effective sample size: 2,540
ρ
−1.0 −0.5 0.0 0.5 1.0
Lag
200 400 600 800 1000 0.0 0.2 0.4 0.6 0.8 1.0
Autocorrelations : ρ
Effective sample size: 2,575
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 29 / 1
Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 30 / 1
Alvarez, R. Michael and Jonathan Nagler. 1995. ‘‘Economics, Issues and the Perot Candidacy: Voter Choice in the 1992 Presidential Election.’’ American Journal of Political Science 39:714--44. Chib, Siddhartha and Edward Greenberg. 1997. ‘‘Analysis of Multivariate Probit Models.’’ Biometrika 85:347--361. Imai, Kosuke and David A. van Dyk. 2005. ‘‘MNP: R Package for Fitting the Multinomial Probit Model.’’ Journal of Statistical Software 14:1--32. McCulloch, Robert E., Nicholas G. Polson and Peter E. Rossi. 1998. ‘‘A Bayesian Analysis of the Multinomial Probit Model with Fully Identified Parameters.’’ Typescript. Graduate School of Business, University of Chicago. McCulloch, Robert E. and Peter E. Rossi. 1994. ‘‘An exact likelihood analysis of the multinomial probit model.’’ Journal of Econometrics 64:207--40. Simon Jackman (Stanford) Bayesian Analysis of Choice Data February 3, 2012 31 / 1