0

Suppose we generate a random variable as follows:

y = np.random.normal(loc=np.random.randint(2),scale=1.2)

Then what is the probability density function(pdf) of y i.e. p(y) in this situation?

Thanks in advance.

  • 1
    I suppose that, if `N(x, m, s)` is the PDF of a normal distribution with mean `m` and standard deviation `s`, the PDF for your distribution would be `(N(x, 0, 1.2) + N(x, 1, 1.2)) / 2`. – jdehesa Oct 16 '20 at 09:23

1 Answers1

1

This is a mixture of an absolutely continuous distribution (the normal distribution) and a discrete distribution (the uniform distribution). In the case at hand, the distribution has a probability density function (PDF) of the following form:

y fy(x) * g(y),

Where—

  • fy is the PDF for the normal(y, 1.2) distribution (mean of y, standard deviation of 1.2), and
  • g(y) is the probability mass function for the discrete uniform distribution over the integers in [0, 2) (which can take on only the values 0 and 1 since numpy.random.randint excludes the endpoint).

See also page 16 of Non-Uniform Random Variate Generation.

In this case, the mixture PDF is:

  • y = 0, 1 N(x; y, 1.2) * (1/2), or
  • (N(x; 0, 1.2) + N(x; 1, 1.2)) / 2,

Where N is the PDF for the normal distribution. See also a comment by "jdehesa".

(Note that numpy.random.* functions, including randint and normal, are legacy functions as of NumPy 1.17; see also this question.)

Peter O.
  • 32,158
  • 14
  • 82
  • 96