STAT 200

A study guide for STAT 200, taught by professor Sagara, Yutaka, at the University of Maryland University College. The majority of the text is taken from Introductory Statistics by OpenStax College, available under the Creative Commons Attribution 3.0 Unported license, professor Sagara's slides, and in-class materials. This is a work in progess...

TODO-List

7. The Central Limit Theorem

According to the central limit theorem, the distribution of sample means and the sums tend to follow a normal distribution. If we were to collect samples of size n that are "large enough," calculate the sum of each sample and create a historgram, then the resulting histogram will again tend to have a normal-bell-shape.

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

np.random.seed(19680801)

# example data
mu = 100  # mean of distribution
sigma = 15  # standard deviation of distribution
x = mu + sigma * np.random.randn(437)

num_bins = 50

fig, ax = plt.subplots()

# the histogram of the data
n, bins, patches = ax.hist(x, num_bins, normed=1)

# add a 'best fit' line
y = mlab.normpdf(bins, mu, sigma)
ax.plot(bins, y, '--')
ax.set_xlabel('Smarts')
ax.set_ylabel('Probability density')
ax.set_title(r'Histogram of IQ: $\mu=100$, $\sigma=15$')

# Tweak spacing to prevent clipping of ylabel
fig.tight_layout()
plt.show()
▶︎
all
running...

7.1 Finding the mean and standard deviation of a sample mean

The mean of a sample mean is represented as μX\mu_X
The sample standard deviation is represnted as σX\sigma_X and can be calculated by using the following formula: σn\frac {\sigma}{\sqrt n}

Example 7.1

In a recent study reported Oct. 29, 2012 on the Flurry Blog, the mean age of tablet users is 34 years. Suppose the standard deviation is 15 years. Take a sample of size nn = 100.

Solution

Before finding the solution we must identify the information given.

a.) Since μX\mu_X is representative of μ\mu, we can say that μX=34\mu_X = 34, or that the mean of the sample is 34. To find the standard deviation, we use the formula
σX=σn\sigma_X = \frac {\sigma}{\sqrt n}
Then we plug in the values that we were given
σX=15100=1.5\sigma_X = \frac {15}{\sqrt {100}} = 1.5
Therefore, we can say that σX=1.5\sigma_X = 1.5, or that the standard deviation for the sample is 1.5.

b.) The second question is asking for the probability that the sample mean age is more than 30 years. We can find this information by determening the z-score and then looking for the area or percentage to the RIGHT of z.

So we begin by finding the z-score using the information provided and the result of σx\sigma_x from the previous question:
z=x−μσnz=30−341.5z=−2.67z=0.0038\begin{gathered} z = \frac {x - \mu}{\frac{\sigma}{\sqrt{n}}} \\ \\ z = \frac {30 - 34}{1.5} \\ \\ z = -2.67 \\ z = 0.0038\end{gathered}

As you can see the area to the LEFT of the z value is 0.0038, this means that there is a 0.38% probability that the sample mean age is 30 years or less. However, the problem is asking for 30 years or more.

Therefore, we must subtract 0.38% from 100%.
100%−0.08%=99.62%100\% - 0.08\% = 99.62\%

Our result for the probability that the sample mean age is more than 30 years, is 99.62%.

c.) In this scenerio, we are told to find the 95th percentile of the sample mean, meaning we need to find the sample mean that has a probability of 95% or less.

We start by using the z-score formula. z=x−μσnz = \frac {x - \mu}{\frac{\sigma}{\sqrt{n}}}

In this case we are looking for the value of x¯\bar{x}. We can use the z-score formula to solve for xx.
x=(z)(σn)+μx = (z)(\frac{\sigma}{\sqrt{n}}) + \mu

We can then use the z-score table to find the value of z given the probability of 95% or 0.95.

Z 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
1.40 0.9192 0.9207 0.9222 0.9236 0.9251 0.9265 0.9279 0.9292 0.9306 0.9319
1.50 0.9332 0.9345 0.9357 0.9370 0.9382 0.9394 0.9406 0.9418 0.9429 0.9441
1.60 0.9452 0.9463 0.9474 0.9484 0.9495 0.9505 0.9515 0.9525 0.9535 0.9545

