我把这个问题的一种解法给出来,供大家讨论。
<br />
#Notation: p1=prob(A beats B), p2=prob(B beats A), p3=prob(tie), M=the number of total competitions, na=the count that A wins, nt=the count of ties.<br />
<br />
#1. H0: p1=p2, p3=nt/M<br />
# H1: p1>p2, p3=nt/M<br />
<br />
#######<br />
#function: mngreater<br />
#input: M--the total competition, n--the count that A wins, nt--the count of ties.<br />
#return: p-the prob that the counts that A occurs in M times is larger or equal than/to n<br />
#######<br />
mngreater=function(M,na,nt){<br />
p3=nt/M<br />
p1=p2=(1-p3)/2<br />
prob=c(p1,p2,p3) <br />
X<-t(as.matrix(expand.grid(na:M, 0:M)));X <- X[, colSums(X) <= M]<br />
X <- rbind(X, M - colSums(X))<br />
return(sum(apply(X, 2, function(x) dmultinom(x, prob = prob))))<br />
}<br />
<br />
M=8<br />
na=3;nt=4<br />
(pvalue=mngreater(M,na,nt))<br />
<br />
M=8<br />
nt=4<br />
pvalue=c()<br />
for(i in seq(M-nt)){<br />
na=i<br />
pvalue[i]=mngreater(M,na,nt)<br />
}<br />
plot(seq(na),pvalue)<br />
<br />
###################################################<br />
#2. H0: p1=p2, p3=nt/M<br />
# H1: p1!=p2, p3=nt/M<br />
<br />
<br />
#######<br />
#function: mnnotequal<br />
#input: M--the total competition, na--the count that A wins, nt--the count of ties.<br />
#return: p-the prob that the absolute difference between the NA and M-NT-NA is larger or equal than/to abs(M-nt-2*na)<br />
#######<br />
mnnotequal=function(M,na,nt){<br />
p3=nt/M<br />
p1=p2=(1-p3)/2<br />
prob=c(p1,p2,p3)<br />
X<-t(as.matrix(expand.grid(0:M, 0:M)));X <- X[, colSums(X) <= M]<br />
X=X[,abs(X[1,]-X[2,])>=abs(M-nt-2*na)]<br />
X <- rbind(X, M - colSums(X))<br />
return(sum(apply(X, 2, function(x) dmultinom(x, prob = prob))))<br />
}<br />
<br />
<br />
M=18<br />
na=2;nt=1<br />
(pvalue=mnnotequal(M,na,nt))<br />
<br />
M=18<br />
nt=1<br />
pvalue=c()<br />
for(i in seq(M-nt)){<br />
na=i<br />
pvalue[i]=mnnotequal(M,na,nt)<br />
}<br />
plot(seq(na),pvalue)<br />
另外,解这个问题后才发现,H0成立的情况下,P-value不一定是均匀分布的。似乎statistic for calculating p-value包含离散随机变量的时候,P-value就不再是均匀分布了。