Confidence Intervals are for Estimating a Range for the True Population-level Measure

Many people find calculating confidence intervals easy - but how do you interpret them?

Confidence intervals – why do we even have them? The reason is we usually don’t have all the data from a population. I downloaded one month of data (December 2024) about electric vehicle (EV) public charge points (CPs) in the United Kingdom (UK). The dataset had 2,848 rows – meaning that is the entire population. So in this case, I can calculate measures based on the entire population. But this is also a good way to demonstrate what happens if you take just a sample from that population, and construct confidence intervals to estimate the true measure, which is what I will do in this blog post.

What are Confidence Intervals?

Consider the term “confidence interval” – especially the word “interval”. Interval literally means a range between one number and another. So confidence intervals represent a range – but what is it a range of? It’s basically a range you construct when you only have of sample of data from a population, where you are very confident that the range contains the true population measure.

In our CP data, one of the variables is Number_of_sessions. This indicates the number of charging sessions that CP had that month. I calculated the true population mean, and it was 39.21. So this means in December 2024, each CP had an average of about 40 charging sessions.

Now, let’s see what happens when we take just a sample of data and try to estimate the population level mean Number_of_sessions by using confidence intervals. I literally did that on a spreadsheet and I’ll show you the result.

Confidence Intervals at Different Sample Sizes

I chose to make 95% confidence intervals, so I can say I’m 95% confident the true population measure falls in the range I will calculate. Then I chose random samples of different sizes.

  • When I chose a sample of 50 CPs, I got a confidence interval of 25.33 to 52.87, which is a range of 27.54.
  • When I chose a sample of 100 CPs, I got a confidence interval of 35.67 to 59.13, which is a range of 23.46.
  • When I chose a sample of 150 CPs, I got a confidence interval of 33.68 to 50.79, which is a range of 17.12.
  • When I chose a sample of 200 CPs, I got a confidence interval of 35.02 to 49.87, which is a range of 14.85.
  • When I chose a sample of 250 CPs, I got a confidence interval of 34.32 to 46.98, which is a range of 12.66.
  • When I chose a sample of 300 CPs, I got a confidence interval of 34.04 to 45.15, which is a range of 11.11.

It’s important to see a certain pattern. Each time a choose a larger sample, the range gets smaller – so you can be more precise about where the true population estimate lies. And luckily, all of my samples contained the true population measure. Because I am constructing a 95% confidence interval, in theory, 5% of my samples will not contain the true population mean.

How to Construct Confidence Intervals

Here I explain how to construct a confidence interval, and at the end I show a graphical depiction using our example spreadsheet.

This is the first step to the data science project

First, you take a sample. In the example spreadsheet, the data are located on the “Main Data” tab, so the sample is specified by a series of cells on that tab.

Second step in a data science project

Next, you calculate the point estimate average of your sample from those cells. In confidence intervals, this point represents the center.

Third step in a data science project

Next, you calculate the standard deviation (SD) of your sample. You will need this to calculate the margin of error (ME).

Fourth step in a data science learning path

After you have the sample average point estimate and the sample SD, you select the value of the Z score associated with how confident you want to be that the true measure is in the range of your confidence interval. We will select the most popular Z score, which is 1.96, which corresponds to the 95% confidence interval. Also, make note of the sample size you selected.

Fancy number five colorful inside a circle with border data SAS programming code

Now that you have the SD, sample size, and Z score selected, you can calculate the ME. The equation is the Z score multiplied by the result of the SD divided by the square root of the sample size. This ME represents the “margin” you will subtract from the point estimate to get the lower level (LL) of the confidence interval, and you will add to the point estimate to get the upper level (UL) of the confidence interval.

Fancy number six colorful inside a circle with border data SAS programming code

Finally, we have our ME. We subtract it from the point estimate to get the LL, and add it to the point estimate to get the UL. Now, you consider the range between the LL and the UL – that is where you are 95% confident the true population measure lies.

Confidence intervals provide a range in which you are confident the true population measure lies.

Read all of our data science blog posts!

Confidence Intervals are for Estimating a Range for the True Population-level Measure

Confidence intervals (CIs) help you get a solid estimate for the true population measure. Read [...]

Continuous Variable? You Can Categorize it!

Continuous variable categorized can open up a world of possibilities for analysis. Read about it [...]

2 Comments

Delete if the Row Meets Criteria? Do it in SAS!

Delete if rows meet a certain criteria is a common approach to paring down a [...]

