Binomial Test using Stata

一笑 发表于 2008-02-24 06:43:46

A Binomial trial is n iid Bernoulli trials denoted B~Bin(n,theta)
we can use stata to find P(X>=k) by Binomial(n,k,theta)
the other command usually used is binomial(n,k,theta) which is to find P(X<=k)
Be careful that  1-Binomial(n, k, theta) not equal to binomial(n,k,theta).
Use F distribution to find P(X>=k)
Ftail(2(n-k+1),2k,x) where x=[k/(n-k+1)]*[(1-theta)/theta]

. di Ftail(2*(10-8+1),16,(8/(10-8+1)*(1-0.45)/0.45))
.02739184
. di Binomial(10,8,0.45)
.02739184
. di 1-binomial(10,8,0.45)
.00450225

To find an exact confident interval
stata 9: use invbinomial(n,k, theta)
. di invbinomial(20,5,0.025)
. di invbinomial(20,5,0.975)

Stata 10 use invbinomial, and invbinomialtail (with continuous correction)
. di invbinomialtail(20,5,0.025)
.08657147

. di invbinomial(20,5,0.025)
.49104587
95% CI: 0.08657147<theta<0.49104587

Large sample arroximation:
with continuous correction need to solve two quadratic equations: e.g (95%CI)
lower: (k-1/2-n*thetaL)/sqrt[n*thetaL(1-thetaL)]=1.96 pick the smaller solution
upper: (k+1/2-n*thetaU)/sqrt[n*thetaU(1-thetaU)]=-1.96 pick the bigger solution
without continuous correction, ignore the 1/2 in the formulas

Linear approximation in Large sample,
p(+1)1.96[sqrt(pq/n)+1/(2n)] with continuous correction
p(+-)1.96[sqrt(pq/n)] without continuous correction

The Angular Transformation:
g(p)=2*arcsin(sqrt(p))
g(p)~N(g(theta),1/n)
we get CI for g(p) then transform back to get CI for theta.
another benefit for this transform is that the variance never depends on theta, good for sample size calculation.

Sign Test is actually a binomial test
(X1, Y1)... (Xn, Yn) be iid pairs with some joint distribution
let Di=Yi-Xi discarding zero differences and redefine n as the left non-zero terms.
define Wi=1 if Di>0 Wi=0 otherwise
Then it follows the binomial test for H0: theta=1/2
The problem for this test is that if there are too many zeros, we lost a lot of information.

Paired dichotomous observations:
X/Y 0 1  
0 a b theta0.
1 c d theta1.
  theta.0 theta.1 1.0
Conditioning on (X<>Y) leads to a binomial distribution
B=b: B~(b+c, theta), theta=b/(b+c)
when theta = 1/2 , we can test the hypothesis E(X)=E(Y)
then use the method describe in binomial to calculate B*,

McNeamar's Test
M=(b-c)^2/(b+c)   or Mc=(|b-c|-1)^2/(b+c)
The critical region is M>=chisquare(.95)[1]  or Mc>=chisquare(.95)[1]
Note that M=B*^2 and Mc=Bc*^2 so the two test are equivalent.

95% CI:
(b-c)/n+-1.96*(1/n*sqrt(b+c-(b-c)^2/n))

曾经的这一天...


收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定