So let's say I've tallied up each letter in a text. I now have a vector whose indices represent the letters, and the values in the vector represent the number of occurences of a letter. Here it is:
v = [545 54 107 129 0 63 57 35 504 12 3 229 74 397 342 108 46 263 341 353 355 52 1 16 19 4].
I have another vector which is made of the theoretical frequencies of each letter, based on the dictionary. Here it is:
freq = [0.1780 0.0870 0.0800 0.0750 0.0750 0.0640 0.0610 0.0600 0.0580 0.0520 0.0390 0.0330 0.0320 0.0260 0.0140 0.0130 0.0120 0.0110 0.0100 0.0070 0.0050 0.0030 0.0030 0.0010 0.0007 0.0003]
Now, my null hypothesis is that the distribution I found conforms to the theoretical frequencies. I want to do a chi-squared to test this out.
Here is what I did; I'm new to this, and have a feeling it's wrong:
So I first created the expected data by multiplying the number of letters in total to the frequencies:
th_dist = sum(v)*freq
Then, I created a matrix made of two rows:
chi_mat = matrix(c(v, th_dst), nrow = 2, byrow = True)
Which creates a vector where the first row is
v and the second row is
Then, I simply used
chisq.test(chi_mat) to do the test.
It returns the following:
Pearson's Chi-squared test data: v X-squared = 942.32, df = 25, p-value < 2.2e-16
Here, I conclude that the null has to be rejected, as my p-value is significantly below my 0.05.
So, is my logic wrong? From what I understand, I'm supposed to be doing a test from independence, right? The issue is, I'm so not used to this that I don't know what sort of values I should be expecting. I haven't built an intuition for these things yet.
Does this successfully do a chi-squared test, and are my conclusions correct? Thank you.