[Gsdesign-commits] r350 - in pkg/gsDesign: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon May 27 13:27:23 CEST 2013


Author: keaven
Date: 2013-05-27 13:27:22 +0200 (Mon, 27 May 2013)
New Revision: 350

Modified:
   pkg/gsDesign/DESCRIPTION
   pkg/gsDesign/NAMESPACE
   pkg/gsDesign/R/gsBinomial.R
   pkg/gsDesign/man/binomial.Rd
   pkg/gsDesign/man/gsDesign.Rd
Log:
ssrCP: new function for sample size re-estimation based on conditional power.

nBinomial: Fixed output when outtype=3, n=NULL, and either scale="RR" or scale="LNOR".  

varBinomial: new function for blinded variance estimation for trials comparing two arms with binary outcome; will be demonstrated with information based sample size re-estimation in future.

vignettes: Two vignettes added demonstrating time-to-event designs using knitr and gsSurv.

xtable.gsDesign: updated to comply with conventions for extensions of generic methods


Modified: pkg/gsDesign/DESCRIPTION
===================================================================
--- pkg/gsDesign/DESCRIPTION	2013-05-18 10:05:57 UTC (rev 349)
+++ pkg/gsDesign/DESCRIPTION	2013-05-27 11:27:22 UTC (rev 350)
@@ -1,10 +1,13 @@
 Package: gsDesign
-Version: 2.8-00
+Version: 2.8-01
 Title: Group Sequential Design
 Author: Keaven Anderson 
 Maintainer: Keaven Anderson <keaven_anderson at merck.com>
 Depends: ggplot2, xtable
+Suggests: knitr
+VignetteBuilder: knitr 
 Description: gsDesign is a package that derives group sequential designs and describes their properties.
 License: GPL (>= 2)
 Copyright: Copyright 2010, Merck Research Laboratories
 Packaged: 2011-12-30 13:26:23 UTC; Anderkea
+Date: 2012-11-12

Modified: pkg/gsDesign/NAMESPACE
===================================================================
--- pkg/gsDesign/NAMESPACE	2013-05-18 10:05:57 UTC (rev 349)
+++ pkg/gsDesign/NAMESPACE	2013-05-27 11:27:22 UTC (rev 350)
@@ -2,9 +2,9 @@
 export(gsBoundCP, gsCP, gsPP, gsPI, gsPOS, gsCPOS, gsDensity, gsPosterior)
 export(gsCPz, gsHR, gsDelta, gsBValue, gsRR, hrn2z, hrz2n, zn2hr)
 export(gsBound, gsBound1, gsDesign, gsProbability)
-export(ciBinomial, nBinomial, simBinomial, testBinomial, gsBinomialExact)
+export(ciBinomial, nBinomial, simBinomial, testBinomial, gsBinomialExact, varBinomial)
 export(nSurvival, nEvents, nNormal)
-export(normalGrid)
+export(normalGrid,ssrCP)
 export(plot.gsDesign, plot.gsProbability, print.gsProbability, print.gsDesign)
 export(print.nSurvival, xtable.gsDesign, gsBoundSummary, xtable.gsSurv)
 export(sfPower, sfHSD, sfExponential, sfBetaDist, sfLDOF, sfLDPocock, sfPoints, sfLogistic, sfExtremeValue, sfExtremeValue2, sfLinear, sfTruncated)

Modified: pkg/gsDesign/R/gsBinomial.R
===================================================================
--- pkg/gsDesign/R/gsBinomial.R	2013-05-18 10:05:57 UTC (rev 349)
+++ pkg/gsDesign/R/gsBinomial.R	2013-05-27 11:27:22 UTC (rev 350)
@@ -111,209 +111,198 @@
     cbind(lower=lower,upper=upper)
 }
 
