The R Project SVN R

Rev

Rev 68948 | Rev 84766 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 70052
Line 1... Line 1...
1
% File src/library/stats/man/Hypergeometric.Rd
1
% File src/library/stats/man/Hypergeometric.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2014 R Core Team
3
% Copyright 1995-2016 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{Hypergeometric}
6
\name{Hypergeometric}
7
\alias{Hypergeometric}
7
\alias{Hypergeometric}
8
\alias{dhyper}
8
\alias{dhyper}
Line 26... Line 26...
26
    white balls.}
26
    white balls.}
27
  \item{m}{the number of white balls in the urn.}
27
  \item{m}{the number of white balls in the urn.}
28
  \item{n}{the number of black balls in the urn.}
28
  \item{n}{the number of black balls in the urn.}
29
  \item{k}{the number of balls drawn from the urn.}
29
  \item{k}{the number of balls drawn from the urn.}
30
  \item{p}{probability, it must be between 0 and 1.}
30
  \item{p}{probability, it must be between 0 and 1.}
31
  \item{nn}{number of observations. If \code{length(nn) > 1}, the length
31
  \item{nn}{number of observations.  If \code{length(nn) > 1}, the length
32
    is taken to be the number required.}
32
    is taken to be the number required.}
33
  \item{log, log.p}{logical; if TRUE, probabilities p are given as log(p).}
33
  \item{log, log.p}{logical; if TRUE, probabilities p are given as log(p).}
34
  \item{lower.tail}{logical; if TRUE (default), probabilities are
34
  \item{lower.tail}{logical; if TRUE (default), probabilities are
35
    \eqn{P[X \le x]}, otherwise, \eqn{P[X > x]}.}
35
    \eqn{P[X \le x]}, otherwise, \eqn{P[X > x]}.}
36
}
36
}
Line 42... Line 42...
42
 
42
 
43
  Invalid arguments will result in return value \code{NaN}, with a warning.
43
  Invalid arguments will result in return value \code{NaN}, with a warning.
44
 
44
 
45
  The length of the result is determined by \code{n} for
45
  The length of the result is determined by \code{n} for
46
  \code{rhyper}, and is the maximum of the lengths of the
46
  \code{rhyper}, and is the maximum of the lengths of the
47
  numerical arguments for the other functions.  
47
  numerical arguments for the other functions.
48
  
48
 
49
  The numerical arguments other than \code{n} are recycled to the
49
  The numerical arguments other than \code{n} are recycled to the
50
  length of the result.  Only the first elements of the logical
50
  length of the result.  Only the first elements of the logical
51
  arguments are used.
51
  arguments are used.
52
}
52
}
53
\details{
53
\details{
Line 58... Line 58...
58
  \deqn{
58
  \deqn{
59
    p(x) = \left. {m \choose x}{n \choose k-x} \right/ {m+n \choose k}%
59
    p(x) = \left. {m \choose x}{n \choose k-x} \right/ {m+n \choose k}%
60
  }{p(x) =      choose(m, x) choose(n, k-x) / choose(m+n, k)}
60
  }{p(x) =      choose(m, x) choose(n, k-x) / choose(m+n, k)}
61
  for \eqn{x = 0, \ldots, k}.
61
  for \eqn{x = 0, \ldots, k}.
62
 
62
 
-
 
63
  Note that \eqn{p(x)} is non-zero only for
-
 
64
  \eqn{\max(0, k-n) \le x \le \min(k, m)}{max(0, k-n) <= x <= min(k, m)}.
-
 
65
 
-
 
66
  With \eqn{p := m/(m+n)} (hence \eqn{Np = N \times p} in the
-
 
67
  reference's notation), the first two moments are mean
-
 
68
  \deqn{E[X] = \mu = k p} and variance
-
 
69
  \deqn{\mbox{Var}(X) = k p (1 - p) \frac{m+n-k}{m+n-1},}{%
-
 
70
               Var(X) = k p (1 - p) * (m+n-k)/(m+n-1),}
-
 
71
  which shows the closeness to the Binomial\eqn{(k,p)} (where the
-
 
72
  hypergeometric has smaller variance unless \eqn{k = 1}).
-
 
73
 
63
  The quantile is defined as the smallest value \eqn{x} such that
74
  The quantile is defined as the smallest value \eqn{x} such that
64
  \eqn{F(x) \ge p}, where \eqn{F} is the distribution function.
75
  \eqn{F(x) \ge p}, where \eqn{F} is the distribution function.
-
 
76
 
-
 
77
  If one of \eqn{m, n, k}, exceeds \code{\link{.Machine}$integer.max},
-
 
78
  currently the equivalent of \code{qhyper(runif(nn), m,n,k)} is used,
-
 
79
  when a binomial approximation may be considerably more efficient.
65
}
80
}
66
\source{
81
\source{
67
  \code{dhyper} computes via binomial probabilities, using code
82
  \code{dhyper} computes via binomial probabilities, using code
68
  contributed by Catherine Loader (see \code{\link{dbinom}}).
83
  contributed by Catherine Loader (see \code{\link{dbinom}}).
69
 
84