R code for performing quantile regression using bivariate copulas

Nelsen explained in his 1999 book An introduction to copulas how to fit a (nonlinear) quantile regression model by means of a bivariate copula (pp. 175-176).

nonlinear-quantile-regression-copulas

In short, Nelsen’s method for fitting a (nonlinear) quantile regression model is as follows:

  1. Take the partial derivative of the copula function C(u, v) with respect to u, where u and v are both defined in [0, 1]. Denote this partial derivative by cu(u, v), and note that cu(u, v) = P{V ≤ v | U = u}.
  2. For fitting the quantile regression model, set cu(u, v) = p, where p is defined in [0, 1].
  3. For regressing v on u, evaluate cu(u, v) at u, and subsequently solve cu(u, v) = p for v (or, similarly, solve 0 = cu(u, v) – p for v).
  4. Replace u by Fx-1(u) and v by Fy-1(v), where Fx-1(·) and Fy-1(·) are the quantile functions for x (=independent variable) and y (=dependent variable), respectively.

The following R code implements this copula method proposed by Nelsen for fitting a (nonlinear) quantile regression model. In addition, the R code may also compute confidence intervals for the fitted quantiles using a Monte-Carlo method. Continue reading R code for performing quantile regression using bivariate copulas

Error propagation in R: Monte Carlo simulations using copulas

Physicists and engineers often have to calculate the uncertainty in a derived quantity.

For instance, a test engineer repeatedly measures two separate angles. The uncertainty (or error) in the measurements of each of these angles appears to be +/- 1 degree. Subsequently, the engineer calculates the sum of these two angles. This sum is a derived quantity. But note that this derived quantity is composed of two measured quantities each having their own uncertainties, so what is the uncertainty (or error) in this derived quantity? In other words, how propagates the uncertainty from the measured quantities (the two angles) to a derived quantity (sum of two angles).

The following R code calculates the uncertainty in a derived quantity using a Monte Carlo simulation. Moreover, the Monte Carlo simulation employs copulas that fall into the Archimedean class of copulas. This class consists of members such as the Clayton and Gumbel copula. These Archimedean copulas make it possible to calculate the uncertainty in a derived quantity when 1) the measured quantities are dependent (correlated), and 2) the measured quantities follow a normal or some asymmetric distribution (e.g., an exponential, lognormal, or Weibull distribution).

R code that uses a Gaussian copula for calculating the uncertainty in a derived quantity can be found in this blog post.

Continue reading Error propagation in R: Monte Carlo simulations using copulas

Error propagation in R: addition in quadrature versus the bootstrap method

Physicists and engineers often have to calculate the uncertainty in a derived quantity.

For instance, a test engineer measures two angles. The uncertainty (or error) in these measurements appears to be +/- 1 degree. Subsequently, the engineer calculates the sum of these two angles. This sum is a derived quantity. But note that this derived quantity is composed of two measurements each having their own uncertainties, so what is the uncertainty (or error) in this derived quantity? In other words, how propagates the uncertainty from the measured quantities (the two angles) to a derived quantity (sum of two angles). For calculating the uncertainty in this derived quantity, physicists and engineers rely on what is called the addition in quadrature procedure.

The addition in quadrature procedure provides an estimate of the Standard Deviation Of the Mean (SDOM), which is a quantification of the uncertainty in a derived quantity. This SDOM, in turn, can be used for constructing confidence intervals for the derived quantity.
Bootstrap methods (such as the bias-corrected bootstrap method) provide another way of obtaining confidence intervals for the derived quantity.

The following R code shows how to compute confidence intervals for a derived physical quantity with (1) the addition in quadrature procedure, and (2) the bias-corrected bootstrap method. The code demonstrates that these two methods usually yield very similar confidence intervals.

Continue reading Error propagation in R: addition in quadrature versus the bootstrap method