Chi-square Test: Insight from Using Microsoft Excel

Chi-square test is hard to grasp – but doing it in Microsoft Excel can give [...]

Identify Elements of Research in Scientific Literature

Identify elements in research reports, and you’ll be able to understand them much more easily. [...]

Design the Most Useful Time Periods for Your Conversions

Time periods are important when creating a time series visualization that actually speaks to you! [...]

Apply Weights? It’s Easy in R with the Survey Package!

Apply weights to get weighted proportions and counts! Read my blog post to learn how [...]

Make Categorical Variable Out of Continuous Variable

Make categorical variables by cutting up continuous ones. But where to put the boundaries? Get [...]

Remove Rows in R with the Subset Command

Remove rows by criteria is a common ETL operation – and my blog post shows [...]

CDC Wonder for Studying Vaccine Adverse Events: The Shameful State of US Open Government Data

CDC Wonder is an online query portal that serves as a gateway to many government [...]

AI Careers: Riding the Bubble

AI careers are not easy to navigate. Read my blog post for foolproof advice for [...]

Descriptive Analysis of Black Friday Death Count Database: Creative Classification

Descriptive analysis of Black Friday Death Count Database provides an example of how creative classification [...]

Classification Crosswalks: Strategies in Data Transformation

Classification crosswalks are easy to make, and can help you reduce cardinality in categorical variables, [...]

FAERS Data: Getting Creative with an Adverse Event Surveillance Dashboard

FAERS data are like any post-market surveillance pharmacy data – notoriously messy. But if you [...]

Dataset Source Documentation: Necessary for Data Science Projects with Multiple Data Sources

Dataset source documentation is good to keep when you are doing an analysis with data [...]

Joins in Base R: Alternative to SQL-like dplyr

Joins in base R must be executed properly or you will lose data. Read my [...]

NHANES Data: Pitfalls, Pranks, Possibilities, and Practical Advice

NHANES data piqued your interest? It’s not all sunshine and roses. Read my blog post [...]

Color in Visualizations: Using it to its Full Communicative Advantage

Color in visualizations of data curation and other data science documentation can be used to [...]

Defaults in PowerPoint: Setting Them Up for Data Visualizations

Defaults in PowerPoint are set up for slides – not data visualizations. Read my blog [...]

Text and Arrows in Dataviz Can Greatly Improve Understanding

Text and arrows in dataviz, if used wisely, can help your audience understand something very [...]

Shapes and Images in Dataviz: Making Choices for Optimal Communication

Shapes and images in dataviz, if chosen wisely, can greatly enhance the communicative value of [...]

Table Editing in R is Easy! Here Are a Few Tricks…

Table editing in R is easier than in SAS, because you can refer to columns, [...]

R for Logistic Regression: Example from Epidemiology and Biostatistics

R for logistic regression in health data analytics is a reasonable choice, if you know [...]

1 Comments

Connecting SAS to Other Applications: Different Strategies

Connecting SAS to other applications is often necessary, and there are many ways to do [...]

Portfolio Project Examples for Independent Data Science Projects

Portfolio project examples are sometimes needed for newbies in data science who are looking to [...]

Project Management Terminology for Public Health Data Scientists

Project management terminology is often used around epidemiologists, biostatisticians, and health data scientists, and it’s [...]

Rapid Application Development Public Health Style

“Rapid application development” (RAD) refers to an approach to designing and developing computer applications. In [...]

Understanding Legacy Data in a Relational World

Understanding legacy data is necessary if you want to analyze datasets that are extracted from [...]

Front-end Decisions Impact Back-end Data (and Your Data Science Experience!)

Front-end decisions are made when applications are designed. They are even made when you design [...]

Reducing Query Cost (and Making Better Use of Your Time)

Reducing query cost is especially important in SAS – but do you know how to [...]

Curated Datasets: Great for Data Science Portfolio Projects!

Curated datasets are useful to know about if you want to do a data science [...]

Statistics Trivia for Data Scientists

Statistics trivia for data scientists will refresh your memory from the courses you’ve taken – [...]

Management Tips for Data Scientists

Management tips for data scientists can be used by anyone – at work and in [...]

REDCap Mess: How it Got There, and How to Clean it Up

REDCap mess happens often in research shops, and it’s an analysis showstopper! Read my blog [...]

GitHub Beginners in Data Science: Here’s an Easy Way to Start!

