Let's say I have 7 urns filled with random numbers of colourful marbles. An example dataset is as below:
data <- matrix (c(5,3,4,4,4,2,1,1,1,1,1,2,2,1,2,2,1,1,2,1,4,1,1,2,4,1,3,1,7,1,1,2,1,3,3), ncol = 5);
rownames(data) <- as.character(seq(1,7));
colnames(data) <- c("red", "blue", "yellow", "green", "pink");
I assume the count-based colour distribution to be multinomial. I want to test whether the contents of Urn 1 follow the colour distribution of Urns 2-7.
I get the MLEs for Urns 2-7 as:
p_sample <- colSums(data[2:7,])/ sum(colSums(data[2:7,]))
1) When I run a $\chi^2$ test as below, R displays a warning message since the expected counts (EC)<5.
obs <- data["1",]
chisq.test(obs,p=p_sample)
# Chi-squared test for given probabilities
# data: obs
# X-squared = 8.0578, df = 4, p-value = 0.08948
#
# Warning message:
# In chisq.test(obs, p = p_sample) :
# Chi-squared approximation may be incorrect
One of the answers to this question states that $\chi^2$ test would nevertheless return accurate results as long as ECs exceed 1.0 if a very simple $\frac{N-1}{N}$ correction is applied to the test statistic. Is the correction implemented simply like this: $\chi^2 = (\sum_i \frac{(O_i - E_i)^2}{E_i} )* \frac{N-1}{N} $ ?
This link suggests so but I am not sure about its reliability:
If one has the regular Pearson chi-square (e.g., in the output from statistical software), it can be converted to the 'N - 1' chi-square as follows:
'N -1' chi-square = Pearson chi-square x (N -1) / N
2) Alternative to $\chi^2$, since the number of counts is low, I ran a Fisher's exact test and got the results below. Is how I call the fisher.test below correct? The result I get makes me think: "No". I am confused since the R help document only refers to use cases for contingency tables.
fisher.test(obs, sum(obs)*p_sample)
# Fisher's Exact Test for Count Data
#
# data: obs and sum(obs) * p_sample
# p-value = 1
# alternative hypothesis: two.sided