As you can see, in our table, 0.95 falls between 1.64 and 1.65, so we can estimate z to be 1.645.

Now we go back to our formula using our z value and solve for xx.

x=(z)(σn)+μx=(1.645)(1.5)+34x=36.4675x≈36.5\begin{gathered} x = (z)(\frac{\sigma}{\sqrt{n}}) + \mu \\ \\ x = (1.645)(1.5) + 34 \\ \\ x = 36.4675 \\ \\ x \approx 36.5\end{gathered}

Our result for the 95th percentile for the sample mean age, is 36.5.

8. Confidence Intervals

Confidence Interval (CI) gives the range with various certainty (90%, 95%, 99%, etc.).

Margin of error (EBM) depends on the confidence level, sample size, and known or estimated deviation

8.1 Definitions

8.2 ZZ-score vs TT-score

Similarities

Differences

If none of those criterias are met, then use nonparametric or bootstrapping methods.

Example 8.1

A study of 415 kindergarten students showed that they have seen on average 5,000 hours of TV. If the sample standard deviation of the population is 900, find the 95% confidence level of the mean for all students. If a parent claimed that his children watched 4,000 hours, would the claim be believable.

Solution

Lets identify the information given.

And the questions being asked are

First we must determine whether to use the z-score or the t-score distribution. The problem provides us with σx\sigma_x = 900. Therefore, we should use the z-score distribution.

Then we look at the first question in the problem which asks us to find the 95% confidence level of the mean of all students. In other words, we are being told that CLCL = 95% or 0.95, and we need to find the confidence interval estimate of that percentage. Remember that CLCL, or the confidence level, is the area in the middle of the standard normal distribution, and that the confidence interval is not just one number, it is a set of numbers.

We can take a look at the graph below to understand it better.

ch08_CL_graph

The confidence interval can be expressed in defferent ways x¯−E<μ<x¯+Eorx¯±Eor(x¯−E,x¯+E)\begin{gathered} \bar{x} - E < \mu < \bar{x} + E \\ or \\ \bar{x} \pm E \\ or \\ (\bar{x} - E, \bar{x} + E) \end{gathered}

So if we update the graph we have

ch08_CL_graph_extended

In order to find the confidence interval, or x¯−E<μ<x¯+E\bar{x} - E < \mu < \bar{x} + E, we need to first find the value of EE, which is the margin of error.
E=zα/2⋅σnE = z_{\alpha/2} \cdot \frac{\sigma}{\sqrt{n}}

As you know, σx=σn\sigma_x = \frac{\sigma}{\sqrt{n}}

If we plug in the values that we were given, we're left with the following
E=zα/2⋅900415E = z_{\alpha/2} \cdot \frac{900}{\sqrt{415}}

We need to find za/2z_{a/2} in order to solve the equation above.

Since CL=1−αCL = 1 - \alpha , we can infer that α=1−CL\alpha = 1 - CL.

α=1−CLα=1−0.95α=0.05\begin{gathered} \alpha = 1 - CL \\ \alpha = 1 - 0.95 \\ \alpha = 0.05\end{gathered}

Since α=0.05\alpha = 0.05, we can say that z0.05/2=z0.025z_{0.05/2} = z_{0.025}. This means that the area to the RIGHT of z0.025z_{0.025} is 0.025, and the area to the LEFT of z0.025z_{0.025} is 1−0.025=0.9751 - 0.025 = 0.975. In our scenario, we are concerned with the area to the LEFT of z0.025z_{0.025}, wich is 0.975.

We can then use the z-score table to look up the zz value given an area of 0.975.

Z 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
1.70 0.9554 0.9564 0.9573 0.9582 0.9591 0.9599 0.9608 0.9616 0.9625 0.9633
1.80 0.9641 0.9649 0.9656 0.9664 0.9671 0.9678 0.9686 0.9693 0.9699 0.9706
1.90 0.9713 0.9719 0.9726 0.9732 0.9738 0.9744 0.9750 0.9756 0.9761 0.9767
2.00 0.9772 0.9778 0.9783 0.9788 0.9793 0.9798 0.9803 0.9808 0.9812 0.9817

