Learn R Programming

errors (version 0.4.2)

correl: Handle Correlations Between errors Objects

Description

Set or retrieve correlations or covariances between errors objects. See the details section below.

Usage

correl(x, y)

correl(x, y) <- value

set_correl(x, y, value)

covar(x, y)

covar(x, y) <- value

set_covar(x, y, value)

Value

correl and covar return a vector of correlations and covariances respectively (or NULL). set_correl and set_covar, which are pipe-friendly versions of the setters, return the x object.

Arguments

x

an object of class errors.

y

an object of class errors.

value

a numeric vector of length 1 or the same length as x.

Details

The uncertainties associated to errors objects are supposed to be independent by default. If there is some known correlation, it can be defined using these methods, and it will be used for the propagation of the uncertainty by the mathematical and arithmetic operations.

The correl method sets or retrieves correlations, i.e., a value (or vector of values) between -1 and 1 (see base cor on how to compute correlations). A covariance is just a correlation value multiplied by the standard deviations (i.e., the standard uncertainty) of both variables. It can be defined using the covar method (see base cov on how to compute covariances). These methods are equivalent; in fact, correl calls covar internally.

Every errors object has a unique ID, and pairwise correlations are stored in an internal hash table. All the functions or methods that modify somehow the dimensions of errors objects (i.e., subsets, binds, concatenations, summaries...) generate new objects with new IDs, and correlations are not, and cannot be, propagated. Only mathematical and arithmetic operations propagate correlations, where appropriate, following the Taylor series method.

Examples

Run this code
x <- set_errors(1:5, 0.1)
y <- set_errors(1:5, 0.1)

# Self-correlation is of course 1, and cannot be changed
correl(x, x)
if (FALSE) {
correl(x, x) <- 0.5}

# Cross-correlation can be set, but must be a value between -1 and 1
correl(x, y)
if (FALSE) {
correl(x, y) <- 1.5}
correl(x, y) <- runif(length(x))
correl(x, y)
covar(x, y)

Run the code above in your browser using DataLab