Hello, I am trying to write code in R statistical programming language regarding the confidence interval width and coverage probability of the population mean with different bootstrap methods under ranked set sampling, but I am not sure whether the code I wrote works correctly. I share the method and the codes I wrote. It'd be great if someone could help me with this. Many thanks in advance!

Method

Step 1 : Draw the ranked set sample with set size (m) and cycle size (r) from the target population. ((sets (m) are in rows, cycles (r) are in columns))

Step 2 : To create bootstrap ranked set sample, r units from the ith row (i=1,2,…,m) are randomly selected by with replacement with probability 1/r.

Step 3 : The sample mean statistic is calculated for each bootstrap sample created.

Step 4: The calculated bootstrap sample means are sorted from smallest to largest.

Step 5 : To represent B bootstrap repetition, the value of the sorted bootstrap sample averages corresponding to (B+1)*α is determined as the lower limit, and the value corresponding to (B+1)*(1-α ) is determined as the upper limit of confidence interval.

Step 6 : By determining the lower and upper limits for all bootstrap repetitions, confidence interval coverage probabilities and average confidence interval width are obtained.

#R Codes

#The number of set size

m<-2

#The number of cycle size

r<-4

#The number of the simulation size

sim<-10000

#The number of times the confidence interval includes the population mean

cpn<-0

#level of significance (alpha)

alpha<-0.05

#Bootstrap Repetition size

B=2000

#Upper and Lower Limits of Confidence interval

ucl<-numeric(sim) #upper limit of confidence interval

lcl<-numeric(sim) #lower limit of confidence interval

#Target Population

x<- rnorm(1000,mean = 0,sd=1) #data from standard normal dist.

x<-as.vector(x)

for (si in 1:sim){

#Ranked Set Sampling Process

#package for Ranked Set Sampling

library(RSSampling)

#Samples from a target population by using ranked set sampling method

RSS<- rss(x, m=m, r=r, sets=TRUE)

#Ranked Set Sample (cycles (r) are in rows, sets(m) are in columns)

matris<-RSS$sample

#Ranked Set Sample (sets (m) are in rows, cycles (r) are in columns)

matrist<-t(matris)

#The matrix for Bootstrap Ranked Set Samples

x1 <- matrix(nrow = m, ncol = r)

#Sample mean observed from Bootstrap ranked set samples.

x2 <- numeric(B)

#Method 1

for (k in 1:B) {

for (j in 1:m) {

y <- sample(matrist[j,1:r], size = r,replace = TRUE,prob=(c((1/r)*rep(1,r))))

x1[j,] <- y

}

#Bootstrap Ranked Set Sample

y2 <- as.vector(x1)

#Sample mean of Bootstrap Ranked Set Sample

meanx <- mean(y2)

#Sample means(B times) of Bootstrap Ranked Set Sample

x2[k] <- meanx

}

#The mean values of Bootstrap Ranked Set samples sorted from smallest to largest

y3 <- sort(x2)

#Lower Limit for Confidence Interval (The Value that corresponding to (B+1)*α)
lcl[si] <- y3[floor((B + 1) * alpha)]
#Upper Limit for Confidence Interval (The Value that corresponding to (B+1)*(1-α))

ucl[si] <- y3[ceiling((B + 1) * (1 - alpha))]

#The coverage probability of confidence interval

if(lcl[si] <= mean(x) & mean(x) <= ucl[si])

{

cpn<- cpn+1}

print(si)

}

#The mean values of upper and lower limits of confidence interval

mean(ucl)

mean(lcl)

#Average Confidence Interval Width

ıw<-mean(ucl)-mean(lcl)

ıw

#The coverage probability of confidence interval

cp<-cpn/sim

cp