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.