Jump to content

Verify distribution uniformity/Chi-squared test: Difference between revisions

Added Julia language
(Added Elixir)
(Added Julia language)
Line 641:
4 4,146 0,38657083 YES [199809.0, 200665.0, 199607.0, 200270.0, 199649.0]
4 790063,276 0,00000000 NO [522573.0, 244456.0, 139979.0, 71531.0, 21461.0]</pre>
 
=={{header|Julia}}==
<lang julia># v0.6
 
using Distributions
 
function eqdist(data::Vector{T}, α::Float64=0.05)::Bool where T <: Real
if ! (0 ≤ α ≤ 1); error("α must be in [0, 1]") end
exp = mean(data)
chisqval = sum((x - exp) ^ 2 for x in data) / exp
pval = ccdf(Chisq(2), chisqval)
return pval > α
end
 
data1 = [199809, 200665, 199607, 200270, 199649]
data2 = [522573, 244456, 139979, 71531, 21461]
 
for data in (data1, data2)
println("Data:\n$data")
println("Hypothesis test: the original population is ", (eqdist(data) ? "" : "not "), "uniform.\n")
end</lang>
 
{{out}}
<pre>Data:
[199809, 200665, 199607, 200270, 199649]
Hypothesis test: the original population is uniform.
 
Data:
[522573, 244456, 139979, 71531, 21461]
Hypothesis test: the original population is not uniform.
</pre>
 
=={{header|Mathematica}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.