-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Progress on incorporating StatsBase into statistics. #31
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this. |
||
""" | ||
Statistics | ||
|
||
|
@@ -11,15 +10,21 @@ using LinearAlgebra, SparseArrays | |
|
||
using Base: has_offset_axes, require_one_based_indexing | ||
|
||
using Printf: @printf | ||
|
||
export cor, cov, std, stdm, var, varm, mean!, mean, | ||
median!, median, middle, quantile!, quantile, | ||
skewness, kurtosis, | ||
AbstractWeights, Weights, AnalyticWeights, FrequencyWeights, ProbabilityWeights, | ||
weights, aweights, fweights, pweights | ||
|
||
weights, aweights, fweights, pweights, | ||
# scalarstats.jl | ||
geomean, harmmean, genmean, mode, modes, percentile, span, variation, sem, mad, mad!, | ||
iqr, genvar, totalvar, entropy, renyientropy, crossentropy, kldivergence, describe | ||
|
||
include("weights.jl") | ||
include("wsum.jl") | ||
include("moments.jl") | ||
include("scalarstats.jl") | ||
|
||
##### mean ##### | ||
|
||
|
@@ -1193,6 +1198,17 @@ julia> quantile(skipmissing([1, 10, missing]), 0.5) | |
quantile(itr, p; sorted::Bool=false, weights::Union{AbstractArray,Nothing}=nothing) = | ||
_quantile(itr, p, sorted, weights) | ||
|
||
""" | ||
quantile(x, n::Integer) | ||
|
||
Return the n-quantiles of collection `x`, i.e. the values which | ||
partition `v` into `n` subsets of nearly equal size. | ||
|
||
Equivalent to `quantile(x, [0:n]/n)`. For example, `quantile(x, 5)` | ||
returns a vector of quantiles, respectively at `[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]`. | ||
""" | ||
quantile(x, n::Integer) = quantile(x, (0:n)/n) | ||
|
||
_quantile(itr, p, sorted::Bool, weights::Nothing) = | ||
quantile!(collect(itr), p, sorted=sorted) | ||
|
||
|
@@ -1272,6 +1288,13 @@ _quantile(v::AbstractArray, p::Real, sorted::Bool, w::AbstractArray) = | |
_quantile(itr, p, sorted::Bool, weights) = | ||
throw(ArgumentError("weights are only supported with AbstractArrays inputs")) | ||
|
||
""" | ||
percentile(x, p) | ||
|
||
Return the `p`th percentile of a collection `x`, i.e. `quantile(x, p / 100)`. | ||
""" | ||
percentile(x, p) = quantile(x, p * 0.01) | ||
|
||
##### SparseArrays optimizations ##### | ||
|
||
function cov(X::SparseMatrixCSC; dims::Int=1, corrected::Bool=true) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,24 +165,6 @@ end | |
# | ||
############################# | ||
|
||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe keep these here for now. That reduces the diff, which makes things less messy, and we may want to move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to do this but can't since this extends methods in statistics and we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Then remove the heading above. |
||
percentile(x, p) | ||
|
||
Return the `p`th percentile of a collection `x`, i.e. `quantile(x, p / 100)`. | ||
""" | ||
percentile(x, p) = quantile(x, p * 0.01) | ||
|
||
# TODO: move to same place as other quantile methods | ||
""" | ||
quantile(x, n::Integer) | ||
|
||
Return the n-quantiles of collection `x`, i.e. the values which | ||
partition `v` into `n` subsets of nearly equal size. | ||
|
||
Equivalent to `quantile(x, [0:n]/n)`. For example, `quantile(x, 5)` | ||
returns a vector of quantiles, respectively at `[0.0, 0.2, 0.4, 0.6, 0.8, 1.0]`. | ||
""" | ||
quantile(x, n::Integer) = quantile(x, (0:n)/n) | ||
|
||
|
||
############################# | ||
|
@@ -230,7 +212,7 @@ end | |
sem(x::AbstractArray) = sqrt(var(x, corrected=true) / length(x)) | ||
|
||
# Median absolute deviation | ||
@irrational mad_constant 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701") | ||
Base.@irrational mad_constant 1.4826022185056018 BigFloat("1.482602218505601860547076529360423431326703202590312896536266275245674447622701") | ||
|
||
""" | ||
mad(x; center=median(x), normalize=true) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to keep this to get CI to pass. We'll remove it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to delete it in order for a Revise-based workflow to work, see my discourse question here.