Two F-test samples for equal deviations in Julia

I am looking for an implementation of a two-frame F-test for equal variances in Julia, similar vartest2in MATLAB.

Is there such an implementation? I performed a few searches but found nothing.

+4
source share
1 answer

AFAIK this test has not yet been implemented in Julia. However, looking at the Wikipedia page , it looks quite simple. Here is the first pass:

#Function for testing equivalence of two variances assuming iid Normal.
#Return is (rejection_indicator::Int, p-value::Float64, test_stat::Float64)
using Distributions
function normvartest{T<:Number}(x::Vector{T}, y::Vector{T} ; alpha::Float64=0.05)
    (length(x) < 2 || length(y) < 2) && return(-1, NaN, NaN)
    fStat = var(x) / var(y)
    fDist = FDist(length(x) - 1, length(y) - 1)
    fCdf = cdf(fDist, fStat)
    fCdf < 0.5 ? (pValue = 2 * fCdf) : (pValue = 2 * (1 - fCdf))
    pValue > alpha ? (h0Int = 0) : (h0Int = 1)
    return(h0Int, pValue, fStat)
end

#Example of use given null
x = 10 + randn(1000)
y = randn(1000)
normvartest(x, y)

#Example of use given alternative alternative
x = 10 + randn(1000)
y = 0.9 * randn(1000)
normvartest(x, y)
+3
source

Source: https://habr.com/ru/post/1657305/


All Articles