[SciPy-User] Why stats.fisher_exact gives results different from R?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] Why stats.fisher_exact gives results different from R?

Peng Yu
See below for the output of python and R.

Why there is a difference in the odds ratio? Given that R is most
widely used by statisticians, I'd prefer the python version print the
same results. Also, confidence intervals are missing in the python's
output.

>>> stats.fisher_exact([[8, 2], [1, 5]])
(20.0, 0.03496503496503495)

R> fisher.test(rbind(c(8, 2), c(1,5)))

    Fisher's Exact Test for Count Data

data:  rbind(c(8, 2), c(1, 5))
p-value = 0.03497
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
    1.008849 1049.791446
sample estimates:
odds ratio
  15.46969

--
Regards,
Peng
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Why stats.fisher_exact gives results different from R?

josef.pktd
On Sat, Apr 6, 2019 at 9:02 AM Peng Yu <[hidden email]> wrote:

>
> See below for the output of python and R.
>
> Why there is a difference in the odds ratio? Given that R is most
> widely used by statisticians, I'd prefer the python version print the
> same results. Also, confidence intervals are missing in the python's
> output.
>
> >>> stats.fisher_exact([[8, 2], [1, 5]])
> (20.0, 0.03496503496503495)
>
> R> fisher.test(rbind(c(8, 2), c(1,5)))
>
>     Fisher's Exact Test for Count Data
>
> data:  rbind(c(8, 2), c(1, 5))
> p-value = 0.03497
> alternative hypothesis: true odds ratio is not equal to 1
> 95 percent confidence interval:
>     1.008849 1049.791446
> sample estimates:
> odds ratio
>   15.46969

estimate
an estimate of the odds ratio. Note that the conditional Maximum
Likelihood Estimate (MLE) rather than the unconditional MLE (the
sample odds ratio) is used. Only present in the 2 by 2 case.
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/fisher.test.html

scipy shows sample odds ratio

The R help page does not show which confidence interval method they
use, and I don't remember or never knew.

Josef

>
> --
> Regards,
> Peng
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Why stats.fisher_exact gives results different from R?

Stuart Reynolds
Also see:
    https://github.com/brentp/fishers_exact_test/issues/18
.... it's a **much** faster implementation of fisher's exact, and also
differs from scipy.stats.fisher_exact.
I think the brentp implementation is the same as R's -- actually would
be good to test this and update the issue.

- Stuart


On Sat, Apr 6, 2019 at 6:22 AM <[hidden email]> wrote:

>
> On Sat, Apr 6, 2019 at 9:02 AM Peng Yu <[hidden email]> wrote:
> >
> > See below for the output of python and R.
> >
> > Why there is a difference in the odds ratio? Given that R is most
> > widely used by statisticians, I'd prefer the python version print the
> > same results. Also, confidence intervals are missing in the python's
> > output.
> >
> > >>> stats.fisher_exact([[8, 2], [1, 5]])
> > (20.0, 0.03496503496503495)
> >
> > R> fisher.test(rbind(c(8, 2), c(1,5)))
> >
> >     Fisher's Exact Test for Count Data
> >
> > data:  rbind(c(8, 2), c(1, 5))
> > p-value = 0.03497
> > alternative hypothesis: true odds ratio is not equal to 1
> > 95 percent confidence interval:
> >     1.008849 1049.791446
> > sample estimates:
> > odds ratio
> >   15.46969
>
> estimate
> an estimate of the odds ratio. Note that the conditional Maximum
> Likelihood Estimate (MLE) rather than the unconditional MLE (the
> sample odds ratio) is used. Only present in the 2 by 2 case.
> https://stat.ethz.ch/R-manual/R-devel/library/stats/html/fisher.test.html
>
> scipy shows sample odds ratio
>
> The R help page does not show which confidence interval method they
> use, and I don't remember or never knew.
>
> Josef
>
> >
> > --
> > Regards,
> > Peng
> > _______________________________________________
> > SciPy-User mailing list
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/scipy-user
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Why stats.fisher_exact gives results different from R?

Stuart Reynolds
Also:

BUG: stats: fisher_exact returns incorrect p-value
https://github.com/scipy/scipy/issues/4130

- Stu

On Sat, Apr 6, 2019 at 12:37 PM Stuart Reynolds
<[hidden email]> wrote:

>
> Also see:
>     https://github.com/brentp/fishers_exact_test/issues/18
> .... it's a **much** faster implementation of fisher's exact, and also
> differs from scipy.stats.fisher_exact.
> I think the brentp implementation is the same as R's -- actually would
> be good to test this and update the issue.
>
> - Stuart
>
>
> On Sat, Apr 6, 2019 at 6:22 AM <[hidden email]> wrote:
> >
> > On Sat, Apr 6, 2019 at 9:02 AM Peng Yu <[hidden email]> wrote:
> > >
> > > See below for the output of python and R.
> > >
> > > Why there is a difference in the odds ratio? Given that R is most
> > > widely used by statisticians, I'd prefer the python version print the
> > > same results. Also, confidence intervals are missing in the python's
> > > output.
> > >
> > > >>> stats.fisher_exact([[8, 2], [1, 5]])
> > > (20.0, 0.03496503496503495)
> > >
> > > R> fisher.test(rbind(c(8, 2), c(1,5)))
> > >
> > >     Fisher's Exact Test for Count Data
> > >
> > > data:  rbind(c(8, 2), c(1, 5))
> > > p-value = 0.03497
> > > alternative hypothesis: true odds ratio is not equal to 1
> > > 95 percent confidence interval:
> > >     1.008849 1049.791446
> > > sample estimates:
> > > odds ratio
> > >   15.46969
> >
> > estimate
> > an estimate of the odds ratio. Note that the conditional Maximum
> > Likelihood Estimate (MLE) rather than the unconditional MLE (the
> > sample odds ratio) is used. Only present in the 2 by 2 case.
> > https://stat.ethz.ch/R-manual/R-devel/library/stats/html/fisher.test.html
> >
> > scipy shows sample odds ratio
> >
> > The R help page does not show which confidence interval method they
> > use, and I don't remember or never knew.
> >
> > Josef
> >
> > >
> > > --
> > > Regards,
> > > Peng
> > > _______________________________________________
> > > SciPy-User mailing list
> > > [hidden email]
> > > https://mail.python.org/mailman/listinfo/scipy-user
> > _______________________________________________
> > SciPy-User mailing list
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/scipy-user
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Why stats.fisher_exact gives results different from R?

Peng Yu
But I don't see the computation of the odds ratio.

On 4/6/19, Stuart Reynolds <[hidden email]> wrote:
> Also:
>
> BUG: stats: fisher_exact returns incorrect p-value
> https://github.com/scipy/scipy/issues/4130
>
> - Stu

--
Regards,
Peng
_______________________________________________
SciPy-User mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/scipy-user