chisq.test(x1,x1)$expected
shows the following:
x1
x1 201601 237168 272003 310418
201601 0.25 0.25 0.25 0.25
237168 0.25 0.25 0.25 0.25
272003 0.25 0.25 0.25 0.25
310418 0.25 0.25 0.25 0.25
Observed counts (chisq.test(x1,x1)$observed
):
x1
x1 201601 237168 272003 310418
201601 1 0 0 0
237168 0 1 0 0
272003 0 0 1 0
310418 0 0 0 1
So like this it assumes that you provide all the pairs, but you only provide the same numbers hence that is the observed count. The expected value is then actually "correct" (though silly in this case). As a side note, chisq.test(cbind(x1,x1))
does what you expect it to do (X-squared = 0, df = 3, p-value = 1
).
Your second result looks good though:
> chisq.test(cbind(x1,x2))$observed
x1 x2
[1,] 272003 239614
[2,] 310418 316515
[3,] 201601 182070
[4,] 237168 198025
> chisq.test(cbind(x1,x2))$expected
x1 x2
[1,] 266912.4 244704.6
[2,] 327073.2 299859.8
[3,] 200162.6 183508.4
[4,] 227041.8 208151.2