#

# An R function [two.stage.ssize] for computing the two-state sample size given by

# equation (5) in Choudhary and Nagaraja (2005, Sequential Analysis, 24, 237-257).

#

# Input required:

# k [the # instruments under comparison]

# alpha [the level of the test of hypotheses (1) in Choudhary and Nagaraja (2005)]

# delta [the indifference zone threshold]

# gamma [the desired probability of correct decision]

# diag.psi [the vector of diagonal elements of the matrix ]

# corr [the correlation matrix associated with ]

#

# Uses:

#  “pmvnorm” function available in the package “mvtnorm”. This package can be

#  downloaded from http://cran.r-project.org/src/contrib/PACKAGES.html

# “uniroot” function available in the “base” package.

#  “mvncdf” function available below.

#

 

two.stage.ssize <- function (k, m, diag.psi, corr, alpha=0.05, gamma=0.20, delta=log(1.2), interval=c(15, 1000))

{

root <- uniroot(function(x) mvncdf(x, k=k, diag.psi=diag.psi, corr=corr, alpha=alpha, gamma=gamma, delta=delta), interval=interval)$root

ssize <- max(ceiling(root), m)

return(ssize)

}

 

#

# The “mvncdf” function

#

mvncdf <- function (l.m, k,  diag.psi, corr, alpha, gamma, delta)

{

  upper <- numeric(k)

  upper[1] <- (sqrt(l.m)*delta/sqrt(diag.psi[1]))-qnorm(1-alpha)

 

            for (i in 2:k)

            { upper[i] <- sqrt(l.m)*delta/sqrt(diag.psi[i]) }

 

  integral <- pmvnorm(upper=upper, corr=corr) - (1-gamma)

  return(integral)

}

 

 

 

#

# Example used for illustration in Choudhary and Nagaraja (2005)

#

 

diag.psi <- c(2.0, 1.17)

corr <- matrix(nrow=2, ncol=2)

corr[1,] <- c(1.0, 0.386)

corr[2,] <- c(0.386, 1.0)

 

two.stage.ssize (k=2, m=15, diag.psi=diag.psi, corr=corr, alpha=0.05, gamma=0.20, delta=log(1.2), interval=c(15, 1000))

 

 

#

# Produces the answer 373.

#