Stat672-HW1

advertisement
Kelly Chase
811-54-6093
Stat 672
Dr. Bailey
1/29/2009
Homework #1
1.)
> #2.4
> #Suppose that ten Bernoulli trials satisfying Assumptions A1-A3 result in eight successes.
> #Investigate the accuracy of the large-sample approximation by comparing the smallest
significance level at which we would reject Ho : p = .5
> #Alternative Hypo: p > .5
> #Compare (2.3) to (2.10)
> #(2.3) -> Table A.2 to find 𝑏𝛼
> #Table A.2 -> 𝑏𝛼 = .0547
> binom.test(8,10,alternative="g")
Exact binomial test
data: 8 and 10
number of successes = 8, number of trials = 10, p-value = 0.05469
alternative hypothesis: true probability of success is greater than 0.5
95 percent confidence interval:
0.4930987 1.0000000
sample estimates:
probability of success
0.8
> #binom.test gives us 𝛼 = .05469
> #(2.10)
> n <- 10
> B <- 8
> p <- .5
> Bstar <- (B-n*p)/((n*p*(1-p))^.5)
> Bstar
[1] 1.897367
> pnorm(Bstar)
[1] 0.9711102
> 1-pnorm(Bstar)
[1] 0.02888979
> #From Table A.1 -> alpha is .0287
Using the large-sample approximation given by Eq 2.10, we conclude that the smallest
significance level to reject the null is approximately .02889. However, using Eq 2.3, we conclude
that the significance level is .05469. This is a problem considering our two values here lie on
both sides of .05 which is a commonly chosen p-value. If we had mistakenly used Eq 2.10 for
such a small number of observations, we would incorrectly reject the null hypothesis at the .05
level.
2.)
> #2.5
> #Return to alpha = .0121 test or Ex 2.1.
> #Recall that test or Ho: p = .15 v H1 : p > .15
> #Rejects if in n=7 trials there are 4 or more successes.
> #Accepts if in n trials there are 3 of fewer successes.
> #What is power of that test when
> #a.) p = .4
> sum(dbinom(4:7, 7, .4))
[1] 0.289792
> pbinom(3,7,.4,lower.tail=F)
[1] 0.289792
The power at p=.4 is .289792.
> #b.) p = .6
> sum(dbinom(4:7, 7, .6))
[1] 0.710208
> pbinom(3,7,.6,lower.tail=F)
[1] 0.710208
The power at p=.6 is .710208.
> #c.) p = .8
> sum(dbinom(4:7, 7, .8))
[1] 0.966656
> pbinom(3,7,.8,lower.tail=F)
[1] 0.966656
The power at p=.8 is .966656.
> ## Plot Power Curve
> plot(x=0:1, y=0:1, type="n", xlab="p", ylab="K(p)", usr=c(0,1,0,1))
> #There may have been a cleaner way to make a 0,1 x 0,1 graph, but this works.
> points(.4, pbinom(3,7,.4,lower.tail=F), pch=22)
> points(.6, pbinom(3,7,.6,lower.tail=F), pch=22)
> points(.8, pbinom(3,7,.8,lower.tail=F), pch=22)
0.0
0.2
0.4
K(p)
0.6
0.8
1.0
> pvals <- seq(.15,1,.01)
> lines(pvals, pbinom(3,7,pvals,lower.tail=F), type="l", col="red")
0.0
0.2
0.4
0.6
0.8
p
I did this with type=”p” too, but this makes it easiest to see the 3 points.
3.)
> #2.16
> #Failed test on 4 out of 20 trials.
> #Let p denote the the failure (ignition) rate.
> #Find CI for p with approx conf coeff .96
> binom.test(4,20,alternative="t",conf.level=.96)
1.0
Exact binomial test
data: 4 and 20
number of successes = 4, number of trials = 20, p-value = 0.01182
alternative hypothesis: true probability of success is not equal to 0.5
96 percent confidence interval:
0.05356505 0.44726457
sample estimates:
probability of success
0.2
> #(2.25)
> B <- 4
> n <- 20
> phat <- B/n
> CIlow96 <- phat - (qnorm(.02,lower.tail=F)*((phat*(1-phat)/n)^.5))
> #(2.26)
> CIupp96 <- phat + (qnorm(.02,lower.tail=F)*((phat*(1-phat)/n)^.5))
> CIlow96
[1] 0.01630711
> CIupp96
[1] 0.3836929
Using binom.test, we find the exact 96% CI is (.05357, .44726). Using Eqs 2.25 and 2.26, we
would conclude that the CI is (.01631, .38369). The approximate confidence interval found using
2.25 and 2.26 is slightly lower than the exact confidence interval.
> binom.test(4,20,alternative="t",conf.level=.95)
Exact binomial test
data: 4 and 20
number of successes = 4, number of trials = 20, p-value = 0.01182
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.057334 0.436614
sample estimates:
probability of success
0.2
> #(2.25)
> B <- 4
> n <- 20
> phat <- B/n
> CIlow95 <- phat - (qnorm(.025,lower.tail=F)*((phat*(1-phat)/n)^.5))
> #(2.26)
> CIupp95 <- phat + (qnorm(.025,lower.tail=F)*((phat*(1-phat)/n)^.5))
> CIlow95
[1] 0.02469549
> CIupp95
[1] 0.3753045
Just for my sake, since 96% CI just seemed weird. 
Download