Drawing from R Gamma Distribution in Octave

Description

This function wraps a call to the standard Octave function randg, which is redefined by RcppOctave to call the R base function rgamma. This enables to exactly reproduce stochastic computations in R and Octave, without changing the original Octave/Matlab code. See o_runif for more details.

Usage

o_rgamma(n, p = n, shape = 1, scale = 1)

Arguments

shape
Mean of the Gamma distribution
scale
Scale of the Gamma distribution
n
number of output rows
p
number of output columns (default to n)

Octave Documentation for <em>randg</em>

USAGE: E = randg(shape, [n, p, scale])

Generates Gamma random variates as R function 'rgamma' -- using the current RNG from R.

Possible calls:
randg(shape)				returns a single draw from G(shape, 1)
randg(shape, n) 			returns n*n matrix with uncorrelated G(shape, 1) deviates drawn in columns
randg(shape, n, p) 		returns n*p matrix with uncorrelated G(shape, 1) deviates drawn in columns
randg(shape, n, p, scale) 	returns n*p matrix with uncorrelated G(shape, scale) deviates drawn in columns


NOTE:
This function substitutes Octave original function in calls from RcppOctave

[Generated from Octave-3.6.4 on 2014-05-21 11:08:20 ]

Examples


## Don't show: 
# roxygen generated flag
options(R_CHECK_RUNNING_EXAMPLES_=TRUE)
## End Don't show

# Draw random gamma values (in vector form)
set.seed(123)
o_rgamma(1)
## [1] 0.1822
o_rgamma(1, 10)
##  [1] 1.69575 1.62088 2.44810 0.87903 2.66732 3.88593 0.96365 0.68263
##  [9] 0.03336 0.91400

# Draw random gamma values (in matrix form)
set.seed(123)
o_rgamma(2)
##        [,1]  [,2]
## [1,] 0.1822 1.621
## [2,] 1.6958 2.448
o_rgamma(2, 5)
##       [,1]   [,2]    [,3]   [,4]   [,5]
## [1,] 0.879 3.8859 0.68263 0.9140 0.2912
## [2,] 2.667 0.9636 0.03336 0.2522 0.1174

# Draw random gamma values with shape and scale parameters
o_rgamma(1, 5, shape=2)
## [1] 3.0978 1.3272 1.6937 0.4299 1.1336
o_rgamma(1, 10, scale=0.5)
##  [1] 0.15656 0.20634 0.62485 0.55275 0.48419 0.22859 0.36157 0.00469
##  [9] 0.18189 0.19540

See also

rgamma Other orandom: o_rexp, o_rnorm, o_runif