Product of two beta distributions

2019-05-19 03:08发布

Say I have two random variables:

X ~ Beta(α1,β1)

Y ~ Beta(α2,β2)

I would like to compute distribution of Z = XY (the product of the random variables)

With scipy, I can get the pdf of a single Beta with:

from scipy.stats import beta
rv = beta(a, b)
x = np.linspace(start=0, stop=1, num=200)
my_pdf = rv.pdf(x)

But what about the product of two Betas? Can I do this analytically? (Python/Julia/R solutions are fine).

2条回答
不美不萌又怎样
2楼-- · 2019-05-19 03:58

For an analytical solution, have a look at this paper and this answer.

A numerical approach in R

set.seed(1) # for reproducability

n <- 100000 # number of random variables

# first beta distribution
a1 <- 0.5
b1 <- 0.9
X <- rbeta(n, a1, b1)

# second beta distribution
a2 <- 0.9
b2 <- 0.5
Y <- rbeta(n, a2, b2)

# calculate product
Z <- X * Y

# Have a look at the distributions
plot(density(Z), col = "red", main = "Distributions")
lines(density(X), lty = 2)
lines(density(Y), lty = 2)

enter image description here

查看更多
Luminary・发光体
3楼-- · 2019-05-19 03:59

FWIW, same in Python

from scipy import stats
import statsmodels.api as sm
import matplotlib.pyplot as plt

N = 100000

y = stats.beta(.5, .9).rvs(N)
x = stats.beta(.9, .5).rvs(N)
z = x*y
dens_z = sm.nonparametric.KDEUnivariate(z)
dens_z.fit()

dens_x = sm.nonparametric.KDEUnivariate(x)
dens_x.fit()

dens_y = sm.nonparametric.KDEUnivariate(y)
dens_y.fit()

fig, ax = plt.subplots()
ax.plot(dens_z.support, dens_z.density, label='z')
ax.plot(dens_x.support, dens_x.density, label='x')
ax.plot(dens_y.support, dens_y.density, label='y')
ax.legend()
plt.draw_if_interactive()

distributions

查看更多
登录 后发表回答