# Chi-Square test of a sample

**URL:** <https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617>\
**Category:** Statistics\
**Tags:** question\
**Created:** [June 26, 2021, 6:44pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617 "2021-06-26T18:44:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [June 26, 2021, 6:44pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/1 "2021-06-26T18:44:36Z")

</div>

Hello!

I am working on a project in which I was given a random sample, and now I want to identify, among 3 distributions, which one created this sample.

By plotting a histogram, it seems that the gamma distribution is the one that performs the best fit, but I would also like to perform a chi-square test.

I am guessing that, maybe, I can use the `ChisqTest` function from `HypothesisTests` package, but I am not sure how to do that…

Also, the values in my random samples are all Float numbers, so I am not sure if I can use this function.

Any tips on how I can do that?

---

<div class="post-metadata">

**Author:** ![AquaIndigo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaindigo/32/15820_2.png) [@AquaIndigo](https://discourse.julialang.org/u/AquaIndigo)\
**Post date:** [June 27, 2021, 1:20am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/2 "2021-06-27T01:20:39Z")

</div>

You can perform the goodness of fit chisq test which need two vectors.

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [June 27, 2021, 2:23am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/3 "2021-06-27T02:23:02Z")

</div>

As an aside, a χ^2 _is_ a Γ distribution though not necessarily vice versa.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 27, 2021, 9:45am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/4 "2021-06-27T09:45:09Z")

</div>

Not a direct answer, but just in case, this [e-handbook page](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm) explains quite clearly the steps involved when performing a Chi-Square Goodness-of-Fit Test, which should be useful before using the `ChisqTest` function from `HypothesisTests.jl`.

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [June 27, 2021, 1:22pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/5 "2021-06-27T13:22:04Z")

</div>

I typically use a non-parametric test in this case. For example:

```julia
using Distributions
using HypothesisTests
using StatsPlots

# generate some fake data (note that they come from a Gamma distribution)
data = rand(Gamma(7.5, 1.0), 75)

# fit a few distributions that I suspect may model the data well
gamma = fit(Gamma, data)
lognormal = fit(LogNormal, data)
rayleigh = fit(Rayleigh, data)

# Use quantile-quantile plots to visually inspect the goodness of fit
qqplot(data,gamma)
qqplot(data,lognormal)
qqplot(data,rayleigh)

# perform a Kolmogorov-Smirnov test (or Anderson-Darling) 
ExactOneSampleKSTest(data, gamma)
ExactOneSampleKSTest(data, lognormal)
ExactOneSampleKSTest(data, rayleigh)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 12, 2021, 1:00pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/7 "2021-07-12T13:00:21Z")

</div>

The following Chi-Square tests seem to work in investigating which of the different input data samples follow a Gamma probability distribution.

One of the references used was [this presentation by Dr. Wolfgang Rolke](https://indico.cern.ch/event/972293/attachments/2136087/3607059/Testing%20Goodness%20of%20Fit.pdf).

![HypothesisTests_asymmetric_distributions](https://global.discourse-cdn.com/julialang/original/3X/f/0/f00db004981dcaee62cd91bcaf40b73440a3d7ea.png)

```julia
using Random, Distributions
using StatsBase, HypothesisTests

n = 1000 # number of data points in sample
nbins = 10 # equi-probable bins will be computed via quantiles

# Draw random samples from asymmetric distributions:
Y1 = rand(LogNormal(), n) # lognormal distribution
Y2 = rand(Gamma(), n) # Gamma distribution
Y3 = rand(Chi(1), n) # Chi(1) distribution

# Test Gamma on Y1:
bins1 = quantile(Y1, LinRange(1/nbins,1,nbins))
h1 = fit(Histogram, Y1, bins1)
fd1 = fit(Gamma,Y1)
theta1 = diff(cdf.(fd1,bins1))
ChisqTest(h1.weights, theta1/sum(theta1)) # Χ² = 34 -> Reject H0

# Test Gamma on Y2:
bins2 = quantile(Y2, LinRange(1/nbins,1,nbins))
h2 = fit(Histogram, Y2, bins2)
fd2 = fit(Gamma,Y2)
theta2 = diff(cdf.(fd2,bins2))
ChisqTest(h2.weights, theta2/sum(theta2)) # Χ² = 4.7 -> Fail to reject H0

# Test Gamma on Y3:
bins3 = quantile(Y3, LinRange(1/nbins,1,nbins))
h3 = fit(Histogram, Y3, bins3)
fd3 = fit(Gamma,Y3)
theta3 = diff(cdf.(fd3,bins3))
ChisqTest(h3.weights, theta3/sum(theta3)) # Χ² = 29.6 -> Reject H0

```

_ **NB:** a word of caution, produced by a non-statistician, just a Julia user_

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 13, 2021, 9:16am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/8 "2021-07-13T09:16:32Z")

</div>

Suppose the i.i.d. sample `Y` is fitted with models A, B, and C.

In order to determine which model’s prediction is likely to be closer to the true (but unknown) distribution that generated the original sample `Y`, one of the standard prescriptions is to use the AIC. Select the model with the smallest AIC.

Ref. [Akaike information criterion - Wikipedia](https://en.wikipedia.org/wiki/Akaike_information_criterion)

In the following example, models A, B, and C are respectively `Gamma`, `Weibull`, and `LogNormal`. I have experimented with three true distributions `Gamma(5, 2)`, `Weibull(2.4, 11.3)`, and `LogNormal(2.2, 0.47)`. These are similar each others. Please look at the graph in the following example.

Results of a Monte Carlo simulation (10^4 iterations) with samples `Y` generated by `Gamma(5, 2)` of size 100:

```julia
     Gamma => 0.6692
   Weibull => 0.1409
 LogNormal => 0.1899

```

The percentage of the correct answer, `Gamma`, being selected is about 67 percent.

In the cases of `Weibull(2.4, 11.3)` and `LogNormal(2.2, 0.47)`, the percentages of the correct answers are about 86 percent and about 81 percent, respectively.

For details, see the following code and results.

```julia
using Distributions, StatsPlots

function aic(model, Y)
    mle = fit_mle(model, Y)
    -2loglikelihood(mle, Y) + 2length(params(mle))
end

function simulate_model_selections(models, truedist, samplesize; niters = 10^4)
    selectedmodel = Vector{Int}(undef, niters)
    Threads.@threads for i in 1:niters
        Y = rand(truedist, samplesize)
        selectedmodel[i] = argmin(aic.(models, Ref(Y)))
    end
    nselected = zeros(Int, 3)
    for i in 1:niters
        nselected[selectedmodel[i]] += 1
    end
    [model => nselected[i]/niters for (i, model) in enumerate(models)]
end

models = (Gamma, Weibull, LogNormal)

a, b = 0, 40
plot(Gamma(5, 2), a, b; label="Gamma(5, 2)")
plot!(Weibull(2.4, 11.3), a, b; label="Weibull(2.4, 11.3)", ls=:dash)
plot!(LogNormal(2.2, 0.47), a, b; label="LogNormal(2.2, 0.47)", ls=:dashdot)

```

![2021-07-13](https://global.discourse-cdn.com/julialang/original/3X/3/d/3da8520f03588d49e6a7c59e4997b7c033952fd4.png)

```julia
simulate_model_selections(models, Gamma(5, 2), 100; niters = 10^4)

```

```julia
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.6692
   Weibull => 0.1409
 LogNormal => 0.1899

```

```julia
simulate_model_selections(models, Weibull(2.4, 11.3), 100; niters = 10^4)

```

```julia
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.1427
   Weibull => 0.856
 LogNormal => 0.0013

```

```julia
simulate_model_selections(models, LogNormal(2.2, 0.47), 100; niters = 10^4)

```

```julia
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.1914
   Weibull => 0.0034
 LogNormal => 0.8052

```

**Pluto notebook:** [Simulation of AIC model selection - Pluto notebook.jl](https://raw.githubusercontent.com/genkuroki/public/main/0011/Simulation%20of%20AIC%20model%20selection%20-%20Pluto%20notebook.jl)

You can execute in Pluto by copy-and-pasting the URL into “Open from file:” input form and click “Open” button.

![2021-07-13 (8)](https://global.discourse-cdn.com/julialang/original/3X/d/1/d16bf5331156039310a593b885e0c161bbec3838.png)

Edit 1: I’m sorry. The original code works with Julia ≥ v1.7.0-beta. The edited code above works also on Julia v1.6.1.

Edit 2: Link to Pluto notebook.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 13, 2021, 11:30am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/9 "2021-07-13T11:30:03Z")

</div>

> [@genkuroki](#):
>
> `simulate_model_selections(models, LogNormal(2.2, 0.47), 100; niters = 10^4)`

```julia
simulate_model_selections(models, Gamma(5, 2), 100; niters = 10^4)
ERROR: TaskFailedException
Stacktrace:
 [1] wait
   @ .\task.jl:322 [inlined]
 [2] threading_run(func::Function)
   @ Base.Threads .\threadingconstructs.jl:34
 [3] macro expansion
   @ .\threadingconstructs.jl:93 [inlined]
 [4] simulate_model_selections(models::Tuple{UnionAll, UnionAll, UnionAll}, truedist::Gamma{Float64}, samplesize::Int64; niters::Int64)
   @ Main .\REPL[50]:3
 [5] top-level scope
   @ REPL[51]:1

    nested task error: MethodError: no method matching keys(::Base.Generator{Tuple{UnionAll, UnionAll, UnionAll}, var"#12#15"{Vector{Float64}}})
    Closest candidates are:
      keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at C:\Users\Hermesr\.julia\packages\Tables\gg6Id\src\Tables.jl:181
      keys(::Missings.SkipMissings{V, T} where {V<:AbstractArray, T<:Tuple{Vararg{AbstractArray, N} where N}})
at C:\Users\Hermesr\.julia\packages\Missings\sx5js\src\Missings.jl:354
      keys(::Missings.EachReplaceMissing) at C:\Users\Hermesr\.julia\packages\Missings\sx5js\src\Missings.jl:94 ...
    Stacktrace:
     [1] pairs(collection::Base.Generator{Tuple{UnionAll, UnionAll, UnionAll}, var"#12#15"{Vector{Float64}}})
       @ Base .\abstractdict.jl:138
     [2] _findmin(a::Base.Generator{Tuple{UnionAll, UnionAll, UnionAll}, var"#12#15"{Vector{Float64}}}, #unused#::Colon)
       @ Base .\array.jl:2284
     [3] findmin(a::Base.Generator{Tuple{UnionAll, UnionAll, UnionAll}, var"#12#15"{Vector{Float64}}})
       @ Base .\array.jl:2281
     [4] argmin(a::Base.Generator{Tuple{UnionAll, UnionAll, UnionAll}, var"#12#15"{Vector{Float64}}})
       @ Base .\array.jl:2346
     [5] macro expansion
       @ .\REPL[50]:5 [inlined]
     [6] (::var"#25#threadsfor_fun#14"{Tuple{UnionAll, UnionAll, UnionAll}, Gamma{Float64}, Int64, Vector{Int64}, UnitRange{Int64}})(onethread::Bool)
       @ Main .\threadingconstructs.jl:81
     [7] (::var"#25#threadsfor_fun#14"{Tuple{UnionAll, UnionAll, UnionAll}, Gamma{Float64}, Int64, Vector{Int64}, UnitRange{Int64}})()
       @ Main .\threadingconstructs.jl:48

```

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 13, 2021, 12:14pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/10 "2021-07-13T12:14:32Z")

</div>

Oh, I’m sorry.

I have corrected the code above to work on Julia v1.6.1.

I usually use the nightly build because I want to enjoy the latest features implemented by the developers. Though the nightly build is sometimes pretty much broken, I enjoy it as proof that the developers are taking on a challenging task.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 13, 2021, 12:31pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/11 "2021-07-13T12:31:56Z")

</div>

```julia
simulate_model_selections(models, Gamma(5, 2), 100; niters = 10^4)
ERROR: TaskFailedException
Stacktrace:
 [1] wait
   @ .\task.jl:322 [inlined]
 [2] threading_run(func::Function)
   @ Base.Threads .\threadingconstructs.jl:34
 [3] macro expansion
   @ .\threadingconstructs.jl:93 [inlined]
 [4] simulate_model_selections(models::Tuple{UnionAll, UnionAll, UnionAll}, truedist::Gamma{Float64}, samplesize::Int64; niters::Int64)
   @ Main .\REPL[11]:3
 [5] top-level scope
   @ REPL[12]:1

    nested task error: UndefVarError: mle not defined
    Stacktrace:
      [1] aic(model::Type, Y::Vector{Float64})
        @ Main .\REPL[10]:2
      [2] _broadcast_getindex_evalf
        @ .\broadcast.jl:648 [inlined]
      [3] _broadcast_getindex
        @ .\broadcast.jl:621 [inlined]
      [4] (::Base.Broadcast.var"#19#20"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(aic), Tuple{Tuple{UnionAll, UnionAll, UnionAll}, Base.RefValue{Vector{Float64}}}}})(k::Int64)
        @ Base.Broadcast .\broadcast.jl:1098
      [5] ntuple
        @ .\ntuple.jl:50 [inlined]
      [6] copy
        @ .\broadcast.jl:1098 [inlined]
      [7] materialize
        @ .\broadcast.jl:883 [inlined]
      [8] macro expansion
        @ .\REPL[11]:5 [inlined]
      [9] (::var"#25#threadsfor_fun#11"{Tuple{UnionAll, UnionAll, UnionAll}, Gamma{Float64}, Int64, Vector{Int64}, UnitRange{Int64}})(onethread::Bool)
        @ Main .\threadingconstructs.jl:81
     [10] (::var"#25#threadsfor_fun#11"{Tuple{UnionAll, UnionAll, UnionAll}, Gamma{Float64}, Int64, Vector{Int64}, UnitRange{Int64}})()
        @ Main .\threadingconstructs.jl:48

Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)

