Let $x$ be a 20-element sample from the T-Student distribution with 4 degree of freedom. I want to do a simulation to estimate the power of the Kolmogorov test for $H_0=F\sim N(0,1)$ if $\alpha=0.01$.
My idea:
n=1000 #number of simulations
alpha=0.1
m=c()
for (i in 1:n){
x=rt(20,4)
pV=ks.test(x=x,y="pnorm")$p.value
m[i]=pV
}
power=m[m<alpha]
print(mean(power))#result
Is this way correct?
I can't help you with the particular programming implementation, but the statistical implementation is simple.
The power of the test is then the number of correct rejections of the null divided by the number of simulations; i.e., the number obtained in Step 3 above divided by the total number of samples generated.
My implementation in Mathematica is one line:
This is for $10^3$ simulations of a $t$-distribution with $\nu = 4$ degrees of freedom and $n = 20$ realizations per sample and $\alpha = 0.01$. The resulting power is small, only about $6.6\%$. Among $10^6$ simulations, the power was about $0.06564$. This suggests that the Student $t$ distribution with $\nu = 4$ is difficult for the KS test to distinguish from a normal distribution at a sample size of $n = 20$.
If you increase the sample size, you would expect the power to increase. At $n = 200$, with all else the same, the power increases to about $54.7\%$. At $\alpha = 0.05$, we have a power of about $74.5\%$.