-"nBinomial"<-function(p1, p2, alpha=0.025, beta=0.1, delta0=0, ratio=1, 
-        sided=1, outtype=1, scale="Difference", n=NULL)
-{   
-    # check input arguments
-    checkVector(p1, "numeric", c(0, 1), c(FALSE, FALSE))
-    checkVector(p2, "numeric", c(0, 1), c(FALSE, FALSE))    
-    checkScalar(sided, "integer", c(1, 2))    
-    checkScalar(alpha, "numeric", c(0, 1 / sided), c(FALSE, FALSE))
-    checkVector(beta, "numeric", c(0, 1 - alpha / sided), c(FALSE, FALSE))
-    checkVector(delta0, "numeric")
-    checkVector(ratio, "numeric", c(0, Inf), c(FALSE, FALSE))
-    checkScalar(outtype, "integer", c(1, 3))
-    checkScalar(scale, "character")
-    if (!is.null(n)) checkVector(n, "numeric")
-    scale <- match.arg(tolower(scale), c("difference", "rr", "or", "lnor"))
-    if (is.null(n)) checkLengths(p1, p2, beta, delta0, ratio, allowSingle=TRUE)
-    else checkLengths(n, p1, p2, delta0, ratio, allowSingle=TRUE)
-    # make all vector arguments the same length
-    len<-max(sapply(list(p1, p2, beta, delta0, ratio),length))
-    if (len > 1)
-    {   if (length(p1) == 1) p1<-array(p1,len)
-        if (length(p2) == 1) p2<-array(p2,len)
-        if (length(alpha) == 1) alpha<-array(alpha,len)
-        if (length(beta) == 1) beta<-array(beta,len)
-        if (length(delta0) == 1) delta0<-array(delta0,len)
-        if (length(ratio) == 1) ratio<-array(ratio,len)
+"nBinomial" <- function(p1, p2, alpha = 0.025, beta = 0.1, delta0 = 0, ratio = 1, 
+                       sided = 1, outtype = 1, scale = "Difference", n = NULL) 
+{
+  checkVector(p1, "numeric", c(0, 1), c(FALSE, FALSE))
+  checkVector(p2, "numeric", c(0, 1), c(FALSE, FALSE))
+  checkScalar(sided, "integer", c(1, 2))
+  checkScalar(alpha, "numeric", c(0, 1/sided), c(FALSE, FALSE))
+  checkVector(beta, "numeric", c(0, 1 - alpha/sided), c(FALSE, 
+                                                        FALSE))
+  checkVector(delta0, "numeric")
+  checkVector(ratio, "numeric", c(0, Inf), c(FALSE, FALSE))
+  checkScalar(outtype, "integer", c(1, 3))
+  checkScalar(scale, "character")
+  if (!is.null(n)) 
+    checkVector(n, "numeric")
+  scale <- match.arg(tolower(scale), c("difference", "rr", 
+                                       "or", "lnor"))
+  if (is.null(n)) 
+    checkLengths(p1, p2, beta, delta0, ratio, allowSingle = TRUE)
+  else checkLengths(n, p1, p2, delta0, ratio, allowSingle = TRUE)
+  len <- max(sapply(list(p1, p2, beta, delta0, ratio), length))
+  if (len > 1) {
+    if (length(p1) == 1) 
+      p1 <- array(p1, len)
+    if (length(p2) == 1) 
+      p2 <- array(p2, len)
+    if (length(alpha) == 1) 
+      alpha <- array(alpha, len)
+    if (length(beta) == 1) 
+      beta <- array(beta, len)
+    if (length(delta0) == 1) 
+      delta0 <- array(delta0, len)
+    if (length(ratio) == 1) 
+      ratio <- array(ratio, len)
+  }
+  if (max(delta0 == 0) > 0 && max(p1[delta0 == 0] == p2[delta0 == 
+                                                          0]) > 0) {
+    stop("p1 may not equal p2 when delta0 is zero")
+  }
+  z.beta <- qnorm(1 - beta)
+  sided[sided != 2] <- 1
+  z.alpha <- qnorm(1 - alpha/sided)
+  d0 <- (delta0 == 0)
+  if (scale == "difference") {
+    if (min(abs(p1 - p2 - delta0)) < 1e-11) {
+      stop("p1 - p2 may not equal delta0 when scale is \"Difference\"")
     }
-    if (max(delta0 == 0) > 0 && max(p1[delta0 == 0] == p2[delta0 == 0]) > 0)
-    {
-            stop("p1 may not equal p2 when delta0 is zero")
+    a <- 1 + ratio
+    b <- -(a + p1 + ratio * p2 + delta0 * (ratio + 2))
+    c <- delta0^2 + delta0 * (2 * p1 + a) + p1 + ratio * 
+      p2
+    d <- -p1 * delta0 * (1 + delta0)
+    v <- (b/(3 * a))^3 - b * c/6/a^2 + d/2/a
+    u <- (sign(v) + (v == 0)) * sqrt((b/3/a)^2 - c/3/a)
+    w <- (pi + acos(v/u^3))/3
+    p10 <- 2 * u * cos(w) - b/3/a
+    p20 <- p10 - delta0
+    p10[d0] <- (p1[d0] + ratio[d0] * p2[d0])/(1 + ratio[d0])
+    p20[d0] <- p10[d0]
+    sigma0 <- sqrt((p10 * (1 - p10) + p20 * (1 - p20)/ratio) * 
+                     (ratio + 1))
+    sigma1 <- sqrt((p1 * (1 - p1) + p2 * (1 - p2)/ratio) * 
+                     (ratio + 1))
+    if (is.null(n)) {
+      n <- ((z.alpha * sigma0 + z.beta * sigma1)/(p1 - p2 - delta0))^2
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1), n2 = ratio * 
+                                  n/(ratio + 1))))
+      }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = beta, Power = 1 - beta, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else return(n = n)
     }
