On Mon, 24 Dec 2012, yinung at Gmail wrote:
I notice that "xtab" command can do Fisher's exact
test. I found that
fisher.test(.) in R (requires vcd package) also produces Fisher's exact
test results. Does anyone know the differences between gretl's and R's
Fisher's exact test?
I test the following data (which can be downloaded from
http://ibeif.files.wordpress.com/2012/12/fishertea.xls
obs real guess
1 1 1
2 1 1
3 1 1
4 1 2
5 2 2
6 2 2
7 2 1
8 2 2
In gretl, the following script
<hansl>
open
http://ibeif.files.wordpress.com/2012/12/fishertea.xls
xtab real guess
</hansl>
produces the results:
Cross-tabulation of real (rows) against guess (columns)
[ 1][ 2] TOT.
[ 1] 3 1 4
[ 2] 1 3 4
TOTAL 4 4 8
Pearson chi-square test = 2 (1 df, p-value = 0.157299)
Warning: Less than of 80% of cells had expected values of 5 or greater.
Fisher's Exact Test:
Left: P-value = 0.985714
Right: P-value = 0.242857
2-Tail: P-value = 0.257143
However, in gretl with the following R script
fisher.test(table(real,guess))
produces the different results:
Fisher's Exact Test for Count Data
data: table(real, guess)
p-value = 0.4857
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
0.2117329 621.9337505
sample estimates:
odds ratio
6.408309
Hmm, there are various ways of computing a 2-sided p-value for
this test, and it looks like gretl and R make different
choices. You can get a very comprehensive printout at
http://www.quantitativeskills.com/sisa/statistics/fisher.htm
For this table we see:
<output>
The total number of cases= 8
The smallest value= 1
The smallest marginal= 4
Use of * (starred) statistics is advised
The p for exactly this table= 0.22857
One sided p-values: for p(O>=E):
p(O>=E): 0.2428571 *
p(O>E): 0.0142857
mid-p: 0.1285714
p(O<=E): 0.9857143
Two sided p-values p(O>=E|O<=E):
p= 0.4857143 * (sum of small p's)
p= 0.2285714 (left+right-exact)
p= 0.2571429 (left+right)
p= 0.485714 (double the single sided p)
p(O>E|O<E)= 0.02857 (sum of small p's)
mid-p 0.2571429 (sum of small p's)
</output>
So the value gretl is giving for the 2-sided p-value is the
one labeled "left+right" above. The one that R gives is the
"sum of small p's", which is starred (recommended) on the
quantitativeskills page. Perhaps we should reconsider or
augment the gretl output.
Allin Cottrell