我正在寻找在Julia中实现等样方差的双样本F检验,类似于MATLAB中的vartest2
。
有没有这样的实施?我已经完成了几次搜索,但一无所获。
答案 0 :(得分:3)
AFAIK此测试尚未在Julia中实施。但是,看Wikipedia page看起来很简单。这是第一遍:
#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)