This is related to another question I asked recently. To recap:
[I had 30 people call a number and then roll a 5 sided die. If the call matches the subsequent face then the trial is a hit, else it is a miss. Each subject completes 25 trials (rolls) and thus, each participant has a score out of 25. Since the die is a virtual one, it cannot be biased. Before the experiment was conducted I was going to compare the subjects score with a one-sample t-test (compared to mu of 5). However I was pointed towards the more powerful z-test, which is appropriate because we know the population parameters for the null hypothesis: that everyone should score at chance. Since NPQ means the binomial approximates to the normal or Gaussian distribution, we can use a parametric test. So I could just forget about it all and go back to the t-test I planned to use, but it seems to me that although the z-test is not often used in real research it is appropriate here. That was the conclusion from my previous question. Now I am trying to understand how to use resampling methods (either permutation or bootstrap) to compliment my parametric analysis.]
Okay. I am trying to program a one-sample permutation z-test, using the DAAG package onet.permutation as inspiration. This is as far as I've got:
perm.z.test = function(x, mu, var, n, prob, nsim){
nx <- length(x)
mx <- mean(x)
z <- array(, nsim)
for (i in 1:nsim) {
mn <- rbinom(nx*1, size=n, prob=prob)
zeta = (mean(mn) - mu) / (sqrt(var/nx))
z[i] <- zeta
}
pval <- (sum(z >= abs(mx)) + sum(z <= -abs(mx)))/nsim
print(signif(pval, 3))
}
Where: x
is the variable to test, n
is the the number of trials (=25) and prob
is the probability of getting it correct (=.2). The population value (mu
) of the mean number correct is np. The population standard deviation, var
, is square-root(np*[1-p]).
Now I guess this compares x to an array composed of randomly generated binomial sample. If I centre x at 0 (variable-mu) I get a p-value. Can somebody confirm that it is doing what I think it is doing?
My testing gives this:
> binom.samp1 <- as.data.frame(matrix(rbinom(30*1, size=25, prob=0.2),
ncol=1))
> z.test(binom.samp1$V1, mu=5, sigma.x=2)
data: binom.samp1$V1
z = 0.7303, p-value = 0.4652
> perm.z.test(binom.samp1$V1-5, 5, 2, 25, .2, 2000)
[1] 0.892
> binom.samp1 <- as.data.frame(matrix(rbinom(1000*1, size=25, prob=0.2),
ncol=1))
> perm.z.test(binom.samp1$V1-5, 5, 2, 25, .2, 2000)
[1] 0.937
Does this look right?
UPDATE:
Since this obviously doesn't do what I want, I do have another angle. This website offers this advice:
There is no reason whatsoever why a permutation test has to use any particular test statistic. Any test statistic will do! ... For one-sample or paired two-sample tests, in particular, for Wilcoxon signed rank tests, the permutations are really subsets. The permutation distribution choses an arbitrary subset to mark + and the complementary subset is marked -. Either subset can be empty.
What about an arbitrary subset with a one-sample z-test?