Skip to content

Instantly share code, notes, and snippets.

@johnmyleswhite
Created May 11, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmyleswhite/6d1739496c46d02fa2c0f407c63a6d35 to your computer and use it in GitHub Desktop.
Save johnmyleswhite/6d1739496c46d02fa2c0f407c63a6d35 to your computer and use it in GitHub Desktop.
using Distributions
using HypothesisTests
n_sims = 1_000_000
n = 20
x = Array{Float64}(n)
y = Array{Float64}(n)
p_d = Array{Float64}(n_sims)
for s in 1:n_sims
for i in 1:n
z = rand(Bernoulli(0.5))
x[i] = z * (1e-12 * rand(Bernoulli(0.5))) + (1 - z) * rand(Bernoulli(1e-6))
y[i] = z * (1e-12 * rand(Bernoulli(0.5))) + (1 - z) * rand(Bernoulli(1e-6))
end
try
p_d[s] = pvalue(UnequalVarianceTTest(x, y))
catch
p_d[s] = NaN
end
end
mean(isfinite.(p_d))
mean(p_d .< 0.05)
mean(p_d .< 0.01)
mean(p_d .< 0.001)
@johnmyleswhite
Copy link
Author

julia> mean(isfinite.(p_d))
0.999917

julia> mean(p_d .< 0.05)
0.018518

julia> mean(p_d .< 0.01)
0.001566

julia> mean(p_d .< 0.001)
4.9e-5

@johnmyleswhite
Copy link
Author

Bug here where z is re-used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment