Two independent normal distributions
Rohit has two freelance jobs. The pay for each job follows two independent normal distributions:
income1
from Rohit's first job has a mean of $500 and a standard deviation of $50income2
from Rohit's second job has a mean of $1,000 and a standard deviation of $200
Rohit has asked for your help simulating his income so that he can budget his expenses properly. You'll use sampling to find the 95% confidence interval of Rohit's total income from both jobs.
You are going to perform simulations using normal distributions, which are probably the most important probability distribution used in Monte Carlo simulation.
The following have been imported for you: NumPy as np
, and SciPy's stats
module as st
.
This exercise is part of the course
Monte Carlo Simulations in Python
Exercise instructions
- Use
st.norm.rvs()
to sample 1,000 times from the normal distribution, setting the proper mean and standard deviation and assigning the results toincome1
andincome2
. - Approximate
total_income
by addingincome1
andincome2
together.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Sample from the normal distribution
income1 = ____
income2 = ____
# Define total_income
total_income = ____
upper = np.quantile(total_income, 0.975)
lower = np.quantile(total_income, 0.025)
print([lower, upper])