-
-    # get z-values needed 
-    z.beta  <- qnorm(1 - beta)    
-    
-    # coerce all sided values not equal to 2 to 1
-    sided[sided != 2] <- 1
-    
-    z.alpha <- qnorm(1 - alpha / sided)
-    d0 <- (delta0 == 0)
-    
-    # sample size for risk difference - Farrington and Manning
-    if (scale == "difference")
-    {   
-        if (min(abs(p1 - p2 - delta0)) < .1e-10)
-        {
-            stop("p1 - p2 may not equal delta0 when scale is \"Difference\"")
-        }
-        a <- 1 + ratio
-        b <- -(a + p1 + ratio * p2 + delta0 * (ratio + 2))
-        c <- delta0 ^ 2 + delta0 * (2 * p1 + a) + p1 + ratio * p2
-        d <- -p1 * delta0 * (1 + delta0)
-        v <- (b / (3 * a)) ^ 3 - b * c / 6 / a ^ 2 + d / 2 / a
-        u <- (sign(v) + (v==0)) * sqrt((b / 3 / a) ^ 2 - c / 3 / a)
-        w <- (pi + acos(v /u ^ 3)) / 3
-        p10 <- 2 * u * cos(w) - b / 3 / a
-        p20 <- p10 - delta0
-        p10[d0] <- (p1[d0] + ratio[d0] * p2[d0]) / (1 + ratio[d0])
-        p20[d0] <- p10[d0]
-        sigma0 <- sqrt((p10 * (1 - p10) + p20 * (1 - p20) / ratio) 
-                        * (ratio + 1))
-        sigma1 <- sqrt((p1 * (1 - p1) + p2 * (1 - p2) / ratio) * (ratio + 1))
-        if (is.null(n)){
-          n <- ((z.alpha * sigma0 + z.beta * sigma1) / (p1 - p2 - delta0)) ^ 2
-          if (outtype == 2)
-          {
-            return(data.frame(cbind(n1=n / (ratio + 1),  n2=ratio * n / (ratio + 1))))
-          }
-          else if (outtype == 3) 
-          {   
-            return(data.frame(cbind(n=n, n1=n / (ratio + 1), n2=ratio * n / (ratio + 1),
-                        alpha = alpha, sided=sided, beta = beta, Power = 1-beta,
-                        sigma0=sigma0, sigma1=sigma1, p1=p1 ,p2=p2, 
-                        delta0=delta0, p10=p10, p20=p20)))
-          }
-          else return(n=n)
-        }
-        else
-        {  pwr <- pnorm(-(qnorm(1-alpha/sided)-sqrt(n) * ((p1 - p2 - delta0)/sigma0))*sigma0/sigma1)
-           if (outtype == 2)
-           {
-               return(data.frame(cbind(n1=n / (ratio + 1),  n2=ratio * n / (ratio + 1), Power=pwr)))
-           }
-           else if (outtype == 3) 
-           {   
-               return(data.frame(cbind(n=n, n1=n / (ratio + 1), n2=ratio * n / (ratio + 1),
-                           alpha = alpha, sided=sided, beta = 1-pwr, Power = pwr,
-                           sigma0=sigma0, sigma1=sigma1, p1=p1 ,p2=p2, 
-                           delta0=delta0, p10=p10, p20=p20)))
-           }
-           else return(Power=pwr)
-        }
+    else {
+      pwr <- pnorm(-(qnorm(1 - alpha/sided) - sqrt(n) * 
+                       ((p1 - p2 - delta0)/sigma0)) * sigma0/sigma1)
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1), n2 = ratio * 
+                                  n/(ratio + 1), Power = pwr)))
+      }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = 1 - pwr, Power = pwr, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else return(Power = pwr)
     }
