At the time of writing, the two answers suggest a binomial test. This is a good approach to assess a binomial set of counts, like in your question.
But there is also a chi-square goodness-of-fit test that can be used in these cases.
R has this built in to the chisq.test()
function.
And it can be used when there are more than two categories. Or when the theoretical proportions aren't equal across categories.
That is,
Gender = c("Female", "Male")
Count = c(12, 8)
chisq.test(Count)
Gender = c("Female", "Male", "Other")
Count = c(12, 8, 6)
chisq.test(Count)
Race = c("American Indian", "Asian", "Black", "Pacific Islander", "White")
Count = c(10, 8, 16, 1, 24)
Theoretical = c(0.10, 0.15, 0.16, 0.0, 0.59)
chisq.test(Count, Theoretical)
Like a chi-square test of association, the chi-square goodness-of-fit test has a suggested minimum for expected values:
Gender = c("Female", "Male")
Count = c(12, 8)
chisq.test(Count)$expected
And you can extract the standardized residuals:
Gender = c("Female", "Male", "Other")
Count = c(12, 8, 6)
chisq.test(Count)$stdres
There are exact and Monte Carlo approaches. You might look at the multinomial.test()
function in the EMT package.
There are also multinomial confidence intervals. You might look at the MultinomCI()
function in the DescTools package.
Often the best way to express effect size is to compare the expected proportions to the observed proportions (e.g. rcompanion.org/handbook/images/image301.png ).
Addendum 1:
Because there's some suggestion in the answers about which test may be better, below is the results for this example from a few different tests.
Without attempting justification as to which is more correct, in this case the p-values from the exact tests and Monte Carlo simulations are similar.
The uncorrected chi-square test is probably too liberal in this case. Though a Yates correction could be applied here too. (Though I don't know of an easy implementation in R for the goodness-of-fit chi-square test with Yates correction).
A = c(12, 8)
N = sum(A)
theoretical =c(0.5, 0.5)
#####################
binom.test(A, N)
### Exact binomial test
###
### number of successes = 12, number of trials = 20, p-value = 0.5034
chisq.test(A)
### Chi-squared test for given probabilities
###
### X-squared = 0.8, df = 1, p-value = 0.3711
chisq.test(A, simulate.p.value=TRUE, B=10000)
### Chi-squared test for given probabilities with simulated p-value (based on 10000 replicates)
###
### X-squared = 0.8, df = NA, p-value = 0.506
library(DescTools)
GTest(A, correct="yates")
### Log likelihood ratio (G-test) goodness of fit test
###
### G = 0.4517, X-squared df = 1, p-value = 0.5015
library(EMT)
multinomial.test(A, theoretical)
### Exact Multinomial Test
###
### Events pObs p.value
### 21 0.1201 0.5034
library(EMT)
multinomial.test(A, theoretical, MonteCarlo = TRUE, ntrial=10000)
### Monte Carlo Multinomial Test
###
### Events pObs p.value
### 21 0.1201 0.5026
Addendum 2:
I couldn't resist seeing how the Yates correction on the chi-square goodness of fit test would work out. With this correction, it's in line with the exact and Monte Carlo tests.
A = c(12, 8)
DF = length(A)-1
Exp = theoretical * N
YatesChisq = sum((abs(A-Exp)-0.5)^2/Exp)
pValue = pchisq(YatesChisq, DF, lower.tail=FALSE)
(data.frame(YatesChisq=round(YatesChisq, 2), pValue=round(pValue,4)))
### YatesChisq pValue
### 0.45 0.5023
Thanks to @utobi for pointing out that the Yates correction can be applied for a chi-square goodness-of-fit test when there are two categories
x = 12
n = 20
prop.test(x, n, correct=TRUE)
### 1-sample proportions test with continuity correction
### X-squared = 0.45, df = 1, p-value = 0.5023
Addendum 3
Comparing the p-values from the chi-square goodness-of-fit test and the binomial test, where the sum of counts for two categories is 20.
G1 = 1:10
G2 = 20-G1
pChiSq = rep(NA, 10)
pBinom = rep(NA, 10)
for(i in 1:10){
pChiSq[i] = chisq.test(c(G1[i],G2[i]))$p.value
pBinom[i] = binom.test(G1[i],(G1[i]+G2[i]))$p.value
}
(data.frame(Count1=G1, Count2=G2, pChiSq=round(pChiSq,5), pBinom=round(pBinom,5)))
### Count1 Count2 pChiSq pBinom
### 1 19 0.00006 0.00004
### 2 18 0.00035 0.00040
### 3 17 0.00175 0.00258
### 4 16 0.00729 0.01182
### 5 15 0.02535 0.04139
### 6 14 0.07364 0.11532
### 7 13 0.17971 0.26318
### 8 12 0.37109 0.50344
### 9 11 0.65472 0.82380
### 10 10 1.00000 1.00000
self-study
tag ? $\endgroup$