tag:blogger.com,1999:blog-590043897961646114.post4085373580547863167..comments2024-02-06T02:06:06.364-08:00Comments on Engaging Market Research: Let's Do Some MORE Hierarchical Bayes Choice Modeling in R!Unknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-590043897961646114.post-6136437069588567112015-02-22T14:56:20.554-08:002015-02-22T14:56:20.554-08:00I welcome all comments but hopefully you will unde...I welcome all comments but hopefully you will understand if I do not try to debug your code. It requires a considerable amount of back-and-forth communication and simply more time than I have available. An alternative is stackoverflow (look under tags for R).Joel Cadwellhttps://www.blogger.com/profile/14946447393733294251noreply@blogger.comtag:blogger.com,1999:blog-590043897961646114.post-32429570759404188332015-02-22T10:54:58.270-08:002015-02-22T10:54:58.270-08:00Thanks for your great blog!
I would greatly appr...Thanks for your great blog!<br /><br /> I would greatly appreciate some help on a similar problem. I am using a matrix of participants(rows) and questions (columns) to generate posterior distributions of responses on a likert scale. I just can't get it to work and really need some assistance. I have attached by attempt and sample dataset<br /><br />1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 4L, 2L, 1L, <br />1L, 1L, 1L, 2L, 2L, 1L, 3L, 2L, 4L, 2L, 1L, 1L, 5L, 1L, 3L), <br /> K2 = c(3L, 1L, 3L, 3L, 4L, 2L, 2L, 1L, 4L, 1L, 5L, 3L, 2L, <br /> 2L, 3L, 3L, 5L, 2L, 4L, 2L, 4L, 5L, 5L, 3L, 2L, 3L, 3L, 3L, <br /> 2L, 2L, 3L, 3L, 3L, 2L, 5L, 5L, 2L, 1L, 4L, 3L, 1L, 2L, 2L<br /> ), K3 = c(3L, 4L, 5L, 2L, 3L, 3L, 4L, 4L, 4L, 3L, 4L, 4L, <br /> 3L, 5L, 4L, 3L, 3L, 2L, 3L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 5L, <br /> 3L, 4L, 3L, 5L, 2L, 2L, 4L, 3L, 4L, 4L, 4L, 2L, 4L, 5L, 3L, <br /> 1L), K4 = c(4L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 1L, 2L, <br /> 1L, 2L, 2L, 3L, 1L, 3L, 3L, 3L, 4L, 3L, 2L, 2L, 2L, 3L, 3L, <br /> 3L, 2L, 3L, 3L, 4L, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 2L, 3L, 3L, <br /> 2L), K5 = c(3L, 5L, 5L, 5L, 2L, 1L, 2L, 5L, 5L, 4L, 5L, 5L, <br /> 5L, 1L, 4L, 2L, 4L, 3L, 3L, 3L, 3L, 2L, 1L, 4L, 2L, 5L, 4L, <br /> 5L, 5L, 3L, 3L, 5L, 4L, 2L, 4L, 2L, 1L, 3L, 5L, 4L, 5L, 1L, <br /> 5L), K6 = c(2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 3L, 2L, 1L, <br /> 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 2L, <br /> 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, <br /> 2L)), .Names = c("Region", "K1", "K2", "K3", "K4", "K5", <br />"K6"), class = "data.frame", row.names = c(NA, -43L))<br /><br /><br />response<-x[,2:7]<br />G<-apply(response,1,scale)<br />Qcor<-cor(response)<br />#cols<-colMeans(response)<br />mat<-matrix(var(G,Qcor),nrow=43)<br /><br />model<-function(a,b){<br />alpha[1]<- -5; alpha[6]<-10; alpha[2]<- 1.5<br />alpha[3]<- 2.5; alpha[4]<-3.5; alpha[5]<-4.5<br /><br />for(i in 1:n) {for(j in 1:m)<br />{lo[i,j]<-((alpha[x[i,j]]-3)/b[i])+3 -a[i]<br />up[i,j]<-((alpha[x[i,j]+1]-3)/b[i])+3 -a[i]}<br />}<br /><br />for(i in 1:n) {z[i,1:m]~dmnorm(mu[],G[,])I(lo[i,],up[i,])}<br /><br /># priors for mu and sigma<br />for(i in 1:m) {mu[i]~dunif(0,6)}<br />G[1:m,1:m]~dwish(R[,],m)<br />varcov[1:m,1:m]<-inverse(G[,])<br />for(j in 1:m) {cor[j,j]<-varcov[j,j]}<br />for(i in 1:m-1) {for(j in i+1:m)<br />{cor[i,j]<-varcov[i,j]/(sqrt(varcov[i,i]*varcov[j,j])); cor[j,i]<-cor[i,j]}<br />}<br /><br /># DP Priors for a's and b's using stick-breaking algorithm<br />for(i in 1:n) {a[i]<-aa[i,1];b[i]<-(aa[i,2])}<br />for(j in 1:n) {for (kk in 1:2) {aa[j,kk]<-theta1[latent[j],kk]}}<br />for(i in 1:n) {latent[i]~dcat(pi[1:L1])} pi[1]<-r[1]<br />for(j in 2:(L1-1)) {log(pi[j])<-log(r[j])+sum(R1[j,1:j-1])<br />for(l in 1:j-1) {R1[j,l]<-log(1-r[l])}} pi[L1]<-1-sum(pi[1:(L1-1)])<br />for(j in 1:L1) {r[j]~dbeta(1,mm)}<br /><br /># baseline distribution for DP as in (5)<br />for(i in 1:L1) {theta1[i,1:2]~dmnorm(zero[1:2],Sab[1:2,1:2])I(LB[],)}<br />zero[1]<-0; zero[2]<-1<br />Sab[1:2,1:2]~dwish(Omega[1:2,1:2],2); varcovab[1:2,1:2]<-inverse(Sab[,])<br />corab<-varcovab[1,2]/sqrt(varcovab[1,1]*varcovab[2,2])<br /><br /># prior for concentration parameter<br />mm~dunif(0.4,10) <br />}Anonymoushttps://www.blogger.com/profile/04644101130892210463noreply@blogger.com