# Bayes Testing

**URL:** <https://discourse.julialang.org/t/bayes-testing/60373>\
**Category:** Statistics\
**Tags:** question, package\
**Created:** [May 1, 2021, 10:16am UTC](https://discourse.julialang.org/t/bayes-testing/60373 "2021-05-01T10:16:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 1, 2021, 10:16am UTC](https://discourse.julialang.org/t/bayes-testing/60373/1 "2021-05-01T10:16:34Z")

</div>

I tried to add BayesTesting.jl , but apparently it’s gone from GitHub. Is there a packages that does Bayesian t-tests or other hypothesis testsing?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [May 1, 2021, 10:27am UTC](https://discourse.julialang.org/t/bayes-testing/60373/2 "2021-05-01T10:27:47Z")

</div>

Hi @brett_knoss I see that you often ask “Do we have a package for X?” in this forum. Have you considered [JuliaHub.com](http://JuliaHub.com) for package search? Check the exploration tab. Also, a simple Google search would have answered your question: [https://github.com/JuliaStats/HypothesisTests.jl](https://github.com/JuliaStats/HypothesisTests.jl)

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 1, 2021, 10:45am UTC](https://discourse.julialang.org/t/bayes-testing/60373/3 "2021-05-01T10:45:42Z")

</div>

> [@brett\_knoss](#):
>
> Is there a packages that does Bayesian t-tests or other hypothesis testsing?

For Bayesian testing, there is a related discussion at [Bayesian Model Selection](https://discourse.julialang.org/t/bayesian-model-selection/55725).

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 1, 2021, 10:58am UTC](https://discourse.julialang.org/t/bayes-testing/60373/4 "2021-05-01T10:58:40Z")

</div>

I think hypothesistests.jl is just probabilistic tests, not Bayesian.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 1, 2021, 11:54am UTC](https://discourse.julialang.org/t/bayes-testing/60373/5 "2021-05-01T11:54:34Z")

</div>

Both frequentist and Bayesian statistics rely heavily upon probability theory. HypothesisTests.jl contains frequentist tests which is possibly what you meant to type.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 1, 2021, 3:21pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/6 "2021-05-01T15:21:44Z")

</div>

I’m not sure, that makes sence. Yes, I meant frequentist. Perhaps I should go over what model to use.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 1, 2021, 9:49pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/7 "2021-05-01T21:49:31Z")

</div>

I’m trying to use Turing.jl

```julia
# Load Turing and MCMCChains.
using Turing, MCMCChains

# Load the distributions library.
using Distributions

# Load StatsPlots for density plots.
using StatsPlots
@model coinflip(y) = begin
    
    # Our prior belief about the probability of heads in a coin.
    p ~ Beta(1, 1)
    
    # The number of observations.
    N = length(y)
    for n in 1:N
        # Heads or tails of a coin are drawn from a Bernoulli distribution.
        y[n] ~ Bernoulli(p)
    end
end
iterations = 1000
ϵ = 0.05
τ = 10
chain = sample(coinflip(data), HMC(ϵ, τ), iterations, progress=false);

```

but i get an error with the last line.

```julia
[ Info: Assume - `p` is a parameter
[ Info: Observe - `y` is an observation
ERROR: MethodError: no method matching sample(::typeof(coinflip_model), ::HMC{Union{}}, ::Int64; progress=false)
Closest candidates are:
  sample(::Function, ::T; chunk_size, save_state, resume_from, reuse_spl_n, adapt_conf) where T<:Turing.Hamiltonian at /home/brett/.julia/packages/Turing/YnwiD/src/samplers/hmc.jl:97 got unsupported keyword argument "progress"
  sample(::AbstractArray, ::AbstractWeights, ::Integer; replace, ordered) at /home/brett/.julia/packages/StatsBase/548SN/src/sampling.jl:788 got unsupported keyword argument "progress"
  sample(::Function, ::Gibbs; save_state, resume_from, reuse_spl_n) at /home/brett/.julia/packages/Turing/YnwiD/src/samplers/gibbs.jl:51 got unsupported keyword argument "progress"
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[39]:1

```

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 1, 2021, 10:14pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/8 "2021-05-01T22:14:09Z")

</div>

You are asking a lot of questions on this forum and most seem to be copy paste from tutorials. This one at least is a literal copy. If I may give you some general advise, then I would advise to change things, run the code and see what happens. 🙂 On this forum, you don’t know whether you will get an answer. The beauty of programming is that you will always get an answer and usually within a second.

EDIT: You can also checkout [StatisticalRethinkingJulia/TuringModels.jl](https://statisticalrethinkingjulia.github.io/TuringModels.jl/). Those run regularly to test whether it all still works.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 12:04am UTC](https://discourse.julialang.org/t/bayes-testing/60373/9 "2021-05-02T00:04:17Z")

</div>

Normally I’d agree, I just cant’ figure out why the tutorial example doesn’t just work.)

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 2, 2021, 12:26am UTC](https://discourse.julialang.org/t/bayes-testing/60373/10 "2021-05-02T00:26:11Z")

</div>

Fair enough. Are all the tutorials broken? What have you tried? I did that tutorial a few months ago and then it worked

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 12:51am UTC](https://discourse.julialang.org/t/bayes-testing/60373/11 "2021-05-02T00:51:27Z")

</div>

I tried just what I showed, and it says there is a probem with the form, it looks like something to do with k.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 1:09am UTC](https://discourse.julialang.org/t/bayes-testing/60373/12 "2021-05-02T01:09:29Z")

</div>

I’m guess are the variables k and mu supposed to be integers?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 3:11am UTC](https://discourse.julialang.org/t/bayes-testing/60373/13 "2021-05-02T03:11:11Z")

</div>

OK, I’m looking it over. What I want to do is compare a Likart Scale, betwen 1 and 5, for 2 nominal variables.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 2, 2021, 8:11am UTC](https://discourse.julialang.org/t/bayes-testing/60373/14 "2021-05-02T08:11:53Z")

</div>

Sorry, I don’t have much experience with nominal data. Hopefully someone else will see your post.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 9:56pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/15 "2021-05-02T21:56:20Z")

</div>

The problem was with other pacages that I had. It didn’t install the latest version, so naturally the tutorial was wrong. I’ve had this problem with other packages.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 10:03pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/16 "2021-05-02T22:03:06Z")

