EVOLUTION-MANAGER
Edit File: Beta.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: The Beta Distribution</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Beta {stats}"><tr><td>Beta {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The Beta Distribution</h2> <h3>Description</h3> <p>Density, distribution function, quantile function and random generation for the Beta distribution with parameters <code>shape1</code> and <code>shape2</code> (and optional non-centrality parameter <code>ncp</code>). </p> <h3>Usage</h3> <pre> dbeta(x, shape1, shape2, ncp = 0, log = FALSE) pbeta(q, shape1, shape2, ncp = 0, lower.tail = TRUE, log.p = FALSE) qbeta(p, shape1, shape2, ncp = 0, lower.tail = TRUE, log.p = FALSE) rbeta(n, shape1, shape2, ncp = 0) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, q</code></td> <td> <p>vector of quantiles.</p> </td></tr> <tr valign="top"><td><code>p</code></td> <td> <p>vector of probabilities.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>number of observations. If <code>length(n) > 1</code>, the length is taken to be the number required.</p> </td></tr> <tr valign="top"><td><code>shape1, shape2</code></td> <td> <p>non-negative parameters of the Beta distribution.</p> </td></tr> <tr valign="top"><td><code>ncp</code></td> <td> <p>non-centrality parameter.</p> </td></tr> <tr valign="top"><td><code>log, log.p</code></td> <td> <p>logical; if TRUE, probabilities p are given as log(p).</p> </td></tr> <tr valign="top"><td><code>lower.tail</code></td> <td> <p>logical; if TRUE (default), probabilities are <i>P[X ≤ x]</i>, otherwise, <i>P[X > x]</i>.</p> </td></tr> </table> <h3>Details</h3> <p>The Beta distribution with parameters <code>shape1</code> <i>= a</i> and <code>shape2</code> <i>= b</i> has density </p> <p style="text-align: center;"><i>Γ(a+b)/(Γ(a)Γ(b))x^(a-1)(1-x)^(b-1)</i></p> <p>for <i>a > 0</i>, <i>b > 0</i> and <i>0 ≤ x ≤ 1</i> where the boundary values at <i>x=0</i> or <i>x=1</i> are defined as by continuity (as limits). <br /> The mean is <i>a/(a+b)</i> and the variance is <i>ab/((a+b)^2 (a+b+1))</i>. These moments and all distributional properties can be defined as limits (leading to point masses at 0, 1/2, or 1) when <i>a</i> or <i>b</i> are zero or infinite, and the corresponding <code>[dpqr]beta()</code> functions are defined correspondingly. </p> <p><code>pbeta</code> is closely related to the incomplete beta function. As defined by Abramowitz and Stegun 6.6.1 </p> <p style="text-align: center;"><i>B_x(a,b) = integral_0^x t^(a-1) (1-t)^(b-1) dt,</i></p> <p>and 6.6.2 <i>I_x(a,b) = B_x(a,b) / B(a,b)</i> where <i>B(a,b) = B_1(a,b)</i> is the Beta function (<code><a href="../../base/html/Special.html">beta</a></code>). </p> <p><i>I_x(a,b)</i> is <code>pbeta(x, a, b)</code>. </p> <p>The noncentral Beta distribution (with <code>ncp</code> <i> = λ</i>) is defined (Johnson <em>et al</em>, 1995, pp. 502) as the distribution of <i>X/(X+Y)</i> where <i>X ~ chi^2_2a(λ)</i> and <i>Y ~ chi^2_2b</i>. </p> <h3>Value</h3> <p><code>dbeta</code> gives the density, <code>pbeta</code> the distribution function, <code>qbeta</code> the quantile function, and <code>rbeta</code> generates random deviates. </p> <p>Invalid arguments will result in return value <code>NaN</code>, with a warning. </p> <p>The length of the result is determined by <code>n</code> for <code>rbeta</code>, and is the maximum of the lengths of the numerical arguments for the other functions. </p> <p>The numerical arguments other than <code>n</code> are recycled to the length of the result. Only the first elements of the logical arguments are used. </p> <h3>Note</h3> <p>Supplying <code>ncp = 0</code> uses the algorithm for the non-central distribution, which is not the same algorithm used if <code>ncp</code> is omitted. This is to give consistent behaviour in extreme cases with values of <code>ncp</code> very near zero. </p> <h3>Source</h3> <ul> <li><p> The central <code>dbeta</code> is based on a binomial probability, using code contributed by Catherine Loader (see <code><a href="Binomial.html">dbinom</a></code>) if either shape parameter is larger than one, otherwise directly from the definition. The non-central case is based on the derivation as a Poisson mixture of betas (Johnson <em>et al</em>, 1995, pp. 502–3). </p> </li> <li><p> The central <code>pbeta</code> for the default (<code>log_p = FALSE</code>) uses a C translation based on </p> <p>Didonato, A. and Morris, A., Jr, (1992) Algorithm 708: Significant digit computation of the incomplete beta function ratios, <em>ACM Transactions on Mathematical Software</em>, <b>18</b>, 360–373. (See also<br /> Brown, B. and Lawrence Levy, L. (1994) Certification of algorithm 708: Significant digit computation of the incomplete beta, <em>ACM Transactions on Mathematical Software</em>, <b>20</b>, 393–397.) <br /> We have slightly tweaked the original “TOMS 708” algorithm, and enhanced for <code>log.p = TRUE</code>. For that (log-scale) case, underflow to <code>-Inf</code> (i.e., <i>P = 0</i>) or <code>0</code>, (i.e., <i>P = 1</i>) still happens because the original algorithm was designed without log-scale considerations. Underflow to <code>-Inf</code> now typically signals a <code><a href="../../base/html/warning.html">warning</a></code>. </p> </li> <li><p> The non-central <code>pbeta</code> uses a C translation of </p> <p>Lenth, R. V. (1987) Algorithm AS226: Computing noncentral beta probabilities. <em>Appl. Statist</em>, <b>36</b>, 241–244, incorporating<br /> Frick, H. (1990)'s AS R84, <em>Appl. Statist</em>, <b>39</b>, 311–2, and<br /> Lam, M.L. (1995)'s AS R95, <em>Appl. Statist</em>, <b>44</b>, 551–2. </p> <p>This computes the lower tail only, so the upper tail suffers from cancellation and a warning will be given when this is likely to be significant. </p> </li> <li><p> The central case of <code>qbeta</code> is based on a C translation of </p> <p>Cran, G. W., K. J. Martin and G. E. Thomas (1977). Remark AS R19 and Algorithm AS 109, <em>Applied Statistics</em>, <b>26</b>, 111–114, and subsequent remarks (AS83 and correction). </p> </li> <li><p> The central case of <code>rbeta</code> is based on a C translation of </p> <p>R. C. H. Cheng (1978). Generating beta variates with nonintegral shape parameters. <em>Communications of the ACM</em>, <b>21</b>, 317–322. </p> </li></ul> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <p>Abramowitz, M. and Stegun, I. A. (1972) <em>Handbook of Mathematical Functions.</em> New York: Dover. Chapter 6: Gamma and Related Functions. </p> <p>Johnson, N. L., Kotz, S. and Balakrishnan, N. (1995) <em>Continuous Univariate Distributions</em>, volume 2, especially chapter 25. Wiley, New York. </p> <h3>See Also</h3> <p><a href="Distributions.html">Distributions</a> for other standard distributions. </p> <p><code><a href="../../base/html/Special.html">beta</a></code> for the Beta function. </p> <h3>Examples</h3> <pre> x <- seq(0, 1, length = 21) dbeta(x, 1, 1) pbeta(x, 1, 1) ## Visualization, including limit cases: pl.beta <- function(a,b, asp = if(isLim) 1, ylim = if(isLim) c(0,1.1)) { if(isLim <- a == 0 || b == 0 || a == Inf || b == Inf) { eps <- 1e-10 x <- c(0, eps, (1:7)/16, 1/2+c(-eps,0,eps), (9:15)/16, 1-eps, 1) } else { x <- seq(0, 1, length = 1025) } fx <- cbind(dbeta(x, a,b), pbeta(x, a,b), qbeta(x, a,b)) f <- fx; f[fx == Inf] <- 1e100 matplot(x, f, ylab="", type="l", ylim=ylim, asp=asp, main = sprintf("[dpq]beta(x, a=%g, b=%g)", a,b)) abline(0,1, col="gray", lty=3) abline(h = 0:1, col="gray", lty=3) legend("top", paste0(c("d","p","q"), "beta(x, a,b)"), col=1:3, lty=1:3, bty = "n") invisible(cbind(x, fx)) } pl.beta(3,1) pl.beta(2, 4) pl.beta(3, 7) pl.beta(3, 7, asp=1) pl.beta(0, 0) ## point masses at {0, 1} pl.beta(0, 2) ## point mass at 0 ; the same as pl.beta(1, Inf) pl.beta(Inf, 2) ## point mass at 1 ; the same as pl.beta(3, 0) pl.beta(Inf, Inf)# point mass at 1/2 </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>