Lab 2

pdf

School

Northeastern University *

*We aren’t endorsed by this school

Course

6200

Subject

Industrial Engineering

Date

Jan 9, 2024

Type

pdf

Pages

10

Uploaded by UltraFog12177

Report
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 48/97
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 49/97 In [44]: n = 100 #sample size n_experiments = 1000 # replicates heads_count = np . random . binomial ( n , 0.5 , n_experiments ) heads , event_count = np . unique ( heads_count , return_counts = True ) event_proba = event_count / n_experiments plt . bar ( heads , event_proba , color = 'blue' ) plt . xlabel ( f'Heads flips (out of { n } tosses)' ) _ = plt . ylabel ( 'Event probability' )
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 50/97 In [39]: import numpy as np import matplotlib.pyplot as plt # Generate a random normal distribution mu = 0 sigma = 1 sample_size = 100 data = np . random . normal ( mu , sigma , sample_size ) # Generate a sampling distribution n_samples = 1000 sample_means = [] for i in range ( n_samples ): sample = np . random . choice ( data , size = sample_size ) sample_means . append ( np . mean ( sample )) # Plot the histogram of the sample means plt . hist ( sample_means , bins = 30 , edgecolor = "red" ) plt . show ()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 51/97 In [5]: # Generate your random samples # Generate your sampling distribution
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 52/97 array([ 0.0058, -1.2987, -0.9235, -2.3325, 0.9518, -0.4459, 1.6942, 0.9853, -0.6772, 0.115 ]) -0.2001710211476492 # Plot the histogram of the sample means In [6]: # Generate a random discrete distribution # Generate a sampling distribution # Plot the histogram of the sample total In [217… x = np . random . normal ( size = 10000 ) x_sample = np . random . choice ( x , size = 10 , replace = False ) # generate a random sample x_sample Out[217]: In [216… np . mean ( x_sample ) Out[216]: In [54]: # Write a function to calculate the means for samples drawn from a given distribution # Begin of your function def sample_mean_calculator ( input_dist , sample_size , n_samples ): # Continue to finish the function
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 53/97 # End of the function In [219… sns . histplot ( sample_mean_calculator ( x , 10 , 20 ), color = 'green' ) #distribution plot _ = plt . xlim ( - 1.5 , 1.5 ) In [221… sns . displot ( sample_mean_calculator ( x , 10 , 1000 ), color = 'green' , kde = True ) # distribution plot with more rep _ = plt . xlim ( - 1.5 , 1.5 ) # What are your observations with a larger number of replicates?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 54/97 In [ ]: sns . displot ( sample_mean_calculator ( x , 100 , 1000 ), color = 'green' , kde = True ) # distribution plot with larger _ = plt . xlim ( - 1.5 , 1.5 ) # What are your observations vs larger number of replicates?
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 55/97 In [ ]: sns . displot ( sample_mean_calculator ( x , 1000 , 1000 ), color = 'green' , kde = True ) _ = plt . xlim ( - 1.5 , 1.5 ) # your comments with large sample size and large number of replicates
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 56/97
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/23, 11:35 AM IE6200 file:///Users/peipauj/Downloads/IE6200 (4).html 57/97 In [7]: # Generate your 500 single observations In [8]: # Display your histogram (b) of 500 sample means of size 2 In [9]: # Display your histogram (b) of 500 sample means of size 10 In [10]: # Display your histogram (b) of 500 sample means of size 30