rquiz_practice_problem_1a(8, 0, 1)
## ----------------------------------
## Problem 1a: sampling from a normal distribution
## 2.228374 -0.3991196 1.02897 0.2104928 -1.324092 -1.502721 1.143419 -0.2782333
rquiz_practice_problem_1b(10, 10, 0.3)
## -----
## 1b: sampling from a binomial distribution
## 5 3 1 3 3 4 2 3 5 3
sample_space = c('Yes', 'No', 'Maybe')
rquiz_practice_problem_1c(sample_space, 7)
## -----
## 1c: sampling from a list with replacement
## Maybe Maybe No Yes Yes Yes Yes
rquiz_practice_problem_1d(6)
## -----
## 1d: Permutations
## 3 4 1 5 2 6
rquiz_practice_problem_1e(2, 2*pi)
## -----
## 1e: Plotting
## See plot: Plot for problem 1e
rquiz_practice_problem_1f(5000, 1, 5)
## -----
## 1f: Sampling and basic statistics
## mean: 3.010489
## median: 3.002567
## var: 1.293794
## sd: 1.137451
## 0.25 and 0.75 quantiles for the data: 2.045466 3.991788
rquiz_practice_problem_1g(50, 1,3)
## -----
## 1g: Sampling and basic statistics
## Covariance of x an z: 0.1393713
## Correlation of x an z: 0.6616549
## See plot: Scatterplot for problem 1g
rquiz_practice_problem_1h(50, 0, 2, 1.5, 2, 0.05, 0, 2)
## -----
## 1h: Sampling and basic statistics
## 1h: n_samples=50, alpha=0.05, mu0=0, sigma0=2
## mu1=0, sigma1=2, mu2=1.5, sigma2=2
## ---Problem 1h(i)
## z_stat = -0.8976517
## p_value = 0.3693713
## The data does not support rejecting H0:mu1 = 0(assuming sigma1=2)
## ---Problem 1h(ii)
## t_stat = -0.8987041
## p_value = 0.3732054
## The data does not support rejecting H0: mu1 = 0
## ---Problem 1h(iii)
## t_stat = -5.050312
## p_value = 2.040877e-06
## Reject H0 in favor of HA: mu1 != mu2
## ---Problem 1h(iv)
## test_stat = 0.8535616
## p_value = 0.5815822
## The data does not support rejecting H0: var(x1) == var(x2)
rquiz_practice_problem_1h(50, 0, 2, 0, 2, 0.05, 0, 2)
## -----
## 1h: Sampling and basic statistics
## 1h: n_samples=50, alpha=0.05, mu0=0, sigma0=2
## mu1=0, sigma1=2, mu2=0, sigma2=2
## ---Problem 1h(i)
## z_stat = -1.752476
## p_value = 0.07969205
## The data does not support rejecting H0:mu1 = 0(assuming sigma1=2)
## ---Problem 1h(ii)
## t_stat = -2.134783
## p_value = 0.03780555
## Reject H0 in favor of HA: The mean is not equal to 0 (assuming sigma1= 2 )
## ---Problem 1h(iii)
## t_stat = -1.944973
## p_value = 0.05464438
## The data does not support rejecting H0 that: mu1 = mu2
## ---Problem 1h(iv)
## test_stat = 0.5583306
## p_value = 0.04386132
## Reject H0 in favor of HA: var(x1) != var(x2)
rquiz_practice_problem_1h(50, 1, 5, 1.5, 2, 0.05, 0, 2)
## -----
## 1h: Sampling and basic statistics
## 1h: n_samples=50, alpha=0.05, mu0=0, sigma0=2
## mu1=1, sigma1=5, mu2=1.5, sigma2=2
## ---Problem 1h(i)
## z_stat = 3.477764
## p_value = 0.0005056143
## Reject H0 in favor of HA: The mean is not equal to 0 (assuming sigma1= 2 )
## ---Problem 1h(ii)
## t_stat = 1.261255
## p_value = 0.2131889
## The data does not support rejecting H0: mu1 = 0
## ---Problem 1h(iii)
## t_stat = -0.03302583
## p_value = 0.9737212
## The data does not support rejecting H0 that: mu1 = mu2
## ---Problem 1h(iv)
## test_stat = 10.33645
## p_value = 1.170175e-13
## Reject H0 in favor of HA: var(x1) != var(x2)
rquiz_practice_problem_2(c(.4,.2,.2,.1,.1), 4)
## ----------------------------------
## Problem 2: Simulation with a mixture of dice
## prior = 0.4 0.2 0.2 0.1 0.1
## chosen die = 6
## roll = 5
## posterior = 0 0.4651163 0.3488372 0.1162791 0.06976744
## Posterior prediction: P( 4 | data) = 0.1343023
rquiz_practice_problem_2(c(.4,.2,.2,.1,.1), 12)
## ----------------------------------
## Problem 2: Simulation with a mixture of dice
## prior = 0.4 0.2 0.2 0.1 0.1
## chosen die = 4
## roll = 3
## posterior = 0.5825243 0.1941748 0.1456311 0.04854369 0.02912621
## Posterior prediction: P( 12 | data) = 0.005501618
rquiz_practice_problem_3a(3)
## ----------------------------------
## Problem 3a: counting Brass rats
## 3 rings can be worn 6 different ways
rquiz_practice_problem_3a(4)
## ----------------------------------
## Problem 3a: counting Brass rats
## 4 rings can be worn 12 different ways
rquiz_practice_problem_3b(30000)
## ----------------------------------
## Problem 3b: more counting Brass Rats
## They would need at least 174 Brass rats.
rquiz_practice_problem_4a(200, 0.7)
## ----------------------------------
## Problem 4a: Plot binomial
## See plot: Plot for 4a
rquiz_practice_problem_4b(200, 129, 0.7, 0.05)
## -----
## Problem 4b: NHST
## H0: Support for Tim is 0.7
## HA: support for Tim is less than 0.7
## rejection region: (left tail): x <= 128
## p = 0.05420741
## Do not reject H0
rquiz_practice_problem_4b(200, 128, 0.7, 0.05)
## -----
## Problem 4b: NHST
## H0: Support for Tim is 0.7
## HA: support for Tim is less than 0.7
## rejection region: (left tail): x <= 128
## p = 0.03962828
## Reject H0
rquiz_practice_problem_5a(0.2)
## ----------------------------------
## Problem 5a: Plot exponential
## See plot: Plot for problem 5a
rquiz_practice_problem_5b(0.2, 1000)
## -----
## Problem 5b: Simulation
## See plot: Problem 5b(i): frequency histogram of data
## See plot: Problem 5b(ii): density histogram of data
rquiz_practice_problem_6a(40, 7)
## ----------------------------------
## Problem 6a: Theoretical mean and variance
## one_bet_mu = -0.05263158
## one_bet_var = 0.9972299
## Expected winnings in one day = -2.105263
## Expected variance of one day's winning = 39.8892
## Expected winnings in 7 days = -14.73684
## Expected variance of 7 winnings in = 279.2244
rquiz_practice_problem_6b(40, 8, 10000)
## -----
## Problem 6b: Simulation
## See plot: Problem 6b(i): histogram of 8 days winnings
## Explanation: Each experimental trial gives the sum of n_days_bets independent bets.
## One bet has mean one_bet_mu and variance one_bet_var.
## So, the Central Limit Theorem, one trial is approximately normal with mean
## n_bets_per_trial*one_bet_mu
## and variance
## n_bets_per_trial*one_bet_var
set.seed(1)
mit_times = rnorm(25, 15, 4)
harvard_times = rnorm(25, 18, 5)
rquiz_practice_problem_7(mit_times, harvard_times, 0.05)
## ----------------------------------
## Problem 7: Using google
## H0: the median speeds of the two schools is the same.
## HA: the median speeds of the two schools are different.
## The median times for MIT and Harvard were 16.55937 and 17.70343 respectively.
## test stat = 208
## p_value = 0.04289115
## Reject H0: the median speeds of the two schools differed at significance level 0.05
## Since the median MIT time is less than that of Harvard, it appears that MIT is the faster school.
18.05 Introduction to Probability and Statistics
Spring 2022
Authors: Jeremy Orloff and Jennifer French
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms