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: src/stdlib_experimental_stats.md
+20-8Lines changed: 20 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -55,17 +55,22 @@ end program demo_mean
55
55
56
56
Returns the variance of all the elements of `array`, or of the elements of `array` along dimension `dim` if provided, and if the corresponding element in `mask` is `true`.
57
57
58
-
The variance is defined as the best unbiased estimator and is computed as:
58
+
Per default, the variance is defined as the best unbiased estimator and is computed as:
59
59
60
60
```
61
61
var(x) = 1/(n-1) sum_i (array(i) - mean(array))^2
62
62
```
63
63
64
+
where n is the number of elements.
65
+
66
+
The use of the term `n-1` for scaling is called Bessel 's correction. The scaling can be changed with the logical argument `corrected`. If `corrected` is `.false.`, then the sum is scaled with `n`, otherwise with `n-1`.
67
+
68
+
64
69
### Syntax
65
70
66
-
`result = var(array [, mask])`
71
+
`result = var(array [, mask [, corrected]])`
67
72
68
-
`result = var(array, dim [, mask])`
73
+
`result = var(array, dim [, mask [, corrected]])`
69
74
70
75
### Arguments
71
76
@@ -75,16 +80,19 @@ The variance is defined as the best unbiased estimator and is computed as:
75
80
76
81
`mask` (optional): Shall be of type `logical` and either by a scalar or an array of the same shape as `array`.
77
82
83
+
`corrected` (optional): Shall be a scalar of type `logical`. If `corrected` is `.true.` (default value), the sum is scaled with `n-1`. If `corrected` is `.false.`, then the sum is scaled with `n`.
84
+
78
85
### Return value
79
86
80
-
If `array` is of type `real` or `complex`, the result is of the same type as`array`.
81
-
If `array` is of type `integer`, the result is of type `double precision`.
87
+
If `array` is of type `real` or `complex`, the result is of type `real` corresponding to the type of`array`.
88
+
If `array` is of type `integer`, the result is of type `real(dp)`.
82
89
83
-
If `dim` is absent, a scalar with the variance of all elements in `array` is returned. Otherwise, an array of rank n-1, where n equals the rank of `array`, and a shape similar to that of `ar
84
-
ray` with dimension `dim` dropped is returned.
90
+
If `dim` is absent, a scalar with the variance of all elements in `array` is returned. Otherwise, an array of rank n-1, where n equals the rank of `array`, and a shape similar to that of `array` with dimension `dim` dropped is returned.
85
91
86
92
If `mask` is specified, the result is the variance of all elements of `array` corresponding to `true` elements of `mask`. If every element of `mask` is `false`, the result is IEEE `NaN`.
87
93
94
+
If the variance is computed with only one single element, then the result is IEEE `NaN` if `corrected` is `.true.` and is `0.` if `corrected` is `.false.`.
0 commit comments