1

I have been using R to calculate the chi-square value for a table of count data using chisq.test from the stats package. This has returned a chi-square value for the whole table.

W=c(98, 354, 105, 28)
WF=c(13, 108, 34, 6)
FNS=c(108, 438, 138, 24)
F=c(22, 61, 24, 2)
P=c(7, 48, 28, 4)
C=c(15, 68, 30, 4)
D=c(25, 106, 53, 5)
HD=c(39, 277, 122, 29)
Grade=cbind(W, WF, FNS, F, P, C, D, HD)
rownames(Grade)=c("3", "4", "5", "6")

Grade.chi=chisq.test(Grade)
Grade.chi

#Chi-squared approximation may be incorrect
#   Pearson's Chi-squared test
#
#data:  Grade
#X-squared = 54.274, df = 21, p-value = 9.012e-05

What I would like to calculate is the chi-square value of each cell, so that I can replace the count data in this table with chi-square values:

     W  WF  FNS  F  P    C   D  HD
"3" 98  13  108 22  7   15  25  39
"4" 354 108 438 61  48  68  106 277
"5" 105 34  138 24  28  30  53  122
"6" 28  6   24  2   4   4   5   29

Is there a pre-existing fraction I can use, or will I need to "manually" calculate it for each cell?

I feel it might be similar to this post, but not sure how to adapt Chi-square p value matrix in r

Any and all help appreciated - I'm still a beginner with R.

JRoo
  • 13
  • 3

1 Answers1

2

If you save the chi square test in a variable say abc, then you have all you need to compute the values

(abc$observed-abc$expected)^2/abc$expected

user2974951
  • 9,535
  • 1
  • 17
  • 24