3

假设我有两个随机变量:

X ~ Beta(α1,β1)

Y ~ Beta(α2,β2)

我想计算 Z = XY 的分布(随机变量的乘积)

使用scipy,我可以通过以下方式获取单个 Beta 的 pdf:

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

但是两个 Beta 的乘积呢?我可以分析地做到这一点吗?(Python/Julia/R 解决方案很好)。

4

2 回答 2

5

FWIW,在 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()

分布

于 2014-02-19T21:28:43.397 回答
3

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

于 2014-02-19T18:55:31.270 回答