What is a good test for comparing frequency counts between two groups?

I am looking for statistical methods used to compare frequency of observations between two groups. I have two geographical locations with data on different soil types present.

for example, my data looks like this:

Location Name         Soil Type A     Soil Type B    Soil Type C   Soil Type D
Location1             23              45             32           54
Location 2            56              64             31           13


Each location has soil types A, B, C, D. The numbers are the number of times a specific soil type occurs in that location. For example soil type A occurs 23 times in location 1 and 59 time in location 2 (the data is bigger than the example).

I want to analyse how different the soil type in location 1 is, as compared to location 2. What is the best test to perform?

• See here ... and a number of similar posts on site; that one should give you some useful search terms with which to find more. – Glen_b Jul 1 '15 at 15:58

You could do a $\chi^2$ test for independence. Basically you would be testing whether or not the location has any affect on the distribution of soil type.
To perform the test you would first estimate the distribution of soil type under the null hypothesis where the distributions are identical. To do this you'd want to find the marginal probability of each soil type, ignoring location (use the total of each soil type divided by the total count). Then, within each cell find the squared difference between the observed and expected counts, divide by the expected counts, and sum over all the cells. Under the null this will approximately follow a $\chi^2$ distribution with $(r - 1)(c - 1)$ degrees of freedom where $r$ and $c$ are the number of rows and columns respectively.