Description Usage Arguments See Also Examples
Determine the probability of type I error of a test with given sample size
1 2 | sampleAlpha(n, a1, b1, a2, b2, a = a1, b = b1, pi0 = 0.5, pi1 = 1 -
pi0, c = 1, family = c("binomial", "poisson"))
|
n |
the sample size (this is the t parameter in the poisson case) |
a1 |
alpha, the hyperparameter of the prior distribution |
b1 |
beta, the hyperparameter of the prior distribution |
a2 |
alpha, the hyperparameter of the prior distribution |
b2 |
beta, the hyperparameter of the prior distribution |
a |
alpha, the hyperparameter of the prior distribution under the null |
b |
beta, the hyperparameter of the prior distribution under the null |
pi0 |
the prior probability of the null hypothesis |
pi1 |
the prior probability of the alternative hypothesis |
c |
relative loss constant (loss due to type II error divided by loss due to type I error) |
family |
"binomial" or "poisson", depending on test |
sampleAlphaBinomial
, sampleAlphaPoisson
, findSize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | ## Not run:
# generate samples of size 30
N <- 10000#00
n <- 30
a1 <- 3; b1 <- 7
a2 <- 7; b2 <- 3
plotBeta(c(a1, a2), c(b1, b2))
pi <- .3
pi <- rbeta(N, a1, b1)
data <- data.frame(
x1 = rbinom(N, n, pi),
x2 = rbinom(N, n, pi)
)
test <- function(x) bayesBinomTest(x, n, a1, b1, a2, b2)$reject
mean( apply(data, 1, test) ) # .061832 at 1E6
sampleAlpha_ryan("binomial", n, 1, a1, b1) # .0204
sampleAlpha(n, a1, b1, a2, b2)
bayesRates:::sampleAlphaPoissonCpp(n, a1, b1, a2, b2, a1, b1, .5, .5, 1)
# note that the significance depends on all parameters
a1 <- 3; b1 <- 7
a2 <- 90; b2 <- 10
plotBeta(c(a1, a2), c(b1, b2))
f <- function(x) bayesBinomTest(x, n, a1, b1, a2, b2)$reject
f(c(11, 8))
mean( apply(data, 1, f) )
sampleAlpha(n, a1, b1, a2, b2)
if(FALSE){
sim_alpha <- function(pi, N = 5E4, n = 30){
data <- data.frame(
x1 = rbinom(N, n, pi),
x2 = rbinom(N, n, pi)
)
a1 <- 3; b1 <- 7
a2 <- 7; b2 <- 3
f <- function(x) bayes_binom_test(x, n, a1, b1, a2, b2)$reject
mean( apply(data, 1, f) )
}
sim_alpha(.3)
s <- seq(.01, .99, length.out = 250)
t1 <- sapply(as.list(s), function(x){
message(".", appendLF = F)
sim_alpha(x)
})
qplot(s, t1, geom = "line") +
labs(x = expression(paste(pi, " = ", pi[1], " = ", pi[2])), y = expression(alpha)) +
coord_equal()
sim_alpha_classic <- function(pi, N = 5E3, n = 30){
data <- data.frame(
x1 = rbinom(N, n, pi),
x2 = rbinom(N, n, pi)
)
f <- function(x) prop.test(x, c(n, n))$p.value < .05
mean( apply(data, 1, f) )
}
sim_alpha_classic(.3)
s <- seq(.01, .99, length.out = 25)
t1 <- sapply(as.list(s), function(x){
message(".", appendLF = F)
sim_alpha_classic(x)
})
qplot(s, t1, geom = "line") +
labs(x = expression(paste(pi, " = ", pi[1], " = ", pi[2])), y = expression(alpha))
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.