qmix: specification of the mixing variables Wi via quantile functions; see pgnvmix().
loc: see pnvmix().
scale: see pnvmix(); must be positive definite.
factor: (d,d) lower triangular matrix
such that factor %*% t(factor) equals scale. Internally used is factor.inv.
factor.inv: inverse of factor; if not provided, computed via solve(factor).
df: vector of length length(unique(groupings)) so that variable i has degrees-of-freedom df[groupings[i]]; all elements must be positive and can be Inf, in which case the corresponding marginal is normally distributed.
control: list specifying algorithm specific parameters; see get_set_param().
log: logical indicating whether the logarithmic density is to be computed.
verbose: see pnvmix().
...: additional arguments (for example, parameters) passed to the underlying mixing distribution when qmix is a character string or an element of qmix is a function.
Returns
dgnvmix() and dgStudent() return a numericn-vector with the computed density values and corresponding attributes "abs. error" and "rel. error"
(error estimates of the RQMC estimator) and "numiter" (number of iterations).
Details
Internally used is factor.inv, so factor and scale are not required to be provided (but allowed for consistency with other functions in the package).
dgStudent() is a wrapper of dgnvmix(, qmix = "inverse.gamma", df = df). If there is no grouping, the analytical formula for the density of a multivariate t distribution is used.
Internally, an adaptive randomized Quasi-Monte Carlo (RQMC) approach is used to estimate the log-density. It is an iterative algorithm that evaluates the integrand at a randomized Sobol' point-set (default) in each iteration until the pre-specified error tolerance control$dnvmix.reltol in the control argument is reached for the log-density. The attribute "numiter" gives the worst case number of such iterations needed (over all rows of x). Note that this function calls underlying C code.
Algorithm specific parameters (such as above mentioned control$dnvmix.reltol) can be passed as a list via the control argument, see get_set_param() for details and defaults.
If the error tolerance cannot be achieved within control$max.iter.rqmc
iterations and fun.eval[2] function evaluations, an additional warning is thrown if verbose=TRUE.
Author(s)
Erik Hintz, Marius Hofert and Christiane Lemieux
References
Hintz, E., Hofert, M. and Lemieux, C. (2020), Grouped Normal Variance Mixtures. Risks 8(4), 103.
Hintz, E., Hofert, M. and Lemieux, C. (2021), Normal variance mixtures: Distribution, density and parameter estimation. Computational Statistics and Data Analysis 157C, 107175.
Hintz, E., Hofert, M. and Lemieux, C. (2022), Multivariate Normal Variance Mixtures in : The Package nvmix. Journal of Statistical Software, tools:::Rd_expr_doi("10.18637/jss.v102.i02") .
McNeil, A. J., Frey, R. and Embrechts, P. (2015). Quantitative Risk Management: Concepts, Techniques, Tools. Princeton University Press.
See Also
rgnvmix(), pgnvmix(), get_set_param()
Examples
n <-100# sample size to generate evaluation points### 1. Inverse-gamma mixture## 1.1. Grouped t with mutliple dofd <-3# dimensionset.seed(157)A <- matrix(runif(d * d), ncol = d)P <- cov2cor(A %*% t(A))# random scale matrixdf <- c(1.1,2.4,4.9)# dof for margin igroupings <-1:d
x <- rgStudent(n, df = df, scale = P)# evaluation points for the density### Call 'dgnvmix' with 'qmix' a string:set.seed(12)dgt1 <- dgnvmix(x, qmix ="inverse.gamma", df = df, scale = P)### Version providing quantile functions of the mixing distributions as listqmix_ <-function(u, df)1/ qgamma(1-u, shape = df/2, rate = df/2)qmix <- list(function(u) qmix_(u, df = df[1]),function(u) qmix_(u, df = df[2]),function(u) qmix_(u, df = df[3]))set.seed(12)dgt2 <- dgnvmix(x, groupings = groupings, qmix = qmix, scale = P)### Similar, but using ellipsis argument:qmix <- list(function(u, df1) qmix_(u, df1),function(u, df2) qmix_(u, df2),function(u, df3) qmix_(u, df3))set.seed(12)dgt3 <- dgnvmix(x, groupings = groupings, qmix = qmix, scale = P, df1 = df[1], df2 = df[2], df3 = df[3])### Using the wrapper 'dgStudent()'set.seed(12)dgt4 <- dgStudent(x, groupings = groupings, df = df, scale = P)stopifnot(all.equal(dgt1, dgt2, tol =1e-5, check.attributes =FALSE), all.equal(dgt1, dgt3, tol =1e-5, check.attributes =FALSE), all.equal(dgt1, dgt4, tol =1e-5, check.attributes =FALSE))## 1.2 Classical multivariate tdf <-2.4groupings <- rep(1, d)# same df for all componentsx <- rStudent(n, scale = P, df = df)# evaluation points for the densitydt1 <- dStudent(x, scale = P, df = df, log =TRUE)# uses analytical formula## If 'qmix' provided as string and no grouping, dgnvmix() uses analytical formuladt2 <- dgnvmix(x, qmix ="inverse.gamma", groupings = groupings, df = df, scale = P, log =TRUE)stopifnot(all.equal(dt1, dt2))## Provide 'qmix' as a function to force estimation in 'dgnvmix()'dt3 <- dgnvmix(x, qmix = qmix_, groupings = groupings, df = df, scale = P, log =TRUE)stopifnot(all.equal(dt1, dt3, tol =5e-4, check.attributes =FALSE))### 2. More complicated mixutre## Let W1 ~ IG(1, 1), W2 = 1, W3 ~ Exp(1), W4 ~ Par(2, 1), W5 = W1, all comonotone## => X1 ~ t_2; X2 ~ normal; X3 ~ Exp-mixture; X4 ~ Par-mixture; X5 ~ t_2d <-5set.seed(157)A <- matrix(runif(d * d), ncol = d)P <- cov2cor(A %*% t(A))b <-3* runif(d)* sqrt(d)# random upper limitgroupings <- c(1,2,3,4,1)# since W_5 = W_1qmix <- list(function(u) qmix_(u, df =2),function(u) rep(1, length(u)), list("exp", rate=1),function(u)(1-u)^(-1/2))# length 4 (# of groups)x <- rgnvmix(n, groupings = groupings, qmix = qmix, scale = P)dg <- dgnvmix(x, groupings = groupings, qmix = qmix, scale = P, log =TRUE)