Appendix A
This section presents the R code for the parametric bootstrap implementation used.
# The libraries to be used are loaded
library(methods)
library(Runuran)
# generates bivariate negative binomial samples
gbnbs = function(gamma0,gamma1,gamma2,N,v){
if (gamma0 > gamma2 && gamma1 > gamma2 && gamma2 >= 0){
q = 1 + gamma0 + gamma1 - gamma2
p1 = (gamma0 - gamma2)/q
p2 = (gamma1 - gamma2)/q
p3 = gamma2/q
tau = gamma2 * q/((gamma0 - gamma2)*(gamma1 - gamma2))
x1 = numeric(N)
x2 = rep(N,0)
x = rep(N,0)
y = numeric(N)
pmf1 = function(a){
p = abs(1 - (p2 + p3)/(1 - p1))
return(choose(v + a - 1,v - 1) * p^v * (1 - p)^a)
}
dy = unuran.discr.new(pmf = pmf1, lb = 0, ub = 10, mode = 0, sum = 1)
gen = unuran.new(distr = dy, method = "dari; squeeze = on")
y = ur(gen,N)
pmf2 = function(t){
P = abs(p3/(p2 + p3))
return(choose(v,t) * P^t * (1 - P)^(v - t))
}
dxg = unuran.discr.new(pmf = pmf2, lb = 0, ub = 2, mode = 0, sum = 1)
gen = unuran.new(distr = dxg, method = "dari; squeeze = on")
x1 = ur(gen,N)
for(j in 1:N){
pmf3 <- function(b){
px2<- abs(1 - p1)
return(choose(v + y[j] + b - 1,v + y[j] - 1) * px2^(v + y[j]) * (1 - px2)^b)
}
dx2 = unuran.discr.new(pmf = pmf3, lb = 0, ub = 10, mode = 0, sum = 1)
gen = unuran.new(distr = dx2, method = "dari; squeeze = on")
x2[j] = ur(gen,1)
x[j] = x1[j] + x2[j]
}
return(list(x = x,y = y))
}
}
# Assignment of the fixed values to be used
v = 5 # Number of trials before the first success or failure
n = 70 # Sample size
K = 500 # Bootstrap iterations
#The initial population data is loaded
load("data_BNBD.rda")
data_x = data_BNBD$x
data_y = data_BNBD$y
freq_ini = table(data_x,data_y)
# Step 1 of the parametric Bootstrap algorithm
#The parameters of the initial population are estimated
gamma_0 = mean(data_x)/v
gamma_1 = mean(data_y)/v
#The third parameter is estimated using the three estimation methods
#MZ is the implementation of Zero-Zero frequency method algorithm
#MM is the implementation of the Method of Moments algorithm
#ML is the implementation of the Maximum Likelihood method algorithm
gammaZZ_2 = MZ(g_0 = gamma_0,g_1 = gamma_1,table = freq_ini,n = n,v = v)
gammaMM_2 = MM(g_0 = gamma_0,g_1 = gamma_1,table = freq_ini,n = n,v = v)
gammaML_2 = ML(g_0 = gamma_0,g_1 = gamma_1,table = freq_ini,n = n,v = v)
#The observed value is obtained for each parameter estimation method
#B_est is the implementation of the test statistic.
B_obs_ZZ = B_est(gamma_0,gamma_1,gammaZZ_2,data_x,data_y,n,v)
B_obs_MM = B_est(gamma_0,gamma_1,gammaMM_2,data_x,data_y,n,v)
B_obs_ML = B_est(gamma_0,gamma_1,gammaML_2,data_x,data_y,n,v)
# Implementation of the parametric Bootstrap method
B_bootZZ = B_bootMM = B_bootML = rep(0,K)
for(k in 1:K){
# Step 2(a) of the parametric Bootstrap algorithm
sampleB_ZZ = gbnbs(gamma_0, gamma_1, gammaZZ_2, n, v)
sampleB_MM = gbnbs(gamma_0, gamma_1, gammaMM_2, n, v)
sampleB_ML = gbnbs(gamma_0, gamma_1, gammaML_2, n, v)
dataB_ZZ = data.frame(x = sampleB_ZZ$x, y = sampleB_ZZ$y)
dataB_MM = data.frame(x = sampleB_MM$x, y = sampleB_MM$y)
dataB_ML = data.frame(x = sampleB_ML$x, y = sampleB_ML$y)
freqB_ZZ = table(dataB_ZZ$x,dataB_ZZ$y)
freqB_MM = table(dataB_MM$x,dataB_MM$y)
freqB_ML = table(dataB_ML$x,dataB_ML$y)
# The Bootstrap parameters are estimated: gammaB
gammaB_ZZ_0 = mean(dataB_ZZ$x)/v
gammaB_ZZ_1 = mean(dataB_ZZ$y)/v
gammaB_MM_0 = mean(dataB_MM$x)/v
gammaB_MM_1 = mean(dataB_MM$y)/v
gammaB_ML_0 = mean(dataB_ML$x)/v
gammaB_ML_1 = mean(dataB_ML$y)/v
# The third parameter is estimated using the three estimation methods
gammaB_ZZ_2 = MZ(g_0 = gammaB_ZZ_0,g_1 = gammaB_ZZ_1,table = freqB_ZZ,n = n,v = v)
gammaB_MM_2 = MM(g_0 = gammaB_MM_0,g_1 = gammaB_MM_1,table = freqB_MM,n = n,v = v)
gammaB_ML_2 = ML(g_0 = gammaB_ML_0,g_1 = gammaB_ML_1,table = freqB_ML,n = n,v = v)
# Step 2(b) of the parametric Bootstrap algorithm
B_boot_ZZ[k] = B_est(gammaB_ZZ_0,gammaB_ZZ_1,gammaB_ZZ_2,dataB_ZZ$x,dataB_ZZ$y,n,v)
B_boot_MM[k] = B_est(gammaB_MM_0,gammaB_MM_1,gammaB_MM_2,dataB_MM$x,dataB_MM$y,n,v)
B_boot_ML[k] = B_est(gammaB_ML_0,gammaB_ML_1,gammaB_ML_2,dataB_ML$x,dataB_ML$y,n,v)
}
# Step 3 of the parametric Bootstrap algorithm
# An approximation of the p-value is accumulated
vpZZ_B = sum(rep(1,K)[B_boot_ZZ > B_obs_ZZ])/K
vpMM_B = sum(rep(1,K)[B_boot_MM > B_obs_MM])/K
vpML_B = sum(rep(1,K)[B_boot_ML > B_obs_ML])/K
Appendix B
This section displays the graphs that complement the numerical tables presented in
Section 6.1.
Note that in
Figure A1,
Figure A2,
Figure A3,
Figure A4,
Figure A5,
Figure A6,
Figure A7,
Figure A8,
Figure A9,
Figure A10,
Figure A11,
Figure A12,
Figure A13,
Figure A14,
Figure A15,
Figure A16,
Figure A17, and
Figure A18 presented below, the areas with a pink background highlight the convergence of the method at the nominal level
represented by the blue dashed line. On the other hand, the areas with an orange background emphasize the convergence of the method at the nominal level
described by the blue dashed line.
Figure A1.
Simulation results for the probability of type I error for .
Figure A1.
Simulation results for the probability of type I error for .
Figure A2.
Simulation results for the probability of type I error for .
Figure A2.
Simulation results for the probability of type I error for .
Figure A3.
Simulation results for the probability of type I error for .
Figure A3.
Simulation results for the probability of type I error for .
Figure A4.
Simulation results for the probability of type I error for .
Figure A4.
Simulation results for the probability of type I error for .
Figure A5.
Simulation results for the probability of type I error for .
Figure A5.
Simulation results for the probability of type I error for .
Figure A6.
Simulation results for the probability of type I error for .
Figure A6.
Simulation results for the probability of type I error for .
Figure A7.
Simulation results for the probability of type I error for .
Figure A7.
Simulation results for the probability of type I error for .
Figure A8.
Simulation results for the probability of type I error for .
Figure A8.
Simulation results for the probability of type I error for .
Figure A9.
Simulation results for the probability of type I error for .
Figure A9.
Simulation results for the probability of type I error for .
Figure A10.
Simulation results for the probability of type I error for .
Figure A10.
Simulation results for the probability of type I error for .
Figure A11.
Simulation results for the probability of type I error for .
Figure A11.
Simulation results for the probability of type I error for .
Figure A12.
Simulation results for the probability of type I error for .
Figure A12.
Simulation results for the probability of type I error for .
Figure A13.
Simulation results for the probability of type I error for .
Figure A13.
Simulation results for the probability of type I error for .
Figure A14.
Simulation results for the probability of type I error for .
Figure A14.
Simulation results for the probability of type I error for .
Figure A15.
Simulation results for the probability of type I error for .
Figure A15.
Simulation results for the probability of type I error for .
Figure A16.
Simulation results for the probability of type I error for .
Figure A16.
Simulation results for the probability of type I error for .
Figure A17.
Simulation results for the probability of type I error for .
Figure A17.
Simulation results for the probability of type I error for .
Figure A18.
Simulation results for the probability of type I error for .
Figure A18.
Simulation results for the probability of type I error for .