Skip to content

Commit

Permalink
ranking.jl and rankcorr.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Sep 25, 2021
1 parent 8629d94 commit 3f29a9c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ makedocs(
"weights.md",
"scalarstats.md",
"cov.md",
"robust.md"]
"robust.md",
"ranking.md"]
)

deploydocs(
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Statistics can be weighted, and several weights types are distinguished to apply
corrections where necessary.

```@contents
Pages = ["weights.md", "scalarstats.md", "cov.md", "robust.md"]
Pages = ["weights.md", "scalarstats.md", "cov.md", "robust.md", "ranking.jl"]
Depth = 2
```
12 changes: 12 additions & 0 deletions docs/src/ranking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Rankings and Rank Correlations

Various strategies for computing ranks and rank correlations are provided.

```@docs
ordinalrank
competerank
denserank
tiedrank
corspearman
corkendall
```
8 changes: 7 additions & 1 deletion src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export std, stdm, var, varm, mean!, mean,
autocov!, autocov, autocor!, autocor, crosscov!, crosscov, crosscor!, crosscor,
pacf!, pacf,
# robust.jl
trim, trim!, trimvar, winsor, winsor!
trim, trim!, trimvar, winsor, winsor!,
# ranking.jl
ordinalrank, competerank, denserank, tiedrank,
# rankcorr
corkendall, corspearman

include("common.jl")
include("weights.jl")
Expand All @@ -44,6 +48,8 @@ include("partialcor.jl")
include("toeplitzsolvers.jl")
include("signalcorr.jl")
include("robust.jl")
include("ranking.jl")
include("rankcorr.jl")

##### mean #####

Expand Down
6 changes: 3 additions & 3 deletions src/ranking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ for (f, f!, S) in zip([:ordinalrank, :competerank, :denserank, :tiedrank],
@eval begin
function $f(x::AbstractArray{>: Missing}; lt = isless, rev::Bool = false)
inds = findall(!ismissing, x)
isempty(inds) && return missings($S, size(x))
xv = disallowmissing(view(x, inds))
isempty(inds) && return Array{Union{$S, Missing}}(missing, size(x))
xv = convert(Array{Int}, view(x, inds))
sp = sortperm(xv; lt = lt, rev = rev)
rks = missings($S, length(x))
rks = Vector{Union{$S, Missing}}(missing, length(x))
$(f!)(view(rks, inds), xv, sp)
rks
end
Expand Down
2 changes: 1 addition & 1 deletion test/rankcorr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StatsBase
using Statistics
using Test

X = Float64[1 0; 2 1; 3 0; 4 1; 5 10]
Expand Down
2 changes: 1 addition & 1 deletion test/ranking.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using StatsBase
using Statistics
using Test

a = [1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 4.0, 5.0]
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -894,4 +894,6 @@ include("moments.jl")
include("cov.jl")
include("partialcor.jl")
include("signalcorr.jl")
include("robust.jl")
include("robust.jl")
include("ranking.jl")
include("rankcorr.jl")

0 comments on commit 3f29a9c

Please sign in to comment.