Power at limits 2 [🇷 for BE/BA]

posted by d_labes  – Berlin, Germany, 2009-10-07 17:15 (5733 d 00:33 ago) – Posting: # 4316
Views: 33,776

Dear All!

Must post to myself because Helmut has posted an important finding in the edit line of the post of mine.


❝ [...] BTW, change the sample size vector to n<-c(4,6,8,10,12,14,16,38,40,152,154,344,346) and watch (the gamma-function needs the faculty, which runs out of steam - at least on 32-bit operating systems). [Helmut]


Seems there is an implementation flaw in the code. And to add insult to injury it runs without error. But power is zero for n=346! :surprised:

After inspecting the code at the R-console
> power.density.equivalence.md
function (power_sigma, alpha = alpha, theta1 = theta1, theta2 = theta2,
    diff = diff, sigma = sigma, n = n, nu = nu)
{
    pdim <- length(power_sigma)
    power_density <- c(1:pdim)
    power_t <- qt(1 - alpha, nu, lower.tail = TRUE, log.p = FALSE)
    a <- sigma/sqrt(nu)
    power_const <- -(nu/2 - 1) * log(2) - log(gamma(nu/2)) - log(a)
    for (isigma in 1:pdim) {
        power_d1 <- ((power_sigma[isigma] * power_t * sqrt(2/n)) +
            (theta1 - diff))/(sigma * sqrt(2/n))
        power_d2 <- ((-power_sigma[isigma] * power_t * sqrt(2/n)) +
            (theta2 - diff))/(sigma * sqrt(2/n))
        power_phi1 <- pnorm(power_d1, mean = 0, sd = 1, lower.tail = TRUE,  log.p = FALSE)
        power_phi2 <- pnorm(power_d2, mean = 0, sd = 1, lower.tail = TRUE,  log.p = FALSE)
        power_phi <- power_phi2 - power_phi1
        power_density[isigma] <- power_phi * exp(power_const +
            (nu - 1) * log(power_sigma[isigma]/(a)) - 0.5 * (power_sigma[isigma]/(a))^2)
    }
    return(power_density)
}

you can see where it is.
So roll your own power.density.equivalence.md and change the line with red marker to
    power_const <- -(nu/2 - 1) * log(2) - lgamma(nu/2) - log(a)
Now we have:
     n        power
[...]
11 154 0.8033132631
12 344 0.9839843189
13 346 0.9844217782
14 500 0.9982834559


This is one example of why open source is so beautiful :love:.

Regards,

Detlew

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,671 registered users;
22 visitors (0 registered, 22 guests [including 13 identified bots]).
Forum time: 17:49 CEST (Europe/Vienna)

Truth and clarity are complementary.    Niels Bohr

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