Hauptinhalt

betastat

Beta mean and variance

Description

m = betastat(a,b) returns the mean of the beta distribution defined by the shape parameters a and b.

[m,v] = betastat(a,b) also returns the variance for the distribution.

example

Examples

collapse all

Compute the mean and variance of a beta distribution.

a = 1;
b = 2;
[m,v] = betastat(a,b)
m = 
0.3333
v = 
0.0556

Create two vectors a and b as the parameters of a beta distribution. Return the mean m and variance v of the beta distribution defined by a and b.

a = 1:6;
b = 2*a;
[m,v] = betastat(a,b)
m = 1×6

    0.3333    0.3333    0.3333    0.3333    0.3333    0.3333

v = 1×6

    0.0556    0.0317    0.0222    0.0171    0.0139    0.0117

If a or b is less than or equal to zero, betastat returns NaN.

a = [-1 2 0];
b = [3 -2 1];
[m,v] = betastat(a,b)
m = 1×3

   NaN   NaN   NaN

v = 1×3

   NaN   NaN   NaN

Input Arguments

collapse all

First shape parameter, specified as a positive scalar value or an array of positive scalar values. If both a and b are arrays, they must be the same size. If either a or b is a scalar, then betastat expands the scalar argument into a constant array of the same size as the other argument.

Data Types: single | double

Second shape parameter, specified as a positive scalar value or an array of positive scalar values. If both a and b are arrays, they must be the same size. If either a or b is a scalar, then betastat expands the scalar argument into a constant array of the same size as the other argument.

Data Types: single | double

Output Arguments

collapse all

Mean for the beta distribution, returned as a numeric scalar or an array of numeric scalars. m is the same size as a and b. Each element in m is the mean of the beta distribution specified by the corresponding elements in a and b. If a(i) or b(i) is less than or equal to zero, then m(i) is NaN.

The mean of the beta distribution with parameters a and b is a / (a + b).

Variance for the beta distribution, returned as a numeric scalar or an array of numeric scalars. v is the same size as a and b. Each element in v is the variance of the beta distribution specified by the corresponding elements in a and b. If a(i) or b(i) is less than or equal to zero, then v(i) is NaN.

The variance of the beta distribution with parameters a and b is

ab(a+b+1)(a+b)2

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a