Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the mean of the TPCP population data? See Step 3 in the Python script. In the Python script, you selected a random sample

  1. What is the mean of the TPCP population data? See Step 3 in the Python script.
  2. In the Python script, you selected a random sample with replacement, of size 50 (note that this is a sufficiently large sample), from the TPCP population. What is the mean of your random sample? Does this sample mean closely approximate the TPCP population mean? See Step 4 in the Python script.
  3. You also selected 1,000 random samples of size 50 and calculated the mean of each sample. Then you stored those means into a dataframe. Check to make sure the output of this step is in your attachment. See Step 5 in the Python script.
  4. Review the plotted data distribution for these 1,000 means. Does this approximate a Normal distribution? Does this confirm the first part of the central limit theorem? Why or why not? See Step 6 in the Python script.
  5. What is the "grand" mean and standard deviation of these 1,000 means? Does the grand mean closely approximate (on a relative basis) the mean of the original distribution? Does this confirm the second part of the central limit theorem? Why or why not? See Step 7 in the Python script.

Step 1: Generating population data

This block of Python code will generate unique TPCP population data of size 500 observations. You will use this data set in this week's discussion. The numpy module in Python can be used to generate datasets with a skewed distribution by randomly generating data from a gamma distribution. You do not need to know what a gamma distribution is or how a dataset is drawn from it. The dataset will be saved in a Python dataframe that you will use in later calculations.

Click the block of code below and hit theRunbutton above.

In[1]:

import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

import scipy.stats as st

# use gamma distribution to randomly generate 500 observations.

shape, scale = 1.95, 2.5

tpcp = 100*np.random.gamma(shape, scale, 500)

# pandas library can be used to convert the array into a dataframe of rounded figures with the column name TPCP.

tpcp_df = pd.DataFrame(tpcp, columns=['TPCP'])

tpcp_df = tpcp_df.round(0)

# print the dataframe to see the first 5 and last 5 observations (note that the index of dataframe starts at 0).

print("TPCP data frame ")

print(tpcp_df)

TPCP data frame

TPCP

0325.0

1346.0

2949.0

3818.0

4533.0

.....

495614.0

496110.0

497305.0

498163.0

499299.0

[500 rows x 1 columns]

Step 2: Creating a histogram plot of population data

You will use the matplotlib module in Python to generate a histogram plot of the population data from Step 1. This plot allows you to visualize the population data distribution and confirm that it is skewed. You will use 50 bins in the histogram to display the distribution.

Click the block of code below and hit theRunbutton above.

NOTE: If the graph is not created, click the code section and hit theRunbutton again.

In[2]:

# generate a figure for the plot.

fig, ax = plt.subplots()

# generate a histogram plot with 50 bins of TPCP population data.

plt.hist(tpcp_df['TPCP'], bins=50)

# set a title for the plot, x-axis, and y-axis.

plt.title('TPCP population distribution', fontsize=20)

ax.set_xlabel('TPCP')

ax.set_ylabel('Frequency')

# show the plot.

plt.show()

Step 3: Calculating the population mean

This step will calculate the mean for the population data.

Click the block of code below and hit theRunbutton above.

In[3]:

# You can use the "mean" method of a pandas dataframe.

pop_mean = tpcp_df['TPCP'].mean()

print("Population mean =", round(pop_mean,2))

Population mean = 499.42

Step 4: Drawing one random sample from the population data and calculating the sample mean

This block of code randomly selects one sample (with replacement) of 50 data points from the population data. Then it calculates the sample mean. You will use the "sample" method of the dataframe to select the sample.

Click the block of code below and hit theRunbutton above.

In[4]:

# use sample method of the dataframe to select a random sample, with replacement, of size 50.

tpcp_sample_df = tpcp_df.sample(50, replace=True)

# print the sample mean.

sample_mean = tpcp_sample_df['TPCP'].mean()

print("Sample mean =", round(sample_mean,2))

Sample mean = 597.56

Step 5: Repeatedly drawing samples and saving the sample mean for each sample

You will now essentially repeat Step 4 one thousand times to select 1,000 random samples, with replacement, of size 50 from the population data. The code below contains a loop so that you can prepare this selection with just one click! You will save the sample mean for each sample in a Python dataframe.

Click the block of code below and hit theRunbutton above.

In[5]:

# run a for loop to repeat the process Step 4 one thousand times to select one thousand samples.

# save the mean of each sample that was drawn in a Python list called means_list.

means_list = []

for i in range(1000):

tpcp_sample_df = tpcp_df.sample(50, replace=True)

sample_mean = tpcp_sample_df['TPCP'].mean()

means_list.append(sample_mean)

# generate a Python dataframe of means.

means_df = pd.DataFrame(means_list, columns=['means'])

print("Dataframe of 1000 sample means ")

print(means_df)

Dataframe of 1000 sample means

means

0542.74

1418.50

2534.08

3466.42

4478.68

.....

995496.90

996453.72

997455.08

998465.38

999555.80

[1000 rows x 1 columns]

Step 6: Creating a histogram plot of the sample means from Step 5

Now you will plot the data distribution of the 1,000 means from Step 5. View the plot to confirm that it approximates a Normal distribution (bell-shaped curve). Note that the original data distribution in Step 2 was skewed. However, the distribution of sample means, calculated by repeatedly drawing large samples, is approximately Normally distributed.

Click the block of code below and hit theRunbutton above.

NOTE: If the graph is not created, click the code section and hit theRunbutton again.

In[6]:

# generate a figure for the plot.

fig, ax = plt.subplots()

# generate a histogram plot with 50 bins of 1,000 means.

plt.hist(means_df['means'], bins=50)

# set a title for the plot, x-axis and y-axis.

plt.title('Distribution of 1000 sample means', fontsize=20) # title

ax.set_xlabel('Means')

ax.set_ylabel('Frequency')

# show the plot.

plt.show()

Step 7: Mean and the standard deviation of the sample mean distribution

Now you will calculate the "grand" mean ("grand" because it is the mean of the 1,000 means) and the standard deviation of 1,000 sample means. Note that the distribution of sample means was approximately Normal (bell-shaped) in Step 6. Therefore, calculating the mean and the standard deviation of this distribution will allow us to calculate probabilities and critical values.

Click the block of code below and hit theRunbutton above.

In[7]:

# calculate mean of the 1,000 sample means (this is called the grand mean or mean of the means).

mean1000 = means_df['means'].mean()

print("Grand Mean (Mean of 1000 sample means) =",round(mean1000,2))

# calculate standard deviation of the 1,000 sample means.

std1000 = means_df['means'].std()

print("Std Deviation of 1000 sample means =",round(std1000,2))

# print the probability that a specific mean is 450 or less for a Normal distribution with mean and standard deviation of 1,000 sample means.

prob_450_less_or_equal = st.norm.cdf(450, mean1000, std1000)

print("Probability that a specific mean is 450 or less =", round(prob_450_less_or_equal,4))

Grand Mean (Mean of 1000 sample means) = 497.54

Std Deviation of 1000 sample means = 50.22

Probability that a specific mean is 450 or less = 0.1719

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Matrix Analysis With Applications

Authors: Edward Barry Saff, Arthur David Snider

1st Edition

111895369X, 9781118953693

More Books

Students also viewed these Mathematics questions

Question

13. Give four examples of psychological Maginot lines.

Answered: 1 week ago