> ### Example: Heart Disease Example Lesson 3 ## > > ## enter data > heart <-c(12,8,31,41,307,246,439,245) > heart<-matrix(heart,4,2,) > heart [,1] [,2] [1,] 12 307 [2,] 8 246 [3,] 31 439 [4,] 41 245 > > ## run the chi-squared test of independence & save it into a new object > result<-chisq.test(heart) > result Pearson's Chi-squared test data: heart X-squared = 35.0285, df = 3, p-value = 1.202e-07 > > ## Let's look at the obseved, expected values and the residuals > result\$observed [,1] [,2] [1,] 12 307 [2,] 8 246 [3,] 31 439 [4,] 41 245 > result\$expected [,1] [,2] [1,] 22.08277 296.9172 [2,] 17.58315 236.4169 [3,] 32.53574 437.4643 [4,] 19.79834 266.2017 > result\$residuals [,1] [,2] [1,] -2.1456212 0.58514314 [2,] -2.2853872 0.62325942 [3,] -0.2692388 0.07342547 [4,] 4.7649169 -1.29946443 > serum<-margin.table(heart,1) > serum [1] 319 254 470 286 > > ## let's look at the counts for the four groups with CHD > heart[,1] [1] 12 8 31 41 > > ## then counts for the four groups with NOCHD, which is the second column of data in the dataframe we created above > heart[,2] [1] 307 246 439 245 > > ### conditional probabilities are: > heart[,1]/serum [1] 0.03761755 0.03149606 0.06595745 0.14335664 > heart[,2]/serum [1] 0.9623824 0.9685039 0.9340426 0.8566434