Title: | Computational Tools for the IG and IGL Copula Families |
---|---|
Description: | Compute distributional quantities for an Integrated Gamma (IG) or Integrated Gamma Limit (IGL) copula, such as a cdf and density. Compute corresponding conditional quantities such as the cdf and quantiles. Generate data from an IG or IGL copula. See the vignette for formulas, or for a derivation, see Coia, V (2017) "Forecasting of Nonlinear Extreme Quantiles Using Copula Models." PhD Dissertation, The University of British Columbia. |
Authors: | Vincenzo Coia [aut, cre], Harry Joe [aut] |
Maintainer: | Vincenzo Coia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.2 |
Built: | 2025-03-01 05:37:51 UTC |
Source: | https://github.com/vincenzocoia/igcop |
As recommended in the "Compiled Code" chapter of the book "R packages" (Version 2) by Hadley Wickham and Jenny Bryan.
.onUnload(libpath)
.onUnload(libpath)
libpath |
Argument |
Internal data used in the test scripts. .u
and .v
are vectors of
matching length containing values between 0 and 1 and reasonably cover
the unit square. .cpar
is a list of IG copula parameter pairs
c(theta, alpha)
, and .theta
and .alpha
are the corresponding
(unique) individual values.
.u .v .cpar .theta .alpha
.u .v .cpar .theta .alpha
Everything is a numeric vector, except .cpar
, which is a list
of bivariate numeric vectors. .u
and .v
are of matching
length; the rest are not intended to have matching lengths.
An object of class numeric
of length 17.
An object of class list
of length 25.
An object of class numeric
of length 14.
An object of class numeric
of length 11.
Ensures input values are non-negative.
check_alpha(alpha) check_theta(theta)
check_alpha(alpha) check_theta(theta)
alpha |
Values of alpha to check. |
theta |
Values of theta to check. |
An error if any theta or alpha is negative;
an invisible value otherwise. NA
values do not throw an error.
The density function, 1|2 conditional cdf,
and 1|2 conditional quantile function of the IG
copula family. Inputs
need to be vectors of the same length.
These functions are called by the R functions of the
same name, without the _vec
suffix.
dig_vec(u, v, theta, alpha) pcondig12_vec(u, v, theta, alpha) qcondig12_vec(p, v, theta, alpha)
dig_vec(u, v, theta, alpha) pcondig12_vec(u, v, theta, alpha) qcondig12_vec(p, v, theta, alpha)
u , v
|
Copula arguments. Vector of values between 0 and 1. |
theta , alpha
|
IG copula parameters. Vector of positive values. |
p |
Function inverse argument. Vector of values between 0 and 1. |
The qcondig12()
function needs its own Newton
Raphson algorithm. It also needs access to some version
of pcondig12()
and dig()
. So, these three functions
are coded up in C++, each with a scalar and vector pair
of functions.
If calling these functions manually, make sure each input are vectors of a common length.
dig()
, pcondig12()
, and qcondig12()
;
and igl_gen_vec()
and family.
When used within a (encapsulating) function, formals_to
recycles the inputs of the encapsulating function so that
they are vectors of the same length, and then sends these
updated arguments to some specified function.
formals_to(.fn)
formals_to(.fn)
.fn |
The function you want to send the recycled arguments to. |
The function .fn
evaluated with the arguments given in
the encapsulating function.
Compute distributional quantities for an Integrated Gamma (IG) or IG Limit (IGL) copula, such as a cdf and density, along with conditional quantities such as the cdf, quantiles, and densities. Generate data from a copula.
Access copula quantities by starting with the p
, d
, q
, or r
prefixes, followed by the copula name – either ig
or igl
, or
their conditional versions, condig
or condigl
.
Maintainer: Vincenzo Coia [email protected]
Authors:
Harry Joe
These are the psi, H, and kappa functions
of the IG and IGL copula families, but with inputs
needing to be vectors of the same length.
These functions are called by the R functions of the
same name, without the _vec
suffix.
igl_gen_vec(x, alpha) igl_gen_D_vec(x, alpha) igl_gen_inv_vec(p, alpha) igl_kappa_vec(x, alpha) igl_kappa_D_vec(x, alpha) igl_kappa_inv_vec(p, alpha) interp_gen_vec(x, eta, alpha) interp_gen_inv_vec(p, eta, alpha) interp_kappa_vec(x, eta, alpha) interp_kappa_inv_vec(p, eta, alpha)
igl_gen_vec(x, alpha) igl_gen_D_vec(x, alpha) igl_gen_inv_vec(p, alpha) igl_kappa_vec(x, alpha) igl_kappa_D_vec(x, alpha) igl_kappa_inv_vec(p, alpha) interp_gen_vec(x, eta, alpha) interp_gen_inv_vec(p, eta, alpha) interp_kappa_vec(x, eta, alpha) interp_kappa_inv_vec(p, eta, alpha)
x |
Function argument. Vector of non-negative values. |
p |
Function inverse argument. Vector of values between 0 and 1. |
eta , alpha
|
Function parameters. Vector of positive values. |
If calling this function manually, make sure each input are vectors of a common length.
igl_gen()
and family;
dig_vec()
, pcondig12_vec()
, and qcondig12_vec()
.
These are the psi, H, and kappa functions of the IG and IGL copula families.
interp_gen_inv(p, eta, alpha) interp_kappa(x, eta, alpha) interp_kappa_inv(p, eta, alpha) interp_gen(x, eta, alpha) igl_kappa(x, alpha) igl_kappa_D(x, alpha) igl_kappa_inv(p, alpha) igl_gen(x, alpha) igl_gen_D(x, alpha) igl_gen_inv(p, alpha)
interp_gen_inv(p, eta, alpha) interp_kappa(x, eta, alpha) interp_kappa_inv(p, eta, alpha) interp_gen(x, eta, alpha) igl_kappa(x, alpha) igl_kappa_D(x, alpha) igl_kappa_inv(p, alpha) igl_gen(x, alpha) igl_gen_D(x, alpha) igl_gen_inv(p, alpha)
p |
Function inverse argument. Vector of values between 0 and 1. |
eta , alpha
|
Function parameters. Vector of positive values. |
x |
Function argument. Vector of non-negative values. |
Kappa function and its relatives have prefix igl_kappa
;
Psi function and its relatives have prefix igl_gen
;
Interpolating function H with either kappa or psi has
igl
prefix replaced with interp
. Relatives of these functions:
suffix inv
indicates inverse; suffix D
represents function
derivative, and D1
derivative with respect to the first argument.
. Suffix _vec
indicates that the entries must be vectors of
the same length; _single
means entries must be
scalars.
The function values, as a vector.
Inputs must be recyclable via vctrs::vec_recycle_common()
.
Functions related to the IG copula family, denoted by 'ig'
.
pcondig21(v, u, theta, alpha) qcondig21(p, u, theta, alpha) qcondig(p, u, theta, alpha) pcondig(v, u, theta, alpha) pcondig12(u, v, theta, alpha) qcondig12(p, v, theta, alpha) dig(u, v, theta, alpha) logdig(u, v, theta, alpha) pig(u, v, theta, alpha) rig(n, theta, alpha)
pcondig21(v, u, theta, alpha) qcondig21(p, u, theta, alpha) qcondig(p, u, theta, alpha) pcondig(v, u, theta, alpha) pcondig12(u, v, theta, alpha) qcondig12(p, v, theta, alpha) dig(u, v, theta, alpha) logdig(u, v, theta, alpha) pig(u, v, theta, alpha) rig(n, theta, alpha)
u , v
|
Vectors of values between 0 and 1 representing values of the first and second copula variables. |
theta |
Parameter of the IG copula family. Vectorized; >0. |
alpha |
Parameter of the IG copula family. Vectorized; >0. |
p |
Vector of quantile levels between 0 and 1 to evaluate a quantile function at. |
n |
Positive integer. Number of observations to randomly draw. |
Numeric vector of length equal to the length of the input vector(s).
Inputting two vectors greater than length 1 is allowed, if they're
the same length.
Also, qcondig21
and pcondig21
are the same as
qcondig
and pcondig
– they're the distributions of
variable 2 given 1.
u <- runif(10) v <- runif(10) pig(u, v, theta = 5, alpha = 1) dig(u, v, theta = 2, alpha = 2) logdig(u, v, theta = 2, alpha = 2) pcondig21(v, u, theta = 3, alpha = 6) qcondig21(v, u, theta = 3, alpha = 6) pcondig12(u, v, theta = 3, alpha = 6) qcondig12(u, v, theta = 3, alpha = 6) rig(10, theta = 3, alpha = 3) # log density available for extra precision log(dig(0.1, 0.1, 2.5, 12.3)) == logdig(0.1, 0.1, 2.5, 12.3)
u <- runif(10) v <- runif(10) pig(u, v, theta = 5, alpha = 1) dig(u, v, theta = 2, alpha = 2) logdig(u, v, theta = 2, alpha = 2) pcondig21(v, u, theta = 3, alpha = 6) qcondig21(v, u, theta = 3, alpha = 6) pcondig12(u, v, theta = 3, alpha = 6) qcondig12(u, v, theta = 3, alpha = 6) rig(10, theta = 3, alpha = 3) # log density available for extra precision log(dig(0.1, 0.1, 2.5, 12.3)) == logdig(0.1, 0.1, 2.5, 12.3)
Functions related to the IGL copula family, denoted by 'igl'
.
qcondigl(p, u, alpha) pcondigl(v, u, alpha) qcondigl21(p, u, alpha) pcondigl21(v, u, alpha) pcondigl12(u, v, alpha) qcondigl12(p, v, alpha) digl(u, v, alpha) pigl(u, v, alpha) rigl(n, alpha) logdigl(u, v, alpha)
qcondigl(p, u, alpha) pcondigl(v, u, alpha) qcondigl21(p, u, alpha) pcondigl21(v, u, alpha) pcondigl12(u, v, alpha) qcondigl12(p, v, alpha) digl(u, v, alpha) pigl(u, v, alpha) rigl(n, alpha) logdigl(u, v, alpha)
p |
Vector of quantile levels between 0 and 1 to evaluate a quantile function at. |
u , v
|
Vectors of values between 0 and 1 representing values of the first and second copula variables. |
alpha |
Single numeric >0; corresponds to parameter |
n |
Positive integer. Number of observations to randomly draw. |
Numeric vector of length equal to the length of the input vector(s).
Inputting two vectors greater than length 1 is allowed, if they're
the same length.
Also, qcondigl21
and pcondigl21
are the same as
qcondigl
and pcondigl
– they are the distributions of
variable 2 given 1.
set.seed(1) u <- runif(10) v <- runif(10) pigl(u, v, alpha = 1) digl(u, v, alpha = 2) logdigl(u, v, alpha = 0.4) pcondigl21(v, u, alpha = 6) qcondigl21(v, u, alpha = 6) pcondigl12(u, v, alpha = 6) qcondigl12(u, v, alpha = 6) rigl(10, alpha = 3)
set.seed(1) u <- runif(10) v <- runif(10) pigl(u, v, alpha = 1) digl(u, v, alpha = 2) logdigl(u, v, alpha = 0.4) pcondigl21(v, u, alpha = 6) qcondigl21(v, u, alpha = 6) pcondigl12(u, v, alpha = 6) qcondigl12(u, v, alpha = 6) rigl(10, alpha = 3)