2014-01-04 18:02:45 +00:00
|
|
|
# Random number generator for the GAL distribution
|
|
|
|
#
|
|
|
|
# Author: Francois Pelletier
|
|
|
|
#
|
|
|
|
# LGPL 3.0
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#' Random number generator for the GAL distribution
|
|
|
|
#' @param n number of observations
|
|
|
|
#' @param param Parameter vector
|
|
|
|
#' @param type Choose between "mu" or "kappa" parametrization
|
|
|
|
#' @param log Logical for log-parameters
|
|
|
|
#' @return A vector of random numbers
|
2014-03-06 02:44:52 +00:00
|
|
|
#' @export rGAL
|
2014-01-04 18:02:45 +00:00
|
|
|
#' @author Francois Pelletier
|
|
|
|
rGAL <- function(n,param,type="mu",log=FALSE)
|
|
|
|
{
|
|
|
|
testparGAL(param,type,log)
|
|
|
|
if(log)
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(rGAL(n,changetypeGAL(param,type="mu",target="kappa"),type="kappa",log=log))
|
2014-01-04 18:02:45 +00:00
|
|
|
}
|
|
|
|
if(type=="kappa")
|
|
|
|
{
|
|
|
|
# simulation de deux variables gamma
|
|
|
|
rgamma1 <- rgamma(n, shape = exp(param[4]), scale = 1/exp(param[3]))
|
|
|
|
rgamma2 <- rgamma(n, shape = exp(param[4]), scale = exp(param[3]))
|
|
|
|
|
|
|
|
# simulation de la variable GAL
|
2014-03-06 02:44:52 +00:00
|
|
|
return(exp(param[1]) + exp(param[2])/sqrt(2)*(rgamma1 - rgamma2))
|
2014-01-04 18:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(rGAL(n,changetypeGAL(param,type="mu",target="kappa"),type="kappa",log=log))
|
2014-01-04 18:02:45 +00:00
|
|
|
}
|
|
|
|
if(type=="kappa")
|
|
|
|
{
|
|
|
|
# simulation de deux variables gamma
|
|
|
|
rgamma1 <- rgamma(n, shape = param[4], scale = 1/param[3])
|
|
|
|
rgamma2 <- rgamma(n, shape = param[4], scale = param[3])
|
|
|
|
|
|
|
|
# simulation de la variable GAL
|
2014-03-06 02:44:52 +00:00
|
|
|
return(param[1] + param[2]/sqrt(2)*(rgamma1 - rgamma2))
|
2014-01-04 18:02:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|