1

Say I have a vector of possible values

[0, 1, 2, 3, 4]

And then I have 2 vectors of discrete probability distributions for this vector, say

[0.2, 0.1, 0.1, 0.4, 0.2]

[0.4, 0.3, 0.1, 0.1, 0.1]

And I want to calculate the expected value and variance from the original vector given the 2 distributions.

I believe I can calculate the expected value relatively easy by taking the weighted mean, for example using the first vector

expected = weighted.mean(vector1, distribution1)

But I'm not sure how I would go about calculating the variance. I thought about using the var() function but am not sure how to apply it with the distributions.

Kermitty
  • 61
  • 1
  • 2
  • See wikipedia https://en.wikipedia.org/wiki/Variance#Discrete_random_variable ... `var` is for unweighted sample variance and has the Bonferroni correction applied. You're dealing with the variance of a discrete distribution $\text{Var(X)}=\sum_{i=1}^k p_i (x_i-\mu)^2$ where $\mu$ is the expected value. – Glen_b Aug 02 '21 at 01:44
  • Hi: sum ((valuevec - expected)^2 * probvec) where valuevec is the vector of values and probvec is the vector of probabilities. expected can be calculated using sum(valuevec * probvec) or the way you did it. – mlofton Aug 02 '21 at 01:46
  • You may view each of these distributions as being a mixture of atoms at $0, \ldots, 4.$ The moments of an atom are trivial to obtain: they are just the powers of its value. You may then directly apply https://stats.stackexchange.com/a/16609/919 to find the moments of this mixture. – whuber Aug 02 '21 at 13:36

0 Answers0