Skip to content

Commit aafbcc6

Browse files
committed
mv_to_central_moment: modif spec
1 parent 95a7771 commit aafbcc6

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/stdlib_experimental_stats.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Descriptive statistics
22

33
* [`mean` - mean of array elements](#mean---mean-of-array-elements)
4-
* [`moment` - raw and central moments of array elements](#moment---raw-and-central-moments-of-array-elements)
4+
* [`moment` - central moments of array elements](#moment---central-moments-of-array-elements)
55
* [`var` - variance of array elements](#var---variance-of-array-elements)
66

77
## `mean` - mean of array elements
@@ -48,24 +48,24 @@ program demo_mean
4848
end program demo_mean
4949
```
5050

51-
## `moment` - raw and central moments of array elements
51+
## `moment` - central moments of array elements
5252

5353
### Description
5454

55-
Returns the _k_-th order raw moment 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`.
55+
Returns the _k_-th order central moment 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`.
5656

57-
If an array `center` is provided, the function returns the _k_-th order central moment 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+
If a scalar or an array `center` is provided, the function returns the _k_-th order moment about 'center', 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`.
5858

5959

60-
The _k_-th order raw moment is defined as :
60+
The _k_-th order central moment is defined as :
6161

6262
```
63-
moment(array) = 1/n sum_i (array(i))^k
63+
moment(array) = 1/n sum_i (array(i) - mean(array))^k
6464
```
6565

6666
where n is the number of elements.
6767

68-
The _k_-th order central moment is defined as :
68+
The _k_-th order moment about `center` is defined as :
6969

7070
```
7171
moment(array) = 1/n sum_i (array(i) - center)^k
@@ -85,7 +85,7 @@ The _k_-th order central moment is defined as :
8585

8686
`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`.
8787

88-
`center` (optional): Shall be a scalar of the same type of `array` if `array` is `real` or `complex`, or of type `real(dp)` if `array` is of type `integer`. If `dim` is provided, `center` shall be an array (with a shape similar to that of `array` with dimension `dim` dropped) of the same type of `array` if `array` is `real` or `complex`, or of type `real(dp)` if `array` is of type `integer`.
88+
`center` (optional): Shall be a scalar of the same type of `result` if `dim` is not provided. If `dim` is provided, `center` shall be a scalar or an array (with a shape similar to that of `array` with dimension `dim` dropped) of the same type of `result`.
8989

9090
`mask` (optional): Shall be of type `logical` and either by a scalar or an array of the same shape as `array`.
9191

@@ -94,9 +94,9 @@ The _k_-th order central moment is defined as :
9494
If `array` is of type `real` or `complex`, the result is of the same type as `array`.
9595
If `array` is of type `integer`, the result is of type `real(dp)`.
9696

97-
If `dim` is absent, a scalar with the _k_-th raw (or central if `center` is provided) moment 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.
97+
If `dim` is absent, a scalar with the _k_-th (central) moment 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.
9898

99-
If `mask` is specified, the result is the _k_-th raw (or central if `center` is provided) moment of all elements of `array` corresponding to `true` elements of `mask`. If every element of `mask` is `false`, the result is IEEE `NaN`.
99+
If `mask` is specified, the result is the _k_-th (central) moment of all elements of `array` corresponding to `true` elements of `mask`. If every element of `mask` is `false`, the result is IEEE `NaN`.
100100

101101
### Example
102102

@@ -106,14 +106,12 @@ program demo_moment
106106
implicit none
107107
real :: x(1:6) = [ 1., 2., 3., 4., 5., 6. ]
108108
real :: y(1:2, 1:3) = reshape([ 1., 2., 3., 4., 5., 6. ], [ 2, 3])
109-
print *, moment(x, 2, center = mean(x)) !returns 2.9167
110-
print *, moment( y, 2,&
111-
center = mean(y)) !returns 2.9167
112-
print *, moment( y, 2, 1,&
113-
center = mean(y, 1)) !returns [0.25, 0.25, 0.25]
114-
print *, moment( y, 2, 1,&
115-
center = mean(y, 1, y > 3.),&
116-
mask = (y > 3.)) !returns [NaN, 0., 0.25]
109+
print *, moment(x, 2) !returns 2.9167
110+
print *, moment( y, 2) !returns 2.9167
111+
print *, moment( y, 2, 1) !returns [0.25, 0.25, 0.25]
112+
print *, moment( y, 2, 1, mask = (y > 3.)) !returns [NaN, 0., 0.25]
113+
print *, moment(x, 2, center = 0.) !returns 15.1667
114+
print *, moment( y, 1, 1, center = 0.) !returns [1.5, 3.5, 5.5]
117115
end program demo_moment
118116
```
119117

0 commit comments

Comments
 (0)