diff --git a/R/cfGAL.R b/R/cfGAL.R index d6ef641..43d2c13 100644 --- a/R/cfGAL.R +++ b/R/cfGAL.R @@ -15,6 +15,7 @@ #' @author Francois Pelletier cfGAL <- function(u,param,type="mu",log=FALSE) { + testparGAL(param,type,log) if(log) { if(type=="mu") diff --git a/R/changetypeGAL.R b/R/changetypeGAL.R index 7ba6131..fbbde25 100644 --- a/R/changetypeGAL.R +++ b/R/changetypeGAL.R @@ -15,6 +15,7 @@ #' @author Francois Pelletier changetypeGAL <- function(param,type="mu",target="kappa",log=FALSE) { + testparGAL(param,type,log) if(log) { if(type=="mu" && target=="kappa") diff --git a/R/dGAL.r b/R/dGAL.r index eecd280..03201f5 100644 --- a/R/dGAL.r +++ b/R/dGAL.r @@ -8,6 +8,7 @@ #' @author Francois Pelletier dGAL <- function(x,param,type="mu",log=FALSE) { + testparGAL(param,type,log) if(log) { if(type=="mu") diff --git a/R/fgmGAL.R b/R/fgmGAL.R index 0d4eb94..df1522a 100644 --- a/R/fgmGAL.R +++ b/R/fgmGAL.R @@ -15,6 +15,7 @@ #' @author Francois Pelletier mgfGAL <- function(u,param,type="mu",log=FALSE) { + testparGAL(param,type,log) if(log) { if(type=="mu") diff --git a/R/rGAL.R b/R/rGAL.R new file mode 100644 index 0000000..e530e85 --- /dev/null +++ b/R/rGAL.R @@ -0,0 +1,52 @@ +# 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 +#' +#' @author Francois Pelletier +rGAL <- function(n,param,type="mu",log=FALSE) +{ + testparGAL(param,type,log) + if(log) + { + if(type=="mu") + { + rGAL(n,changetypeGAL(param,type="mu",target="kappa"),type="kappa",log=log) + } + 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 + exp(param[1]) + exp(param[2])/sqrt(2)*(rgamma1 - rgamma2) + } + } + else + { + if(type=="mu") + { + rGAL(n,changetypeGAL(param,type="mu",target="kappa"),type="kappa",log=log) + } + 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 + param[1] + param[2]/sqrt(2)*(rgamma1 - rgamma2) + } + } +} diff --git a/R/testparGAL.R b/R/testparGAL.R new file mode 100644 index 0000000..3065434 --- /dev/null +++ b/R/testparGAL.R @@ -0,0 +1,53 @@ +# Check for the validity of a parameter vector. Stop at error. +# +# Author: Francois Pelletier +# +# LGPL 3.0 +############################################################################### + + +#' Check for the validity of a parameter vector. Stop at error. +#' @param param Parameter vector +#' @param type Choose between "mu" or "kappa" parametrization +#' @param log Logical for log-parameters +#' @return logical +#' +#' @author Francois Pelletier +testparGAL <- function(param,type="mu",log=FALSE) +{ + if(log) + { + if(type=="mu") + { + if(exp(param[2])<=0) + stop("param 2 must be positive") + if(exp(param[4])<=0) + stop("param 4 must be positive") + } + if(type=="kappa") + { + if(exp(param[2])<=0) + stop("param 2 must be positive") + if(exp(param[4])<=0) + stop("param 4 must be positive") + } + } + else + { + if(type=="mu") + { + if(param[2]<=0) + stop("param 2 must be positive") + if(param[4]<=0) + stop("param 4 must be positive") + } + if(type=="kappa") + { + if(param[2]<=0) + stop("param 2 must be positive") + if(param[4]<=0) + stop("param 4 must be positive") + } + } + TRUE +} diff --git a/man/rGAL.Rd b/man/rGAL.Rd new file mode 100644 index 0000000..cfd2211 --- /dev/null +++ b/man/rGAL.Rd @@ -0,0 +1,26 @@ +\name{rGAL} +\alias{rGAL} +\title{Random number generator for the GAL distribution} +\usage{ +rGAL(n, param, type = "mu", log = FALSE) +} +\arguments{ + \item{n}{number of observations} + + \item{param}{Parameter vector} + + \item{type}{Choose between "mu" or "kappa" + parametrization} + + \item{log}{Logical for log-parameters} +} +\value{ +A vector of random numbers +} +\description{ +Random number generator for the GAL distribution +} +\author{ +Francois Pelletier +} + diff --git a/man/testparGAL.Rd b/man/testparGAL.Rd new file mode 100644 index 0000000..7abde38 --- /dev/null +++ b/man/testparGAL.Rd @@ -0,0 +1,25 @@ +\name{testparGAL} +\alias{testparGAL} +\title{Check for the validity of a parameter vector. Stop at error.} +\usage{ +testparGAL(param, type = "mu", log = FALSE) +} +\arguments{ + \item{param}{Parameter vector} + + \item{type}{Choose between "mu" or "kappa" + parametrization} + + \item{log}{Logical for log-parameters} +} +\value{ +logical +} +\description{ +Check for the validity of a parameter vector. Stop at +error. +} +\author{ +Francois Pelletier +} +