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
.
Diese Übung ist Teil des Kurses
Monte Carlo Simulations in Python
Anleitung zur Übung
- 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.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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])