Per whuber's comment, the standard way to test for a particular discrete distribution (e.g., a uniform one - but also any other one) is the Pearson chi squared test. In R, use chisq.test()
. A simulation:
> set.seed(1)
> rolls <- sample(1:6,10,replace=TRUE)
> chisq.test(rbind(table(factor(rolls,levels=1:6)),rep(length(rolls),6)/6))
Pearson's Chi-squared test
data: rbind(table(factor(rolls, levels = 1:6)), rep(length(rolls), 6)/6)
X-squared = 0.94156, df = 5, p-value = 0.9671
You will get a warning that the p value may be incorrect because we have a small sample size (as a rule of thumb, the approximation used here works if each number is expected to come up at least five times). In such a case, you can instead use a simulation for the distribution of the test statistic under the null hypothesis. Just use simulate.p.value=TRUE
(and possibly increase the number of Monte Carlo draws from the default of 2,000 using the B
parameter).
R
code, but you can try to implement his suggestions inR
and edit your question with your ownR
code if you have trouble. $\endgroup$ – Mark Miller Jan 6 '17 at 12:08pchisq(sum(((table(X)-N/6)^2)/N*6),5)
where X is a vector of dice results and N is the length of the vector $\endgroup$ – zugabe Jan 6 '17 at 13:35'fair die' test example
, etc. If you cannot get the correct answer then post your code above in your question along with the correct answer. $\endgroup$ – Mark Miller Jan 6 '17 at 13:47R
code to test whether a die is fair: math.stackexchange.com/questions/1578932/… $\endgroup$ – Mark Miller Jan 6 '17 at 14:29