myStatistic = numeric(N) #N is some large number, say 10000
for(i in 1:N) {
##generate the data using the model
myStatistic[i] = #compute the value of the statistic for the data
}
sd(myStatistic)
hist(myStatistic,prob=T)
mean(myStatistic < 3.4)Take some time to understand how this line works.
quantile does this for you:
quantile(myStatistic,0.95)This finds a cut-off such that 95\% of the statistic values are below it, and 5\% are above it. Now, you may easily guess that this rather vague description has problems: what if we have no such cut-off, more than one such cut-off? There are different ways to solve this problem. If you look up the help of the
quantile function, you will find a input
called type that chooses the specific algorithm to
be used. However, if you do the simulation a large number of
times (i.e., after statistical regularity has set in), all the
methods give you essentially the same answer for the continuous
distribution. So you do not need to bother much about the exact
algorithm being used. Generally, we refrain from using
the quantile function for the discrete case.