Skip to content
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

first commit delong_test #22

Merged
merged 6 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ uuid = "f535d66d-59bb-5153-8d2b-ef0a426c6aff"
repo = "https://github.com/davidavdav/ROCAnalysis.jl.git"
version = "0.3.3"

[compat]
julia = "1"
RecipesBase = "1"
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1"
DataFrames = "0.20, 0.21, 0.22, 1"

[deps]
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
DataFrames = "0.20, 0.21, 0.22, 1"
RecipesBase = "1"
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1"
julia = "1"

[extras]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
64 changes: 64 additions & 0 deletions src/delong.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Distributions

function ψ(x,y)
return if x > y
1
elseif x < y
0
else
1/2
end
end

function V₁₀(x::Float64; Y)
sum(ψ.(x,Y)) / length(Y)
end

function V₀₁(y::Float64; X)
sum(ψ.(X, y)) / length(X)
end

function V₁₀(X::Vector{N},Y::Vector{N}) where {N<:Real}
V₁₀.(X, Y=Y)
end

function V₀₁(X::Vector{N},Y::Vector{N}) where {N<:Real}
V₀₁.(Y, X=X)
end

function S₁₀(tars, nontars, θs)
Xs = hcat(map(zip(tars, nontars, θs)) do (tar, nontar, θ)
V₁₀.(tar, Y=nontar) .- θ
end...)
cov(Xs)
end

function S₀₁(tars, nontars, θs)
Xs = hcat(map(zip(tars, nontars, θs)) do (tar, nontar, θ)
V₀₁.(nontar, X=tar) .- θ
end...)
cov(Xs)
end

function delong_test(tar1, nontar1, tar2, nontar2)


# Adjust the lengths in case of different lengths
m = minimum(length.([tar1, tar2]))
n = minimum(length.([nontar1, nontar2]))

tars = [tar1[1:m], tar2[1:m]]
nontars = [nontar1[1:n], nontar2[1:n]]

θ₁ = auc(tar1, nontar1)
θ₂ = auc(tar2, nontar2)
θ = [θ₁, θ₂]

l = [1, -1]

S₁₀(tars, nontars, θ)
S₀₁(tars, nontars, θ)
Delon_stat = abs((θ₁ - θ₂)) / √(l' * (S₁₀(tars, nontars, θ)/m + S₀₁(tars, nontars, θ)/n) * l)

1 - cdf(Normal(0,1), Delon_stat) + cdf(Normal(0,1), -Delon_stat)
end
2 changes: 2 additions & 0 deletions src/includes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ include("dcf.jl")
include("plotrecipes.jl")

include("dataframes.jl")

include("delong.jl")
17 changes: 17 additions & 0 deletions test/delong.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@testset "test delong" begin
target = [0,0,1,1,1]
modela = [0.1, 0.2, 0.6, 0.7, 0.8]
modelb = [0.3,0.6,0.2,0.7,0.9]
nontara, tara = modela[1:2], modela[3:end]
nontarb, tarb = modelb[1:2], modelb[3:end]

@test round(ROCAnalysis.delong_test(tara, nontara, tarb, nontarb), digits=4) == 0.3173

target = [0,0,0,0,0,0,1,1,1,1,1,1,1]
modela = [0.1,0.2,0.05,0.3,0.1,0.6,0.6,0.7,0.8,0.99,0.8,0.67,0.5]
modelb = [0.3,0.6,0.2,0.1,0.1,0.9,0.23,0.7,0.9,0.4,0.77,0.3,0.89]
nontara, tara = modela[1:6], modela[7:end]
nontarb, tarb = modelb[1:6], modelb[7:end]

@test round(ROCAnalysis.delong_test(tara, nontara, tarb, nontarb), digits=5) == 0.09453
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ using Random
include("extremes.jl")
include("big.jl")
include("dcf.jl")
include("delong.jl")