# BiasedUrn-2-Univariate: Biased urn models: Univariate distributions In BiasedUrn: Biased Urn Model Distributions

## Description

Statistical models of biased sampling in the form of noncentral hypergeometric distributions, including Wallenius' noncentral hypergeometric distribution and Fisher's noncentral hypergeometric distribution (also called extended hypergeometric distribution).

These are distributions that you can get when taking colored balls from an urn without replacement, with bias. The univariate distributions are used when there are two colors of balls. The multivariate distributions are used when there are more than two colors of balls.

Please see `vignette("UrnTheory")` for a definition of these distributions and how to decide which distribution to use in a specific case.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20``` ```dWNCHypergeo(x, m1, m2, n, odds, precision=1E-7) dFNCHypergeo(x, m1, m2, n, odds, precision=1E-7) pWNCHypergeo(x, m1, m2, n, odds, precision=1E-7, lower.tail=TRUE) pFNCHypergeo(x, m1, m2, n, odds, precision=1E-7, lower.tail=TRUE) qWNCHypergeo(p, m1, m2, n, odds, precision=1E-7, lower.tail=TRUE) qFNCHypergeo(p, m1, m2, n, odds, precision=1E-7, lower.tail=TRUE) rWNCHypergeo(nran, m1, m2, n, odds, precision=1E-7) rFNCHypergeo(nran, m1, m2, n, odds, precision=1E-7) meanWNCHypergeo(m1, m2, n, odds, precision=1E-7) meanFNCHypergeo(m1, m2, n, odds, precision=1E-7) varWNCHypergeo(m1, m2, n, odds, precision=1E-7) varFNCHypergeo(m1, m2, n, odds, precision=1E-7) modeWNCHypergeo(m1, m2, n, odds, precision=1E-7) modeFNCHypergeo(m1, m2, n, odds, precision=0) oddsWNCHypergeo(mu, m1, m2, n, precision=0.1) oddsFNCHypergeo(mu, m1, m2, n, precision=0.1) numWNCHypergeo(mu, n, N, odds, precision=0.1) numFNCHypergeo(mu, n, N, odds, precision=0.1) minHypergeo(m1, m2, n) maxHypergeo(m1, m2, n) ```

## Arguments

 `x` Number of red balls sampled. `m1` Initial number of red balls in the urn. `m2` Initial number of white balls in the urn. `n` Total number of balls sampled. `N` Total number of balls in urn before sampling. `odds` Probability ratio of red over white balls. `p` Cumulative probability. `nran` Number of random variates to generate. `mu` Mean x. `precision` Desired precision of calculation. `lower.tail` if TRUE (default), probabilities are P(X <= x), otherwise, P(X > x).

## Details

Allowed parameter values
All parameters must be non-negative. `n` cannot exceed `N = m1 + m2`. The code has been tested with odds in the range 1E-9 to 1E9 and zero. The code may work with odds outside this range, but errors or NAN can occur for extreme values of odds. A ball with odds = 0 is equivalent to no ball. `mu` must be within the possible range of `x`.

Calculation time
The calculation time depends on the specified precision.

## Value

`dWNCHypergeo` and `dFNCHypergeo` return the probability mass function for Wallenius' and Fisher's noncentral hypergeometric distribution, respectively. A single value is returned if `x` is a scalar. Multiple values are returned if `x` is a vector.

`pWNCHypergeo` and `pFNCHypergeo` return the cumulative probability function for Wallenius' and Fisher's noncentral hypergeometric distribution, respectively. A single value is returned if `x` is a scalar. Multiple values are returned if `x` is a vector.

`qWNCHypergeo` and `qFNCHypergeo` return the quantile function for Wallenius' and Fisher's noncentral hypergeometric distribution, respectively. A single value is returned if `p` is a scalar. Multiple values are returned if `p` is a vector.

`rWNCHypergeo` and `rFNCHypergeo` return random variates with Wallenius' and Fisher's noncentral hypergeometric distribution, respectively.

`meanWNCHypergeo` and `meanFNCHypergeo` calculate the mean of Wallenius' and Fisher's noncentral hypergeometric distribution, respectively. A simple and fast approximation is used when precision >= 0.1.

`varWNCHypergeo` and `varFNCHypergeo` calculate the variance of Wallenius' and Fisher's noncentral hypergeometric distribution, respectively. A simple and fast approximation is used when precision >= 0.1.

`modeWNCHypergeo` and `modeFNCHypergeo` calculate the mode of Wallenius' and Fisher's noncentral hypergeometric distribution, respectively.

`oddsWNCHypergeo` and `oddsFNCHypergeo` estimate the odds of Wallenius' and Fisher's noncentral hypergeometric distribution from a measured mean. A single value is returned if `mu` is a scalar. Multiple values are returned if `mu` is a vector. A simple and fast approximation is used regardless of the specified precision. Exact calculation is not supported. See `demo(OddsPrecision)`.

`numWNCHypergeo` and `numFNCHypergeo` estimate the number of balls of each color in the urn before sampling from an experimental mean and a known odds ratio for Wallenius' and Fisher's noncentral hypergeometric distributions. The returned numbers `m1` and `m2` are not integers. A vector of `m1` and `m2` is returned if `mu` is a scalar. A matrix is returned if `mu` is a vector. A simple approximation is used regardless of the specified precision. Exact calculation is not supported. The precision of calculation is indicated by `demo(OddsPrecision)`.

`minHypergeo` and `maxHypergeo` calculate the minimum and maximum value of `x`. The value is valid for Wallenius' and Fisher's noncentral hypergeometric distribution as well as for the (central) hypergeometric distribution.

## References

`vignette("UrnTheory")`
`BiasedUrn-Multivariate`.
`BiasedUrn`.
`fisher.test`

## Examples

 ```1 2``` ```# get probability dWNCHypergeo(12, 25, 32, 20, 2.5) ```

### Example output

```[1] 0.2183387
```

BiasedUrn documentation built on May 2, 2019, 11:05 a.m.