-    # sample size for risk ratio - Farrington and Manning
-    else if (scale == "rr")
-    {   
-        RR <- exp(delta0)
-        if (min(abs(p1 / p2 - RR)) < .1e-6)
-        {
-            stop("p1/p2 may not equal exp(delta0) when scale=\"RR\"")
-        }
-        a <- (1 + ratio)
-        b <- -(RR * (1 + ratio * p2) + ratio + p1)
-        c <- RR * (p1 + ratio * p2)
-        p10 <- (-b - sqrt(b ^ 2 - 4 * a * c)) / 2 / a
-        p20 <- p10 / RR
-        p10[d0] <- (p1[d0] + ratio[d0] * p2[d0]) / (1 + ratio[d0])
-        p20[d0] <- p10[d0]
-        sigma0 <- sqrt((ratio + 1) * 
-                        (p10 * (1 - p10) + RR ^ 2 * p20 * (1 - p20) / ratio))
-        sigma1 <- sqrt((ratio + 1) * 
-                        (p1 * (1 - p1) + RR ^ 2 * p2 * (1 - p2) / ratio))
-        if (is.null(n)){
-          n <- ((z.alpha * sigma0 + z.beta * sigma1) / (p1 - p2 * RR)) ^ 2
-          if (outtype == 2)
-          {
-            return(data.frame(data.frame(cbind(n1=n / (ratio + 1), 
-                        n2=ratio * n / (ratio + 1)))))
-          }
-          else if (outtype == 3) 
-          {   
-            return(data.frame(cbind(n=n, n1=n / (ratio + 1), n2=ratio * n / (ratio + 1),
-                        alpha = alpha, sided=sided, beta = 1-pwr, Power = pwr,
-                        sigma0=sigma0, sigma1=sigma1, p1=p1, p2=p2, 
-                        delta0=delta0, p10=p10, p20=p20)))
-          }
-          else return(n=n)
-        }
-        else
-        {  pwr <- pnorm(-(qnorm(1-alpha/sided)-sqrt(n) * ((p1 - p2 * RR)/sigma0))*sigma0/sigma1)
-           if (outtype == 2)
-           {
-             return(data.frame(cbind(n1=n / (ratio + 1),  n2=ratio * n / (ratio + 1), Power=pwr)))
-           }
-           else if (outtype == 3) 
-           {   
-             return(data.frame(cbind(n=n, n1=n / (ratio + 1), n2=ratio * n / (ratio + 1),
-                         alpha = alpha, sided=sided, beta = 1-pwr, Power = pwr,
-                         sigma0=sigma0, sigma1=sigma1, p1=p1 ,p2=p2, 
-                         delta0=delta0, p10=p10, p20=p20)))
-           }
-           else return(Power=pwr)
-        }
+  }
+  else if (scale == "rr") {
+    RR <- exp(delta0)
+    if (min(abs(p1/p2 - RR)) < 1e-07) {
+      stop("p1/p2 may not equal exp(delta0) when scale=\"RR\"")
+    }
+    a <- (1 + ratio)
+    b <- -(RR * (1 + ratio * p2) + ratio + p1)
+    c <- RR * (p1 + ratio * p2)
+    p10 <- (-b - sqrt(b^2 - 4 * a * c))/2/a
+    p20 <- p10/RR
+    p10[d0] <- (p1[d0] + ratio[d0] * p2[d0])/(1 + ratio[d0])
+    p20[d0] <- p10[d0]
+    sigma0 <- sqrt((ratio + 1) * (p10 * (1 - p10) + RR^2 * 
+                                    p20 * (1 - p20)/ratio))
+    sigma1 <- sqrt((ratio + 1) * (p1 * (1 - p1) + RR^2 * 
+                                    p2 * (1 - p2)/ratio))
+    if (is.null(n)) {
+      n <- ((z.alpha * sigma0 + z.beta * sigma1)/(p1 - p2 * RR))^2
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1),
+                                n2 = ratio * n/(ratio + 1))))
       }
-    
-    # sample size for log-odds-ratio - based on Miettinen and Nurminen max
-    # likelihood estimate and asymptotic variance from, e.g., Lachin (2000)
-    else
-    {   
-        OR <- exp(-delta0)
-        if (min(abs(p1 / (1 - p1) / p2 * (1 - p2) * OR) - 1) < .1e-6)
-        {
-            stop("p1/(1-p1)/p2*(1-p2) may not equal exp(delta0) when scale=\"OR\"")
-        }
-        a <- OR - 1
-        b <- 1 + ratio * OR + (1 - OR) * (ratio * p2 + p1)
-        c <- -(ratio * p2 + p1)
-        p10 <- (-b + sqrt(b ^ 2 - 4 * a * c)) / 2 / a
-        p20 <- OR * p10 / (1 + p10 * (OR - 1))
-        p10[d0] <- (p1[d0] + ratio[d0] * p2[d0]) / (1 + ratio[d0])
-        p20[d0] <- p10[d0]
-        sigma0 <- sqrt((ratio + 1) * 
-                        (1 / p10 / (1 - p10) + 1 / p20 / (1 - p20) / ratio))
-        sigma1 <- sqrt((ratio + 1) * 
-                        (1 / p1 / (1 - p1) + 1 / p2 / (1 - p2) / ratio))
-        
-        if (is.null(n)){
-          n <- ((z.alpha * sigma0 + z.beta * sigma1) / 
-                    log(OR / p2 * (1 - p2) * p1 / (1 - p1))) ^ 2
-        
-          if (outtype == 2)
-          {
-             return(data.frame(cbind(n1=n / (ratio + 1), n2=ratio * n / (ratio + 1))))
-          }
-          else if (outtype == 3) 
-          {   
-            return(data.frame(cbind(n=n, n1=n / (ratio+1), n2=ratio * n / (ratio + 1),
-                        alpha = alpha, sided=sided, beta = 1-pwr, Power = pwr,
-                        sigma0=sigma0, sigma1=sigma1, p1=p1, p2=p2, 
-                        delta0=delta0, p10=p10, p20=p20)))
-          }
-          else
-          {
-              return(n=n)
-          }
-        }
-        else
-        {  pwr <- pnorm(-(qnorm(1-alpha/sided)-sqrt(n) * 
-              (log(OR / p2 * (1 - p2) * p1 / (1 - p1))/sigma0))*sigma0/sigma1)
-           if (outtype == 2)
-           {
-             return(data.frame(cbind(n1=n / (ratio + 1),  n2=ratio * n / (ratio + 1), Power=pwr)))
-           }
-           else if (outtype == 3) 
-           {   
-             return(data.frame(cbind(n=n, n1=n / (ratio + 1), n2=ratio * n / (ratio + 1),
-                         alpha = alpha, sided=sided, beta = 1-pwr, Power = pwr,
-                         sigma0=sigma0, sigma1=sigma1, p1=p1 ,p2=p2, 
-                         delta0=delta0, p10=p10, p20=p20)))
-           }
-           else return(Power=pwr)
-        }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = beta, Power = 1-beta, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else return(n = n)
     }
