tools_stats namespace
Utilities for statistical analysis.
Classes
- class BoxCovering
- Covers the unit hypercube with boxes and assigns each sample to a box.
- struct SmoothingWorkspace
Functions
-
auto simulate_uniform(const size_
t& n, const size_ t& d, bool qrng, std::vector<int> seeds) -> Eigen::MatrixXd - Simulates from the multivariate uniform distribution.
-
auto simulate_normal(const size_
t& n, const size_ t& d, bool qrng, std::vector<int> seeds) -> Eigen::MatrixXd - Simulates from independendent normals.
- auto pseudo_obs_1d_impl(std::vector<double>&& xvec, const std::string& ties_method, const std::vector<double>& weights, const std::vector<int>& seeds, double scale) -> Eigen::VectorXd
- auto to_pseudo_obs(Eigen::MatrixXd x, const std::string& ties_method, const Eigen::VectorXd& weights, std::vector<int> seeds, double scale) -> Eigen::MatrixXd
- Applies the empirical probability integral transform to a data matrix.
- auto to_pseudo_obs_1d(Eigen::VectorXd x, const std::string& ties_method, const Eigen::VectorXd& weights, std::vector<int> seeds, double scale) -> Eigen::VectorXd
- Applies the empirical probability integral transform to a data vector.
- auto default_soft_scale() -> double
- The
scaleofto_for copula data: the square root of the machine epsilon.pseudo_ obs() - auto swaps_pair(const Eigen::MatrixXd& u) -> bool
- Whether a pair is in the order of its own values.
- auto pair_soft_pseudo_obs(const Eigen::MatrixXd& data, const Eigen::VectorXd& weights, double scale, const std::vector<int>& seeds) -> Eigen::MatrixXd
- Pseudo-observations of a pair, as a kernel pair copula ranks it.
-
auto mix64(uint64_
t z) -> uint64_ t -
auto find_latent_sample(const Eigen::MatrixXd& u,
double b,
size_
t niter) -> Eigen::MatrixXd - Recovers a continuous latent sample from a sample of a discrete copula.
-
auto next_power_of_two(size_
t n) -> size_ t -
auto win(const Eigen::VectorXd& x,
size_
t wl, SmoothingWorkspace& ws) -> Eigen::VectorXd - window smoother
-
auto cef(const Eigen::VectorXd& x,
const Eigen::Matrix<size_
t, Eigen::Dynamic, 1>& ind, const Eigen::Matrix<size_ t, Eigen::Dynamic, 1>& ranks, size_ t wl, SmoothingWorkspace& ws) -> Eigen::VectorXd - helper routine for ace (In R, this would be win(x[ind], wl)[ranks])
-
auto ace(const Eigen::MatrixXd& data,
const Eigen::VectorXd& weights = Eigen::VectorXd(),
size_
t wl = 0, size_ t outer_iter_max = 100, size_ t inner_iter_max = 10, double outer_abs_tol = 2e-15, double inner_abs_tol = 1e-4) -> Eigen::MatrixXd - alternating conditional expectation algorithm
-
auto ghalton(const size_
t& n, const size_ t& d, const std::vector<int>& seeds) -> Eigen::MatrixXd - Simulates from the multivariate Generalized Halton Sequence.
-
auto sobol(const size_
t& n, const size_ t& d, const std::vector<int>& seeds) -> Eigen::MatrixXd - Simulates from the multivariate Sobol sequence.
- auto pbvt(const Eigen::MatrixXd& z, int nu, double rho) -> Eigen::VectorXd
- Computes bivariate t probabilities.
- auto pbvnorm(const Eigen::MatrixXd& z, double rho) -> Eigen::VectorXd
- Compute bivariate normal probabilities.
- auto dnorm(const Eigen::MatrixXd& x) -> Eigen::MatrixXd
- Density function of the Standard normal distribution.
- auto pnorm(const Eigen::MatrixXd& x) -> Eigen::MatrixXd
- Distribution function of the Standard normal distribution.
- auto qnorm(const Eigen::MatrixXd& x) -> Eigen::MatrixXd
- Quantile function of the Standard normal distribution.
- auto dt(const Eigen::MatrixXd& x, double nu) -> Eigen::MatrixXd
- Density function of the Student t distribution.
- auto pt(const Eigen::MatrixXd& x, double nu) -> Eigen::MatrixXd
- Distribution function of the Student t distribution.
- auto qt(const Eigen::MatrixXd& x, double nu) -> Eigen::MatrixXd
- Quantile function of the Student t distribution.
Dependence measures
- auto pairwise_mcor(const Eigen::MatrixXd& x, const Eigen::VectorXd& weights) -> double
- auto pairwise_cxi(const Eigen::MatrixXd& x, const Eigen::VectorXd& weights) -> double
- calculates the pairwise symmetrized Chatterjee's xi.
Function documentation
Eigen::MatrixXd vinecopulib:: tools_stats:: simulate_uniform(const size_ t& n,
const size_ t& d,
bool qrng,
std::vector<int> seeds)
Simulates from the multivariate uniform distribution.
| Parameters | |
|---|---|
| n | Number of observations. |
| d | Dimension. |
| qrng | If true, quasi-numbers are generated. |
| seeds | Seeds of the random number generator; if empty (default), the random number generator is seeded randomly. Given seeds draw the same numbers on every platform. |
| Returns | An matrix of independent random variables, on a grid of . |
If qrng = TRUE, generalized Halton sequences (see ghalton()) are used for and Sobol sequences otherwise (see sobol()).
Eigen::MatrixXd vinecopulib:: tools_stats:: simulate_normal(const size_ t& n,
const size_ t& d,
bool qrng,
std::vector<int> seeds)
Simulates from independendent normals.
| Parameters | |
|---|---|
| n | Number of observations. |
| d | Dimension. |
| qrng | If true, quasi-numbers are generated. |
| seeds | Seeds of the random number generator; if empty (default), the random number generator is seeded randomly. //! |
| Returns | An matrix of independent random variables. |
Eigen::MatrixXd vinecopulib:: tools_stats:: to_pseudo_obs(Eigen::MatrixXd x,
const std::string& ties_method,
const Eigen::VectorXd& weights,
std::vector<int> seeds,
double scale)
Applies the empirical probability integral transform to a data matrix.
| Parameters | |
|---|---|
| x | A matrix of real numbers. |
| ties_method | Indicates how to treat ties; same as in R, see https:/ |
| weights | Vector of weights for the observations. |
| seeds | Seeds for the random number generator, used only when ties_method = "random"; each column appends its index to them. |
| scale | Distance below which distinct values rank partly as tied, in the units of x; zero (default) ranks by value. |
| Returns | Pseudo-observations of the copula, i.e. (column-wise). |
Gives pseudo-observations from the copula by applying the empirical distribution function (scaled by ) to each margin/column.
Eigen::VectorXd vinecopulib:: tools_stats:: to_pseudo_obs_1d(Eigen::VectorXd x,
const std::string& ties_method,
const Eigen::VectorXd& weights,
std::vector<int> seeds,
double scale)
Applies the empirical probability integral transform to a data vector.
| Parameters | |
|---|---|
| x | A vector of real numbers. |
| ties_method | Indicates how to treat ties; same as in R, see https:/ |
| weights | Vector of weights for the observations. |
| seeds | Seeds for the random number generator, used only when ties_method = "random". |
| scale | As for to_. |
| Returns | Pseudo-observations of the copula, i.e. . |
Gives pseudo-observations from the copula by applying the empirical distribution function (scaled by ) to each margin/column.
double vinecopulib:: tools_stats:: default_soft_scale()
The scale of to_ for copula data: the square root of the machine epsilon.
bool vinecopulib:: tools_stats:: swaps_pair(const Eigen::MatrixXd& u)
Whether a pair is in the order of its own values.
| Parameters | |
|---|---|
| u | A pair, [u1, u2] or [u1, u2, u1^-, u2^-]. |
| Returns | Whether the columns have to be swapped. |
At the first row whose two values (or, with four columns, left limits) differ, the smaller comes first.
Eigen::MatrixXd vinecopulib:: tools_stats:: pair_soft_pseudo_obs(const Eigen::MatrixXd& data,
const Eigen::VectorXd& weights,
double scale,
const std::vector<int>& seeds)
Pseudo-observations of a pair, as a kernel pair copula ranks it.
| Parameters | |
|---|---|
| data | The pair, [u1, u2] or [u1, u2, u1^-, u2^-]. |
| weights | Optional weights, one per observation. |
| scale | As for to_. |
| seeds | Seeds of the tie order. |
| Returns | An matrix of pseudo-observations. |
to_pseudo_obs(pair, "random", weights, seeds, scale) of the first two columns, ranked in the pair's own order (swaps_).
Eigen::MatrixXd vinecopulib:: tools_stats:: find_latent_sample(const Eigen::MatrixXd& u,
double b,
size_ t niter)
Recovers a continuous latent sample from a sample of a discrete copula.
| Parameters | |
|---|---|
| u | An matrix holding each observation's distribution function values and their left limits; any other number of columns throws. |
| b | The bandwidth of the kernel density estimator. |
| niter | The number of sweeps. |
| Returns | An matrix of pseudo-observations of the latent sample, i.e. on the copula scale rather than the normal scale the sweeps run on. |
Treats the discrete sample as an interval-censored density estimation problem: observation is only known to lie in the rectangle . A latent point is initialized inside that rectangle and then refined by niter sweeps: for each observation, one of the observations whose current latent point falls in its own rectangle (widened by on the normal scale) is picked uniformly at random, and the latent point is set to that neighbor's value plus Gaussian noise of scale — a draw from a Gaussian kernel density estimate restricted to the compatible observations. The refined points are not confined to the original rectangles.
The draw is deterministic: every random component is drawn from a fixed-seed generator, so repeated calls on the same input agree bit for bit. It is also independent of argument order: recovering the latent sample of and of gives the same pair of columns, swapped.
size_ t vinecopulib:: tools_stats:: next_power_of_two(size_ t n)
Eigen::MatrixXd vinecopulib:: tools_stats:: ace(const Eigen::MatrixXd& data,
const Eigen::VectorXd& weights = Eigen::VectorXd(),
size_ t wl = 0,
size_ t outer_iter_max = 100,
size_ t inner_iter_max = 10,
double outer_abs_tol = 2e-15,
double inner_abs_tol = 1e-4)
alternating conditional expectation algorithm
Eigen::MatrixXd vinecopulib:: tools_stats:: ghalton(const size_ t& n,
const size_ t& d,
const std::vector<int>& seeds)
Simulates from the multivariate Generalized Halton Sequence.
| Parameters | |
|---|---|
| n | Number of observations. |
| d | Dimension. |
| seeds | Seeds to scramble the quasi-random numbers; if empty (default), the quasi-random number generator is seeded randomly. |
| Returns | An matrix of quasi-random variables. |
For more information on Generalized Halton Sequence, see Faure, H., Lemieux, C. (2009). Generalized Halton Sequences in 2008: A Comparative Study. ACM-TOMACS 19(4), Article 15.
Eigen::MatrixXd vinecopulib:: tools_stats:: sobol(const size_ t& n,
const size_ t& d,
const std::vector<int>& seeds)
Simulates from the multivariate Sobol sequence.
| Parameters | |
|---|---|
| n | Number of observations. |
| d | Dimension. |
| seeds | Seeds to scramble the quasi-random numbers; if empty (default), the quasi-random number generator is seeded randomly. |
| Returns | An matrix of quasi-random variables. |
For more information on the Sobol sequence, see S. Joe and F. Y. Kuo (2008), constructing Sobol sequences with better two-dimensional projections, SIAM J. Sci. Comput. 30, 2635–2654.
Eigen::VectorXd vinecopulib:: tools_stats:: pbvt(const Eigen::MatrixXd& z,
int nu,
double rho)
Computes bivariate t probabilities.
| Parameters | |
|---|---|
| z | An matrix of evaluation points. |
| nu | Number of degrees of freedom. |
| rho | Correlation. |
| Returns | An vector of probabilities. |
Based on the method described by Dunnett, C.W. and M. Sobel, (1954), A bivariate generalization of Student's t-distribution with tables for certain special cases, Biometrika 41, pp. 153-169. Translated from the Fortran routines of Alan Genz (www.math.wsu.edu/faculty/genz/software/fort77/mvtdstpack.f).
Eigen::VectorXd vinecopulib:: tools_stats:: pbvnorm(const Eigen::MatrixXd& z,
double rho)
Compute bivariate normal probabilities.
| Parameters | |
|---|---|
| z | An matrix of evaluation points. |
| rho | Correlation. |
| Returns | An vector of probabilities. |
A function for computing bivariate normal probabilities; developed using Drezner, Z. and Wesolowsky, G. O. (1989), On the Computation of the Bivariate Normal Integral, J. Stat. Comput. Simul.. 35 pp. 101-107. with extensive modifications for double precisions by Alan Genz and Yihong Ge. Translated from the Fortran routines of Alan Genz (www.math.wsu.edu/faculty/genz/software/fort77/mvtdstpack.f).
double vinecopulib:: tools_stats:: pairwise_mcor(const Eigen::MatrixXd& x,
const Eigen::VectorXd& weights)
calculates the pairwise maximum correlation coefficient.
Symmetric in the two variables, as the measure is by definition.
double vinecopulib:: tools_stats:: pairwise_cxi(const Eigen::MatrixXd& x,
const Eigen::VectorXd& weights)
calculates the pairwise symmetrized Chatterjee's xi.
Chatterjee's xi measures how well one variable is a measurable function of the other and is therefore asymmetric. The symmetrized version is the larger of the two directions, so it detects a functional relationship whichever way it runs.