HYPGEOM.DIST function

PRO

The HYPGEOM.DIST function in Jspreadsheet Formulas Pro returns the hypergeometric distribution, the probability of a given number of successes in a sample drawn without replacement from a finite population. It applies whenever each draw changes the composition of the remaining population, such as inspecting a few items from a batch or drawing cards from a deck. Unlike the compatibility function HYPGEOMDIST, it accepts a cumulative flag that returns the probability of at most sample_s successes.

Documentation

Returns the hypergeometric distribution, the probability of a given number of sample successes given the sample size, population successes and population size.

Category

Statistical

Syntax

HYPGEOM.DIST(sample_s, number_sample, population_s, number_pop, cumulative)

Parameter Description
sample_s The number of successes in the sample.
number_sample The size of the sample.
population_s The number of successes in the population.
number_pop The size of the population.
cumulative TRUE returns the probability of at most sample_s successes. FALSE returns the probability of exactly sample_s successes.

Behavior

The HYPGEOM.DIST function evaluates the probability mass function when cumulative is FALSE and the cumulative distribution function when it is TRUE.

  • All five arguments are required. Calling the function with four arguments returns #N/A, so cumulative cannot be omitted as in Excel. Use HYPGEOMDIST when you need the four-argument form.
  • Negative counts return #NUM!.
  • Impossible combinations do not raise an error. A sample_s greater than number_sample, or a population_s greater than number_pop, returns 0.
  • Non-integer counts are truncated, so HYPGEOM.DIST(1.8, 4, 8, 20, FALSE) equals HYPGEOM.DIST(1, 4, 8, 20, FALSE).
  • Text arguments return #VALUE!.

Common Errors

Error Description
#NUM! Returned when any of the counts is negative.
#VALUE! Returned when an argument is text that cannot be interpreted as a number.

Best practices

  • Always pass the cumulative argument, since the function does not accept the four-argument form.
  • Wrap the counts with INT when they come from calculations, because decimal values are truncated silently.
  • Check in a separate formula that sample_s is at most number_sample and population_s at most number_pop, since inconsistent inputs return 0 instead of an error.
  • Use absolute references for the population cells when copying the formula down a column of sample_s values, for example $B$1.

Usage

A few examples using the HYPGEOM.DIST function.

HYPGEOM.DIST(1, 4, 8, 20, FALSE)
// Returns 0.363261, exactly 1 success in a sample of 4 from a population of 20 with 8 successes

HYPGEOM.DIST(1, 4, 8, 20, TRUE)
// Returns 0.465428, at most 1 success

HYPGEOM.DIST(5, 4, 8, 20, FALSE)
// Returns 0, more successes than the sample size

HYPGEOM.DIST(1, 4, 8, 20)
// Returns #N/A because cumulative is required

Interactive Spreadsheet Demo

<html>
<script src="https://jsuites.net/v6/jsuites.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jspreadsheet@13/dist/index.min.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jspreadsheet@13/dist/jspreadsheet.min.css" type="text/css" />

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>

<div id="spreadsheet"></div>

<script>
// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('ZmQ1YmFlMzhkY2Y5NTNmNTA1MjQyZjQ2MzdiMmEzNGIyNzc0OTQ2N2ZjODlmY2VhOTAxZTQ0YzgwYzA1MzQwYzY1ODczZDE3MzkwMmJlZjk3MGZmNWQyYTNjYjc3MzNkN2UzMDU3OWI5OWI4ZGYzM2QxMmFkZmViMDMzZTNlZTgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpreE1ESTRORE14TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

// Set the extensions
jspreadsheet.setExtensions({ formula });

// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
  worksheets: [{
    data: [
    [
        "sample_s",
        "number_sample",
        "population_s",
        "number_pop",
        "cumulative",
        "HYPGEOM.DIST"
    ],
    [
        1,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A2, B2, C2, D2, E2)"
    ],
    [
        1,
        4,
        8,
        20,
        true,
        "=HYPGEOM.DIST(A3, B3, C3, D3, E3)"
    ],
    [
        2,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A4, B4, C4, D4, E4)"
    ],
    [
        0,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A5, B5, C5, D5, E5)"
    ]
]
  }]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";

