You appear to have confused some things together.
There's more than one chi-squared test.
For example, there's
(i) the goodness of fit test, which you would specify probabilities for;
(ii) the test of independence, which you would not specify probabilities for; it doesn't make sense in this case - the expected values follow from the null hypothesis (and the assumptions).
(iii) the test of homogeneity. This is usually performed as a chi-squared test, in which case the conditioning on both margins makes it equivalent to the test of independence.
It is the second kind of case (testing for dependence against the null of independence) that the Fisher exact test corresponds to. It doesn't make sense to specify probabilities for that case.
Your circumstance -- "test whether there's a significant difference between the proportion of people in three unequally-sized groups who studied STEM subjects at university" -- sounds like a test for homogeneity, in which case you could test it by conditioning on both margins and using the Fisher exact test. (That's what I expect Fisher would have done.)
Exact tests for the goodness of fit case
While the usual Fisher exact test doesn't apply to the goodness of fit case, that doesn't mean you can't construct an exact test for the goodness of fit situation. Indeed it should be straightforward.
You can specify some statistic - even one like the "probability of the table itself" that's used in the Fisher test, though for myself I'd lean toward the chi-square statistic - and then compute the exact probability of all tables more extreme (by the ordering induced by the choice of test statistic) than your observed one under the usual multinomial assumption.
Indeed, in R, chisq.test
can essentially give you this (up to sampling error, which you can control), by simulation. You set the simulate.p.value
argument to TRUE
and choose the number of replicates (simulated tables), by setting the argument B
. I usually choose a larger value than the default for B
(simulations are fast). Here's an example (with the result simulated twice so you can see the slight variation in p-value):
> p=c(.1,.2,.3,.4)
> x=c(3,5,16,10)
> chisq.test(x,p=p,simulate.p.value=TRUE,B=10000)
Chi-squared test for given probabilities with simulated p-value (based on 10000
replicates)
data: x
X-squared = 4.7745, df = NA, p-value = 0.1904
> chisq.test(x,p=p,simulate.p.value=TRUE,B=10000)
Chi-squared test for given probabilities with simulated p-value (based on 10000
replicates)
data: x
X-squared = 4.7745, df = NA, p-value = 0.1922
There are also some R packages that might be of assistance in the goodness of fit case if you were trying to do a precise calculation of p-value (whether complete enumeration or enumeration of all more-extreme cases)