mean1=function(x){mean(x, na.rm=T)} likelihood.Anae=function(cred.temp){ ## pvector=c(p1(1|1), p1(0|0), ..., p5(1|1), p5(0|0) ### update each reviewer one by one data.work=options()$data.work pi1=options()$pi1 K=options()$K R=options()$R credmatrix=options()$credmatrix credmatrix[((R-1)*K*(K-1)+1):((R-1)*K*(K-1)+K*(K-1))]=cred.temp n1=dim(data.work)[[1]] m1=dim(data.work)[[2]] ## p(x)=p(x|y=1)*p(y=1)+...+p(x|y=K)*p(y=K) ## p(x1, x2, x3)=p(x1, x2, x3|y=1)*p(y=1)+...+p(x1,x2,x3|y=K)*p(y=K) ## constraint p(1|1)p(1)+p(0|1)p(1)+p(1|0)p(0)+p(0|0)p(0)=1 value=0 penalty=0 for(ii in 1:n1) { pvector=rep(1, K) for (jj in 1:m1) { kk=ifelse(jj>3, jj-2, 1) cred.temp=credmatrix[((kk-1)*K*(K-1)+1):((kk-1)*K*(K-1)+K*(K-1))]; cred.temp=matrix(cred.temp, ncol=K-1, nrow=K) cred.temp=cbind(cred.temp, 1-rowSums(cred.temp)) if(sum(cred.temp<0)>0) penalty=1.e10 obs=data.work[ii,jj] pvector=pvector*cred.temp[,obs] } temp=pvector*pi1[ii, ] a=sum(temp) if(a<=0) a=1.e-10 value= value+log(a) } value= sum(credmatrix<0 | credmatrix>1)*1.e10+ penalty -value value }