+    else {
+      pwr <- pnorm(-(qnorm(1 - alpha/sided) - sqrt(n) * 
+                       ((p1 - p2 * RR)/sigma0)) * sigma0/sigma1)
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1), n2 = ratio * 
+                                  n/(ratio + 1), Power = pwr)))
+      }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = 1 - pwr, Power = pwr, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else return(Power = pwr)
+    }
+  }
+  else {
+    OR <- exp(-delta0)
+    if (min(abs(p1/(1 - p1)/p2 * (1 - p2) * OR) - 1) < 1e-07) {
+      stop("p1/(1-p1)/p2*(1-p2) may not equal exp(delta0) when scale=\"OR\"")
+    }
+    a <- OR - 1
+    b <- 1 + ratio * OR + (1 - OR) * (ratio * p2 + p1)
+    c <- -(ratio * p2 + p1)
+    p10 <- (-b + sqrt(b^2 - 4 * a * c))/2/a
+    p20 <- OR * p10/(1 + p10 * (OR - 1))
+    p10[d0] <- (p1[d0] + ratio[d0] * p2[d0])/(1 + ratio[d0])
+    p20[d0] <- p10[d0]
+    sigma0 <- sqrt((ratio + 1) * (1/p10/(1 - p10) + 1/p20/(1 - p20)/ratio))
+    sigma1 <- sqrt((ratio + 1) * (1/p1/(1 - p1) + 1/p2/(1 - p2)/ratio))
+    if (is.null(n)) {
+      n <- ((z.alpha * sigma0 + z.beta * sigma1)/log(OR/p2 * (1 - p2) * p1/(1 - p1)))^2
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1), n2 = ratio * 
+                                  n/(ratio + 1))))
+      }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = beta, Power = 1-beta, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else {
+        return(n = n)
+      }
+    }
+    else {
+      pwr <- pnorm(-(qnorm(1 - alpha/sided) - sqrt(n) * 
+                       (log(OR/p2 * (1 - p2) * p1/(1 - p1))/sigma0)) * 
+                     sigma0/sigma1)
+      if (outtype == 2) {
+        return(data.frame(cbind(n1 = n/(ratio + 1), n2 = ratio * 
+                                  n/(ratio + 1), Power = pwr)))
+      }
+      else if (outtype == 3) {
+        return(data.frame(cbind(n = n, n1 = n/(ratio + 1), 
+                                n2 = ratio * n/(ratio + 1), alpha = alpha, 
+                                sided = sided, beta = 1 - pwr, Power = pwr, 
+                                sigma0 = sigma0, sigma1 = sigma1, p1 = p1, 
+                                p2 = p2, delta0 = delta0, p10 = p10, p20 = p20)))
+      }
+      else return(Power = pwr)
+    }
+  }
 }
 "simBinomial" <- function(p1, p2, n1, n2, delta0=0, nsim=10000, chisq=0, adj=0, 
         scale="Difference")

Modified: pkg/gsDesign/man/binomial.Rd
===================================================================
--- pkg/gsDesign/man/binomial.Rd	2013-05-18 10:05:57 UTC (rev 349)
+++ pkg/gsDesign/man/binomial.Rd	2013-05-27 11:27:22 UTC (rev 350)
@@ -3,6 +3,7 @@
 \alias{ciBinomial}
 \alias{nBinomial}
 \alias{simBinomial}
