In order to calculate the mean using R, you will need to generate 2 different sets of variables for the values (x) and their respective probabilities (px).
x <- 1:5
px <- c(.1, .15, .2, .25, .3)
Then, you multiply these two datasets and find the sum of the weighted probabilities:
x*px
sum(x*px) # E(X)
You can also do this in the following way:
weighted.mean(x, px)
3.3 Variance
You can calculate the variance in 2 ways:
1) Manually computing the variance formula where you find the sum of the squared differences of each value with the mean
3.3 Expected value
In order to calculate the mean using R, you will need to generate 2 different sets of variables for the values (x) and their respective probabilities (px).
Then, you multiply these two datasets and find the sum of the weighted probabilities:
You can also do this in the following way:
3.3 Variance You can calculate the variance in 2 ways: 1) Manually computing the variance formula where you find the sum of the squared differences of each value with the mean
2) Using the fact that E(X^2) - [E(X)]^2 (find these two values using the formula for expectation):
I think the sections on Binomial, Poisson and Hypergeometric distributions are very well explained and complete