Correlation Statistics block
This block calculates a time-weighted moving correlation statistics of two fields.
Correlation Statistics block
Description
The output of the block is the moving correlation statistics between two input variables calculated over the last T seconds. The moving correlation statistics are respectively, cross-correlation, correlation coefficient R, and covariance. The moving correlation statistics are thus calculated over a time window of fixed span (width). The window moves forward as time progresses with the one end anchored to current time.
The cross correlation, RXY, between two variables, X and Y, is calculated over the time window as follows: RXY = ∑i Xi Yi. The larger the absolute value of RXY, the higher the correlation. A value of 0 indicates no correlation.
Cross correlation is one way to evaluate the relative correlations between several variables. For example, the relative values of two cross correlations, say RXY and RXZ, indicates whether X is more correlated on Y or Z.
Note that the cross correlation function does not adjust for the averages of the two variables over the time window, i.e. it does not first make them zero-average by subtracting their respective averages before calculating the cross correlation. The covariance function does the latter. In the case where the two variables are zero-mean, the cross correlation and covariance functions are identical.
Correlation analysis attempts to measure the strength of linear relationships between variables by means of a single number called a correlation coefficient R. The measure of linear association between two variables X and Y is estimated by the sample correlation coefficient R, where N is the number of samples in the window and R is calculated as follows:
R will have values that range between 1 and +1. A value of +1 indicates that the two variables are identical over the time window (perfect positive correlation), e.g. X = Y. A value of 0 indicates that there is no correlation or relationship between the two variables over the time window. A value of 1 indicates perfect negative correlation, i.e., the one signal is the negative of the other, e.g. X = -Y.
Sometimes R2 is used as a measure of the relationship between two variables in stead of just R. R2 will have values that range between 0 and 1. A value of 0 indicates that there is no correlation between the two variables over the time window. A value of 1 indicates that the two variables are perfectly correlated over the time window, either positively or negatively. The closer the value is to 1 the better the correlation is between the two variables, the closer the value is to 0 the worse the correlation is between the two variables.
It is important to take note that the correlation coefficient is a measure of the linear relation between two variables. Therefore, even if two variables are very well correlated via some nonlinear relationship, e.g. Y = X2, the correlation coefficient may indicate a weak correlation. Also note that outliers can skew the correlation coefficient such that weakly correlated variables may seem to have strong correlation. Also, the correlation coefficient does not adjust for the averages of the two variables over the time window, i.e. it does not first make them zero-average by subtracting their respective averages before calculating the correlation coefficient.
The covariance, CXY, between two variables, X and Y, is calculated over the time window as follows: CXY = ∑i (Xi - μX) (Yi - μY), where μX is the mean of X and μY is the mean of Y over the window. The larger the absolute value of CXY the higher the covariance. A value of 0 indicates no covariance.
In essence the covariance function calculates the cross correlation between the variances of two variables over the time window. In the case where the two variables are zero-mean, the cross correlation and covariance functions are identical.
Note that the cross correlation function does not adjust for the averages of the two variables over the time window, i.e. it does not first make them zero-average by subtracting their respective averages before calculating the cross correlation. The covariance function does the latter.
Correlation statistics block
Block Type
Statistical block
Input/Output ports
Both input ports can have only fields of type double.
There are three output ports, namely cross correlation, correlation coefficient, and covariance. Every output port has a field for each configured output correlation.
In order for this block to run, both input ports must be connected to sources that only have fields of type double. The window span must also be larger than 0 seconds.
Functions performed on tags
-
On the values The cross correlation port contains fields that has the cross correlation of the configured input fields. The correlation coefficient port contains fields that have the R of the configured input fields. The covariance port contains fields that have the covariance of the configured input fields.
-
On the timestamp The output time stamp is always set to the execute time.
-
On the quality The quality is set based on the quality threshold. The quality level is calculated as the number of seconds that both the signals had good quality over the window. This quality level is expressed as a percentage of the window span. If the quality level is less that the quality threshold, the output quality is set to bad, otherwise it is good.
Example
-
Sample period = 60s
-
Window span = 300s
-
Quality threshold = 80%
Time Stamps |
Process Variable X |
Process Variable Y |
Cross Corre-lation |
Cross Corr. Quality |
Corr. Coeff. R |
Corr. Coeff. Quality |
Co-variance |
Co-variance Quality |
02/03/26 12:37 |
23 |
87 |
2001.0 |
0 |
0 |
0 |
0.00 |
0 |
02/03/26 12:38 |
12 |
34 |
400.2 |
0 |
1 |
0 |
320.16 |
0 |
02/03/26 12:39 |
44 |
23 |
481.8 |
0 |
0.9917 |
0 |
312.40 |
0 |
02/03/26 12:40 |
34 |
54 |
684.2 |
0 |
0.4347 |
0 |
229.16 |
0 |
02/03/26 12:41 |
26 |
71 |
1051.4 |
1 |
0.3416 |
1 |
156.44 |
1 |
02/03/26 12:42 |
62 |
8 |
1420.6 |
1 |
-0.2985 |
1 |
-75.04 |
1 |
02/03/26 12:43 |
17 |
29 |
1119.6 |
1 |
-0.6208 |
1 |
-233.20 |
1 |
02/03/26 12:44 |
45 |
34 |
1136.6 |
1 |
-0.6216 |
1 |
-217.60 |
1 |
02/03/26 12:45 |
78 |
67 |
1240.2 |
1 |
-0.5998 |
1 |
-202.36 |
1 |
02/03/26 12:46 |
18 |
83 |
1918.2 |
1 |
0.0226 |
1 |
12.12 |
1 |
02/03/26 12:47 |
22 |
61 |
1847.8 |
1 |
-0.1490 |
1 |
-97.00 |
1 |
02/03/26 12:48 |
70 |
49 |
2017.0 |
1 |
0.0928 |
1 |
44.20 |
1 |
02/03/26 12:49 |
10 |
13 |
2604.4 |
1 |
-0.3371 |
1 |
-135.68 |
1 |
02/03/26 12:50 |
21 |
26 |
2324.4 |
1 |
0.2425 |
1 |
162.24 |
1 |
02/03/26 12:51 |
39 |
31 |
1388.4 |
1 |
0.1508 |
1 |
79.92 |
1 |
Example of processing by Correlation Statistics block
Related topics: