The Chi-Squared Statistic is a measure of how two categorical distributions differ from one another. So for 2 identical distributions the score would be 0 and as the distributions begin to diff the score will increase. The formula is…
Oi is the observed count of that letter in your text.
Ei is the expected count of that letter in the length of your text.
Chi-Squared Statistic in words is, “the sum, of the squared difference between observed count and expected count divided by the expected count, of each letter.”
Example: ‘WHENTHECLOCKSTRIKESTWELVEATTACK’ Text length = 31
|Letter||Observed Count (Oi)||Frequency in English||Expected Count (Ei)*||(Oi – Ei)2/Ei|
* Expected Count = FREQ / 100 × LEN
For English a Chi-Squared value of about 150 or less is expected anything above does likely does not resemble English.
WHENTHECLOCKSTRIKESTWELVEATTACK, X2 = 51.92133 THWKEEVIWTETSCANHKERCTTAKSCLLOE, X2 = 51.92133 ZDXPLXTDOWXSWCRSGPWVVOCWEOTTXOK, X2 = 425.59631
As you can see English text scores low however score is independent of letter order and a random text does not score highly.
I have created an Excel spreadsheet that can calculate Chi-Squared when given the frequencies of letters. It does not use macros. Chi-Squared Calculator