Meet Jenny. Jenny is bright and intelligent and is known as “the problem solver” among her friends. She usually goes unnoticed in the crowd due to her calm and composed nature, but by god, she is assertive when it is most needed. Her analytical neurons are razor sharp and you cannot mumbo-jumbo with her. She loves science fiction, history, and occasional Woody Allen. Oh, and she likes swimming, surfing, summer, and beaches.

Her second summer Rockaway beach trip is coming up and she is excited. With all the surfing kit packed, she pulled up the NYC Beach Water Quality website to monitor the status. “The Enterococci Bacteria Count is within limit!” she thought.

She got busy with other things, but the thought of beach samples bothered her. “Where do they take these samples from? They show Rockaway beach, but does the sample represent the whole beach? How many samples do they take? If they use one sample, how do we know what the truth is? I have been to this place several times, I wonder what the true water quality of the beach is?” These questions kept her awake. I told you she is a problem solver.

The next morning she met Joe to discuss the problem. Friends of this classroom know who Joe is. He is now the resident expert on statistical topics.

So, you want to know the true water quality from the sample data. Why don’t you develop the confidence interval of the mean water quality? This will at least give you a range, an interval where the true water quality will be.

How can we do that using the sample? Or, maybe I should ask, can you explain what is an interval and how to derive it.

Okay. Let’s get some simple/sample data first. NYC Open Data should definitely have data on beaches. Here, they have a link for DOHMH Beach Water Quality Data. The description says that this is the data of water quality sample results collected by the Department of Health and Mental Hygiene from all New York City Beaches. Amazing! Which Rockaway beach are you going to?

I usually go to the one on the 95th Street and stay north.

We can take the data from ROCKAWAY BEACH 95TH – 116TH then. Let me show you how to write a code in R to extract this subset of the data.

Hey, I can do that with ease.

I forgot to tell you that Jenny is a member of the local girls who code club. She pulls up her Macbook and types a few lines. Meanwhile, Joe does some coding too on the same data.

There are samples that had a result below the detection limit. If I remove those from the ROCKAWAY BEACH 95TH – 116TH data, we are left with 48 data points collected at various times from 2005 to 2018. Look.

Wonderful. I am guessing that the blue color triangle in the histogram is the sample mean ( ).

Yes. This is an estimate (good guess) for the average Enterococci Bacteria count for this part of the beach based on 48 samples over several years.

We can describe the uncertainty in this estimate using the confidence intervals. The key link is to realize that this estimate, i.e., the sample mean ( ) is a random variable. For instance, if we were to take another data sample from different times of the year or over different parts of the beach, we would get a slightly different sample mean. The value of the estimate changes with the change of sample, so we can think of estimate as a range of values or a probability distribution.

Yes, that makes perfect sense, but what probability distribution does it follow?

The sample mean is given by the equation .

s are independent and identically distributed random samples. Look at the equation carefully, it is the summation of random variables. Convolution. We learned in Lesson 48 that for a large enough sample size, this summation will converge to the normal distribution — Central Limit Theorem. As the samples grow (n becomes large), convolution or function multiplications yield a smooth center heavy and thin-tailed bell function — the normal density.

Ah, I see. So it is reasonable to assume a normal distribution for the sample mean .

Yes, follows a normal distribution with an expected value and variance .

. The sample mean is an unbiased estimate of the true mean, so the expected value of the sample mean is equal to the truth. This is in Lesson 67.

The variance of the sample mean . We derived this in Lesson 68. Variance tells us how widely the estimate is distributed around the center of the distribution.

The standard deviation of the sample mean, or the standard error of the estimate is .

So,

Jenny looks at the equation for a bit. She takes a piece of paper, draws on it and instantly types a few lines of code.

Here, I am showing this visually.

is a normal distribution. It is centered on with a standard deviation of . One standard deviation range is , two standard deviations range is and three standard deviations range is .

Yup. The standard normal way of saying this is .

The Z-score!

Yes, let me ask you something. What is the area under the normal density curve between -1.96 and 1.96?

