Appendx Appendx I. Detals used n M-step of Secton 4. Now wrte h (r) and expect ultmately t wll close to zero. and h (r) = [δq(α ; α (r) )/δα ] α =α (r 1) = [δq(α ; α (r) )/δα ] α =α (r 1) δ log L(α (r 1) )/δα [δq(α ; α (r 1) )/δα ] α =α (r 1) = [ψ(α ) ψ(α j ) + ψ(n j + α (r) j ) ψ(n + α (r) )] α =α (r 1) [ψ(α ) ψ(α j ) + ψ(n j + α (r 1) j ) ψ(n + α (r 1) )] α =α (r 1) = ψ(n j + α (r) j ) ψ(n + α (r) where B (0) matrx e (r) ) ψ(n j + α (r 1) j = α (r) v (r) c (r) α (r 1), error term = h (r) + B (r 1) e (r) ) + ψ(n + α (r 1) ) (A1) = 1/(v (r)t e (r) ) (A2) = I d, whch corresponds to ntal EM gradent step, and f the I c (α (r) ; n ) + B (r) fals to be postve defnte, then t s replaced by I c (α (r) ; n ) + ( 1 2 )m B (r), where m s the smallest postve nteger such that the above matrx s postve defnte. & B (r) = B (r 1) + c (r) v (r) v (r)t, for all = 1,, k (A3) Ideas of (A1), (A2) and (A3) are due to Davdon (1959). Appendx II. Program for smulaton of sample observatons for gven probabltes The smulaton() functon needs an argument. Value of n s the sample sze and p be the vector of probabltes. 1
smulaton<- functon(n, p) f(sum(p)!=1.0) stop( Probabltes are not properly gven ) k<- length(p) obs<- matrx(0, ncol=500, nrow= k) rowsum.obs<-c(rep(0,k)) for(j n 1:500) cumul.obs<- c(rep(0, k)) cumul.prob<- c(rep(0, k)) obs[1,j]<- rbnom(1, n, p[1]) cumul.obs[1]<- obs[1,j] cumul.prob[1]<- p[1] for( n 2:k) f((p[]/(1-cumul.prob[-1])) 1.0) obs[,j]<- rbnom(1, n-cumul.obs[-1], p[]/(1-cumul.prob[-1])) else obs<- n - cumul.obs[-1] cumul.obs[]<- cumul.obs[-1]+obs[,j] cumul.prob[]<- cumul.prob[-1]+p[] for( n 1:k) rowsum.obs[]<- sum(obs[, ])/500 return(round(rowsum.obs, dgts=0)) Program for calculaton of rsks for gven observatons and pror The rsk.est() functon needs an argument. Value of N s the sample sze and alpha be the vector of pror parameters. rsk.est<- functon(n, alpha) numer<- 0.0 denom<- 0.0 2
rsk1<- 0.0 rsk2<- 0.0 rsk<- 0.0 numer<- sum(alpha)*sum(alpha)-sum(alpha*alpha) denom1<- sum(n)*sum(alpha)*(sum(alpha)+1) denom2<- (sum(n)+sum(alpha))*sum(alpha)*(sum(alpha)+1) rsk1<- numer/denom1 cat( Bayes rsk of unbased estmate ) prnt(rsk1) rsk2<- numer/denom2 cat( Bayes rsk of Bayes estmate ) prnt(rsk2) k<- length(alpha) f(length(n)!=k) stop( Gven vectors are not of same dmenson ) fsher.nf<- matrx(0,ncol=k,nrow=k) nv.fnf<- matrx(0,ncol=k,nrow=k) B0<- dag(k) B<- matrx(0,ncol=k,nrow=k) D<- matrx(0,ncol=k,nrow=k) S<- rep(0,k) d<- rep(0,k) v<- rep(0,k) h<- rep(0,k) hd<- matrx(0, 500, k) w<- rep(1,k) z<- numerc(0) g<- 0 m<- 0 u<- rep(0,k) eps<- 0.00001 for(j n 1:k) D[j,j]<- trgamma(alpha[j])-trgamma(n[j]+alpha[j]) u[j]<- dgamma(alpha[j])-dgamma(n[j]+alpha[j]) hd[1,j]<- dgamma(n[j]+alpha[j])-dgamma(sum(n)+sum(alpha)) 3
z<- trgamma(sum(alpha))-trgamma(sum(n)+sum(alpha)) g<- dgamma(sum(alpha))-dgamma(sum(n)+sum(alpha)) fsher.nf<- D-z*(w%*%t(w)) nv.fnf<- solve(fsher.nf+b0) d<- nv.fnf%*%s alpha<- alpha + d f(any(abs(d) eps,na.rm=f)) break for(r n 2:500) f(any(alpha =0.0)) alpha=alpha-mn(alpha)+1 for(j n 1:k) D[j,j]<- trgamma(alpha[j])-trgamma(n[j]+alpha[j]) u[j]<- dgamma(alpha[j])-dgamma(n[j]+alpha[j]) hd[r,j]<- dgamma(n[j]+alpha[j])-dgamma(sum(n)+sum(alpha)) z<- trgamma(sum(alpha))-trgamma(sum(n)+sum(alpha)) g<- dgamma(sum(alpha))-dgamma(sum(n)+sum(alpha)) fsher.nf<- D-z*(w%*%t(w)) h<- hd[r, ]-hd[r-1, ] v<- h+b0%*%d m<- t(v)%*%d q<- matrx(m, ncol=k, nrow=k) P<- v%*%t(v) B<- B0+(P/q) nv.fnf<- solve(fsher.nf+b) d<- nv.fnf%*%s alpha -alpha+d f(any(abs(d) eps, na.rm=f)) break cat( Estmate of drchlet parameter ) prnt(alpha) numer<- sum(alpha)*sum(alpha)-sum(alpha*alpha) denom<-(sum(n)+sum(alpha))*sum(alpha)*(sum(alpha)+1) rsk<- numer/denom cat( Bayes rsk of emprcal Bayes estmate ) prnt(rsk) 4
Appendx III. Program for Emprcal Bayes estmator of transton probablty matrx when all states have dfferent pror (Drchlet) parameters usng EM algorthm. The embayes.est() functon needs an argument. Value of N s the sample transton matrx and alpha s the ntal value of the Drchlet parameters. embayes.est<- functon(n, alpha) f(ncol(n)!=nrow(n)) stop( Gven matrx s not a square one ) f(ncol(alpha)!=nrow(alpha)) stop( Gven parameter matrx s not asquare one ) f(ncol(n)!=ncol(alpha)) stop( Gven matrces are not of same dmenton ) k<-ncol(n) bayes.est<- matrx(0,ncol=k,nrow=k) embayes.est<- matrx(0,ncol=k,nrow=k) fsher.nf<- matrx(0,ncol=k,nrow=k) nv.fnf<- matrx(0,ncol=k,nrow=k) B0<- dag(k) B<- matrx(0,ncol=k,nrow=k) D<- matrx(0,ncol=k,nrow=k) P<- matrx(0,ncol=k,nrow=k) S<- rep(0,k) d<- rep(0,k) v<- rep(0,k) h<- rep(0,k) hd<- matrx(0,100,k) w<- rep(1,k) z<- 0 g<- 0 m<- 0 u<- rep(0,k) eps<- 0.00001 5
#Loop for Bayes estmate# for( n 1:k) for(j n 1:k) bayes.est[,j]=(n[,j]+alpha[,j])/(sum(n[,])+sum(alpha[,])) cat( Bayes estmate of transton pobablty matrx ) prnt(bayes.est) #To calculate Fsher nformaton matrx# for( n 1:k) for(j n 1:k) D[j,j]<- trgamma(alpha[,j])-trgamma(n[,j]+alpha[,j]) u[j]<- dgamma(alpha[,j])-dgamma(n[,j]+alpha[,j]) hd[1,j]<- dgamma(n[,j]+alpha[,j])-dgamma(sum(n[,])+sum(alpha[,])) z<- trgamma(sum(alpha[,]))-trgamma(sum(n[,])+sum(alpha[,])) g<- dgamma(sum(alpha[,]))-dgamma(sum(n[,])+sum(alpha[,])) fsher.nf<- D-z*(w%*%t(w)) nv.fnf<- solve(fsher.nf+b0) d<- nv.fnf%*%s alpha[,] -alpha[,]+d f(any(abs(d)<eps,na.rm=f)) break for(r n 2:100) f(any(alpha[, ]<=0.0)) alpha[, ]<- alpha[, ]-mn(alpha[,])+1 for(j n 1:k) D[j,j]<- trgamma(alpha[,j])-trgamma(n[,j]+alpha[,j]) u[j]<- dgamma(alpha[,j])-dgamma(n[,j]+alpha[,j]) hd[r,j]<- dgamma(n[,j]+alpha[,j])-dgamma(sum(n[,])+sum(alpha[,])) z<- trgamma(sum(alpha[,]))-trgamma(sum(n[,])+sum(alpha[,])) g<- dgamma(sum(alpha[,]))-dgamma(sum(n[,])+sum(alpha[,])) fsher.nf<- D-z*(w%*%t(w)) h<- hd[r, ]-hd[r-1, ] v<- h+b0%*%d 6
m<- t(v)%*%d q<- matrx(m, ncol=k, nrow=k) P<- v%*%t(v) B<- B0+P/q nv.fnf<- solve(fsher.nf+b) d<- nv.fnf%*%s alpha[,]<- alpha[,]+d f(any(abs(d)<eps, na.rm=f)) break cat( Estmate of Drchlet parameter. ) prnt(alpha) for( n 1:k) for(j n 1:k) embayes.est[, j]<- (N[, j]+alpha[, j])/(sum(n[, ])+sum(alpha[, ])) cat( Emprcal Bayes estmate of tranton probablty matrx. ) prnt(embayes.est) 7