~ubuntu-branches/ubuntu/trusty/r-cran-vgam/trusty

« back to all changes in this revision

Viewing changes to man/betabinUC.Rd

  • Committer: Package Import Robot
  • Author(s): Chris Lawrence
  • Date: 2011-11-04 13:13:06 UTC
  • mfrom: (1.2.9)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20111104131306-w9fd83i51rw60gxf
Tags: upstream-0.8-4
ImportĀ upstreamĀ versionĀ 0.8-4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
\name{Betabin}
2
 
\alias{Betabin}
3
 
\alias{dbetabin}
4
 
\alias{pbetabin}
5
 
%\alias{qbetabin}
6
 
\alias{rbetabin}
7
 
\alias{dbetabin.ab}
8
 
\alias{pbetabin.ab}
9
 
%\alias{qbetabin.ab}
10
 
\alias{rbetabin.ab}
11
 
\title{The Beta-Binomial Distribution}
12
 
\description{
13
 
  Density, distribution function, and random
14
 
  generation for the beta-binomial distribution.
15
 
 
16
 
}
17
 
\usage{
18
 
dbetabin(x, size, prob, rho, log = FALSE)
19
 
pbetabin(q, size, prob, rho, log.p = FALSE)
20
 
rbetabin(n, size, prob, rho)
21
 
dbetabin.ab(x, size, shape1, shape2, log = FALSE)
22
 
pbetabin.ab(q, size, shape1, shape2, log.p = FALSE)
23
 
rbetabin.ab(n, size, shape1, shape2)
24
 
}
25
 
\arguments{
26
 
  \item{x, q}{vector of quantiles.}
27
 
% \item{p}{vector of probabilities.}
28
 
  \item{size}{number of trials.}
29
 
  \item{n}{number of observations.
30
 
  Must be a positive integer of length 1.}
31
 
  \item{prob}{
32
 
  the probability of success \eqn{\mu}{mu}.
33
 
  Must be in the unit open interval \eqn{(0,1)}.
34
 
 
35
 
  }
36
 
  \item{rho}{
37
 
  the correlation parameter \eqn{\rho}{rho}.
38
 
  Must be in the unit open interval \eqn{(0,1)}.
39
 
 
40
 
  }
41
 
  \item{shape1, shape2}{
42
 
  the two (positive) shape parameters of the standard
43
 
  beta distribution. They are called \code{a} and \code{b} in
44
 
  \code{\link[base:Special]{beta}} respectively.
45
 
 
46
 
  }
47
 
  \item{log, log.p}{
48
 
  Logical.
49
 
  If \code{TRUE} then all probabilities \code{p} are given as \code{log(p)}.
50
 
 
51
 
  }
52
 
}
53
 
\value{
54
 
  \code{dbetabin} and \code{dbetabin.ab} give the density,
55
 
  \code{pbetabin} and \code{pbetabin.ab} give the distribution function, and
56
 
% \code{qbetabin} and \code{qbetabin.ab} gives the quantile function, and
57
 
  \code{rbetabin} and \code{rbetabin.ab} generate random deviates.
58
 
 
59
 
}
60
 
\author{ T. W. Yee }
61
 
\details{
62
 
  The beta-binomial distribution is a binomial distribution whose
63
 
  probability of success is not a constant but it is generated from a
64
 
  beta distribution with parameters \code{shape1} and \code{shape2}.
65
 
  Note that the mean of this beta distribution is
66
 
  \code{mu = shape1/(shape1+shape2)}, which therefore is the
67
 
  mean or the probability of success.
68
 
 
69
 
  See \code{\link{betabinomial}} and \code{\link{betabin.ab}},
70
 
  the \pkg{VGAM} family functions for
71
 
  estimating the parameters, for the formula of the probability density
72
 
  function and other details.
73
 
 
74
 
}
75
 
\note{
76
 
  \code{pbetabin} and \code{pbetabin.ab} can be particularly slow.
77
 
  The functions here ending in \code{.ab} are called from those
78
 
  functions which don't.
79
 
  The simple transformations
80
 
  \eqn{\mu=\alpha / (\alpha + \beta)}{mu=alpha/(alpha+beta)} and
81
 
  \eqn{\rho=1/(1 + \alpha + \beta)}{rho=1/(1+alpha+beta)} are used,
82
 
  where \eqn{\alpha}{alpha} and \eqn{\beta}{beta} are the two
83
 
  shape parameters.
84
 
 
85
 
}
86
 
\seealso{
87
 
  \code{\link{betabinomial}},
88
 
  \code{\link{betabin.ab}}.
89
 
 
90
 
}
91
 
\examples{
92
 
\dontrun{
93
 
N = 9; xx = 0:N; s1 = 2; s2 = 3
94
 
dy = dbetabin.ab(xx, size = N, shape1 = s1, shape2 = s2)
95
 
barplot(rbind(dy, dbinom(xx, size = N, prob = s1/(s1+s2))),
96
 
        beside = TRUE, col = c("blue","green"), las = 1,
97
 
        main = paste("Beta-binomial (size=",N,", shape1=",s1,
98
 
                   ", shape2=",s2,") (blue) vs\n",
99
 
        " Binomial(size=", N, ", prob=", s1/(s1+s2), ") (green)", sep = ""),
100
 
        names.arg = as.character(xx), cex.main = 0.8)
101
 
sum(dy*xx) # Check expected values are equal
102
 
sum(dbinom(xx, size = N, prob = s1/(s1+s2))*xx)
103
 
cumsum(dy) -  pbetabin.ab(xx, N, shape1 = s1, shape2 = s2)
104
 
 
105
 
y = rbetabin.ab(n = 10000, size = N, shape1 = s1, shape2 = s2)
106
 
ty = table(y)
107
 
barplot(rbind(dy, ty/sum(ty)),
108
 
        beside = TRUE, col = c("blue","red"), las = 1,
109
 
        main = paste("Beta-binomial (size=",N,", shape1=",s1,
110
 
                   ", shape2=",s2,") (blue) vs\n",
111
 
        " Random generated beta-binomial(size=", N, ", prob=", s1/(s1+s2),
112
 
        ") (red)", sep = ""), cex.main = 0.8,
113
 
        names.arg = as.character(xx))
114
 
}
115
 
}
116
 
\keyword{distribution}
117
 
 
118