0
$\begingroup$

Can we be 99% sure that there is a difference between the health habits of the group suffering from the disease and the group not suffering from the disease? The calculation formula and data are shown in the figure below.That is to say, is there any built-in function in mathematica to automatically calculate the formula k ^ 2 in the diagram?

enter image description here

Clear["Global`*"]

data1 = {{"", "not good enough", "good", "total"}, {"case group", 40, 
    60, 100}, {"control group", 10, 90, 100}, {"total", 50, 150, 200}};

Grid[data1, Frame -> All, ItemSize -> 15]
$\endgroup$
2

1 Answer 1

2
$\begingroup$

You can analyze contingency tables in Mathematica by using Poisson regression:

myData={{notGood,case,40},{good,case,60},
 {notGood,control,10},{good,control,90}};

myModel=GeneralizedLinearModelFit[myData,{x,y},{x,y},
 NominalVariables->All,ExponentialFamily->"Poisson"];

myModel["PearsonChiSquare"]

This returns the value of the chi-square test statistic to be 24. Since 24 exceeds the tabled value of 6.635, then we reject the null hypothesis of independence at the 0.010 level, and conclude that there is a difference between the health habits of the group suffering from the disease and the group not suffering from the disease.

This analysis can be extended to contingency tables of any size.

$\endgroup$
2
  • $\begingroup$ Clear["Global`*"] data1 = {{"", "not good enough", "good", "total"}, {"case group", 40, 60, 100}, {"control group", 10, 90, 100}, {"total", 50, 150, 200}}; Grid[data1, Frame -> All, ItemSize -> 15] $\endgroup$
    – csn899
    Jan 31 at 23:34
  • $\begingroup$ How to find Chi square with the above code? Because the code above is easy to draw tables $\endgroup$
    – csn899
    Jan 31 at 23:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.