Generating continuous random variables
1. Generating continuous random variables
Now that we're familiar with discrete distributions, let's look at some continuous ones!2. Normal distribution
The most common continuous distribution is the normal distribution, whose probability density function (or PDF) has a well-known bell-shaped curve. There are two parameters for defining a normal distribution: the standard deviation, also known as the scale, and the mean, also known as the loc. For example, the heights of American adult males are normally distributed with a mean of 177 centimeters and a standard deviation of eight centimeters. This graph shows the theoretical PDF of American male heights.3. Changing the scale (standard deviation)
If the standard deviation is increased from eight to 15 while keeping the mean the same, the curve becomes flatter and the peak becomes wider. This is represented in green, and we notice that a larger standard deviation indicates more height variation among American males. On the other hand, if the standard deviation is decreased from eight to five, the curve becomes sharper and the peak becomes narrower, as we see in blue.4. Changing the loc (mean)
Alternatively, let's see what happens if we hold the standard deviation constant but change the mean. Because the standard deviation is not changed, the height and width of the curve do not change either. However, if the mean is increased from 177 to 185, the curve moves right, with the center of the peak now at 185. This is represented by the green curve. If the mean is decreased from 177 to 165, the curve moves left, with the center of the peak now at 165. We can see this in blue.5. Changing both scale and loc
What if we change both the standard deviation and mean? The mean values will define the center of the peak for the corresponding PDF curve, while the standard deviation defines its height and width.6. Sampling from normal distributions
Let's sample from a normal distribution to answer a question of interest. What is the combined percentage of American adult males with a height either above 190 centimeters or below 165 centimeters? We obtain the normal distribution using dot-norm and use dot-rvs to sample from it 10,000 times using a loc of 177 and a scale of eight. Next, we define qualified to filter the simulated heights which are either above 190 or below 165, and then calculate the percentage of total heights that these heights comprise. Our results indicate that around 12% of American adult males have a height either above 190 or below 165 centimeters given the distribution defined.7. Plotting simulation results
Examining the simulation results using histplot, we see the region of interest defined by plt-dot-axvline.8. More continuous probability distributions
There are many more continuous probability distributions. Two commonly used ones are continuous uniform distributions and exponential distributions, which are the continuous counterparts of the discrete uniform and geometric distributions we learned in the previous lesson. While we don't have time to cover every probability distribution in this course, understanding more distributions is a great way to improve Monte Carlo simulation skills.9. Let's practice!
Now, let's practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.