# Comparing two frequencies

Say I have two samples and I am measuring the amount of times a molecule appears in each. In sample 1, this particular molecule appears 200 out of the 1000 total molecules measured. For sample 2, it's 40 out of 300 total molecules.

If I want to see if this difference is statistically significant, do I use a chi-square test where the contingency table would be something like this?

200 | 800
40  | 260


Or is a different test more appropriate? Does it matter if the two samples have very different numbers of total molecules measured?

A test of two binomial proportions in R, seems appropriate to test $$H_0: p_1=p_2$$ against $$H_a: p_1 \ne p_2.$$ The two estimated proportions are $$\hat p_1 = 40/300 = 0.13$$ and $$\hat p_2 = 200/1000 = 0.20,$$ so the observed proportions are different. Then prop.test in R gives a P-value $$0.009 < 0.01 = 1\%,$$ so the difference is statistically significant at the 1% level.

prop.test(c(40, 200), c(300,1000), cor=F)

2-sample test for equality of proportions
without continuity correction

data:  c(40, 200) out of c(300, 1000)
X-squared = 6.8134, df = 1, p-value = 0.009048
alternative hypothesis: two.sided
95 percent confidence interval:
-0.11243026 -0.02090307
sample estimates:
prop 1    prop 2
0.1333333 0.2000000


Notes: (1) Your table is in the correct format for a chi-squared test, shown below. (The different sample sizes are not a problem.) It gives the same P-value as 'prop.test',

TAB = rbind(c(200,40), c(800, 260))
TAB
[,1] [,2]
[1,]  200   40
[2,]  800  260

chisq.test(TAB, cor=F)

Pearson's Chi-squared test

data:  TAB
X-squared = 6.8134, df = 1, p-value = 0.009048


(2) I did not use the various correctios in these two tests (arguments cor=F) on account of the sample sizes over 100.

(3) A test similar to prop.test, which you can try with hand computation is described on this NIST page.