CS计算机代考程序代写 ############################################################################
############################################################################
# Create initial cpf with AC[l,u] endpoints by choosing coverage
# probability from highest acceptance curve with minimal span.
cpf.matrix <- matrix(NA,ncol=3,nrow=iter+1)
colnames(cpf.matrix)<-c("p","low","upp")
for (i in 1:(iter/2+1)){
p <- (i-1)/iter
bin <- dbinom(0:n,n,p)
x <- 0:n
pmf <- cbind(x,bin)
# Binomial probabilities ordered in descending sequence
pmf <- pmf[order(-pmf[,2],pmf[,1]),]
pmf <- data.frame(pmf)
# Select the endpoints (l,u) such that AC[l,u] will
# be at least equal to LEVEL. The cumulative sum of
# the ordered pmf will identify when this occurs.
m.row <- min(which((cumsum(pmf[,2])>=level)==TRUE))
low.val <-min(pmf[1:m.row,][,1])
upp.val <-max(pmf[1:m.row,][,1])
cpf.matrix[i,] <- c(p,low.val,upp.val)
}