1) Generate nN
samples from beta distribution (a, b) and the parameter of wighted c
Subscript[a, 0] = 2;
Subscript[b, 0] = 4;
nN = 1000;
n = 50;
α = 0.05;
n1 = nN*α;
c = 2;
w1 =
Table[
RandomVariate[BetaDistribution[Subscript[a, 0], Subscript[b, 0]]],
{i, nN}, {j, 1, n}];
me = Subscript[a, 0]/(Subscript[a, 0] + Subscript[b, 0])
se =
{(Subscript[a, 0] Subscript[b, 0])/
((Subscript[a, 0] + Subscript[b, 0])^2 (Subscript[a, 0] + Subscript[b, 0] + 1))}
2) Calculate unknown parameters a,b for each random sample*)
m6 = Table[Mean[w1[[i, All]]], {i, nN}];
s6 = Table[Variance[w1[[i, All]]], {i, nN}];
e6 = Table[m6[[i]] - a/(a + b) == 0, {i, nN}];
e26 = Table[s6[[i]] - (a b)/((a + b)^2 (a + b + 1)) == 0, {i, nN}];
v1 =
Table[
FindRoot[{e6[[i]], e26[[i]]}, {{a, 1.5}, {b, 3.5}}, MaxIterations -> 5],
{i, nN}];}
OverHat[a] = a /. v1;
OverHat[b] = b /. v1;
f1 = Mean[OverHat[a]]
f2 = Mean[OverHat[b]]
3) Calculate suggested test statistical
T =
Table[
(1/n)*
Sum[
(w1[[i, l]]*w1[[i, k]] - 2*(w1[[i, l]]*m6[[i]]) + m6[[i]]^2)/
((w1[[i, l]] + w1[[i, k]] + c)*m6[[i]]^2) +
(2*(w1[[i, l]]*w1[[i, k]]*(1 - w1[[i, k]]) -
(w1[[i, l]]*m6[[i]])*(1 - w1[[i, l]])))/
((w1[[i, l]] + w1[[i, k]] + c)^2*OverHat[a][[i]]*m6[[i]]) +
(2*(w1[[i, l]]*w1[[i, k]]*(w1[[i, k]]*(w1[[i, l]] - 2) + 1)))/
((w1[[i, l]] + w1[[i, k]] + c)^3*OverHat[a][[i]]^2),
{l, 1, n}, {k, 1, n}],
{i, nN}];
4) Simulate (n1) bootstrap samples from a beta distribution with parameters OverHat[a], OverHat[b])
w2 =
Table[
RandomVariate[BetaDistribution[OverHat[a][[i]], OverHat[b][[i]]]],
{i, nN}, {j, 1, n}];
w3 = Table[RandomChoice[w2[[i]], {n1, n}], {i, nN}];
Dimensions[w3]
m7 = Table[Mean[w3[[i, r, All]]], {i, nN}, {r, n1}];
s7 = Table[Variance[w3[[i, r, All]]], {i, nN}, {r, n1}];}
5) Calculate for each bootstrap sample the value of the test statistic
v2 =
Table[
FindRoot[
{m7[[i, r]] - a1/(a1 + b1) == 0,
s7[[i, r]] - (a1 b1)/((a1 + b1)^2 (a1 + b1 + 1)) == 0},
{a1, f1}, {b1, f2},
MaxIterations -> 5],
{i, nN}, {r, n1}];
OverHat[a1] = a1 /. v2;
SuperStar[T] =
(Table[(1/n)*
Sum[
(w3[[i, k, l]]*w3[[i, k, z]] - 2*(w3[[i, k, l]]*m7[[i, k]]) + m7[[i, k]]^2)/
((w3[[i, k, l]] + w3[[i, k, z]] + c)*m7[[i, k]]^2) +
(2*(w3[[i, k, l]]*w3[[i, k, z]]*(1 - w3[[i, k, z]]) -
(w3[[i, k, l]]*m7[[i, k]])*(1 - w3[[i, k, l]])))/
((w3[[i, k, l]] + w3[[i, k, z]] + c)^2*OverHat[a1][[i, k]]*m7[[i, k]]) +
(2*(w3[[i, k, l]]*w3[[i, k, z]]*(w3[[i, k, z]]*(w3[[i, k, l]] - 2) + 1)))/
((w3[[i, k, l]] + w3[[i, k, z]] + c)^3*OverHat[a1][[i, k]]^2),
{l, 1, n}, {z, 1, n}],
{i, nN}, {k, n1}];)
Dimensions[SuperStar[T]]}
6) Calculate p_value as order statistic of the bootstrap sample
arr = Sort /@ SuperStar[T];
Dimensions[arr]
d = n1 - (n1*α)
l = Round[d]
pn = arr[[All, l]];
Dimensions[pn]}
7) Calculate power of test (Reject the hypothesis if the test statistic
T of your original sample is greater than p_n)
pp = Total[Positive[T - pn]]
repp = Total[UnitStep[T - pn]]
repp2 = Total[UnitStep[pn - T]]}