# Bayes Testing

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?

Hi @brett_knoss I see that you often ask “Do we have a package for X?” in this forum. Have you considered JuliaHub.com for package search? Check the exploration tab. Also, a simple Google search would have answered your question: GitHub - JuliaStats/HypothesisTests.jl: Hypothesis tests for Julia

3 Likes

For Bayesian testing, there is a related discussion at Bayesian Model Selection.

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

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

1 Like

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

I’m trying to use Turing.jl

``````# 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.

``````[ 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
``````

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. Those run regularly to test whether it all still works.

4 Likes

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

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

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

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

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

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

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.

1 Like

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.

(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.

1 Like

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

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.

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.

I think I found a different version

``````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.