两个beta版本的产品

时间:2014-02-19 18:18:34

标签: python r statistics julia statsmodels

假设我有两个随机变量:

X~Beta(α1,β1)

Y~β(α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)

但两个Betas的产品怎么样?我可以分析吗? (Python / Julia / R解决方案很好)。

2 个答案:

答案 0 :(得分:3)

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

distributions

答案 1 :(得分:2)

对于分析解决方案,请查看this paperthis answer

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