You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_experimental_stats.md
+48-1
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,54 @@ title: experimental_stats
6
6
7
7
[TOC]
8
8
9
+
## `corr` - Pearson correlation of array elements
10
+
11
+
### Description
12
+
13
+
Returns the Pearson correlation of the elements of `array` along dimension `dim` if the corresponding element in `mask` is `true`.
14
+
15
+
The Pearson correlation between two rows (or columns), say `x` and `y`, of `array` is defined as:
16
+
17
+
```
18
+
corr(x, y) = cov(x, y) / sqrt( var(x) * var(y))
19
+
```
20
+
21
+
### Syntax
22
+
23
+
`result = [[stdlib_experimental_stats(module):corr(interface)]](array, dim [, mask])`
24
+
25
+
### Arguments
26
+
27
+
`array`: Shall be a rank-1 or a rank-2 array of type `integer`, `real`, or `complex`.
28
+
29
+
`dim`: Shall be a scalar of type `integer` with a value in the range from 1 to `n`, where `n` is the rank of `array`.
30
+
31
+
`mask` (optional): Shall be of type `logical` and either a scalar or an array of the same shape as `array`.
32
+
33
+
### Return value
34
+
35
+
If `array` is of rank 1 and of type `real` or `complex`, the result is of type `real` and has the same kind as `array`.
36
+
If `array` is of rank 2 and of type `real` or `complex`, the result is of the same type and kind as `array`.
37
+
If `array` is of type `integer`, the result is of type `real(dp)`.
38
+
39
+
If `array` is of rank 1 and of size larger than 1, a scalar equal to 1 is returned. Otherwise, IEEE `NaN` is returned.
40
+
If `array` is of rank 2, a rank-2 array with the corresponding correlations is returned.
41
+
42
+
If `mask` is specified, the result is the Pearson correlation of all elements of `array` corresponding to `true` elements of `mask`. If every element of `mask` is `false`, the result is IEEE `NaN`.
0 commit comments