I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.30
sub units 0.50
+
0

Covariance

Calculates the covariance of a given set of data
Controller: CodeCogs

get GPL add to cart

Dependents

Info

Interface

C++

Covariance

 
template<class T> doublecovarianceintn
T*data
T*data1 )
The covariance of two random variables X_1 and X_2 with mean \overline{X_1} and \overline{X_2} respectively is defined as

The covariance of a random variable X with itself is simply the variance

Covariance captures a measure of the correlation of two variables.

Positive covariance indicates that as X_1 increases, so does X_2 . Negative covariance indicates X_1 decreases as X_2 increases and vice versa. Zero covariance can indicate that X_1 and X_2 are uncorrelated. Covariance is defined as:

In the example below the covariance of two random variables is calculated, yielding the result: <em> -1.64 </em>. These two variables are also displayed in the following graphs.

1/covariance-6-965.png
+

Example 1

#include <codecogs/statistics/moments/covariance.h>
#include <iostream>
int main()
 {
  int x[5] = {2 , 4 , 8 , 9 , 3};
  int y[5] = {3 , 5 , 7 , 2 , 9};
  double cov = Stats::Moments::covariance<int>(5, x , y);
  std::cout << "The covariance of x and y is: " << cov << std::endl;
  return 0;
}
Output:
The covariance of x and y is: -1.64

Parameters

nthe size of the first array and of the second array
datathe actual population data given as the first array
data1the second array

Returns

the covariance of a given population

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.