// Set license
jspreadsheet.setLicense('ZmQ1YmFlMzhkY2Y5NTNmNTA1MjQyZjQ2MzdiMmEzNGIyNzc0OTQ2N2ZjODlmY2VhOTAxZTQ0YzgwYzA1MzQwYzY1ODczZDE3MzkwMmJlZjk3MGZmNWQyYTNjYjc3MzNkN2UzMDU3OWI5OWI4ZGYzM2QxMmFkZmViMDMzZTNlZTgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpreE1ESTRORE14TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

// Set the extensions
jspreadsheet.setExtensions({ formula });

export default function App() {
    // Spreadsheet array of worksheets
    const spreadsheet = useRef();

    // Worksheet data
    const data = [
    [
        "sample_s",
        "number_sample",
        "population_s",
        "number_pop",
        "cumulative",
        "HYPGEOM.DIST"
    ],
    [
        1,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A2, B2, C2, D2, E2)"
    ],
    [
        1,
        4,
        8,
        20,
        true,
        "=HYPGEOM.DIST(A3, B3, C3, D3, E3)"
    ],
    [
        2,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A4, B4, C4, D4, E4)"
    ],
    [
        0,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A5, B5, C5, D5, E5)"
    ]
];

    // Render component
    return (
        <Spreadsheet ref={spreadsheet}>
            <Worksheet data={data} />
        </Spreadsheet>
    );
}
<template>
    <Spreadsheet ref="spreadsheet">
        <Worksheet :data="data" />
    </Spreadsheet>
</template>

<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";

// Set license
jspreadsheet.setLicense('ZmQ1YmFlMzhkY2Y5NTNmNTA1MjQyZjQ2MzdiMmEzNGIyNzc0OTQ2N2ZjODlmY2VhOTAxZTQ0YzgwYzA1MzQwYzY1ODczZDE3MzkwMmJlZjk3MGZmNWQyYTNjYjc3MzNkN2UzMDU3OWI5OWI4ZGYzM2QxMmFkZmViMDMzZTNlZTgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpreE1ESTRORE14TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

// Set the extensions
jspreadsheet.setExtensions({ formula });

export default {
    components: {
        Spreadsheet,
        Worksheet,
    },
    data() {
        // Worksheet data
        const data = [
    [
        "sample_s",
        "number_sample",
        "population_s",
        "number_pop",
        "cumulative",
        "HYPGEOM.DIST"
    ],
    [
        1,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A2, B2, C2, D2, E2)"
    ],
    [
        1,
        4,
        8,
        20,
        true,
        "=HYPGEOM.DIST(A3, B3, C3, D3, E3)"
    ],
    [
        2,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A4, B4, C4, D4, E4)"
    ],
    [
        0,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A5, B5, C5, D5, E5)"
    ]
]

        return {
            data
        };
    }
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import formula from "@jspreadsheet/formula-pro";

// You can use the following license for quick testing on localhost, StackBlitz, or CodeSandbox.
// The license is valid for one day, after which the spreadsheet will become read-only.
// For a longer trial period, you can create a free account and generate a demo license with an extended expiration date.
jspreadsheet.setLicense('ZmQ1YmFlMzhkY2Y5NTNmNTA1MjQyZjQ2MzdiMmEzNGIyNzc0OTQ2N2ZjODlmY2VhOTAxZTQ0YzgwYzA1MzQwYzY1ODczZDE3MzkwMmJlZjk3MGZmNWQyYTNjYjc3MzNkN2UzMDU3OWI5OWI4ZGYzM2QxMmFkZmViMDMzZTNlZTgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpreE1ESTRORE14TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0luWXhNaUlzSW5ZeE15SXNJbU5vWVhKMGN5SXNJbVp2Y20xeklpd2labTl5YlhWc1lTSXNJbkJoY25ObGNpSXNJbkpsYm1SbGNpSXNJbU52YlcxbGJuUnpJaXdpYVcxd2IzSjBaWElpTENKaVlYSWlMQ0oyWVd4cFpHRjBhVzl1Y3lJc0luTmxZWEpqYUNJc0luQnlhVzUwSWl3aWMyaGxaWFJ6SWl3aVkyeHBaVzUwSWl3aWMyVnlkbVZ5SWl3aWMyaGhjR1Z6SWl3aVptOXliV0YwSWl3aWNHbDJiM1FpWFN3aVpHVnRieUk2ZEhKMVpYMD0=');

// Set the extensions
jspreadsheet.setExtensions({ formula });

@Component({
    standalone: true,
    selector: "app-root",
    template: `<div #spreadsheet></div>`
})
export class AppComponent {
    @ViewChild("spreadsheet") spreadsheet: ElementRef;
    // Worksheets
    worksheets: jspreadsheet.worksheetInstance[];

    // Create a new data grid
    ngAfterViewInit() {
        // Create spreadsheet
        this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
            worksheets: [{
                data: [
    [
        "sample_s",
        "number_sample",
        "population_s",
        "number_pop",
        "cumulative",
        "HYPGEOM.DIST"
    ],
    [
        1,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A2, B2, C2, D2, E2)"
    ],
    [
        1,
        4,
        8,
        20,
        true,
        "=HYPGEOM.DIST(A3, B3, C3, D3, E3)"
    ],
    [
        2,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A4, B4, C4, D4, E4)"
    ],
    [
        0,
        4,
        8,
        20,
        false,
        "=HYPGEOM.DIST(A5, B5, C5, D5, E5)"
    ]
]
            }]
        });
    }
}