c("DescTools")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
factor(c("+", "+", "-", "+", "-", "+", "+"), levels=c("+", "-"))
DV <- length(DV)
N <- table(DV)) (tab <-
DV
+ -
5 2
0.25
pH0 <-binom.test(tab, p=pH0, alternative="greater", conf.level=0.95)
Exact binomial test
data: tab
number of successes = 5, number of trials = 7, p-value = 0.01288
alternative hypothesis: true probability of success is greater than 0.25
95 percent confidence interval:
0.3412614 1.0000000
sample estimates:
probability of success
0.7142857
20
N <- 10
hits <-binom.test(hits, N, p=pH0, alternative="two.sided")
Exact binomial test
data: hits and N
number of successes = 10, number of trials = 20, p-value = 0.01704
alternative hypothesis: true probability of success is not equal to 0.25
95 percent confidence interval:
0.2719578 0.7280422
sample estimates:
probability of success
0.5
sum(dbinom(hits:N, N, p=pH0)) + sum(dbinom(0, N, p=pH0))
[1] 0.01703563
library(DescTools)
BinomCI(tab[1], sum(tab), method="wilson")
est lwr.ci upr.ci
[1,] 0.7142857 0.3589345 0.9177811
c(4000, 5000, 3000)
total <- c( 585, 610, 539)
hits <-prop.test(hits, total)
3-sample test for equality of proportions without continuity
correction
data: hits out of total
X-squared = 50.5873, df = 2, p-value = 1.035e-11
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3
0.1462500 0.1220000 0.1796667
try(detach(package:DescTools))
R markdown - markdown - R code - all posts