cov {complexlm}R Documentation

Variance, Covariance, and Correlation for Complex Data

Description

Wrappers of stats::var, stats::cov, and stats::cor that are capable of handling complex input.

Usage

cov(
  x,
  y = NULL,
  na.rm = FALSE,
  method = "pearson",
  use = "everything",
  pseudo = FALSE,
  ...
)

cor(
  x,
  y = NULL,
  na.rm = FALSE,
  use = "everything",
  method = "pearson",
  pseudo = FALSE,
  ...
)

var(x, y = NULL, na.rm = FALSE, use = "everything", pseudo = FALSE, ...)

Arguments

x

a numeric or complex vector, matrix, or dataframe.

y

NULL (default) or a numeric vector, matrix, or dataframe with dimensions compatible with x.

na.rm

logical. Should missing values be removed? Only considered when x is a vector.

method

The method for calculating correlation coefficient. Only "pearson" is supported for complex variables, so this parameter is ignored.

use

character string giving the desired method of computing covariances in the presence of missing values. Options are "everything" (default), "all.obs", "complete.obs", or "na.or.complete". See stats::cov for explanation of what each one does. Note that "pairwise.complete.obs" is not available for this complex method.

pseudo

logical, if TRUE the pseudo variance, covariance, or correlation is calculated. i.e. no complex conjugation is performed.

...

Other parameters, ignored.

Details

For vector input, the sample variance is calculated as,
sum(Conj( mean(x) - x ) * ( mean(x) - x )) / (length(x) - 1)
And the sample covariance is calculated as,
sum(Conj( mean(x) - x ) * ( mean(y) - y )) / (length(x) - 1)
The Pearson correlation coefficient, which is the only kind available for complex data, is the covariance divided by the product of the standard deviations of all variables. If pseudo = TRUE, these same expressions, sans Conj(), are used to calculate the pseudo, AKA relational, versions of variance, covariance, or correlation.

Value

numeric or complex the sample variance, covariance, or correlation of the input data.

Functions

Examples

set.seed(4242)
n <- 9
foo <- complex(real = rnorm(n), imaginary = rnorm(n))
var(foo)
bar <- complex(real = rnorm(n), imaginary = rnorm(n))
var(x = foo, y = bar)
foobar <- data.frame(foo, bar)
cov(foobar)
cor(foobar)

[Package complexlm version 1.1.2 Index]