1
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ I think you can use TransformedDistribution[d1 d2, {Distributed[d1, KernelMixtureDistribution[data1], Distributed[d2, KernelMixtureDistribution[data2]}]. $\endgroup$
    – Carl Woll
    Jul 21, 2017 at 3:57

1 Answer 1

1
$\begingroup$

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 = #[[1]] #[[2]] & /@ 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.