Version

Infragistics Correlation Calculator

This topic introduces the CorrelationCalculator which is part of the Infragistics Math Calculators™ library and explains, with code examples, how to use it to calculate correlation between two variables in a data set.

Overview

The topic is organized as follows:

Introduction

In statistic, data correlation is often referred to as Pearson’s product-moment correlation coefficient (PPMCC). Correlation is used to measure a linear association between two variables in a data set. Furthermore, it indicates the degree of linear relationship between these variables. The Correlation coefficient is calculated using the CorrelationCalculator class.

Correlation Formula

Correlation coefficient is derived by dividing the covariance of the two variables by the product of their standard deviations:

IG Math Correlation Calculators 01.png

where

IG Math Correlation Calculators 02.png
IG Math Correlation Calculators 03.png

Figure 1 – Formula for Data Correlation

Legend
IG Math Correlation Calculators 04.png
  • Represents the correlation between X and Y variable in a data set

IG Math Correlation Calculators 05.png
  • Represents the covariance of X and Y variables in a data set

IG Math Correlation Calculators 06.png
  • Represents the standard deviations of X variables in a data set

IG Math Correlation Calculators 07.png
  • Represents the standard deviations of Y variables in a data set

IG Math Correlation Calculators 08.png
  • Represents the mean of X variables in a data set

IG Math Correlation Calculators 09.png
  • Represents the mean of Y variables in a data set

IG Math Correlation Calculators 10.png
  • Represents the X variable at the i index in a data set

IG Math Correlation Calculators 11.png
  • Represents the Y variable at the i index in a data set

IG Math Correlation Calculators 12.png
  • Represents the total count of numbers in a data set

Types of Data Correlation

The correlation coefficient ranges between positive one and negative one. The closer the coefficient is to either −1 or 1, the stronger the relationship between the variables in a data set. In a perfect positive (increasing) relationship, the correlation is +1. It’s −1 with a perfect decreasing (negative) linear relationship and a value between −1 and 1 in all other cases. As the correlation approaches zero there is less of a relationship between the variables in a data set.

Table 1 – Types of Data Correlation

Correlation Type Negative Correlation Positive Correlation

None

Range: -0.1 to 0.0

IG Math Correlation Calculators 13.png

Range: 0.0 to 0.1

IG Math Correlation Calculators 14.png

Low

Range: -0.3 to -0.1

IG Math Correlation Calculators 15.png

Range: 0.1 to 0.3

IG Math Correlation Calculators 16.png

Medium

Range: -0.5 to -0.3

IG Math Correlation Calculators 17.png

Range: 0.3 to 0.5

IG Math Correlation Calculators 18.png

High

Range: -1.0 to -0.5

IG Math Correlation Calculators 19.png

Range: 0.5 to 1.0

IG Math Correlation Calculators 20.png

Correlation Calculator Properties

This section provides a list of properties of the CorrelationCalculator object.

Property Name Property Type Description

ItemsSource

Gets or sets the data items source for the calculator.

XMemberPath

string

Gets or sets the X member path of a data item.

YMemberPath

string

Gets or sets the Y member path of a data item.

Value

double

Gets the value of data correlation.

Requirements

NuGet Package Requirements

In order to use the CorrelationCalculator, the following Nuget package reference must be added to a WPF project.

  • Infragistics.WPF.Math.Calculators

For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.

Data Requirements

The CorrelationCalculator uses ItemsSource property for data binding and XMemberPath and YMemberPath properties for data mapping. Any object that meets the following requirements can be bound to this property:

  • The data model must implement IEnumerable interface (e.g. List, Collection, Queue, Stack)

  • The data model must contain items that have at least two numeric data columns for calculating the correlation between them.

An example of object that meets above criteria is the CorrelationDataSample which you can download from the Correlation Data Sample resource and use it in your project.

Example

This example demonstrates how to calculate correlation between two variables in a set of data using the CorrelationCalculator. The CorrelationCalculator is a non-visual element and it should be defined in resources section on application, page, or control level, the same way as you would define a data source. Refer also to the Series Data Correlation topic for example on how to integrate the CorrelationCalculator with the xamDataChart™ control.

Note
Note:

The following example assumes that you added all required assemblies for the CorrelationCalculator and the Correlation Data Sample object as data source in your project.

In XAML:

xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:local="clr-namespace:Infragistics.Samples.Data.Models.Series"

In XAML:

<local:CorrelationDataSample x:Key="Data"/>
<ig:CorrelationCalculator x:Key="CorrelationCalc"
                          XMemberPath="X" YMemberPath="Y"
                          ItemsSource="{StaticResource Data}">
</ig:CorrelationCalculator>

In Visual Basic:

Imports Infragistics.Samples.Data.Models.Series
Imports Infragistics.Math.Calculators
'...
Dim data As New CorrelationDataSample()
Dim correlationCalc As New CorrelationCalculator()
correlationCalc.ItemsSource = data
correlationCalc.XMemberPath = "X"
correlationCalc.YMemberPath = "Y"
Dim correlation As Double = correlationCalc.Value

In C#:

using Infragistics.Samples.Data.Models.Series;
using Infragistics.Math.Calculators;
//...
CorrelationDataSample data = new CorrelationDataSample();
CorrelationCalculator correlationCalc = new CorrelationCalculator();
correlationCalc.ItemsSource = data;
correlationCalc.XMemberPath = "X";
correlationCalc.YMemberPath = "Y";
double correlation = correlationCalc.Value;