import javastat.inference.ChisqTest;

 

/**

 *

 * <p>Example: class ChisqTest.</p>

 */

 

double[][] chisqdata1 = { {29, 22}, {95, 121}, {518, 135} };

String[] colvar = {"M", "F", "M", "M", "M", "F", "F", "M", "F", "M",

               "F", "F", "M", "F", "M", "M", "F", "F", "M", "F",

               "M", "F", "F", "F", "F", "F", "M", "F", "M", "F",

               "F", "M", "M", "F", "M", "F", "F", "F", "M", "F",

               "F", "F", "M", "M", "F", "F", "F", "M", "F", "F"};

String[] rowvar = {"Editor", "AE", "Referee", "Editor", "Editor", "AE",

                "AE", "AE", "AE", "Editor", "Editor", "AE", "AE",

                "AE", "Referee", "Referee", "AE", "AE", "AE",

                "Editor", "Referee", "Referee", "Editor", "AE",

                "AE", "AE", "Referee", "Editor", "AE", "Referee",

                "Referee", "Referee", "Referee", "AE", "Referee",

                "AE", "Editor", "AE", "Referee", "AE", "Editor",

                "Referee", "Editor", "Referee", "AE", "AE",

                "Referee", "Editor", "Editor", "AE"};

 

testclass1 = new ChisqTest(chisqdata1);

testStatistic = testclass1.testStatistic;

pValue = testclass1.pValue;

print("The test statistic (non-null constructor)    = " + testStatistic);

print("The p-value based (non-null constructor)  = " + pValue);

 

testclass2 = new ChisqTest();

testStatistic = testclass2.testStatistic(colvar, rowvar);

pValue = testclass2.pValue(colvar, rowvar);

print("The test statistic (null constructor)    = " + testStatistic);

print("The p-value based (null constructor)  = " + pValue);

 

Results:

The test statistic based on non-null constructor for data set I     = 100.434

The p-value based on non-null constructor for data set I         = 0.0

The test statistic based on null constructor for data set II        = 9.013

The p-value based on null constructor for data set II            = 0.011

 

See also:

Hypothesis Test: Multinomial Population,

Test of Independence: Contingency Tables