I'm trying to implement the Aldor-Noiman's algorithm in order to visualize the Tail-Sensitive (TS) confidence bands using R. But I'm missing something at the time of calculate the tail probability A_{i} and find the minimum C^{m}.
The main idea of the algorithm is this
This is my code
ts_confidence_intervals <- function(M, n, alpha){
mu <- 0
sigma <- 1
CValues <- numeric(M)
LowerBound <- numeric(n)
UpperBound <- numeric(n)
for(i in 1:M){
samples <- rnorm(n, mu, sigma)
Zi <- (samples - mu)/sigma
Yi <- qnorm(pnorm(Zi))
Y <- sort(Yi)
for(i in 1:n){
A <- qbeta(Y[i], i, n + 1 - i)
}
C <- 2*min(min(A, 1 - A))
CValues[i] <- C
}
gamma <- quantile(CValues, 1 - alpha)
for(i in 1:n){
LowerBound[i] <- qnrom(qbeta(gamma/2, i, n + 1 - i))
UpperBound[i] <- qnrom(qbeta(1 - gamma/2, i, n + 1 - i))
}
return(list("LowerBound" = LowerBound, "UpperBound" = UpperBound))
}
result <- ts_confidence_intervals(500, 10, 0.05)
print(result$LowerBound)
print(result$UpperBound)