jtr13/1201

Chapter 3 suggestions

arianagamero opened this issue · 0 comments

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

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
x - 3.5
(x - 3.5)^2
((x - 3.5)^2)*px
sum(((x - 3.5)^2)*px)   # V(X)
  1. Using the fact that E(X^2) - [E(X)]^2 (find these two values using the formula for expectation):
x
px
x^2
(x^2)*px
sum((x^2)*px)  # E(X^2)
14-3.5^2     # E(X^2) - [E(X)]^2

I think the sections on Binomial, Poisson and Hypergeometric distributions are very well explained and complete