一~~~~笑 » 日志 » Binomial Test using Stata
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:
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))
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 |
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))
曾经的这一天...
- » 2006年: 球赛
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