+\alias{varBinomial}
 \title{3.2: Testing, Confidence Intervals, Sample Size and Power for Comparing Two Binomial Rates}
 \description{Support is provided for sample size estimation, power, testing, confidence intervals and simulation for fixed sample size trials 
 (that is, not group sequential or adaptive) with two arms and binary outcomes. 
@@ -31,6 +32,9 @@
 As noted in documentation for \code{bpower.sim()} in the HMisc package, by using \code{testBinomial()} you can see that the formulas without any continuity correction are quite accurate. 
 In fact, Type I error for a continuity-corrected test is significantly lower (Gordon and Watson, 1996) than the nominal rate. 
 Thus, as a default no continuity corrections are performed.
+
+\code{varBinomial} computes blinded estimates of the variance of the estimate of 1) event rate differences, 2) logarithm of the risk ratio, or 3) logarithm of the odds ratio. This is intended for blinded sample size re-estimation for comparative trials with a binary outcome.
+
 }
 
 \usage{
@@ -41,6 +45,7 @@
 ciBinomial(x1, x2, n1, n2, alpha=.05, adj=0, scale="Difference")
 simBinomial(p1, p2, n1, n2, delta0=0, nsim=10000, chisq=0, adj=0,
             scale="Difference")
+varBinomial(x,n,delta0=0,ratio=1,scale="Difference")
 }
 \arguments{
 For \code{simBinomial()} and \code{ciBinomial()} all arguments must have length 1.
@@ -49,7 +54,9 @@
 
 For \code{nBinomial()}, \code{p1, p2, beta, delta0} and \code{ratio} may be vectors.
 
-For \code{nBinomial()} or \code{testBinomial()}, when one or more arguments is a vector, the routines return a vector of sample sizes and powers, respectively.
+For \code{varBinomial()}, \code{x} may be a vector.
+
+For \code{nBinomial()}, \code{testBinomial()} and \code{varBinomial()}, when one or more arguments is a vector, the routines return a vector of sample sizes or powers (\code{nBinomial}), test statistics (\code{testBinomial}), or variance estimates (\code{varBinomial}).
 Where vector arguments are allowed, there may be a mix of scalar and vector arguments. 
 All arguments specified using vectors must have the same length.  
 
@@ -70,7 +77,8 @@
 3 returns a data frame with total sample size (\code{n}), sample size in each group (\code{n1, n2}), Type I error (\code{alpha}), 1 or 2 (\code{sided}, as input), Type II error (\code{beta}), power (\code{Power}), 
 null and alternate hypothesis standard deviations (\code{sigma0, sigma1}), input event rates (\code{p1, p2}), null hypothesis difference in treatment group meands (\code{delta0}) and null hypothesis event rates (\code{p10, p20}). 
 }
-\item{n}{If power is to be computed in \code{nBinomial()}, input total trial sample size in \code{n}.}
+\item{n}{If power is to be computed in \code{nBinomial()}, input total trial sample size in \code{n}; this may be a vector. This is also the sample size in \code{varBinomial}, in which case the argument must be a scalar.}
+\item{x}{Number of \dQuote{successes} in the combined control and experimental groups.}
 \item{x1}{Number of \dQuote{successes} in the control group}
 \item{x2}{Number of \dQuote{successes} in the experimental group}
 \item{n1}{Number of observations in the control group}
@@ -111,7 +119,7 @@
 and a difference between these rates under the null hypothesis, \code{delta0}.
 From these values, actual rates under the null hypothesis are computed, which are labeled \code{p10} and \code{p20} when \code{outtype=3}.
 The rates \code{p1} and \code{p2} are used to compute a variance for a Z-test comparing rates under the alternative hypothesis,
-while \code{p10} and \code{p20} are used under the null hypothesis.
+while \code{p10} and \code{p20} are used under the null hypothesis. This computational method is also used to estimate variances in \code{varBinomial()} based on the overall event rate observed and the input treatment difference specified in \code{delta0}.
 
 Sample size with \code{scale="Difference"} produces an error if \code{p1-p2=delta0}. 
 Normally, the alternative hypothesis under consideration would be \code{p1-p2-delta0}$>0$.
@@ -124,6 +132,8 @@
   
   \code{ciBinomial()} returns a vector with a confidence interval.
   
+  \code{varBinomial()} returns a vector of (blinded) variance estimates of the difference of event rates (\code{scale="Difference"}), logarithm of the odds-ratio (\code{scale="OR"}) or logarithm of the risk-ratio (\code{scale="RR"}).
+  
   With the default \code{outtype=1}, \code{nBinomial()} returns a vector of total sample sizes is returned.
   With \code{outtype=2}, \code{nBinomial()} returns a data frame containing two vectors \code{n1} and \code{n2} containing
   sample sizes for groups 1 and 2, respectively; if \code{n} is input, this option also returns the power in a third vector, \code{Power}.