GitHub beginners – even in data science – often feel intimidated when starting their GitHub [...]

ETL Pipeline Documentation: Here are my Tips and Tricks!

ETL pipeline documentation is great for team communication as well as data stewardship! Read my [...]

Benchmarking Runtime is Different in SAS Compared to Other Programs

Benchmarking runtime is different in SAS compared to other programs, where you have to request [...]

End-to-End AI Pipelines: Can Academics Be Taught How to Do Them?

End-to-end AI pipelines are being created routinely in industry, and one complaint is that academics [...]

Referring to Columns in R by Name Rather than Number has Pros and Cons

Referring to columns in R can be done using both number and field name syntax. [...]

The Paste Command in R is Great for Labels on Plots and Reports

The paste command in R is used to concatenate strings. You can leverage the paste [...]

Coloring Plots in R using Hexadecimal Codes Makes Them Fabulous!

Recoloring plots in R? Want to learn how to use an image to inspire R [...]

Adding Error Bars to ggplot2 Plots Can be Made Easy Through Dataframe Structure

Adding error bars to ggplot2 in R plots is easiest if you include the width [...]

AI on the Edge: What it is, and Data Storage Challenges it Poses

“AI on the edge” was a new term for me that I learned from Marc [...]

Pie Chart ggplot Style is Surprisingly Hard! Here’s How I Did it

Pie chart ggplot style is surprisingly hard to make, mainly because ggplot2 did not give [...]

Time Series Plots in R Using ggplot2 Are Ultimately Customizable

Time series plots in R are totally customizable using the ggplot2 package, and can come [...]

Data Curation Solution to Confusing Options in R Package UpSetR

Data curation solution that I posted recently with my blog post showing how to do [...]

Making Upset Plots with R Package UpSetR Helps Visualize Patterns of Attributes

Making upset plots with R package UpSetR is an easy way to visualize patterns of [...]

6 Comments

Making Box Plots Different Ways is Easy in R!

Making box plots in R affords you many different approaches and features. My blog post [...]

Convert CSV to RDS When Using R for Easier Data Handling

Convert CSV to RDS is what you want to do if you are working with [...]

GPower Case Example Shows How to Calculate and Document Sample Size

GPower case example shows a use-case where we needed to select an outcome measure for [...]

Querying the GHDx Database: Demonstration and Review of Application

Querying the GHDx database is challenging because of its difficult user interface, but mastering it [...]

Variable Names in SAS and R Have Different Restrictions and Rules

Variable names in SAS and R are subject to different “rules and regulations”, and these [...]

Referring to Variables in Processing Data is Different in SAS Compared to R

Referring to variables in processing is different conceptually when thinking about SAS compared to R. [...]

Counting Rows in SAS and R Use Totally Different Strategies

Counting rows in SAS and R is approached differently, because the two programs process data [...]

Native Formats in SAS and R for Data Are Different: Here’s How!

Native formats in SAS and R of data objects have different qualities – and there [...]

SAS-R Integration Example: Transform in R, Analyze in SAS!

Looking for a SAS-R integration example that uses the best of both worlds? I show [...]

Dumbbell Plot for Comparison of Rated Items: Which is Rated More Highly – Harvard or the U of MN?

Want to compare multiple rankings on two competing items – like hotels, restaurants, or colleges? [...]

2 Comments

Data for Meta-analysis Need to be Prepared a Certain Way – Here’s How

Getting data for meta-analysis together can be challenging, so I walk you through the simple [...]

Sort Order, Formats, and Operators: A Tour of The SAS Documentation Page

Get to know three of my favorite SAS documentation pages: the one with sort order, [...]

Confused when Downloading BRFSS Data? Here is a Guide

I use the datasets from the Behavioral Risk Factor Surveillance Survey (BRFSS) to demonstrate in [...]

2 Comments

Doing Surveys? Try my R Likert Plot Data Hack!

I love the Likert package in R, and use it often to visualize data. The [...]

3 Comments

I Used the R Package EpiCurve to Make an Epidemiologic Curve. Here’s How It Turned Out.

With all this talk about “flattening the curve” of the coronavirus, I thought I would [...]

Which Independent Variables Belong in a Regression Equation? We Don’t All Agree, But Here’s What I Do.

During my failed attempt to get a PhD from the University of South Florida, my [...]

Confidence intervals (CIs) help you get a solid estimate for the true population measure. Read my blog and try my CI calculator!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Verified by MonsterInsights