Skip to content

Commit

Permalink
Fix deprecations (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] authored and ararslan committed Aug 27, 2017
1 parent 0c2de83 commit 3a00ff7
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 106 deletions.
8 changes: 4 additions & 4 deletions src/HypothesisTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using Rmath: pwilcox, psignrank
import StatsBase.confint

export testname, pvalue, confint
@compat abstract type HypothesisTest end
abstract type HypothesisTest end

check_same_length(x::AbstractVector, y::AbstractVector) = if length(x) != length(y)
throw(DimensionMismatch("Vectors must be the same length"))
Expand Down Expand Up @@ -99,7 +99,7 @@ function check_alpha(alpha::Float64)
end

# Pretty-print
function Base.show{T<:HypothesisTest}(io::IO, test::T)
function Base.show(io::IO, test::T) where T<:HypothesisTest
println(io, testname(test))
println(io, repeat("-", length(testname(test))))

Expand Down Expand Up @@ -136,12 +136,12 @@ function Base.show{T<:HypothesisTest}(io::IO, test::T)
end

# parameter of interest: name, value under h0, point estimate
population_param_of_interest{T<:HypothesisTest}(test::T) = ("not implemented yet", NaN, NaN)
population_param_of_interest(test::T) where {T<:HypothesisTest} = ("not implemented yet", NaN, NaN)

# is the test one- or two-sided
default_tail(test::HypothesisTest) = :undefined

function show_params{T<:HypothesisTest}(io::IO, test::T, ident="")
function show_params(io::IO, test::T, ident="") where T<:HypothesisTest
fieldidx = find(Bool[t<:Number for t in T.types])
if !isempty(fieldidx)
lengths = [length(string(T.names[i])) for i in fieldidx]
Expand Down
12 changes: 6 additions & 6 deletions src/anderson_darling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

export OneSampleADTest, KSampleADTest

@compat abstract type ADTest <: HypothesisTest end
abstract type ADTest <: HypothesisTest end

## ONE SAMPLE AD-TEST
### http://www.itl.nist.gov/div898/handbook/eda/section3/eda35e.htm