Looking at the table we can then say that given that the area to the left of zz is 0.975, the z-score is 1.96.

We can then go back to our confidence interval formula and plugin the remaining value
E=zα/2⋅900415E=1.96⋅900415E=86.60\begin{gathered} E = z_{\alpha/2} \cdot \frac{900}{\sqrt{415}} \\ \\ E = 1.96 \cdot \frac{900}{\sqrt{415}} \\ \\E = 86.60\end{gathered}

This result E=86.60E = 86.60 means that the margin of error is 86.60.

Now we have all the information neccessary to answer x¯−E<μ<x¯+E\bar{x} - E < \mu < \bar{x} + E. Lets plug in the values.
x¯−E<μ<x¯+E5,000−E<μ<5,000+E5,000−86.60<μ<5,000+86.604,913.4<μ<5,086.64,913<μ<5,087\begin{gathered} \bar{x} - E < \mu < \bar{x} + E \\ 5,000 - E < \mu < 5,000 + E \\ 5,000 - 86.60 < \mu < 5,000 + 86.60 \\ 4,913.4 < \mu < 5,086.6 \\ 4,913 < \mu < 5,087 \end{gathered}

a.) So the answer the first question is 4,913<μ<5,0874,913 < \mu < 5,087.

With this information we can then answer the second question.

b.) If a parent claimed that his children watched 4,000 hours, it would not be believable since it is outside of the confidence interval, 4,000 < 4,913.

Example 8.2

A health care professional wishes to estimate the birth weights of infants. How large a sample must be obtained if she desires to be 90% confident that the true mean is within 2 ounces of the sample mean? Assume σ=8\sigma = 8 ounces.

Solution

Lets list all the given information.

The problem is asking for "how large a sample must be", meaning the value of nn.

Lets begin be determining if we can use the z-score or the t-distribution. We are given σ=8\sigma = 8. Therefore we can use the z-score distribution.

In order to find nn with the information that we have, we can use:
E=za/2⋅σnE = z_{a/2} \cdot \frac{\sigma}{\sqrt{n}}

Using that formula we can solve for nn and we're left with:
n=[(zα/2⋅σ)/E]2n = [({z_{\alpha/2 \cdot \sigma})/E}]^2

As the previous example, we need to find the value of zα/2z_{\alpha/2}, more specifically the area to the LEFT of zα/2z_{\alpha/2}.

We know that α=1−CL\alpha = 1 - CL, and since we were given CLCL = 0.90, we can say that α=1−0.90\alpha = 1 - 0.90 or 0.100.10.

Therefore, zα/2=0.05z_{\alpha/2} = 0.05, and the area to the LEFT of z0.05z_{0.05} is 1−0.05=1 - 0.05 = 0.950.95.

So if we search for the value of zz in the z-score table for the area of 0.95...

Z 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
1.40 0.9192 0.9207 0.9222 0.9236 0.9251 0.9265 0.9279 0.9292 0.9306 0.9319
1.50 0.9332 0.9345 0.9357 0.9370 0.9382 0.9394 0.9406 0.9418 0.9429 0.9441
1.60 0.9452 0.9463 0.9474 0.9484 0.9495 0.9505 0.9515 0.9525 0.9535 0.9545

...we don't have 0.95 exactly in this table, but we can estimate that it is between 1.64 and 1.65, so we can go with 1.645.

Now we can go back to our formula to find the value of nn.
n=[(zα/2⋅σ)/E]2n=[(1.645⋅8)/2]2n=[(13.16)/2]2n=6.82n=43.2964n≈44\begin{gathered} n = [({z_{\alpha/2 \cdot \sigma})/E}]^2 \\ n =[(1.645 \cdot 8)/2]^2 \\ n = [(13.16)/2]^2 \\ n = 6.8^2 \\ n = 43.2964 \\ n \approx 44 \end{gathered}

Notice that n=43.2964n = 43.2964, but we must always round UP to the next higher integer to ensure that the sample size is large enough.

Therefore, our final answer is n=44n = 44.

Example 8.3