@@ -135,8 +145,8 @@
   \item{sided}{As input}
   \item{beta}{As input; if \code{n} is input, this is computed}
   \item{Power}{If \code{n=NULL} on input, this is \code{1-beta}; otherwise, the power is computed for each sample size input}
-\item{sigma0}{A vector containing the standard deviation of the treatment effect difference under the null hypothesis}
-  \item{sigma1}{A vector containing the standard deviation of the treatment effect difference under the alternative hypothesis}
+\item{sigma0}{A vector containing the standard deviation of the treatment effect difference under the null hypothesis times \code{sqrt(n)} when \code{scale="Difference"} or \code{scale="OR"}; when \code{scale="RR"}, this is the standard deviation time \code{sqrt(n)} for the numerator of the Farrington-Manning test statistic \code{x1-exp(delta0)*x2}.}
+  \item{sigma1}{A vector containing the values as \code{sigma0}, in this case estimated under the alternative hypothesis.}
   \item{p1}{As input}
   \item{p2}{As input}
   \item{p10}{group 1 event rate used for null hypothesis}
@@ -224,6 +234,17 @@
 legend(x=c(.15, .2),y=c(4500, 6000),lty=c(2, 1, 3, 4), lwd=2,
        legend=c("25 pct reduction", "33 pct reduction",
                 "40 pct reduction", "50 pct reduction"))
+
+# compute blinded estimate of treatment effect difference
+x1 <- rbinom(n=1,size=100,p=.2)
+x2 <- rbinom(n=1,size=200,p=.1)
+# blinded estimate of risk difference variance
+varBinomial(x=x1+x2,n=300,ratio=2,delta0=0)
+# blnded estimate of log-risk-ratio
+varBinomial(x=x1+x2,n=300,ratio=2,delta0=0,scale="RR")
+# blinded estimate of log-odds-ratio
+varBinomial(x=x1+x2,n=300,ratio=2,delta0=0,scale="OR")
+
 }
 
 \keyword{design}

Modified: pkg/gsDesign/man/gsDesign.Rd
===================================================================
--- pkg/gsDesign/man/gsDesign.Rd	2013-05-18 10:05:57 UTC (rev 349)
+++ pkg/gsDesign/man/gsDesign.Rd	2013-05-27 11:27:22 UTC (rev 350)
@@ -1,16 +1,18 @@
 \name{gsDesign}
 \alias{gsDesign}
 \alias{print.gsDesign}
+\alias{xtable.gsDesign}
 \title{2.1: Design Derivation}
 \description{\code{gsDesign()} is used to find boundaries and trial size required for a group sequential design.}
 \usage{
 gsDesign(k=3, test.type=4, alpha=0.025, beta=0.1, astar=0,  
          delta=0, n.fix=1, timing=1, sfu=sfHSD, sfupar=-4,
          sfl=sfHSD, sflpar=-2, tol=0.000001, r=18, n.I = 0,
-         maxn.IPlan = 0, nFixSurv=0, endpoint=NULL, delta1=1, delta0=0) 
-
-\method{print}{gsDesign}(x,...)}
-
+         maxn.IPlan = 0, nFixSurv=0, endpoint=NULL, delta1=1, delta0=0)
+\method{print}{gsDesign}(x,\dots)
+\method{xtable}{gsDesign}(x, caption = NULL, label=NULL, align=NULL, digits=NULL, display=NULL,
+                             footnote = NULL, fnwid = "9cm", deltaname="delta", 
+                             Nname="N",logdelta=FALSE, \dots)}
 \arguments{
 	\item{k}{Number of analyses planned, including interim and final.}
 	\item{test.type}{\code{1=}one-sided \cr
@@ -25,7 +27,7 @@
 	probability of crossing a lower bound at all analyses combined. 
 	This will be changed to \eqn{1 - }\code{alpha} when default value of 0 is used. 
 	Since this is the expected usage, normally \code{astar} is not specified by the user.}
-	\item{delta}{Standardized effect size for theta under alternative hypothesis. See details and examples.}
+	\item{delta}{Effect size for theta under alternative hypothesis. For \code{xtable.gsDesign} this would normally be set to the natural parameter value. For \code{gsDesign} this can be set to the standardized effect size to generate a sample size if \code{n.fix=NULL}. See details and examples.}
 	\item{n.fix}{Sample size for fixed design with no interim; used to find maximum group sequential sample size. For a time-to-event outcome, input number of events required for a fixed design rather than sample size
 and enter fixed design sample size (optional) in \code{nFixSurv}.
 	See details and examples.}
@@ -57,14 +59,24 @@
 	\item{n.I}{Used for re-setting bounds when timing of analyses changes from initial design; see examples.}
 	\item{maxn.IPlan}{Used for re-setting bounds when timing of analyses changes from initial design; see examples.}
 	\item{nFixSurv}{If a time-to-event variable is used, \code{nFixSurv} computed as the sample size from \code{nSurvival} may be entered to have \code{gsDesign}
-	compute the total sample size required as well as the number of events at each analysis that will be returned in \code{n.fix}; this is rounded up to an even number.}|
-	\item{x}{In \code{print.gsDesign} this is an object of class gsDesign.}
-	\item{...}{This should allow optional arguments that are standard when calling \code{print}.}
+	compute the total sample size required as well as the number of events at each analysis that will be returned in \code{n.fix}; this is rounded up to an even number.}
 
