2014-02-22 18:28:27 +00:00
|
|
|
# Derivative vector of the mean and standard deviation of GAL distribution
|
|
|
|
#
|
|
|
|
# Author: Francois Pelletier
|
|
|
|
#
|
|
|
|
# LGPL 3.0
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#' Derivative vector of the mean and standard deviation of GAL distribution
|
|
|
|
#' @param param Parameter vector
|
|
|
|
#' @param order 1 for mean, 2 for standard deviation
|
|
|
|
#' @param type Choose between "mu" or "kappa" parametrization
|
|
|
|
#' @param log Logical for log-parameters
|
|
|
|
#' @return A vector of the derivative of the analytical moment
|
2014-03-06 02:44:52 +00:00
|
|
|
#' @export dmGAL
|
2014-02-22 18:28:27 +00:00
|
|
|
#' @author Francois Pelletier
|
|
|
|
dmGAL <- function(param,order,type="mu",log=FALSE)
|
|
|
|
{ if(log)
|
|
|
|
{
|
|
|
|
eparam <- exp(param)
|
|
|
|
if(order==1)
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(1,0,eparam[4],eparam[3]))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
else if(type=="kappa")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(1,
|
2014-02-22 18:28:27 +00:00
|
|
|
-(1/2)*sqrt(2)*eparam[4]*(-1+eparam[3]^2)/eparam[3],
|
|
|
|
-(1/2)*eparam[4]*eparam[2]*sqrt(2)*(eparam[3]^2+1)/eparam[3]^2,
|
2014-03-06 02:44:52 +00:00
|
|
|
-(1/2)*sqrt(2)*eparam[2]*(-1+eparam[3]^2)/eparam[3]))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(order==2)
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(0,
|
2014-02-22 18:28:27 +00:00
|
|
|
eparam[4]*eparam[2]/sqrt(eparam[4]*eparam[2]^2+eparam[4]*eparam[3]^2),
|
|
|
|
eparam[4]*eparam[3]/sqrt(eparam[4]*eparam[2]^2+eparam[4]*eparam[3]^2),
|
2014-03-06 02:44:52 +00:00
|
|
|
(1/2)*(eparam[2]^2+eparam[3]^2)/sqrt(eparam[4]*eparam[2]^2+eparam[4]*eparam[3]^2)))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
else if(type=="kappa")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(0,
|
2014-02-22 18:28:27 +00:00
|
|
|
(1/2)*sqrt(2)*eparam[4]*eparam[2]*(eparam[3]^4+1)/(sqrt(eparam[4]*eparam[2]^2*(eparam[3]^4+1)/eparam[3]^2)*eparam[3]^2),
|
|
|
|
(1/2)*sqrt(2)*eparam[4]*eparam[2]^2*(eparam[3]^4-1)/(sqrt(eparam[4]*eparam[2]^2*(eparam[3]^4+1)/eparam[3]^2)*eparam[3]^3),
|
2014-03-06 02:44:52 +00:00
|
|
|
(1/4)*sqrt(2)*eparam[2]^2*(eparam[3]^4+1)/(sqrt(eparam[4]*eparam[2]^2*(eparam[3]^4+1)/eparam[3]^2)*eparam[3]^2)))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(order==1)
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(1,0,param[4],param[3]))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
else if(type=="kappa")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(1,
|
2014-02-22 18:28:27 +00:00
|
|
|
-(1/2)*sqrt(2)*param[4]*(-1+param[3]^2)/param[3],
|
|
|
|
-(1/2)*param[4]*param[2]*sqrt(2)*(param[3]^2+1)/param[3]^2,
|
2014-03-06 02:44:52 +00:00
|
|
|
-(1/2)*sqrt(2)*param[2]*(-1+param[3]^2)/param[3]))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(order==2)
|
|
|
|
{
|
|
|
|
if(type=="mu")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(0,
|
2014-02-22 18:28:27 +00:00
|
|
|
param[4]*param[2]/sqrt(param[4]*param[2]^2+param[4]*param[3]^2),
|
|
|
|
param[4]*param[3]/sqrt(param[4]*param[2]^2+param[4]*param[3]^2),
|
2014-03-06 02:44:52 +00:00
|
|
|
(1/2)*(param[2]^2+param[3]^2)/sqrt(param[4]*param[2]^2+param[4]*param[3]^2)))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
else if(type=="kappa")
|
|
|
|
{
|
2014-03-06 02:44:52 +00:00
|
|
|
return(c(0,
|
2014-02-22 18:28:27 +00:00
|
|
|
(1/2)*sqrt(2)*param[4]*param[2]*(param[3]^4+1)/(sqrt(param[4]*param[2]^2*(param[3]^4+1)/param[3]^2)*param[3]^2),
|
|
|
|
(1/2)*sqrt(2)*param[4]*param[2]^2*(param[3]^4-1)/(sqrt(param[4]*param[2]^2*(param[3]^4+1)/param[3]^2)*param[3]^3),
|
2014-03-06 02:44:52 +00:00
|
|
|
(1/4)*sqrt(2)*param[2]^2*(param[3]^4+1)/(sqrt(param[4]*param[2]^2*(param[3]^4+1)/param[3]^2)*param[3]^2)))
|
2014-02-22 18:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|