function adstats{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
function adstats(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real
n = length(x)
y = sort(x)
μ = mean(y)
Expand All @@ -23,7 +23,7 @@ function adstats{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
(n, μ, σ, A²)
end

immutable OneSampleADTest <: ADTest
struct OneSampleADTest <: ADTest
n::Int # number of observations
μ::Float64 # sample mean
σ::Float64 # sample std
Expand All @@ -39,7 +39,7 @@ is not drawn from `d`.
Implements: [`pvalue`](@ref)
"""
function OneSampleADTest{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
function OneSampleADTest(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real
OneSampleADTest(adstats(x, d)...)
end

Expand Down Expand Up @@ -72,7 +72,7 @@ function pvalue(x::OneSampleADTest)
end

## K-SAMPLE ANDERSON DARLING TEST
immutable KSampleADTest <: ADTest
struct KSampleADTest <: ADTest
k::Int # number of samples
n::Int # number of observations
σ::Float64 # variance A²k
Expand All @@ -96,7 +96,7 @@ Implements: [`pvalue`](@ref)
* F. W. Scholz and M. A. Stephens, K-Sample Anderson-Darling Tests, Journal of the
American Statistical Association, Vol. 82, No. 399. (Sep., 1987), pp. 918-924.
"""
function KSampleADTest{T<:Real}(xs::AbstractVector{T}...; modified=true)
function KSampleADTest(xs::AbstractVector{T}...; modified=true) where T<:Real
KSampleADTest(a2_ksample(xs, modified)...)
end

Expand Down
4 changes: 2 additions & 2 deletions src/augmented_dickey_fuller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

export ADFTest

immutable ADFTest <: HypothesisTest
struct ADFTest <: HypothesisTest
n ::Int # number of observations
deterministic ::Symbol # deterministic terms included in regression
lag ::Int # number of lags in test statistic
Expand Down Expand Up @@ -58,7 +58,7 @@ External links
* [Augmented Dickey-Fuller test on Wikipedia](https://en.wikipedia.org/wiki/Augmented_Dickey–Fuller_test)
"""
function ADFTest{T<:Real}(y::AbstractVector{T}, deterministic::Symbol, lag::Int)
function ADFTest(y::AbstractVector{T}, deterministic::Symbol, lag::Int) where T<:Real

nobs = length(y)
Δy = diff(y)
Expand Down
8 changes: 4 additions & 4 deletions src/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export BinomialTest, SignTest

## BINOMIAL TEST

immutable BinomialTest <: HypothesisTest
struct BinomialTest <: HypothesisTest
p::Float64
x::Int
n::Int
Expand Down Expand Up @@ -176,7 +176,7 @@ end

## SIGN TEST

immutable SignTest <: HypothesisTest
struct SignTest <: HypothesisTest
median::Float64
x::Int
n::Int
Expand All @@ -193,9 +193,9 @@ hypothesis that the median is not equal to `median`.
Implements: [`pvalue`](@ref), [`confint`](@ref)
"""
SignTest{T<:Real}(x::AbstractVector{T}, median::Real=0) =
SignTest(x::AbstractVector{T}, median::Real=0) where {T<:Real} =
SignTest(median, sum(x .> median), sum(x .!= median), sort(x))
SignTest{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S}) =
SignTest(x::AbstractVector{T}, y::AbstractVector{S}) where {T<:Real, S<:Real} =
SignTest(x - y, 0.0)

testname(::SignTest) = "Sign Test"
Expand Down
8 changes: 4 additions & 4 deletions src/box_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export BoxPierceTest, LjungBoxTest

# Box-Pierce test

immutable BoxPierceTest <: HypothesisTest
struct BoxPierceTest <: HypothesisTest
y::Vector{Float64} # time series vector
n::Int # number of observations
lag::Int # number of lags in test statistic
Expand All @@ -49,7 +49,7 @@ External links
* [Box-Pierce test on Wikipedia](https://en.wikipedia.org/wiki/Ljung–Box_test#Box-Pierce_test)
"""
function BoxPierceTest{T<:Real}(y::AbstractVector{T}, lag::Int, dof::Int=0)
function BoxPierceTest(y::AbstractVector{T}, lag::Int, dof::Int=0) where T<:Real
if dof>=lag
throw(ArgumentError("Number of lags has to be larger than degrees of" *
" freedom correction"))
Expand All @@ -75,7 +75,7 @@ pvalue(x::BoxPierceTest) = pvalue(Chisq(x.lag-x.dof), x.Q; tail=:right)

#Ljung-Box test

immutable LjungBoxTest <: HypothesisTest
struct LjungBoxTest <: HypothesisTest
y::Vector{Float64} # time series vector
n::Int # number of observations
lag::Int # number of lags in test statistic
Expand All @@ -98,7 +98,7 @@ External links
* [Ljung-Box test on Wikipedia](https://en.wikipedia.org/wiki/Ljung–Box_test)
"""
function LjungBoxTest{T<:Real}(y::AbstractVector{T}, lag::Int, dof::Int=0)
function LjungBoxTest(y::AbstractVector{T}, lag::Int, dof::Int=0) where T<:Real
if dof>=lag
throw(ArgumentError("Number of lags has to be larger than degrees of" *
" freedom correction"))
Expand Down
6 changes: 3 additions & 3 deletions src/breusch_godfrey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

export BreuschGodfreyTest

immutable BreuschGodfreyTest <: HypothesisTest
struct BreuschGodfreyTest <: HypothesisTest
n::Int # number of observations
lag::Int # number of lags in test statistic
BG::Float64 # test statistic
Expand All @@ -46,8 +46,8 @@ External links
* [Breusch-Godfrey test on Wikipedia](https://en.wikipedia.org/wiki/Breusch–Godfrey_test)
"""
function BreuschGodfreyTest{T<:Real}(xmat::AbstractArray{T}, e::AbstractVector{T},
lag::Int, start0::Bool=true)
function BreuschGodfreyTest(xmat::AbstractArray{T}, e::AbstractVector{T},
lag::Int, start0::Bool=true) where T<:Real
n = size(e,1)
elag = zeros(Float64,n,lag)
for ii = 1:lag # construct lagged residuals
Expand Down
22 changes: 11 additions & 11 deletions src/circular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export RayleighTest, FisherTLinearAssociation, JammalamadakaCircularCorrelation

## RAYLEIGH TEST OF UNIFORMITY AGAINST AN UNSPECIFIED UNIMODAL ALTERNATIVE

immutable RayleighTest <: HypothesisTest
struct RayleighTest <: HypothesisTest
Rbar::Float64 # mean resultant length
n::Int # number of observations
end
function RayleighTest{S <: Complex}(samples::Vector{S})
function RayleighTest(samples::Vector{S}) where S <: Complex
s = Float64(abs(sum(samples./abs(samples))))
n = length(samples)
Rbar = s/n
RayleighTest(Rbar, n)
end
function RayleighTest{S <: Real}(samples::Vector{S})
function RayleighTest(samples::Vector{S}) where S <: Real
s = Float64(abs(sum(exp, im * samples)))
n = length(samples)
Rbar = s/n
Expand All @@ -68,14 +68,14 @@ end

## N.I. FISHER'S TEST OF T-LINEAR CIRCULAR-CIRCULAR ASSOCIATION

immutable FisherTLinearAssociation{S <: Real, T <: Real} <: HypothesisTest
struct FisherTLinearAssociation{S <: Real, T <: Real} <: HypothesisTest
rho_t::Float64 # circular correlation coefficient
theta::Vector{S} # radians of group 1
phi::Vector{T} # radians of group 2
uniformly_distributed::Union{Bool,Void} # is distribution of theta and phi uniform?
end
function FisherTLinearAssociation{Stheta <: Real, Sphi <: Real}(theta::Vector{Stheta},
phi::Vector{Sphi}, uniformly_distributed::Union{Bool,Void})
function FisherTLinearAssociation(theta::Vector{Stheta},
phi::Vector{Sphi}, uniformly_distributed::Union{Bool,Void}) where {Stheta <: Real, Sphi <: Real}
check_same_length(theta, phi)

A = sum(cos.(theta).*cos.(phi))
Expand All @@ -93,8 +93,8 @@ function FisherTLinearAssociation{Stheta <: Real, Sphi <: Real}(theta::Vector{St
rho_t = 4*T/sqrt((n^2 - E^2 - F^2)*(n^2-G^2-H^2))
FisherTLinearAssociation(rho_t, theta, phi, uniformly_distributed)
end
FisherTLinearAssociation{S <: Real, T <: Real}(theta::Vector{S},
phi::Vector{T}) = FisherTLinearAssociation(theta, phi, nothing)
FisherTLinearAssociation(theta::Vector{S},
phi::Vector{T}) where {S <: Real, T <: Real} = FisherTLinearAssociation(theta, phi, nothing)

testname(::FisherTLinearAssociation) =
"T-linear test of circular-circular association"
Expand Down Expand Up @@ -188,11 +188,11 @@ end

## JAMMALAMADAKA'S CIRCULAR CORRELATION

immutable JammalamadakaCircularCorrelation <: HypothesisTest
struct JammalamadakaCircularCorrelation <: HypothesisTest
r::Float64 # circular-circular correlation coefficient
Z::Float64 # test statistic
end
function JammalamadakaCircularCorrelation{S <: Real, T <: Real}(alpha::Vector{S}, beta::Vector{T})
function JammalamadakaCircularCorrelation(alpha::Vector{S}, beta::Vector{T}) where {S <: Real, T <: Real}
check_same_length(alpha, beta)
# calculate sample mean directions
alpha_bar = angle(sum(exp, im * alpha))
Expand Down Expand Up @@ -225,7 +225,7 @@ pvalue(x::JammalamadakaCircularCorrelation; tail=:both) = pvalue(Normal(), x.Z;
# Complex numbers
for fn in (:JammalamadakaCircularCorrelation, :FisherTLinearAssociation)
@eval begin
$(fn){S <: Complex, T <: Complex}(x::Vector{S}, y::Vector{T}) =
$(fn)(x::Vector{S}, y::Vector{T}) where {S <: Complex, T <: Complex} =
$(fn)(angle(x), angle(y))
end
end
6 changes: 3 additions & 3 deletions src/durbin_watson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

export DurbinWatsonTest

immutable DurbinWatsonTest <: HypothesisTest
struct DurbinWatsonTest <: HypothesisTest
xmat::Array{Float64} # regressor matrix
n::Int # number of observations
DW::Float64 # test statistic
Expand Down Expand Up @@ -73,8 +73,8 @@ and `:right` (positive serial correlation).
https://en.wikipedia.org/wiki/Durbin–Watson_statistic
](https://en.wikipedia.org/wiki/Durbin–Watson_statistic)
"""
function DurbinWatsonTest{T<:Real}(xmat::AbstractArray{T}, e::AbstractArray{T};
p_compute::Symbol = :ndep)
function DurbinWatsonTest(xmat::AbstractArray{T}, e::AbstractArray{T};
p_compute::Symbol = :ndep) where T<:Real

n = length(e)
DW = sum(diff(e) .^2) / sum(e .^2)
Expand Down
2 changes: 1 addition & 1 deletion src/fisher.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Implements: [`pvalue`](@ref), [`confint`](@ref)
Blaker’s exact tests". Biostatistics, Volume 11, Issue 2, 1 April 2010, Pages 373–374,
[link](https://doi.org/10.1093/biostatistics/kxp050)
"""
immutable FisherExactTest <: HypothesisTest
struct FisherExactTest <: HypothesisTest
# Format:
# X1 X2
# Y1 a b
Expand Down
4 changes: 2 additions & 2 deletions src/jarque_bera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

export JarqueBeraTest

immutable JarqueBeraTest <: HypothesisTest
struct JarqueBeraTest <: HypothesisTest
n::Int # number of observations
JB::Float64 # test statistic
skew::Float64 # skewness
Expand Down Expand Up @@ -52,7 +52,7 @@ nominal levels up to about 3% and under-sized for larger nominal levels (Mantalo
* [Jarque-Bera test on Wikipedia](https://en.wikipedia.org/wiki/Jarque–Bera_test)
"""
function JarqueBeraTest{T<:Real}(y::AbstractVector{T})
function JarqueBeraTest(y::AbstractVector{T}) where T<:Real
n = length(y)
M = Base.promote_op(/, T, typeof(n))
m1r = m2r = m3r = m4r = zero(M)
Expand Down
22 changes: 11 additions & 11 deletions src/kolmogorov_smirnov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ export
ExactOneSampleKSTest,
ApproximateOneSampleKSTest, ApproximateTwoSampleKSTest

@compat abstract type KSTest <: HypothesisTest end
@compat abstract type ApproximateKSTest <: KSTest end
@compat abstract type ExactKSTest <: KSTest end
abstract type KSTest <: HypothesisTest end
abstract type ApproximateKSTest <: KSTest end
abstract type ExactKSTest <: KSTest end

population_param_of_interest(x::KSTest) = ("Supremum of CDF differences", 0.0, x.δ) # parameter of interest: name, value under h0, point estimate
default_tail(test::KSTest) = :both

## ONE SAMPLE KS-TEST

# compute supremum of differences between target and empirical cdf before and after the jump of the empirical cdf.
function ksstats{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
function ksstats(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real
n = length(x)
cdfs = cdf(d, sort(x))
δp = maximum((1:n) / n - cdfs)
Expand All @@ -47,7 +47,7 @@ end

### EXACT KOLMOGOROV SMIRNOV TEST

immutable ExactOneSampleKSTest <: ExactKSTest
struct ExactOneSampleKSTest <: ExactKSTest
n::Int # number of observations
δ::Float64 # supremum of CDF differences
δp::Float64 # supremum of the positive CDF differences
Expand All @@ -63,7 +63,7 @@ sample is not drawn from `d`.
Implements: [`pvalue`](@ref)
"""
function ExactOneSampleKSTest{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
function ExactOneSampleKSTest(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real
if length(x) > length(unique(x))
warn("This test is inaccurate with ties")
end
Expand Down Expand Up @@ -91,7 +91,7 @@ end

### APPROXIMATE KOLMOGOROV SMIRNOV TEST

immutable ApproximateOneSampleKSTest <: ApproximateKSTest
struct ApproximateOneSampleKSTest <: ApproximateKSTest
n::Int # number of observations
δ::Float64 # supremum of CDF differences
δp::Float64 # supremum of the positive CDF differences
Expand All @@ -107,7 +107,7 @@ that the sample is not drawn from `d`.
Implements: [`pvalue`](@ref)
"""
function ApproximateOneSampleKSTest{T<:Real}(x::AbstractVector{T}, d::UnivariateDistribution)
function ApproximateOneSampleKSTest(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real
if length(x) > length(unique(x))
warn("This test is inaccurate with ties")
end
Expand Down Expand Up @@ -139,7 +139,7 @@ end

### APPROXIMATE KOLMOGOROV SMIRNOV TEST

immutable ApproximateTwoSampleKSTest <: ApproximateKSTest
struct ApproximateTwoSampleKSTest <: ApproximateKSTest
n_x::Int # number of observations
n_y::Int # number of observations
δ::Float64 # supremum of CDF differences
Expand All @@ -161,7 +161,7 @@ Implements: [`pvalue`](@ref)
* [Approximation of one-sided test (Encyclopedia of Mathematics)
](https://www.encyclopediaofmath.org/index.php/Kolmogorov-Smirnov_test)
"""
function ApproximateTwoSampleKSTest{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S})
function ApproximateTwoSampleKSTest(x::AbstractVector{T}, y::AbstractVector{S}) where {T<:Real, S<:Real}
n_x, n_y = length(x), length(y)
if n_x+n_y > length(unique([x; y]))
warn("This test is inaccurate with ties")
Expand Down Expand Up @@ -192,7 +192,7 @@ function pvalue(x::ApproximateTwoSampleKSTest; tail=:both)
end

# compute supremum of differences between empirical cdfs.
function ksstats{T<:Real, S<:Real}(x::AbstractVector{T}, y::AbstractVector{S})
function ksstats(x::AbstractVector{T}, y::AbstractVector{S}) where {T<:Real, S<:Real}
n_x, n_y = length(x), length(y)
sort_idx = sortperm([x; y])
pdf_diffs = [ones(n_x)/n_x; -ones(n_y)/n_y][sort_idx]
Expand Down

0 comments on commit 3a00ff7

Please sign in to comment.