-	\item{endpoint}{An optional character string that should represent the type of endpoint used for the study. This may be used by output functions. Types most likely to be recognized initially are "TTE" for time-to-event outcomes with fixed design sample size generated by \code{nSurvival()} and "Binomial" for 2-sample binomial outcomes with fixed design sample size generated by \code{nBinomial()}.}
+  \item{endpoint}{An optional character string that should represent the type of endpoint used for the study. This may be used by output functions. Types most likely to be recognized initially are "TTE" for time-to-event outcomes with fixed design sample size generated by \code{nSurvival()} and "Binomial" for 2-sample binomial outcomes with fixed design sample size generated by \code{nBinomial()}.}
 
 	\item{delta1}{\code{delta1} and \code{delta0} may be used to store information about the natural parameter scale compared to \code{delta} that is a standardized effect size. \code{delta1} is the alternative hypothesis parameter value on the natural scale (e.g., the difference in two binomial rates).}
 	\item{delta0}{The parameter value under the null hypothesis on the natural parameter scale. Default is 0, which might normally be interpreted as no difference between two treatment groups. If non-zero, this would normally represent a non-inferiority margin.}
+	\item{x}{In \code{print.gsDesign} this is an object of class gsDesign.}
+  \item{caption}{Table caption.} 
+  \item{label}{Character vector of length 1 containing the LaTeX label or HTML anchor. Set to NULL to suppress the label. Default value is NULL.}
+  \item{align}{Character vector of length equal to the number of columns of the resulting table indicating the alignment of the corresponding columns. Also, "|" may be used to produce vertical lines between columns in LaTeX tables, but these are effectively ignored when considering the required length of the supplied vector. If a character vector of length one is supplied, it is split as strsplit(align, "")[[1]] before processing. Since the row names are printed in the first column, the length of align is one greater than ncol(x) if x is a data.frame. Use "l", "r", and "c" to denote left, right, and center alignment, respectively. Use "p\{3cm\}" etc for a LaTeX column of the specified width. For HTML output the "p" alignment is interpreted as "l", ignoring the width request. Default depends on the class of x.}
+  \item{digits}{Numeric vector of length equal to one (in which case it will be replicated as necessary) or to the number of columns of the resulting table or matrix of the same size as the resulting table indicating the number of digits to display in the corresponding columns. Since the row names are printed in the first column, the length of the vector digits or the number of columns of the matrix digits is one greater than ncol(x) if x is a data.frame. Default depends of class of x. If values of digits are negative, the corresponding values of x are displayed in scientific format with abs(digits) digits.} 
+  \item{display}{Character vector of length equal to the number of columns of the resulting table indicating the format for the corresponding columns. Since the row names are printed in the first column, the length of display is one greater than ncol(x) if x is a data.frame. These values are passed to the formatC function. Use "d" (for integers), "f", "e", "E", "g", "G", "fg" (for reals), or "s" (for strings). "f" gives numbers in the usual xxx.xxx format; "e" and "E" give n.ddde+nn or n.dddE+nn (scientific format); "g" and "G" put x[i] into scientific format only if it saves space to do so. "fg" uses fixed format as "f", but digits as number of significant digits. Note that this can lead to quite long result strings. Default depends on the class of x.}
+  \item{footnote}{Table footnote.}
+  \item{fnwid}{Width for table footnote.}
+  \item{deltaname}{Parameter name for output.}
+  \item{Nname}{Sample size name for output (e.g., N, Events, Deaths, Information).}
+  \item{logdelta}{TRUE if natural parameter is on log-scale, but you want output on linear scale.}
+  \item{\dots}{This should allow optional arguments that are standard when calling \code{print} or \code{xtable}.}
 }
 \value{
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/gsdesign -r 350


More information about the Gsdesign-commits mailing list