00:01
In this exercise, we refer back to the probability mass function in exercise 32, which i've provided in the table here.
00:08
And we want to write some code that will simulate this random variable, and using that simulation, find, or approximate the expected value and the standard deviation.
00:21
So the strategy here is three steps.
00:24
First, we will simulate 10 ,000 values from the probability distribution, then calculate the mean from the values.
00:43
And then calculate the standard deviation from the values.
00:55
So i did this in r, and the code that i created in r is as follows.
01:02
So in the first line of code, what we're doing is we're sampling from this vector space.
01:08
So sampling from these three values, we're taking 10 ,000 samples.
01:13
True means that we are sampling with replacement.
01:17
And this vector is a probability vector for the three values of our vector that we're sampling from.
01:25
So it assigns to each of these values a probability.
01:31
So it samples the values with their respective probabilities.
01:38
And obviously the second line finds the mean of these values.
01:42
And the third line finds the standard deviation of the values.
01:48
So now if we run this in r, we get the following...