Skip to content

Commit 3f29a9c

Browse files
committed
ranking.jl and rankcorr.jl
1 parent 8629d94 commit 3f29a9c

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ makedocs(
1212
"weights.md",
1313
"scalarstats.md",
1414
"cov.md",
15-
"robust.md"]
15+
"robust.md",
16+
"ranking.md"]
1617
)
1718

1819
deploydocs(

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Statistics can be weighted, and several weights types are distinguished to apply
1010
corrections where necessary.
1111

1212
```@contents
13-
Pages = ["weights.md", "scalarstats.md", "cov.md", "robust.md"]
13+
Pages = ["weights.md", "scalarstats.md", "cov.md", "robust.md", "ranking.jl"]
1414
Depth = 2
1515
```

docs/src/ranking.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Rankings and Rank Correlations
2+
3+
Various strategies for computing ranks and rank correlations are provided.
4+
5+
```@docs
6+
ordinalrank
7+
competerank
8+
denserank
9+
tiedrank
10+
corspearman
11+
corkendall
12+
```

src/Statistics.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export std, stdm, var, varm, mean!, mean,
3232
autocov!, autocov, autocor!, autocor, crosscov!, crosscov, crosscor!, crosscor,
3333
pacf!, pacf,
3434
# robust.jl
35-
trim, trim!, trimvar, winsor, winsor!
35+
trim, trim!, trimvar, winsor, winsor!,
36+
# ranking.jl
37+
ordinalrank, competerank, denserank, tiedrank,
38+
# rankcorr
39+
corkendall, corspearman
3640

3741
include("common.jl")
3842
include("weights.jl")
@@ -44,6 +48,8 @@ include("partialcor.jl")
4448
include("toeplitzsolvers.jl")
4549
include("signalcorr.jl")
4650
include("robust.jl")
51+
include("ranking.jl")
52+
include("rankcorr.jl")
4753

4854
##### mean #####
4955

src/ranking.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ for (f, f!, S) in zip([:ordinalrank, :competerank, :denserank, :tiedrank],
182182
@eval begin
183183
function $f(x::AbstractArray{>: Missing}; lt = isless, rev::Bool = false)
184184
inds = findall(!ismissing, x)
185-
isempty(inds) && return missings($S, size(x))
186-
xv = disallowmissing(view(x, inds))
185+
isempty(inds) && return Array{Union{$S, Missing}}(missing, size(x))
186+
xv = convert(Array{Int}, view(x, inds))
187187
sp = sortperm(xv; lt = lt, rev = rev)
188-
rks = missings($S, length(x))
188+
rks = Vector{Union{$S, Missing}}(missing, length(x))
189189
$(f!)(view(rks, inds), xv, sp)
190190
rks
191191
end

test/rankcorr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using StatsBase
1+
using Statistics
22
using Test
33

44
X = Float64[1 0; 2 1; 3 0; 4 1; 5 10]

test/ranking.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using StatsBase
1+
using Statistics
22
using Test
33

44
a = [1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 4.0, 5.0]

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,4 +894,6 @@ include("moments.jl")
894894
include("cov.jl")
895895
include("partialcor.jl")
896896
include("signalcorr.jl")
897-
include("robust.jl")
897+
include("robust.jl")
898+
include("ranking.jl")
899+
include("rankcorr.jl")

0 commit comments

Comments
 (0)