New in Wolfram Mathematica 7: Statistical Model Analysis  previous | next 
Model Count Data from a Contingency Table
Fit count data from a contingency table and display data, fitted values and standardized residuals in tabular form.
In[1]:=

Click for copyable input
data = {{groupA, agree, 15}, {groupA, disagree, 66}, {groupB, 

    disagree, 63}, {groupB, disagree, 90}, {groupC, agree, 

    92}, {groupC, disagree, 46}};
In[2]:=

Click for copyable input
model = GeneralizedLinearModelFit[data, {var1, var2}, {var1, var2}, 

   NominalVariables -> All, ExponentialFamily -> "Poisson"];
In[3]:=

Click for copyable input
colorItem[item_, gl_: .95] := Item[item, Background -> GrayLevel[gl]]
In[4]:=

Click for copyable input
gridForProperty[prop_, title_] := 

 Grid[Join[{{colorItem[title, .85], SpanFromLeft}, 

    Map[colorItem, {"", "Group A", "Group B", "Group C"}]}, 

   Join[{{colorItem["Agree"]}, {colorItem["Disagree"]}}, 

    Transpose[Partition[model[prop], 2]], 2]], Dividers -> All, 

  ItemSize -> {10, 1.5}]
In[5]:=

Click for copyable input
gridForProperty2[prop_, title_] := 

 Grid[Join[{{colorItem[title, .85], SpanFromLeft}, 

    Map[colorItem, {"", "Group A", "Group B", "Group C"}]}, 

   Join[{{colorItem["Agree"]}, {colorItem["Disagree"]}}, 

    Transpose[

     Partition[

      Map[Column[#, Alignment -> {Center}] &, 

       Transpose[model[prop]]], 2]], 2]], Dividers -> All, 

  ItemSize -> {10, 2}]
In[6]:=

Click for copyable input
Style[Column[{gridForProperty["Response", "Counts"], 

   gridForProperty["PredictedResponse", "Predicted Values"], 

   gridForProperty2[{"FitResiduals", "StandardizedPearsonResiduals"}, 

    "Residuals & Standardized Residuals"]}, 

  Spacings -> 2], "DialogStyle"]
Out[6]=