Sample size for a given precision of CI [Power / Sample Size]

posted by Ben – Germany, 2011-11-21 20:13 (5329 d 14:13 ago) – Posting: # 7694
Views: 10,323

Dear all,

I started from scratch. The only thing that's important is the requirement
P(S·(bk/n)-1/2·tdf, 1-α/2 ≤ ω) ≥ 1-γ,

where df is the appropriate degrees of freedom of the considered design, S the estimate of the standard deviation and bk the design constant. We want the smallest integer so that the above inequality holds. In the article they derive inequalities that are easier to handle than the probability. Since nowadays evaluating P is no problem (fast computers) we can directly go with the above relation. (The reason why I got different results was that (i) one derived inequality was conservative and (ii) the initial sample size was based on the z-quantile and not on the t-quantile.) Now the above inequality can be equivalently stated as
P(df·S2/σ² ≤ (ω/σ)2·df·(bk/n)1/F1, df, 1-α) ≥ 1-γ

Then (df·S²)/σ² is chi squared distributed with df degrees of freedom (is that always true for every considered design?) and we can set up the following code to get the desired sample size:
require(PowerTOST)
ss_ci <- function(w, sigma, design="2x2", alpha=0.1, gamma=0.05) {
# w is the desired precision
# 1-alpha is the confidence level
# 1-gamma is the coverage probability

# get degrees of freedom
# and design constant
# (copied from CVfromCI)
d.no <- .design.no(design)
if (is.na(d.no))
   stop("Unknown design!", call. = FALSE)
desi <- .design.props(d.no)
dfe <- parse(text = desi$df[1], srcfile = NULL)
bk <- desi$bk

n <- 1
while ( eval(dfe) < 1 ) {
  n <- n+1
}
x <- (w/sigma)^2*eval(dfe)*n/bk*1/qf(1-alpha, 1, eval(dfe))
prob <- pchisq(x, eval(dfe))
while ( prob < 1-gamma ) {
  n <- n+1
  x <- (w/sigma)^2*eval(dfe)*n/bk*1/qf(1-alpha, 1, eval(dfe))
  prob <- pchisq(x, eval(dfe))
}
return(n)
}

Again, I will look into the design constant and the correct usage of it more closely but at the moment I don't see a difference to CVfromCI(). For the parallel and the 2x2 crossover design the results are the same as those from nQuery (sometimes it differs, but only +-1, probably due to rounding/higher precision).

Comments are highly appreciated.

Best regards,
Ben

Complete thread:

UA Flag
Activity
 Admin contact
23,655 posts in 4,993 threads, 1,571 registered users;
141 visitors (0 registered, 141 guests [including 22 identified bots]).
Forum time: 11:26 CEST (Europe/Vienna)

The great tragedy of Science – the slaying
of a beautiful hypothesis by an ugly fact.    Thomas Henry Huxley

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5