Question: Problem # 1 Write a Python function named CentralLimitDemoExp that takes as input arguments: n - the number of samples to be taken from an
Problem #
Write a Python function named CentralLimitDemoExp that takes as input arguments:
n the number of samples to be taken from an exponential distribution,
samplesizes a x numpy array holding the size of each of the n samples for that value of n different size of each sample for a fixed,
mu the mean of the exponential random variable.
And returns as output:
fig a figure displaying six histograms, one for each value of samplesize specified for the given value of n
samplemeans a numpy array of size x n holding the n samplemeans,
samplemeansstdevs a numpy array of size x holding the standard deviation of the list of samplemeans.
Test your function by setting samplesizes nparray and running the command fig means devs CentralLimitDemoExp samplesizes,
import numpy as np
import matplotlib.pyplot as plt
import random
import statistics
from numpy.random import seed
def CentralLimitDemoExpn samplesizes, mu:
# This line will reinitialize the random seed everytime the function is run and produce the same
# samples every time, you can comment it out
seed
# Create a figure consisting of subplots arranged into two rows and three columns
fig, axs pltsubplots figsize
fig.subplotsadjusthspace
fig.subplotsadjustwspace
# Figure indeces
axsrow
axscol
# Create a numpy array to hold the standard deviation of the list of sample means x
samplemeansstdev # Fill in code here
# Loop to generate n samples of sizes samplesizes samplesizes
# keep track of how many of the listed samplesizes have been completed
k
for samplesize in samplesizes:
# Create an nparray to hold all n means
samplemeans # Fill in code here
# Loop to generate the n samples of size samplesize
for j in rangen:
# Create a sample by drawing samplesize elements from an exponential distribution
sample # Fill in code here
# Find its mean
samplemean # Fill in code here
# And add it to the list of samplemeans
samplemeansj samplemean
# Find the standard deviation of each of the six lists of n sample means and store them in samplemeansstdev
samplemeansstdevk npstdsamplemeans
# Increase the count of completed samplesizes
k
# Generate the histogram of the n samplemeans of size samplesize
# Histogram
axsaxsrow, axscolhistsamplemeans, color "green"
# Plot and axis labels
axsaxsrow, axscolsettitlesamplesize s samplesize
axsaxsrow, axscolsetylabelFrequency
axsaxsrow, axscolsetxlabelObserved Sample Mean"
# Figure title
fig.suptitleSample Mean Distribution for different values of samplesize'
# Advance figure row and column counters
if axscol :
axscol
else:
axscol
axsrow
return fig, samplemeans, samplemeansstdev
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
