Lesson 72 – Jenny’s confidence, on the average

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 (\bar{x}).

 

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 (\bar{x}) 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 \bar{x} = \frac{1}{n}{\displaystyle \sum_{i=1}^{n}x_{i}}.
x_{i}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 \bar{x}.

 

 

Yes, \bar{x} follows a normal distribution with an expected value E[\bar{x}] and variance V[\bar{x}].

 

E[\bar{x}]=\mu. 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 V[\bar{x}] =\frac{\sigma^{2}}{n}. 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 \frac{\sigma}{\sqrt{n}}.

 

So, \bar{x} \sim N(\mu, \frac{\sigma}{\sqrt{n}})

 

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.

 

\bar{x} is a normal distribution. It is centered on \mu with a standard deviation of \frac{\sigma}{\sqrt{n}}. One standard deviation range is \mu \pm \frac{\sigma}{\sqrt{n}} , two standard deviations range is \mu \pm 2\frac{\sigma}{\sqrt{n}} and three standard deviations range is \mu \pm 3\frac{\sigma}{\sqrt{n}} .

 

Yup. The standard normal way of saying this is Z = \frac{\bar{x}-\mu}{\frac{\sigma}{\sqrt{n}}} \sim N(0,1).

 

 

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 P(Z \le -1.96) = 0.025, which means the area on the right side of the tail P(Z \ge 1.96) = 0.025. The area between -1.96 and 1.96 is 0.95. 95%.

 

There is a 95% probability that the standard normal variable \frac{\bar{x}-\mu}{\frac{\sigma}{\sqrt{n}}} is between -1.96 and 1.96.

P(-1.96 \le \frac{\bar{x}-\mu}{\frac{\sigma}{\sqrt{n}}} \le 1.96) = 0.95

I will modify the inequality in this equation.

Multiplying throughout by \frac{\sigma}{\sqrt{n}}, we get P(-1.96 \frac{\sigma}{\sqrt{n}} \le \bar{x}-\mu \le 1.96 \frac{\sigma}{\sqrt{n}}) = 0.95

Subtracting \bar{x} and multiplying by -1 throughout, we get

P(\bar{x} - 1.96\frac{\sigma}{\sqrt{n}} \le \mu \le \bar{x} + 1.96 \frac{\sigma}{\sqrt{n}}) = 0.95

We derived that the probability of the true population mean \mu lying between two end-points \bar{x} - 1.96\frac{\sigma}{\sqrt{n}} and \bar{x} + 1.96 \frac{\sigma}{\sqrt{n}} is 0.95.

This interval [\bar{x} - 1.96\frac{\sigma}{\sqrt{n}}, \bar{x} + 1.96 \frac{\sigma}{\sqrt{n}}] is called the 95% confidence interval of the population mean. The interval itself is random since it is derived from \bar{x}. As we dicsused before, a different sample will have a different \bar{x} and hence a different interval or range.

There is a 95% probability that this random interval [\bar{x} - 1.96\frac{\sigma}{\sqrt{n}}, \bar{x} + 1.96 \frac{\sigma}{\sqrt{n}}] contains the true value of \mu.

 

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 \mu is \bar{x} - 2.58\frac{\sigma}{\sqrt{n}} \le \mu \le \bar{x} + 2.58 \frac{\sigma}{\sqrt{n}}.

Usually, this % confidence interval is described using a confidence coefficient 1-\alpha where \alpha is between 0 and 1. For a 95% confidence interval, \alpha = 0.05, and for a 99% confidence interval, \alpha = 0.01. The Z-critical value is denoted using Z_{\frac{\alpha}{2}}.

 

Yes yes. For 95% confidence interval, Z_{\frac{\alpha}{2}} = Z_{0.025} = 1.96.

In summary, we can define a 100(1-\alpha)% confidence interval for the true mean \mu as

[\bar{x} - Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}} \le \mu \le \bar{x} + Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}}]

 

Correct. \bar{x} 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 \mu and true standard deviation \sigma. The end-points [\bar{x} - Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}}, \bar{x} + Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}}] 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 \bar{x}=7.9125 counts per 100 ml.

.
.
.
Wait, we don’t know the value of \sigma, 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

\bar{x} - 1.96\frac{\sigma}{\sqrt{n}} \le \mu \le \bar{x} + 1.96\frac{\sigma}{\sqrt{n}}.

