# RandomVariate from Multiplying distributions

Mathematica's RandomVariate works fine with the KernelMixtureDistribution[] function, but it doesn't seem to work if you wish to generate random numbers from a product of KernelMixtureDistributions.

If d1 = KernelMixtureDistribution[data1] and d2 = KernelMixtureDistribution[data2], you can do RandomVariate[d1] and RandomVariate[d2], but, you get an error if you try RandomVariate[d1*d2].

Any ideas on how to get around this?

Thanks.

• I think you can use TransformedDistribution[d1 d2, {Distributed[d1, KernelMixtureDistribution[data1], Distributed[d2, KernelMixtureDistribution[data2]}]. Jul 21, 2017 at 3:57

If you want to obtain a random sample of the product of two independent random variables, then you just need to use something like

n = 1000;
xy = RandomVariate[d1, n]*RandomVariate[d2, n];


If the observations are paired (each dataset having the exact same number of observations and observation k in one dataset is matched with observation k in the other dataset), then you can construct a bivariate distribution and then sample from that distribution:

d12 = KernelMixtureDistribution[Thread[{data1, data2}]]
x2 = #[] #[] & /@ RandomVariate[d12, n];


If the random variables are not independent and the two datasets are not matched, then you need to characterize the relationship between the two random variables.