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.
varis 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