First I will show you how to do this with a loop.
n <- 20:200
MAX = -Inf ## initialize maximum
for (i in 1:length(n)) {
x <- qbinom(0.05, n[i], 0.47) - 1
if (x > MAX) MAX <- x
}
MAX
Note. I do not keep a record of all 181 generated values. Each value is considered a temporary value and will be overwritten at the next iteration. In the end, we have only one meaning MAX.
, .
n <- 20:200
MAX = -Inf
x <- numeric(length(n))
for (i in 1:length(n)) {
x[i] <- qbinom(0.05, n[i], 0.47) - 1
if (x[i] > MAX) MAX <- x[i]
}
head(x)
MAX
.
max(qbinom(0.05, 20:200, 0.47) - 1)
# [1] 81
R-, , . , , ?rbinom .
, . , :
qbinom(0.05, 1:4, 0.47)
R :
p: 0.05 0.05 0.05 0.05
mean: 1 2 3 4
sd: 0.47 0.47 0.47 0.47
qbinom(p[i], mean[i], sd[i])
C.
, 20: 200 , ?
x <- qbinom(0.05, 20:200, 0.47) - 1
i <- which.max(x)
# [1] 179
. i - 20:200. n, , :
(20:200)[i]
# 198
x[i]
# [1] 81
source
share