Skip to content

Commit

Permalink
add link to where implementation was taken from + fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
rawls238 committed Apr 18, 2016
1 parent 749f64b commit de11b0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/wilcoxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ end
## EXACT WILCOXON SIGNED RANK TEST

immutable ExactSignedRankTest{T<:Real} <: HypothesisTest
vals::Vector # original values
vals::Vector{T} # original values
W::Float64 # test statistic: Wilcoxon rank-sum statistic
ranks::Vector{T} # ranks without ties (zero values)
ranks::Vector{Float64} # ranks without ties (zero values)
signs::BitArray{1} # signs of input of ranks
tie_adjustment::Float64 # adjustment for ties
n::Int # number of observations
Expand Down Expand Up @@ -129,15 +129,15 @@ function pvalue(x::ExactSignedRankTest; tail=:both)
end
end

ci(x::ExactSignedRankTest, alpha::Float64=0.05; tail=:both) = calculate_ci(x.vals, alpha; tail=tail)
ci(x::ExactSignedRankTest, alpha::Real=0.05; tail=:both) = calculate_ci(x.vals, alpha; tail=tail)


## APPROXIMATE SIGNED RANK TEST

immutable ApproximateSignedRankTest{T<:Real} <: HypothesisTest
vals::Vector # original values
vals::Vector{T} # original values
W::Float64 # test statistic: Wilcoxon rank-sum statistic
ranks::Vector{T} # ranks without ties (zero values)
ranks::Vector{Float64} # ranks without ties (zero values)
signs::BitArray{1} # signs of input of ranks
tie_adjustment::Float64 # adjustment for ties
n::Int # number of observations
Expand Down Expand Up @@ -182,9 +182,10 @@ function pvalue(x::ApproximateSignedRankTest; tail=:both)
end
end

ci(x::ApproximateSignedRankTest, alpha::Float64=0.05; tail=:both) = calculate_ci(x.vals, alpha; tail=tail)
ci(x::ApproximateSignedRankTest, alpha::Real=0.05; tail=:both) = calculate_ci(x.vals, alpha; tail=tail)

function calculate_ci(x::AbstractVector, alpha::Float64=0.05; tail=:both)
# implementation method inspired by these notes: http://www.stat.umn.edu/geyer/old03/5102/notes/rank.pdf
function calculate_ci(x::AbstractVector, alpha::Real=0.05; tail=:both)
check_alpha(alpha)

if tail == :both
Expand All @@ -193,8 +194,8 @@ function calculate_ci(x::AbstractVector, alpha::Float64=0.05; tail=:both)
c = 1 - 2 * alpha
end
n = length(x)
m = convert(Int, n * (n + 1) / 2)
k_range = 1:(m/2)
m = div(n * (n + 1), 2)
k_range = 1:div(m, 2)
l = [1 - 2 * psignrank(i, n, true) for i in k_range]
k = indmin(abs(l-c))
vals = Float64[]
Expand Down
1 change: 0 additions & 1 deletion test/wilcoxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ show(IOBuffer(), ApproximateSignedRankTest([1:10;], [1:10;]))
@test abs(pvalue(SignedRankTest([1:10;], [2:11;])) - 0.0020) <= 1e-4
show(IOBuffer(), SignedRankTest([1:10;], [2:2:20;]))

<<<<<<< 4ae28a8eaa0388f913e1d34095c583fbf3422469
# One Sample tests
# P-value computed using R wilcox.test
@test abs(pvalue(SignedRankTest([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] - 10.1)) - 0.09460449) <= 1e-4
Expand Down

0 comments on commit de11b0a

Please sign in to comment.