Variance, Covariance, and Correlation for Complex Data
Variance, Covariance, and Correlation for Complex Data
Wrappers of stats::var , stats::cov , and stats::cor that are capable of handling complex input.
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.
Returns
numeric or complex the sample variance, covariance, or correlation of the input data.
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.
Functions
cor: Correlation coefficient of complex variables.
var: S3 Variance or Pseudo Variance of Complex Variables, a synonym for cov .