</div>

OK thanks. @Storopoli suggested using the Savage-Dickey method. But there isn’t a package for it, so I will have to put something together, from the paper he provided.

[https://www-sciencedirect-com.cyber.usask.ca/science/article/pii/S0010028509000826#fig3](https://www-sciencedirect-com.cyber.usask.ca/science/article/pii/S0010028509000826#fig3)  
(behind a pay wall, if you’re not affiliated with a University)

And, I’m not sure that I’m the best at that,but I’ll give it a go.

As I said earlier, the problem was with the version, which always makes it hard to explain what’s wrong.

---

<div class="post-metadata">

**Author:** ![Storopoli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/storopoli/32/209278_2.png) [@Storopoli](https://discourse.julialang.org/u/Storopoli)\
**Post date:** [May 2, 2021, 10:21pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/17 "2021-05-02T22:21:23Z")

</div>

Note that the original Savage-Dickey method is for similar “nested” models. You might also be interested in a “generalized” Savage-Dickey method: [[1311.1292v1] A Generalized Savage-Dickey Ratio](https://arxiv.org/abs/1311.1292v1)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 2, 2021, 10:47pm UTC](https://discourse.julialang.org/t/bayes-testing/60373/18 "2021-05-02T22:47:17Z")

</div>

Do I need to calculate indefinate integrals? Currently there is no Julia pacakge for this (although, one is intended to be in ModelingToolkit.jl). If integrals can be done arithmetically, then ForwardDiff is great.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 3, 2021, 2:39am UTC](https://discourse.julialang.org/t/bayes-testing/60373/19 "2021-05-03T02:39:34Z")

</div>

Unfortunately, I’m not sure how to read this. 😕 I was also looking at a Bayesian t-test but the one package that had one disappeared sometime around 2018, and I would have to see if QuadGK can calculate an integral from 0 to infinity.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 3, 2021, 5:16am UTC](https://discourse.julialang.org/t/bayes-testing/60373/20 "2021-05-03T05:16:46Z")

</div>

I think I found a different version

```julia
B[i] =(p(delta[i]=delta[i-1] | y,m[1])/(p(delta[i]=delta[i-1]|m[i]) 
# Bayes Factor is the propabilty of the different equaling the previous difference knowing y and 
m[i], divided by the probabilty of delta[i]=delta[i-1] knowing m[i])
#where y is the dependent variables, and m[i] is a model for each itteration, modifying for what is now known.

```

I think I have an idea of how a model is constructed in Turing.jl , but I will need to play around with this.

[Next page](https://discourse.julialang.org/t/bayes-testing/60373.md?page=2)