Looking up from the standard normal tables, we get , which means the area on the right side of the tail . The area between -1.96 and 1.96 is 0.95. 95%.

There is a 95% probability that the standard normal variable is between -1.96 and 1.96.

I will modify the inequality in this equation.

Multiplying throughout by , we get

Subtracting and multiplying by -1 throughout, we get

We derived that the probability of the true population mean lying between two end-points and is 0.95.

This interval is called the 95% confidence interval of the population mean. The interval itself is random since it is derived from . As we dicsused before, a different sample will have a different and hence a different interval or range.

There is a 95% probability that this random interval contains the true value of .

Neat. So to generalize this to any confidence interval, we can replace 1.96 with a Z-critical value.

Yes. For instance, if we want a 99% confidence interval, we should find the Z-critical value that gives 99% area under the normal density curve.

That would be 2.58. So the 99% confidence interval for true mean is .

Usually, this % confidence interval is described using a confidence coefficient where is between 0 and 1. For a 95% confidence interval, , and for a 99% confidence interval, . The Z-critical value is denoted using .

Yes yes. For 95% confidence interval, .

In summary, we can define a % confidence interval for the true mean as

Correct. is the mean of a random sample of size n. The assumption is that the sample is drawn from a population with a true mean and true standard deviation . The end-points are called the lower and upper confidence limits.

Let us develop the confidence intervals of the mean water quality. The sample I have has n = 48 data points. The sample mean is counts per 100 ml.

.

.

.

Wait, we don’t know the value of , the true standard deviation. There is still an unknown in the equation.

Assume it is 9.95 counts per 100 ml.

Where did that come from.

Take my word for now and get the confidence interval.

Jenny reluctantly does some calculations on a piece of paper.

The 95% confidence interval for the mean water quality is

.

.

There is a 95% probability that the true mean water quality will be between 7.064 and 8.761. Now tell me where the 9.95 came from.

Well, strictly speaking, your statement should have been, “there is a 95% probability of selecting a sample for which the confidence interval will contain the true value of .”

Let me explain. can be true or can be false depending on the sample we obtained. is a random variable, a probability distribution whose mean is . Our sample mean represents a random draw from this distribution. So, if we got a sample whose mean is close to the truth, the interval will contain the truth. If we got a sample who mean is somewhat far away from the truth, its confidence interval may not contain the truth. This graphic should make it more clear. The green interval does not contain the true value. The purple interval does. Both these sample means ( ) are equally likely; it depends on what sample data we get.

Hmm. So, we should think of this phenomenon as a long-run relative frequency outcome. If we have a lot of different samples, and compute the 95% confidence intervals for these samples, in the long-run, 95% of these intervals will contain the true value of .

Exactly. The 95% confidence level is what would happen if a large number of random intervals were constructed; not for any particular interval.

So while you were coding to get the subset of data from the ROCKAWAY BEACH 95TH – 116TH, I downloaded all the data that had ROCKAWAY BEACH in the file. There are eight locations along the beach where these samples are taken. Assuming that these are eight different samples, I developed the 95% confidence intervals for each of these samples. Here is how they look relative to the truth. One of them does not contain the true . Like this, in the long-run, 5% of the samples will not contain the true mean for 95% confidence intervals.

How did you get the true value for ?

Based on the principle of consistency.

.

As n approaches infinity, the sample estimate approaches the true parameter. I took data from the eight beach locations and computed the overall mean and overall standard deviation. While they are not exactly the true values, based on the idea of consistency, we can assume that they are.

and counts per 100 ml.

There you go. I see why you insisted on using .

You are welcome!

But not always we will have such a large sample. Most often, the data is limited. How can we know what the true standard deviation is?

In that case, you can use the sample standard deviation. In your sample data case it was 6.96 counts per 100 ml, I think.

Hmm, but that is very different from the true value. Aren’t we inducing more error into the estimation of the intervals?

Perhaps. Hey, do you want to take a break? Can I buy you a drink? Is Guinness okay?

If you find this useful, please like, share and subscribe.

You can also follow me on Twitter @realDevineni for updates on new lessons.