diff --git a/run_tests.jl b/run_tests.jl index de4e034e91b1ba..6c674e618bac9b 100644 --- a/run_tests.jl +++ b/run_tests.jl @@ -7,7 +7,8 @@ using Stats my_tests = ["test/01.jl" - "test/means.jl"] + "test/means.jl", + "test/variability.jl"] #"test/statquiz.jl"] println("Running tests:") diff --git a/src/scalar_stats.jl b/src/scalar_stats.jl index 10590e9834af1e..90415448f41a70 100644 --- a/src/scalar_stats.jl +++ b/src/scalar_stats.jl @@ -51,6 +51,7 @@ end # Skewness +# This is Type 1 definition according to Joanes and Gill (1998) function skewness{T<:Real}(v::AbstractVector{T}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) @@ -69,8 +70,8 @@ end skewness{T<:Real}(v::AbstractVector{T}) = skewness(v, mean(v)) - # (excessive) Kurtosis +# This is Type 1 definition according to Joanes and Gill (1998) function kurtosis{T<:Real}(v::AbstractVector{T}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) diff --git a/test/variability.jl b/test/variability.jl new file mode 100644 index 00000000000000..109eb4dbf30214 --- /dev/null +++ b/test/variability.jl @@ -0,0 +1,30 @@ +using Stats +using Base.Test + +# Should this be 4 - 2? +# @test_approx_eq iqr([1, 2, 3, 4, 5]) + +@test_approx_eq kurtosis([1, 2, 3, 4, 5]) -1.3 +@test_approx_eq kurtosis([1, 2, 3, 3, 2]) -1.1530612244897953 + +@test_approx_eq mad([1, 2, 3, 4, 5]) 1.4826 +# TODO: This shouldn't fail +# @test_approx_eq mad(1:5) 1.4826 + +@test_approx_eq midrange([1, 2, 3, 4, 5]) 3.0 +@test_approx_eq midrange([1, 2, 2, 2, 5]) 3.0 +@test_approx_eq midrange([1, 4, 4, 4, 5]) 3.0 +@test_approx_eq midrange([1:5]) 3.0 + +@test_approx_eq range([1, 2, 3, 4, 5]) 4.0 +@test_approx_eq range([1, 2, 2, 2, 5]) 4.0 +@test_approx_eq range([1, 4, 4, 4, 5]) 4.0 +@test_approx_eq range([1:15]) 14.0 + +@test_approx_eq skewness([1, 2, 3, 4, 5]) 0.0 +@test_approx_eq skewness([1, 2, 2, 2, 5]) 1.1731251294063556 +@test_approx_eq skewness([1, 4, 4, 4, 5]) -1.1731251294063556 + +# sem() + +# variation()