hypergeotable: Calculation exact Hypergeometric Probabilities Table using...

Description Usage Arguments Details Value Note References Examples

View source: R/hypergeotable.R

Description

This is an algorithm for efficient and exact calculation of hypergeometric probabilities using Chebyshev polynomials. For a fixed population size N and fixed sample size n, such calculations simultaneously produce distributions for all possible values of the population number of "successes" M.

The well-known hypergeometric distribution arises in the combinatorial problem in which a finite population of N ob-jects contains M of one kind which may be labeled "success." A sample of n objects is picked without replacement from this set of N objects and it is wished to find the probability that the sample contains exactly x objects labeled "success", where x = 0,1, ... ,N. The probability of observing exactly x such objects is given by The hypergeometric distribution is used for sampling without replacement:

p(x)=choose(M,x)choose(N-M,n-x)/choose(N,n)

where max(0,n-N+M)<=x<=min(n,M)

This algorthim calculate the exact probability even for large N of n, while other algorthims simply use binomial approximation.

Usage

1
hypergeotable(N,n,output='density')

Arguments

N

population size N.

n

sample size n.

output

The output can be 'density', 'distribution' or 'both'. Default output is 'density'

Details

The detailed algorthim can be found: Alvo, M., & Cabilio, P. (2000). Calculation of hypergeometric probabilities using Chebyshev polynomials. The American Statistician, 54(2), 141-144.

Value

a matrix containing in row M=0,1,...,N, the required values of the hypergeometric probabilities(or distribution if output='distribution') indexed by the columns x=0,1,..,n.

Note

N can be very large say 2000 in our algorthim.

References

Alvo, M., & Cabilio, P. (2000). Calculation of hypergeometric probabilities using Chebyshev polynomials. The American Statistician, 54(2), 141-144.

Examples

1
2
3
4
# Calculate the hypergeometric probabilities for N=10, n=5.
hypergeotable(10,5)
# Calculate the hypergeometric distribution for N=10, n=5.
hypergeotable(10,5,output='distribution')

Example output

                   x=0          1          2          3          4          5
Density M=0 1.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
1           0.50000000 0.50000000 0.00000000 0.00000000 0.00000000 0.00000000
2           0.22222222 0.55555556 0.22222222 0.00000000 0.00000000 0.00000000
3           0.08333333 0.41666667 0.41666667 0.08333333 0.00000000 0.00000000
4           0.02380952 0.23809524 0.47619048 0.23809524 0.02380952 0.00000000
5           0.00396825 0.09920635 0.39682540 0.39682540 0.09920635 0.00396825
6           0.00000000 0.02380952 0.23809524 0.47619048 0.23809524 0.02380952
7           0.00000000 0.00000000 0.08333333 0.41666667 0.41666667 0.08333333
8           0.00000000 0.00000000 0.00000000 0.22222222 0.55555556 0.22222222
9           0.00000000 0.00000000 0.00000000 0.00000000 0.50000000 0.50000000
10          0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 1.00000000
Warning messages:
1: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

2: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

3: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

4: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

5: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

6: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

                        x=0          1          2         3         4 5
Distribution M=0 1.00000000 1.00000000 1.00000000 1.0000000 1.0000000 1
1                0.50000000 1.00000000 1.00000000 1.0000000 1.0000000 1
2                0.22222222 0.77777778 1.00000000 1.0000000 1.0000000 1
3                0.08333333 0.50000000 0.91666667 1.0000000 1.0000000 1
4                0.02380952 0.26190476 0.73809524 0.9761905 1.0000000 1
5                0.00396825 0.10317460 0.50000000 0.8968254 0.9960317 1
6                0.00000000 0.02380952 0.26190476 0.7380952 0.9761905 1
7                0.00000000 0.00000000 0.08333333 0.5000000 0.9166667 1
8                0.00000000 0.00000000 0.00000000 0.2222222 0.7777778 1
9                0.00000000 0.00000000 0.00000000 0.0000000 0.5000000 1
10               0.00000000 0.00000000 0.00000000 0.0000000 0.0000000 1
Warning messages:
1: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

2: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

3: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

4: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

5: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

6: In eps/(norm_term * exp((i - 1)/2)) :
  Recycling array of length 1 in vector-array arithmetic is deprecated.
  Use c() or as.vector() instead.

hypersampleplan documentation built on May 2, 2019, 9:12 a.m.