File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -404,14 +404,17 @@ span(x) = ((a, b) = extrema(x); a:b)
404
404
405
405
# Variation coefficient: std / mean
406
406
"""
407
- variation(x, m=mean(x))
407
+ variation(x, m=mean(x); corrected=true )
408
408
409
409
Return the coefficient of variation of collection `x`, optionally specifying
410
- a precomputed mean `m`. The coefficient of variation is the ratio of the
411
- standard deviation to the mean.
412
- """
413
- variation (x, m) = stdm (x, m) / m
414
- variation (x) = ((m, s) = mean_and_std (x); s/ m)
410
+ a precomputed mean `m`, and the optional correction parameter `corrected`.
411
+ The coefficient of variation is the ratio of the
412
+ standard deviation to the mean. If `corrected` is `false`,
413
+ then `std` is calculated with denominator `n`. Else, the `std` is
414
+ calculated with denominator `n-1`.
415
+ """
416
+ variation (x, m; corrected:: Bool = true ) = stdm (x, m; corrected= corrected) / m
417
+ variation (x; corrected:: Bool = true ) = ((m, s) = mean_and_std (x; corrected= corrected); s/ m)
415
418
416
419
# Standard error of the mean: std / sqrt(len)
417
420
# Code taken from var in the Statistics stdlib module
Original file line number Diff line number Diff line change @@ -163,7 +163,13 @@ z2 = [8. 2. 3. 1.; 24. 10. -1. -1.; 20. 12. 1. -2.]
163
163
@test span (skipmissing ([1 , missing , 5 , missing ])) == 1 : 5
164
164
165
165
@test variation ([1 : 5 ;]) ≈ 0.527046276694730
166
+ @test variation ([1 : 5 ;]; corrected= false ) ≈ 0.471404520791032
166
167
@test variation (skipmissing ([missing ; 1 : 5 ; missing ])) ≈ 0.527046276694730
168
+ @test isnan (variation (1 ))
169
+ @test variation (1 ; corrected= false ) == 0
170
+ # Possibly deprecated
171
+ @test variation ([1 : 5 ;],4 ) ≈ 0.4841229182759271
172
+ @test variation ([1 : 5 ;],4 ; corrected= false ) ≈ 0.4330127018922193
167
173
168
174
@test @inferred (sem ([1 : 5 ;])) ≈ 0.707106781186548
169
175
@test @inferred (sem (skipmissing ([missing ; 1 : 5 ; missing ]))) ≈ 0.707106781186548
You can’t perform that action at this time.
0 commit comments