-2

I am attempting to make a table that would hold the sample size determination from several methods for different initial probabilities. I would like it to look something like the following

Prob.    .80    .81    .82 ...
Wald     xxx    yyy    zzz
AC       qqq    rrr    sss
Jeff.    ddd    uuu    iii

With the letters being the actual output I would like to populate with based on the type of interval and the probability value. In order to get an individual value I could use the following pieces of code, but am struggling to put them together.

library(binom)
n_wald <- ciss.wald(p, d, alpha = a)
n_agricoull <- ciss.agresticoull(p, d, alpha = a)
n_jeffreys <- ciss.binom(p, d, alpha = a, prior.shape1 = 0.5,
 prior.shape2 = 0.5, method = "bayes")

I want help in converting the sample size calculations into a table for each increment of initial probability. Basically, I am trying to use the second piece of code to fill in the "xxx" for the table.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
a.powell
  • 1,572
  • 4
  • 28
  • 39

1 Answers1

1

The functions you reference are actually in the binomSamSize package. They are vectorized, which makes this a little easier, unless you're providing multiple values to more than one argument.

I used dplyr just to make it a little easier to push these into a data frame.

library(binomSamSize)
library(dplyr)
p0_vec <- seq(0.8, 0.9, by = 0.02)

rbind(
  ciss.wald(p0=p0_vec, 
            alpha=0.1, 
            d=0.05),
  ciss.agresticoull(p0=p0_vec, 
                    alpha=0.1, 
                    d=0.05),
  vapply(p0_vec,
         ciss.binom,
         numeric(1),
         alpha=0.1, 
         d=0.05,
         prior.shape1 = 0.5,
         prior.shape2 = 0.5, 
         method = "bayes")
) %>%
  as.data.frame() %>%
  bind_cols(
    data.frame(type = c("Wald", "AC", "Jeff"), 
               stringsAsFactors = FALSE),
    .
  ) %>%
setNames(c("type", p0_vec))
Benjamin
  • 16,897
  • 6
  • 45
  • 65