############################################################################################# #R-code for constructing GCI, AGCI, BPCI, FCI and F- HPDCI ############################################################################################# library(statmod) library(MASS) library(EnvStats) library(HDInterval) CI.SINGIG=function(M,m,n,mu,lambda) { # Start starttime = proc.time() B=1000 # number of bootstrap sample CP.GCI = rep(0,M) # coverage probability of CI based on GCI Length.GCI = rep(0,M) # average length of CI based on GCI R_theta_GCI = rep(0,m) CP.AGCI = rep(0,M) # coverage probability of CI based on AGCI Length.AGCI = rep(0,M) # average length of CI based on AGCI R_theta_AGCI = rep(0,m) CP.BPCI = rep(0,M) # coverage probability of CI based on BPCI Length.BPCI = rep(0,M) # average length of CI based on BPCI theta.star = rep(0,B) CP.FCI = rep(0,M) # coverage probability of CI based on Fiducial Length.FCI = rep(0,M) # average length of CI based on Fiducial CP.FHPD = rep(0,M) # coverage probability of CI based on Fiducial HPD Length.FHPD = rep(0,M) # average length of CI based on Fiducial HPD mu.t = c() lambda.t = c() mu.gibbs = c() lambda.gibbs = c() muhat.t = c() lambdahat.t = c() ################################ Estimation of parameter of interest ################################ theta = sqrt(mu/lambda) # single CV #############################Start Iteration########################## for (i in 1:M) { # begin loop i x = rinvgauss(n, mu, lambda) # generate x muhat = mean(x) # compute mean of x lambdahat_inverse = (1/n)*sum((1/x)-(1/muhat)) lambdahat = 1/lambdahat_inverse # compute scale of x ################################Compute CI based on GCI& AGCI################################ for (j in 1:m) { # begin loop j xbar = rinvgauss(1, mu, n*lambda) A=rchisq(1,n-1) Z=rnorm(1,0,1) V=A/(n*lambda) R_lambda = A/(n*lambdahat_inverse) # compute GPQ for scale of x R_mu_GCI =xbar/abs(1+Z*(sqrt(xbar/(n*R_lambda)))) # compute GPQ for mean of x R_theta_GCI[j]=sqrt(R_mu_GCI/R_lambda) # compute GPQ for single CV W = (sqrt(n-1)*(xbar/mu-1))/sqrt(V*xbar) R_mu_AGCI = xbar/max(0,1+(W*sqrt((V*xbar)/(n-1)))) # compute GPQ for mean of x R_theta_AGCI[j] = sqrt(R_mu_AGCI/R_lambda) # compute GPQ for single CV } # end loop j L.GCI <- quantile( R_theta_GCI,0.025,type=8) # compute lower based on GCI of theta U.GCI <- quantile( R_theta_GCI,0.975,type=8) # compute upper based on GCI of theta L.AGCI <- quantile( R_theta_AGCI,0.025,type=8) # compute lower based on AGCI of theta U.AGCI <- quantile( R_theta_AGCI,0.975,type=8) # compute upper based on AGCI of theta CP.GCI[i] <- ifelse( L.GCI