I have just a simple question i think.
I tried to implement the $\chi^2$-test.I have this document where it is said on page 41, that I have to implement the test like this:$$\frac{\sum_{0\leq i < r}(f_i)^2}{N/r} - N$$ But then they say, that mathematically it would be expressed like this: $$\frac{\sum_{0\leq i < r}(f_i - N/r)^2}{N/r}$$
Now i don't understand, why this is the same.
I would do the transformation like this:
$$\frac{\sum_{0\leq i < r}(f_i)^2}{N/r} - N = \frac{\sum_{0\leq i < r}(f_i)^2-N^2/r}{N/r} \neq \frac{\sum_{0\leq i < r}(f_i)^2-N^2/r^2}{N/r} = \frac{\sum_{0\leq i < r}(f_i - N/r)^2}{N/r}$$
So it doesn't work. Can you help me guys ?
$\underline{\text{For your help:}}$ $N$ is the number of generated random numbers. $[0,r-1]$ is the range of values, which the generated random numbers can have. And the $f_i$ are the numbers of how often a number got generated. So every number between $0$ and $r$ should be generated $N/r$ times in best case, but just got generated $f_i$ times.
Thank you so much.
Consider $$S=\sum_i\left(f(i)-\frac{N}{r}\right)^2,$$ then $$S=\sum_if(i)^2-2\sum_if(i)\frac{N}{r}+\sum_i\frac{N^2}{r^2}, $$ thus $$S=\sum_if(i)^2-2\frac{N^2}{r}+\frac{N^2}{r^2}r=\sum_if(i)^2-\frac{N^2}{r}$$
Remarks: