jtr13 / 1201

STAT 1201 Supplemental Materials
https://jtr13.github.io/1201/
3 stars 9 forks source link

Chapter 3 suggestions #49

Closed arianagamero closed 2 years ago

arianagamero commented 2 years ago

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)

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