({{, (RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution])[α,β,n] 
represents a beta binomial mixture distribution with beta distribution parameters α and β, and n binomial trials.}})

OpenersNotesSection(Spacer1)Details

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) is also known as a Pólya distribution and as a negative hypergeometric distribution.

The beta binomial distribution is a binomial distribution with n trials whose probability parameter p follows a beta distribution with shape parameters α and β. »

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) allows α and β to be any positive real numbers, and n to be any positive integer.

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) can be used with such functions as (RefLink[Mean, paclet:ref/Mean]), (RefLink[CDF, paclet:ref/CDF]), and (RefLink[RandomVariate, paclet:ref/RandomVariate]). »

OpenersPrimaryExamplesSection(Spacer1)Examples  (22)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Probability mass function:

DiscretePlot[Table[PDF[BetaBinomialDistribution[α,.3,20],x],{α,{0.5,1,3}}]//Evaluate,{x,0,20},PlotMarkers->Automatic]

DiscretePlot[Table[PDF[BetaBinomialDistribution[1.2,β,20],x],{β,{0.5,2,3}}]//Evaluate,{x,0,20},PlotMarkers->Automatic]

PDF[BetaBinomialDistribution[α,β,n],x]

Cumulative distribution function:

DiscretePlot[Table[CDF[BetaBinomialDistribution[α,.3,20],x],{α,{0.5,1,3}}]//Evaluate,{x,0,20},ExtentSize->Right]

DiscretePlot[Table[CDF[BetaBinomialDistribution[1.2,β,20],x],{β,{0.5,2,3}}]//Evaluate,{x,0,20},ExtentSize->Right]

CDF[BetaBinomialDistribution[α,β,n],x]

Mean and variance:

Mean[BetaBinomialDistribution[α,β,n]]

Variance[BetaBinomialDistribution[α,β,n]]

OpenersExampleSection1(Spacer1)Scope  (7)

Generate a sample of pseudorandom numbers from a beta binomial distribution:

data=RandomVariate[BetaBinomialDistribution[2,3,50],10^4];

Compare its histogram to the PDF:

Show[
Histogram[data,{5},"PDF"],
DiscretePlot[PDF[BetaBinomialDistribution[2,3,50],x],{x,0,50},PlotStyle->PointSize[Medium]]]

Distribution parameters estimation:

sample=RandomVariate[BetaBinomialDistribution[.5,.3,30],10^3];

Assuming known n, estimate the distribution parameters from sample data:

edist=EstimatedDistribution[sample, BetaBinomialDistribution[α,β,30]]

Compare a density histogram of the sample with the PDF of the estimated distribution:

Show[Histogram[sample,{1},"PDF"],DiscretePlot[PDF[edist,x],{x,0,30},PlotStyle->PointSize[Medium]]]

Skewness:

Plot3D[Skewness[BetaBinomialDistribution[α, β, 100]],{α,0,20},{β,0,20},MeshFunctions->{#3&},MeshShading->ColorData[35,"ColorList"],AxesLabel->Automatic,ViewPoint->{15,-8,5}]

Skewness[BetaBinomialDistribution[α,β,n]]

Kurtosis:

Plot3D[Kurtosis[BetaBinomialDistribution[α, β,100]],{α,0,20},{β,0,20},MeshFunctions->{#3&},MeshShading->ColorData[35,"ColorList"],AxesLabel->Automatic,ViewPoint->{15,8,5}]

Kurtosis[BetaBinomialDistribution[α,β,n]]

Different moments with closed forms as functions of parameters:

FormulaGrid[list_,type_]:=Grid[Transpose[{list}],Alignment->{Left,Automatic},Background->{None,{{Lighter[Blend[Switch[type,M,{Blue,Green},CM,{Red,Orange},FM,{Magenta,Cyan},C,{Purple,Red}]],.8],White}}},Dividers->{None,{Darker[Gray,.6],{False},Darker[Gray,.6]}},ItemSize->30]

(RefLink[Moment, paclet:ref/Moment]):

FormulaGrid[Table[Moment[BetaBinomialDistribution[α,β,n],k]//FullSimplify,{k,3}],M]

(RefLink[CentralMoment, paclet:ref/CentralMoment]):

FormulaGrid[Table[CentralMoment[BetaBinomialDistribution[α,β,n],k]//Simplify,{k,3}],CM]

(RefLink[FactorialMoment, paclet:ref/FactorialMoment]):

FormulaGrid[Table[FactorialMoment[BetaBinomialDistribution[α,β,n],k]//Simplify,{k,3}],FM]

Closed form for symbolic order:

FactorialMoment[BetaBinomialDistribution[α,β,n],r]

(RefLink[Cumulant, paclet:ref/Cumulant]):

FormulaGrid[Table[Cumulant[BetaBinomialDistribution[α,β,n],k]//Simplify,{k,3}],C]

Hazard function:

DiscretePlot[Table[HazardFunction[BetaBinomialDistribution[α,.2,20],x],{α,{0.1,0.5,1}}]//Evaluate,{x,0,20},PlotMarkers->Automatic]

DiscretePlot[Table[HazardFunction[BetaBinomialDistribution[0.4,β,20],x],{β,{0.1,0.5,0.7}}]//Evaluate,{x,0,20},PlotMarkers->Automatic]

HazardFunction[BetaBinomialDistribution[α,β,n],x]

Quantile function:

𝒟=BetaBinomialDistribution[3,2,10];
points=Table[CDF[𝒟,x],{x,0,10}]//N;

DiscretePlot[Quantile[𝒟,p],{p,points},ExtentSize->Right,ExtentMarkers->{"Empty","Filled"}]

OpenersExampleSection2(Spacer1)Applications  (4)

The probability of more than 50 successes in 100 trials assuming a beta distribution on p:

1-CDF[BetaBinomialDistribution[4,5,100],50]

N[%]

Define a negative hypergeometric distribution:

NegativeHypergeometricDistribution[w_,wtot_,btot_]:=BetaBinomialDistribution[w,wtot-w+1,btot]

Find the probability that b black balls were sampled without replacement before a w(^th) white ball was drawn from an urn initially filled with (Subscript[k, b]) black and (Subscript[k, w]) white balls:

Probability[x==b,x\[Distributed]NegativeHypergeometricDistribution[w,(Subscript[k, w]),(Subscript[k, b])]]

Alternatively, compute the probability of drawing a white ball provided that there were b black balls in the previous b+w-1 samplings without replacement:

FullSimplify[%==Probability[y==b,y\[Distributed]HypergeometricDistribution[w+b-1,(Subscript[k, b]),(Subscript[k, w])+(Subscript[k, b])]]((((Subscript[k, w])-w+1))/((Subscript[k, w])+(Subscript[k, b])-w-b+1)),0<w<(Subscript[k, w])&&0<b<(Subscript[k, b])&&(w|b|(Subscript[k, w])|(Subscript[k, b]))∈Integers]

Define the Pólya distribution:

PolyaDistribution[p_,α_,n_]:=BetaBinomialDistribution[p/α,(1-p)/α,n]

PDF[PolyaDistribution[p,α,n],k]

Generate random numbers:

RandomVariate[PolyaDistribution[1/3,10/3,10],10]

Compute probabilities:

Probability[x≤5,x\[Distributed]PolyaDistribution[1/3,10/3,10]]

Define the Pólya–Eggenberg urn distribution:

PolyaEggenbergDistribution[w_,b_,c_,n_]:=BetaBinomialDistribution[w/c,b/c,n]

The distribution models an urn scheme. An urn contains w white balls and b black balls. When a ball is drawn it is returned to the urn together with c additional balls of the same color. The distribution gives the probability of drawing k white balls in n draws:

PDF[PolyaEggenbergDistribution[w,b,c,n],k]

Find the number of white balls in 10 draws:

RandomVariate[PolyaEggenbergDistribution[5,5,1,10],20]

OpenersExampleSection3(Spacer1)Properties & Relations  (5)

The probability of getting negative integers, integers beyond n, or noninteger numbers is zero:

PDF[BetaBinomialDistribution[α,β,n],π]

Relationships to other distributions:

(RefLink[DiscreteUniformDistribution, paclet:ref/DiscreteUniformDistribution]) is a special case of a beta binomial distribution:

PDF[BetaBinomialDistribution[1,1,99],x]//FullSimplify

PDF[DiscreteUniformDistribution[{0,99}],x]

%-%%//Simplify

For α=1 and β=2, the beta binomial distribution has a triangular shape but is not a discrete version of (RefLink[TriangularDistribution, paclet:ref/TriangularDistribution]):

DiscretePlot[{PDF[BetaBinomialDistribution[1,2,6],x],DifferenceDelta[CDF[TriangularDistribution[{0,7},0],x],x]}//Evaluate,{x,0,7},Filling->{1->{2}},PlotLegends->{"BetaBinomial","floor of Triangular"}]

PDF[BetaBinomialDistribution[1,2,6],x]//FullSimplify

FullSimplify[DifferenceDelta[CDF[TriangularDistribution[{0,7},0],x],x],x∈Integers]

Confirm that the preceding expression gives the PDF of (Floor[y]) where y follows a (RefLink[TriangularDistribution, paclet:ref/TriangularDistribution]):

Assuming[x∈Integers,FullSimplify[PiecewiseExpand[%==Probability[x≤y<x+1,y\[Distributed]TriangularDistribution[{0,7},0]]]]]

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) is a mixture of (RefLink[BinomialDistribution, paclet:ref/BinomialDistribution]) and (RefLink[BetaDistribution, paclet:ref/BetaDistribution]):

ParameterMixtureDistribution[BinomialDistribution[n,p],p\[Distributed]BetaDistribution[α,β]]

OpenersExampleSection4(Spacer1)Possible Issues  (3)

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) is not defined when α or β is non-positive:

Mean[BetaBinomialDistribution[-4,6.2,40]]

(RefLink[BetaBinomialDistribution, paclet:ref/BetaBinomialDistribution]) is not defined when n is not a positive integer:

Mean[BetaBinomialDistribution[5,6.2,-10]]

Substitution of invalid parameters into symbolic outputs gives results that are not meaningful:

Mean[BetaBinomialDistribution[α,β,n]]/.{α->3+I,β->7,n->23}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BinomialDistribution, paclet:ref/BinomialDistribution])  ▪  (RefLink[BetaDistribution, paclet:ref/BetaDistribution])  ▪  (RefLink[BetaNegativeBinomialDistribution, paclet:ref/BetaNegativeBinomialDistribution])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Discrete Distributions, paclet:tutorial/DiscreteDistributions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Discrete Univariate Distributions, paclet:guide/DiscreteUnivariateDistributions])}, {▪(RefLinkPlain[Distributions Used in Actuarial Science, paclet:guide/DistributionsUsedInActuarialScience])}, {▪(RefLinkPlain[Urn Model Distributions, paclet:guide/UrnModelDistributions])}, {▪(RefLinkPlain[Bounded Domain Distributions, paclet:guide/BoundedDomainDistributions])}})}})