If the components of the Java applet seem to be on crooked, please set the “zoom” to 100% or reset the zoom to zero, depending on the browser. The zoom control is commonly on the “view” dropdown menu.
The Java™ applet on this page is a freeware exact frequentist deterministic program to work two-dimensional contingency tables with structural zeroes, testing quasi-independence of rows against columns. It is a toy program for tiny samples. Scientific researchers will probably find my program useless. Perhaps they might look at the aylmer package of the “R” language. I did. I then copied the “Brobdingnag” feature of the aylmer package into the present program. The feature is explained in more detail in the Determ2.java source file, which is in the Determ2.jar archive.
The AWT controls in order are a multi-line TextArea which I will call the upper text area, a Button called “goEnumerate,” a faded Button called “stop,” and a multi-line TextArea which I will call the lower text area.
Sir Ronald Fisher’s famous experiment, “A Lady Tasting Tea,” resulted in a contingency table looking like
0 4 4 0I respectfully request the reader to select that two-by-two table with the mouse, copy the table, move the mouse to the upper text area, and paste into the table. Then I request the reader to click on the “goEnumerate” button. The computer program will print
pValue is 0.028571428571428588 time to run was 0.0 secondsor the like into the the lower text area. (Your time may vary.) The reader may have been expecting the one-sided p-value 1/70, but the present program is two-sided, so it prints the decimal form of 2/70.
A two-by-two may have big numbers in it, provided that they all are in the same column or in the same row:
61 39
1000000 1000000
The answer is
pValue is 0.03519564717753634 time to run was 0.297 seconds
That was just a two-by-two table. Here is a six-by-six:
2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2 0 0 0 0 0 0 2Again I request the reader to select, and copy, and clear the upper text area, and paste, and click on the button. This time the answer will be
pValue is 7.749452193895736E-6 time to run was 1.422 secondsor the like.
Seven by seven, such as
2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2takes much more time:
pValue is 6.2606411813866214E-6 time to run was 71.109 secondsGolly! That much more time to increase the edge size from six to seven.
I promised structural zeroes. Here is a table with strictly negative integers to signify structural zeroes:
2 0 0 0 0 -1 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 -1 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2The answer is
pValue is 7.116023516380913E-6 time to run was 38.703 secondsNotice, please, that the p-value is bigger but the time to run is smaller.
In practice, it is more usual to have the structural zeroes on a diagonal:
-1 1 2 4 3 -1 9 27 64 16 -1 4 125 25 5 -1The answer is
pValue is 2.1919849173653625E-14 time to run was 17.781 seconds
A table may be either square or oblong.
to Top
Browsers and Java
All the famous modern browsers can do this page correctly, but the “zoom” must be set to 100% or reset to zero, depending on the browser. The zoom control will commonly be on the “view” dropdown menu. If the zoom is wrong, then the “layout” of the Java applet will be wrong.
However, the program can work only if Java is installed and Java is turned on. If there is no Java or if Java has been turned off, then the text areas and the “goEnumerate” and “stop” buttons will not even be visible. In that case, the user is respectfully requested to download and install Java and/or to turn Java back on. Users who have trouble doing this are respectfully asked to get help from their classmates, children, spouses, or teachers.
to Top
Download
A reader or user wishing to download the files of this applet is respectfully invited to click on
Determ2.jar
to save the “jar” file. All the other Determ2 files are zipped into it, so it can be unzipped after download to see and change them all. Yes, a “jar” file is merely a special kind of “zip” file.
If the browser’s downloader renames the “jar” file to a “zip” file, please be sure to rename it back to a “jar”. I know a browser which takes too much on itself in this way.
to Top
The algorithm
Let the contingency table in the upper text area be called the “original” table. The recur method calls itself recursively to find all the tables whose marginal totals are the same as those of the original table and which have the same structural zeroes as the original table. For each table, original or not, we calculate the “weight” using the multinomial coefficient. Also for each table we calculate the chi-square statistic of Karl Pearson. Let us call the chi-square of the original table the “genuine.” We add up the total of weights for chi-squares less than or equal to the genuine. The ratio of this total to the total of all weights is the p-value.
The algorithm has to be run twice, the first time to calculate the expected values and the second time to use those expected values in the chi-square.
Actually, we use logarithms for the weights and for the totals of the weights. We use Brobdingnag arithmetic to get the logarithms of the totals of the weights.
to Top
Advantages and disadvantages
Advantages: The test on the present page is frequentist and exact and deterministic and free, and it can do structural zeroes. Bayes inferences are not frequentist. Asymptotic tests are not exact. Monte Carlo tests are not deterministic. Perhaps there are proprietary tests competing against the present page, but I do not know about them. However, there does exist the freeware aylmer package of the freeware “R” language.
Disadvantages: The test on the present page is usually slow. It can cause floating-point underflow.
to Top
A note to developers
Statisticians who do not plan to change or repair the program need not read this. The attention of developers is respectfully drawn to the line
final boolean debugging=false;in the Determ2.java file. The debugging variable is used in the try/catch statement
try
{
parse();
}
catch( Throwable thro )
{
String temp="";
temp+=thro.getClass().getCanonicalName();
temp+="\n\n";
temp+=thro.getMessage();
temp+="\n";
lowerTextArea.setText( temp );
if( debugging )
{
StackTraceElement[] ste=thro.getStackTrace();
int n=ste.length;
for( int j=0;j<n;j++ )
{
lowerTextArea.append( "\n"+ste[j] );
}
}
}
where I have bolded and bigged the line where debugging is used. When debugging is true, the StackTraceElements will be shown in the lower text area. That is, the program will say not only what happened, but also where it happened. Doubtless the professional Java programmers know about this already, but I am an amateur and I just found out. After the program is changed or repaired, the value of debugging can of course be set back to false.
The package may be downloaded from http://cran.r-project.org/web/packages/aylmer.
The R language page is http://cran.r-project.org/.
to Top
Revision date, licenses, and e-mail address
This program and its files are revised 7 March 2012. Their license is the Gnu General Public License, a copy of which is included in the download archive.
The tabular data quoted from journals and books and other web pages are copyrighted by their publishers.
The Java™ language is the property of Oracle.
Please send all criticism, both constructive and destructive, to me, Harold M. Kaplan,
at dot
smtw2gh gmail com
to Top