Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:48:56+00:00 2026-05-23T12:48:56+00:00

In R, I use the phyper function to do a hypergeometric test for bioinformatics

  • 0

In R, I use the phyper function to do a hypergeometric test for bioinformatics analysis. However I use a lot of Python code and using rpy2 here is quite slow. So, I started looking for alternatives. It seemed that scipy.stats.hypergeom had something similar.

Currently, I call phyper like this:

pvalue <- 1-phyper(45, 92, 7518, 1329)

where 45 is the number of selected items having the property of interest, 92 the number of total items having the property, 7518 the number of non selected items not having the property, and 1329 the total number of selected items.

In R, this yields 6.92113e-13.

Attempting to do the same with scipy.stats.hypergeom however yields a completely different result (notice, the numbers are swapped because the function accepts numbers in a different way):

import scipy.stats as stats   
pvalue = 1-stats.hypergeom.cdf(45, 7518, 92. 1329)
print pvalue

However this returns -7.3450134863151106e-12, which makes little sense. Notice that I’ve tested this on other data and I had little issues (same precision up to the 4th decimal, which is enough for me).

So it boils down to these possibilities:

  1. I’m using the wrong function for the job (or wrong parameters)
  2. There’s a bug in scipy

In case of “1”, are there other alternatives to phyper that can be used in Python?

EDIT: As the comments have noted, this is a bug in scipy, fixed in git master.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:48:57+00:00Added an answer on May 23, 2026 at 12:48 pm

    From the docs, you could try:

    hypergeom.sf(x,M,n,N,loc=0) :
    survival function (1-cdf — sometimes
    more accurate)

    Also, I think you might have the values mixed up.

    Models drawing objects from a bin. M
    is total number of objects, n is total
    number of Type I objects. RV counts
    number of Type I objects in N drawn
    without replacement from population.

    Therefore, by my reading: x=q, M=n+m, n=m, N=k.

    So I would try:

    stats.hypergeom.sf(45,(92+7518),92,1329)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is
use Data::Dumper; %hash = ( Key => {test => [[testvalue, 10], [testvalue, 20]]}, Key2
use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub {
Use case example: Client A comes to request sales information, enters their zip code
Use Selenium a lot, but wondering the folowing question Just a little bit curious,
Use AES/Rijndael or any symmetric encryption. Encrypt the hidden value using itself as the
Use http://jobs.sitesixteen.com/ for reference. I'm using YQL for the city, state auto-complete. IF you
I use Qt 4.4.2 in Visual Studio 2008. When I am writing code, IntelliSense
I use to work with Visual Studio + C#, and have been using svn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.