Suppose that a committee is studying whether or not there is waste of time in our judicial system. It is interested in the mean amount of time individuals waste at the courthouse waiting to be called for jury duty. The committee randomly surveyed 81 people who recently served as jurors. The sample mean wait time was eight hours with a sample standard deviation of four hours.

a. Construct a 95% confidence interval for the population mean time wasted.

Solution

Lets list all the information we were given.

Once again, lets determine what distribution we should use. We were told that 81 people were surveyed, or that nn = 81. This information meets one of the criterias for the z-score and t-score. Now lets look further into the problem to decide which distribution we should use out of those two. The next key information is that the sample standard deviation is four hours, or that sxs_x = 4. The fact that we were told the standard deviation of the sample (sxs_x) and not of the population (σ\sigma), meets the criteria for using the t-score distribution.

Remember that given that either n > 30, or that the population is normally distributed, you would use the z-score distribution when the standard deviation of the population is known (σ\sigma), but if σ\sigma is unknown, then you would use the t-score distribution.

a.) Before finding the 95% confidence interval for the population mean time wasted, lets update the information that we have.

We know from previous examples that in order to find the confidence interval we can use the formula E=tα/2⋅σnE = t_{\alpha/2}\cdot\frac{\sigma}{\sqrt{n}}

But before we do that we need to find the value of tα/2t_{\alpha/2}.

We know that CL=1−αCL = 1 - \alpha. Therefore, in this scenerio, 95% or 0.95 = 1 - α\alpha. To find alpha we can say:
α=1−CLα=1−0.95α=0.05\begin{gathered}\alpha = 1 - CL \\ \alpha = 1 - 0.95 \\ \alpha = 0.05 \end{gathered}

Now that we know that α=0.05\alpha = 0.05, we can say that
tα/2=t0.05/2tα/2=t0.025\begin{gathered}t_{\alpha/2} = t_{0.05/2} \\ t_{\alpha/2} = t_{0.025}\end{gathered}

Before moving on, it is important to recall that tα/2t_{\alpha/2} gives us the area to the RIGHT of tα/2t_{\alpha/2}. This fact can be confusing, but it is crucial.

Next, in order to find the value of t0.025t_{0.025} we can use the t-distribution table.

Testing Graphs

1. First Graph

var TESTER = document.getElementById('tester')
Plotly.plot(TESTER, [{
    x: [1, 2, 3, 4],
    y: [1, 2, 3, 4]
}, {
    margin: {f: 0}
}])
''
▶︎
all
running...
11.522.533.5411.522.533.54

2. Second Graph

var y0=[],y1=[]
for (var i = 0; i < 50; i ++) 
{
    y0[i] = Math.random();
    y1[i] = Math.random();
}

var trace1 = {
  y: y0,
  type: 'box'
};

var trace2 = {
  y: y1,
  type: 'box'
};

var data = [trace1, trace2];

Plotly.newPlot('myDiv', data);

▶︎
all
running...
trace 0trace 100.20.40.60.81
trace 0trace 1

3. Third Graph

var trace1 = {
  x: [1, 2, 3, 4, 4, 4, 8, 9, 10],
  type: 'box',
  name: 'Set 1'
};
var trace2 = {
  x: [2, 3, 3, 3, 3, 5, 6, 6, 7],
  type: 'box',
  name: 'Set 2'
};

var data = [trace1, trace2];

var layout = {
  title: 'Horizontal Box Plot'
};

Plotly.newPlot('myDiv2', data, layout);

▶︎
all
running...
246810Set 1Set 2
Horizontal Box PlotSet 1Set 2

4. Fourth Graph

import matplotlib.pyplot as plt
plt.plot([1,2,3, 4])
plt.show()
▶︎
all
running...

5. Fifth Graph

import numpy as np
import matplotlib.pyplot as plt


x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)

y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
y2 = np.cos(2 * np.pi * x2)

plt.subplot(2, 1, 1)
plt.plot(x1, y1, 'o-')
plt.title('A tale of 2 subplots')
plt.ylabel('Damped oscillation')

plt.subplot(2, 1, 2)
plt.plot(x2, y2, '.-')
plt.xlabel('time (s)')
plt.ylabel('Undamped')

plt.show()
▶︎
all
running...
≡