Sample size for a given precision of CI [Power / Sample Size]
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:
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
Comments are highly appreciated.
Best regards,
Ben
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:
- Trials to a given precision; Sample size Ben 2011-11-14 19:16
- Sample size for a given precision of CI d_labes 2011-11-16 09:40
- Sample size for a given precision of CI Ben 2011-11-18 16:57
- Sample size for a given precision of CIBen 2011-11-21 19:13
- Some minor comments d_labes 2011-11-22 15:37
- Some minor comments Ben 2011-11-23 21:12
- Some minor comments Ben 2011-11-25 17:28
- Using undocumented functions - PowerTOST v0.9-0 d_labes 2011-12-15 09:28
- Using undocumented functions - PowerTOST v0.9-0 Ben 2011-12-16 19:06
- Using undocumented functions - PowerTOST v0.9-0 d_labes 2011-12-15 09:28
- Some minor comments Ben 2011-11-25 17:28
- Some minor comments Ben 2011-11-23 21:12
- Some minor comments d_labes 2011-11-22 15:37
- Sample size for a given precision of CIBen 2011-11-21 19:13
- Sample size for a given precision of CI Ben 2011-11-18 16:57
- Sample size for a given precision of CI d_labes 2011-11-16 09:40
