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 |
method |
The method for calculating correlation coefficient. Only |
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 |
... |
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
-
cor
: Correlation coefficient of complex variables. -
var
: S3 Variance or Pseudo Variance of Complex Variables, a synonym for cov.
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)