```

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [July 13, 2021, 1:28pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/12 "2021-07-13T13:28:39Z")

</div>

The following is how it works fine in my environment.

 ![2021-07-13 (5)](https://global.discourse-cdn.com/julialang/original/3X/e/a/ea672a6e33bbdc4be0dba7c64916c0346d79b1ab.png)

 ![2021-07-13 (6)](https://global.discourse-cdn.com/julialang/original/3X/3/f/3fee190b339de4b0837cfa73ead0c35b7fe3eab1.png)

Pluto notebook version:

 ![2021-07-13 (7)](https://global.discourse-cdn.com/julialang/original/3X/a/d/ad7a9c5c9171bf3c0931584d076e22100356d9cb.png)

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 14, 2021, 1:28pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/13 "2021-07-14T13:28:49Z")

</div>

Why can’t I update the package to the desired version?

```julia
>st
      Status `C:\Users\Hermesr\.julia\environments\v1.6\Project.toml`
  [31c24e10] Distributions v0.24.18
>up Distributions@0.25.10
    Updating registry at `C:\Users\Hermesr\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
  No Changes to `C:\Users\Hermesr\.julia\environments\v1.6\Project.toml`
  No Changes to `C:\Users\Hermesr\.julia\environments\v1.6\Manifest.toml`

>st Distributions
      Status `C:\Users\Hermesr\.julia\environments\v1.6\Project.toml`
  [31c24e10] Distributions v0.24.18

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 14, 2021, 2:06pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/14 "2021-07-14T14:06:57Z")

</div>

I think you mean `add Distributions@0.25.10`?

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 14, 2021, 2:17pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/15 "2021-07-14T14:17:47Z")

</div>

> [@nilshg](#):
>
> Distributions@0.25.10

```julia
(@v1.6) pkg> rm Distributions
    Updating `C:\Users\Hermesr\.julia\environments\v1.6\Project.toml`
  [31c24e10] - Distributions v0.24.18
  No Changes to `C:\Users\Hermesr\.julia\environments\v1.6\Manifest.toml`

