This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

binom.test(3,12,0.45, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  3 and 12
## number of successes = 3, number of trials = 12, p-value = 0.9579
## alternative hypothesis: true probability of success is greater than 0.45
## 95 percent confidence interval:
##  0.07187026 1.00000000
## sample estimates:
## probability of success 
##                   0.25
binom.test(3,12,0.40, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  3 and 12
## number of successes = 3, number of trials = 12, p-value = 0.9166
## alternative hypothesis: true probability of success is greater than 0.4
## 95 percent confidence interval:
##  0.07187026 1.00000000
## sample estimates:
## probability of success 
##                   0.25
# binom.test(5,12,0.45, alternative=c("greater"))
binom.test(3,20,0.35, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  3 and 20
## number of successes = 3, number of trials = 20, p-value = 0.9879
## alternative hypothesis: true probability of success is greater than 0.35
## 95 percent confidence interval:
##  0.04216941 1.00000000
## sample estimates:
## probability of success 
##                   0.15
binom.test(4,20,0.35, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  4 and 20
## number of successes = 4, number of trials = 20, p-value = 0.9556
## alternative hypothesis: true probability of success is greater than 0.35
## 95 percent confidence interval:
##  0.07135388 1.00000000
## sample estimates:
## probability of success 
##                    0.2
binom.test(5,20,0.35, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  5 and 20
## number of successes = 5, number of trials = 20, p-value = 0.8818
## alternative hypothesis: true probability of success is greater than 0.35
## 95 percent confidence interval:
##  0.1040808 1.0000000
## sample estimates:
## probability of success 
##                   0.25
binom.test(3,20,0.40, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  3 and 20
## number of successes = 3, number of trials = 20, p-value = 0.9964
## alternative hypothesis: true probability of success is greater than 0.4
## 95 percent confidence interval:
##  0.04216941 1.00000000
## sample estimates:
## probability of success 
##                   0.15
binom.test(4,20,0.40, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  4 and 20
## number of successes = 4, number of trials = 20, p-value = 0.984
## alternative hypothesis: true probability of success is greater than 0.4
## 95 percent confidence interval:
##  0.07135388 1.00000000
## sample estimates:
## probability of success 
##                    0.2
binom.test(5,20,0.40, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  5 and 20
## number of successes = 5, number of trials = 20, p-value = 0.949
## alternative hypothesis: true probability of success is greater than 0.4
## 95 percent confidence interval:
##  0.1040808 1.0000000
## sample estimates:
## probability of success 
##                   0.25
binom.test(3,20,0.45, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  3 and 20
## number of successes = 3, number of trials = 20, p-value = 0.9991
## alternative hypothesis: true probability of success is greater than 0.45
## 95 percent confidence interval:
##  0.04216941 1.00000000
## sample estimates:
## probability of success 
##                   0.15
binom.test(4,20,0.45, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  4 and 20
## number of successes = 4, number of trials = 20, p-value = 0.9951
## alternative hypothesis: true probability of success is greater than 0.45
## 95 percent confidence interval:
##  0.07135388 1.00000000
## sample estimates:
## probability of success 
##                    0.2
binom.test(5,20,0.45, alternative=c("greater"))
## 
##  Exact binomial test
## 
## data:  5 and 20
## number of successes = 5, number of trials = 20, p-value = 0.9811
## alternative hypothesis: true probability of success is greater than 0.45
## 95 percent confidence interval:
##  0.1040808 1.0000000
## sample estimates:
## probability of success 
##                   0.25
library(pwr)
pwr.p.test(h=0.35, n=12, sig.level=0.025, alternative="greater")
## 
##      proportion power calculation for binomial distribution (arcsine transformation) 
## 
##               h = 0.35
##               n = 12
##       sig.level = 0.025
##           power = 0.2273723
##     alternative = greater
pwr.2p.test(h=0.35, n=12, sig.level=0.025, alternative="greater")
## 
##      Difference of proportion power calculation for binomial distribution (arcsine transformation) 
## 
##               h = 0.35
##               n = 12
##       sig.level = 0.025
##           power = 0.1350912
##     alternative = greater
## 
## NOTE: same sample sizes
p=0.4
p0=0.025
alpha=0.025
beta=0.20
n=12
z=(p-p0)/sqrt(p0*(1-p0)/n)
(Power=pnorm(sqrt(p0*(1-p0)/p/(1-p))*(abs(z)-qnorm(1-alpha))))
## [1] 0.9786704
library(pwr)
pwr.p.test(h = ES.h(p1 = 0.4, p2 = 0.05),
           sig.level = 0.025,n=c(10,12),
           alternative = "greater")
## 
##      proportion power calculation for binomial distribution (arcsine transformation) 
## 
##               h = 0.9184116
##               n = 10, 12
##       sig.level = 0.025
##           power = 0.827494, 0.889053
##     alternative = greater
library(EnvStats)
## 
## Attaching package: 'EnvStats'
## The following objects are masked from 'package:stats':
## 
##     predict, predict.lm
## The following object is masked from 'package:base':
## 
##     print.default
  propTestPower(n.or.n1 = c(10,12), p.or.p1 = 0.4, p0 = 0.05, approx=FALSE,sample.type = "one.sample", alternative = "greater",alpha=0.025) 
## $power
## [1] 0.8327102 0.9165567
## 
## $alpha
## [1] 0.01150356 0.01956826
## 
## $q.critical.upper
## [1] 2 2