<< distfun_gampdf Gamma distfun_gamstat >>

Distfun >> Distfun > Gamma > distfun_gamrnd

distfun_gamrnd

Gamma random numbers

Calling Sequence

R = distfun_gamrnd ( a , b )
R = distfun_gamrnd ( a , b , v )
R = distfun_gamrnd ( a , b , m , n )

Parameters

a :

a 1x1 or nxm matrix of doubles, the shape parameter, greater or equal to zero

b :

a 1x1 or nxm matrix of doubles, the scale parameter, greater or equal to zero

v :

a 1x2 or 2x1 matrix of doubles, the size of R

v(1) :

the number of rows of R

v(2) :

the number of columns of R

m :

a 1x1 matrix of floating point integers, the number of rows of R

n :

a 1x1 matrix of floating point integers, the number of columns of R

R:

a matrix of doubles, the random numbers.

Description

Generates random variablesfrom the Gamma distribution function.

Any scalar input argument is expanded to a matrix of doubles of the same size as the other input arguments.

As a side effect, it modifies the internal seed of the grand function.

Notice that b, the scale, is the inverse of the rate. Other computing languages (including R), use rate=1/b as the second parameter of the Gamma distribution.

Examples

// Set the seed so as to always get the same results.
distfun_seedset(1);

// Use R = distfun_gamrnd ( a , b )
distfun_gamrnd(1:6,(1:6)^-1)
distfun_gamrnd(1:6,1)
distfun_gamrnd(1,(1:6)^-1)

// Check mean and variance for R = distfun_gamrnd ( a , b )
N = 1000;
a = 1:6;
b = (1:6)^-1;
m = a .* b; // Expectation
v = m .* b; // Variance
for i = 1:N
computed(i,1:6) = distfun_gamrnd(a,b);
end
c = mean(computed(1:N,1:6) , "r" )
c = st_deviation(computed(1:N,1:6) , "r" )
e = sqrt(v)

// Check R = distfun_gamrnd ( a , b , v )
computed = distfun_gamrnd(2,1,[1 5])
computed = distfun_gamrnd(2,1,[3 2])

// Check mean and variance for R = distfun_gamrnd ( a , b )
N = 1000;
a = 2;
b = 3;
m = a .* b; // Expectation
v = m .* b; // Variance
computed = distfun_gamrnd(2,3,[1 N]);
c = mean(computed(1:N) )
c = st_deviation(computed(1:N) )
e = sqrt(v)

// Check R = distfun_gamrnd ( a , b , m , n )
computed = distfun_gamrnd([1 2 3;4 5 6],0.1,2,3)
computed = distfun_gamrnd(2,1,2,3)
computed = distfun_gamrnd(1,[1 2 3;4 5 6],2,3)

// Check mean and variance for R = distfun_gamrnd ( a , b )
N = 1000;
a = 2;
b = 3;
m = a .* b; // Expectation
v = m .* b; // Variance
computed = distfun_gamrnd(a,b,1,N);
c = mean(computed(1:N) )
c = st_deviation(computed(1:N) )
e = sqrt(v)

// Make a plot of the actual distribution of the numbers
scf();
a = 2;
b = 3;
data = distfun_gamrnd(a,b,1,1000);
histplot(10,data)
x = linspace(0,30,1000);
y = distfun_gampdf(x,a,b);
plot(x,y)

Authors

<< distfun_gampdf Gamma distfun_gamstat >>