(@v1.6) pkg> add Distributions@0.25.10
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Distributions [31c24e10]:
 Distributions [31c24e10] log:
 ├─possible versions are: 0.16.0-0.25.10 or uninstalled
 ├─restricted to versions 0.25.10 by an explicit requirement, leaving only versions 0.25.10
 └─restricted by compatibility requirements with Gadfly [c91e804a] to versions: 0.16.0-0.24.18 — no versions left
   └─Gadfly [c91e804a] log:
     ├─possible versions are: 0.8.0-1.3.3 or uninstalled
     └─restricted to versions * by an explicit requirement, leaving only versions 0.8.0-1.3.3

(@v1.6) pkg> add Distributions
   Resolving package versions...
    Updating `C:\Users\Hermesr\.julia\environments\v1.6\Project.toml`
  [31c24e10] + Distributions v0.24.18
  No Changes to `C:\Users\Hermesr\.julia\environments\v1.6\Manifest.toml`

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 14, 2021, 2:24pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/16 "2021-07-14T14:24:59Z")

</div>

So there’s your answer!

(NB you don’t have to `rm` if you want to install a specific version, `add Package@version` essentially does what you thought `up Package@version` would do)

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 14, 2021, 2:32pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/17 "2021-07-14T14:32:07Z")

</div>