7.9125 - 1.96\frac{9.95}{\sqrt{48}} \le \mu \le 7.9125 + 1.96\frac{9.95}{\sqrt{48}}.

7.064 \le \mu \le 8.761

 

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 \mu.

 

 

 

Let me explain. 7.064 \le \mu \le 8.761 can be true or can be false depending on the sample we obtained. \bar{x} is a random variable, a probability distribution whose mean is \mu. 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 [\bar{x} - Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}}, \bar{x} + Z_{\frac{\alpha}{2}}\frac{\sigma}{\sqrt{n}}] 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 (\bar{x}) 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 \mu.

 

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 \mu. 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 \mu?

 

 

Based on the principle of consistency.

\displaystyle{\lim_{n\to\infty} P(|T_{n}(\theta)-\theta|>\epsilon)} \to 0.

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.

\mu = 8.97 and \sigma = 9.95 counts per 100 ml.

 

There you go. I see why you insisted on using \sigma = 9.95.

 

 

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.

Lesson 71 – How confident are you?

Switch on the television or open your favorite news website; every few weeks you will find people’s opinion about something. Here’s one that came out a few days back. Our best days are ahead – so they say.

If you are a regular reader here, you would have already asked about the survey method and sample size.

Results for this Gallup poll are based on telephone interviews conducted June 18-24, 2018, with a random sample of 1,505 adults, aged 18 and older, living in all 50 U.S. states and the District of Columbia. For results based on the total sample of national adults, the margin of sampling error is ±3 percentage points at the 95% confidence level.

The margin of sampling error is ±3% points at the 95% confidence level.

Margin of sampling error,” “95% confidence level” – Have you ever asked yourself what these are?

In another news, the state of NJ passed a new “multi-millionaires tax,” Airbnb tax and Uber/Lyft tax among others. I hope the residents of NJ were asked about some of these increases, and this is what they wanted.

If they were to be asked, how do we know how many people to survey?

If a subset of people were to represent the population of NJ, how do we know that the resulting opinion is what the entire population actually wants?

Jill is having fun this summer. He is one of the volunteers at the BIG CITY FISHING SUNDAYS on Pier 84 . He is busy collecting water samples from the Hudson River. This week he computed the mean dissolved oxygen level as 4.9 mg/L. If the acceptable water quality level is a mean dissolved oxygen of 5 mg/L, how reliable is the estimate that Jill got? Can it be deemed acceptable?

In another news, Wilfred Quality Jr. is still thinking about his grandfather’s question: “how confident are you that the true value lies within two standard deviations?”

Jill’s boss is a variance control freak. Can we give him an upper bound on how much the dissolved oxygen in the Hudson River can vary? He usually likes to be 99% confident.

In another news, St Patrick’s Day should remind you of all those pints of Guinness, and “Student.”  No, I am not under the influence.


All these questions can be answered with a little knowledge about how to describe uncertainty in estimates.

To take you back to Lesson 62, the objective of inference is to use a ‘sample’ to compute a number which represents a good guess for the true value of the parameter. The true population parameter is unknown, and what we estimate from the sample will enable us to obtain the closest answer in some sense.

The cliched way of saying this is that the mean (\bar{x}) and variance (s^{2}) of the sample data are good guesses (estimates or estimators) of the mean (\mu) and variance (\sigma^{2}) of the population.

A different sample will yield a different estimate for the parameter. So we have to think of the estimate as a range of values or a probability distribution instead of a single value.

For any estimator \hat{\theta}, we can compute the expected value E[\hat{\theta}] as a measure of the central tendency, and V[\hat{\theta}] as a measure of the spread of the distribution giving us a range of values. Like this.

This range is called an interval. Naturally, the interval will be wider for data that has more variability. We can be confident that the truth may be in this interval if we have good representative samples.

How confident we are is a probability statement. For example, if there is a 95% probability that the interval contains the true value, it is equivalent to saying that this interval is the 95% confidence interval.

The interval will have a stated probability of containing the truth, the degree of plausibility specified by the confidence level → 95% interval or 99% interval.

Over the next several lessons, we will dive into the core concepts of confidence intervals, how to construct them for different population parameters and use them for designing experiments.

Meanwhile, do you know about Guinness and Student? Guinness, I am sure, but are you confident that you know Student?

If you find this useful, please like, share and subscribe.
You can also follow me on Twitter @realDevineni for updates on new lessons.

error

Enjoy this blog? Please spread the word :)