/// <summary> /// Estimates the unbiased population covariance from the provided samples. /// On a dataset of size N will use an N-1 normalizer (Bessel's correction). /// Returns NaN if data has less than two entries or if any entry is NaN. /// </summary> /// <param name="samples1">A subset of samples, sampled from the full population.</param> /// <param name="samples2">A subset of samples, sampled from the full population.</param> public static double Covariance(this IEnumerable <double> samples1, IEnumerable <double> samples2) { var array1 = samples1 as double[]; var array2 = samples2 as double[]; return(array1 != null && array2 != null ? ArrayStatistics.Covariance(array1, array2) : StreamingStatistics.Covariance(samples1, samples2)); }