Description Usage Arguments Details Value Author(s) References Examples
Simulate random number from a truncated Gamma distribution.
1 |
n |
int, optional |
A |
double, optional |
B |
double, optional |
range |
array_like, optional |
It provide a way to simulate from a truncated Gamma distribution with given pameters A,B and range range. This will be used during the posterior sampling in th Gibbs sampler.
rgammatr
returns the simulated value of the distribution:
u |
double |
L. Rimella, lorenzo.rimella@hotmail.it
[1] Y. Wang, A. Canale, D. Dunson.
"Scalable Geometric Density Estimation" (2016).
The implementation of rgammatr is inspired to the Matlab
implementation of gamrndtruncated by Ye Wang.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #Simulate a truncated Gamma with parameters 1,2 in the range
#1,5.
#Set the range:
range<- c(1,5)
#Simulate the truncated Gamma
set.seed(123)
vars1<-rgammatr(1000,1,2,range)
#Look at the histogram
hist(vars1,freq=FALSE,ylim=c(0,2),xlim = c(0,5))
lines(density(vars1))
#Compare with a non truncated Gamma
set.seed(123)
vars2<-rgamma(1000,1,2)
#Compare the two results
lines(density(vars2),col='red')
#Observation: simulate without range is equivalent to simulate from
#rgamma(1000,1,2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.