R-code shortening [Power / Sample Size]

posted by d_labes  – Berlin, Germany, 2014-08-13 18:32 (3926 d 09:59 ago) – Posting: # 13375
Views: 19,820

Dear Helmut,

here comes my programming gem :cool: for the sensitivity with respect to sample size: Replace all the code for the different designs by

  ####################################
  # min. n for minimum accept. power #
  # workaround, since uniroot() does #
  # not accept two vectors as limits #
  ####################################

  Ns <- seq(n.est, 12, by=-1) # don't drop below 12 subjects
  j <- 0
  pwrN <- pwr.est
  n.min <- NULL; pBEn <- NULL
  # get # of sequences f.i. via this clumsy construct
  seqs <- known.designs()[known.designs()$design==des,"steps"]
  n    <- vector("numeric", length=seqs)
  ni   <- 1:seqs
  # may it be that j grows greater than length(Ns)?
  # paranoia

  nNs  <- length(Ns)
  while(pwrN >= pwr.min & j<nNs){
    j <- j+1
    # distribute total Ns to the sequence groups
    # n[-seqs] is n[1:(seqs-1)]

    n[-seqs] <- diff(floor(Ns[j]*ni/seqs))
    n[seqs]  <- Ns[j] -sum(n[-seqs])
    # can use allways power2.TOST() if PowerTOST V1.1-13 is used
    # else an if() construct is necessary switching to power.TOST()
    # in case of des=="paired"

    pwrN <- power2.TOST(CV=CV, n=n, theta0=GMR, design=des)
    if(pwrN >= pwr.min) {
      # stepwise growing vectors is R-Inferno Circle 2
      # but here we dont know the dimension in advance. Right?

      n.min <- c(n.min, sum(n))
      pBEn  <- c(pBEn, 100*pwrN)
    } else {
      break
    }
  }
  # plot code follows
  ...

Regards,

Detlew

Complete thread:

UA Flag
Activity
 Admin contact
23,424 posts in 4,927 threads, 1,670 registered users;
128 visitors (0 registered, 128 guests [including 9 identified bots]).
Forum time: 04:31 CEST (Europe/Vienna)

Only dead fish go with the current.    Scuba divers' proverb

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