Distributions.jl: how to create a mixture of a scaled Beta distribution?

Defining a mixture of 2 Beta distributions works as one would expect:

using Distributions, GLMakie
LocationScale(0.5, 1, Beta(1, 1))

d = MixtureModel(
    Beta[
        Beta(1, 1),
        Beta(2, 10)], [0.5, 0.5])

xaxis = range(-0.1, 1.1, length=1000)
lines(xaxis, pdf.(d, xaxis))

image

Scaling one distribution works too:

d = 0.5 * Beta(2, 10)
lines(xaxis, pdf.(d, xaxis))

image

Unfortunately, setting a mixture of 2 scaled Beta distributions fails:

d = MixtureModel(
    Beta[
        0.5 * Beta(1, 1),
        0.5 * Beta(2, 10)], [0.5, 0.5])
ERROR: MethodError: Cannot `convert` an object of type 
  LocationScale{Float64, Continuous, Beta{Float64}} to an object of type
  Beta

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84

I also tried setting the LocationScale for the first Beta but to no avail:

d = MixtureModel(
    LocationScale(0, 1, Beta(1, 1))[
        0.5 * Beta(1, 1),
        0.5 * Beta(2, 10)], [0.5, 0.5])
ERROR: MethodError: no method matching getindex(::LocationScale{…}, ::LocationScale{…}, ::LocationScale{…})

Any help to create a mixture of 2 scaled Betas would be much appreciated

If X\sim Beta(a,b), and c is a number in (0,1), then cX
isn’t Beta distributed. Hence your d is not a mixture of Beta distributions.
It works with just:

d = MixtureModel([0.5 * Beta(1, 1), 0.5 * Beta(2, 10)], [0.5, 0.5])
2 Likes

Aah makes sense. Thanks!

1 Like