> [@nilshg](#):
>
> Distributions@0.25.10

My intention was to upgrade the Distribution package to version 0.25.10.  
Think that, with up Distributions@0.25.10. that goal was achieved.  
Then I do add Distributions@0.25.10. And I present the following alert. I don’t know how to solve it!:

```julia
add Distributions@0.25.10
   Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Distributions [31c24e10]:
 Distributions [31c24e10] log:
 ├─possible versions are: 0.16.0-0.25.10 or uninstalled
 ├─restricted to versions 0.25.10 by an explicit requirement, leaving only versions 0.25.10
 └─restricted by compatibility requirements with Gadfly [c91e804a] to versions: 0.16.0-0.24.18 — no versions left
   └─Gadfly [c91e804a] log:
     ├─possible versions are: 0.8.0-1.3.3 or uninstalled
     └─restricted to versions * by an explicit requirement, leaving only versions 0.8.0-1.3.3

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 14, 2021, 2:34pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/18 "2021-07-14T14:34:50Z")

</div>

I understood that, and the error message tells you pretty explicitly what’s going on - Gadfly is only compatible with Distributions up to 0.24, so you cannot install Gadfly and Distributions@0.25 in the same environment. I feel like I’ve given you this advice before, but to reiterate you generally shouldn’t have all your packages in the default (`@v1.6`) environment, but rather work in project specific environments containing only the packages you actually need for whatever you’re currently trying to do.

---

<div class="post-metadata">

**Author:** ![HerAdri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heradri/32/5816_2.png) [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Post date:** [July 14, 2021, 2:57pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/19 "2021-07-14T14:57:33Z")

</div>

> [@nilshg](#):
>
> Distributions@0.25.10

```julia
julia> simulate_model_selections(models, Gamma(5, 2), 100; niters = 10^4)
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.6696
   Weibull => 0.1463
 LogNormal => 0.1841

julia> simulate_model_selections(models, Weibull(2.4, 11.3), 100; niters = 10^4)
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.144
   Weibull => 0.8538
 LogNormal => 0.0022

julia> simulate_model_selections(models, LogNormal(2.2, 0.47), 100; niters = 10^4)
3-element Vector{Pair{UnionAll, Float64}}:
     Gamma => 0.1836
   Weibull => 0.0035
 LogNormal => 0.8129

(Julia Statistics) pkg> st
      Status `C:\projects\Julia Statistics\Project.toml`
  [31c24e10] Distributions v0.25.10
  [91a5bcdd] Plots v1.19.0
  [f3b207a7] StatsPlots v0.14.25

(Julia Statistics) pkg> 

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 14, 2021, 3:05pm UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/20 "2021-07-14T15:05:13Z")

</div>

I assume you’re saying it’s working now, in which case glad to see that it is!

---

<div class="post-metadata">

**Author:** ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)\
**Post date:** [July 16, 2021, 8:50am UTC](https://discourse.julialang.org/t/chi-square-test-of-a-sample/63617/21 "2021-07-16T08:50:22Z")

</div>

Thanks everybody for the great answers!!
