Tutorials › Introduction to Statistics › Building an Interval from Raw Data

Confidence Intervals for Means · Tutorial 583 of 996

Building an Interval from Raw Data

Work from individual observations to a one-sample t interval, keeping the calculations, degrees of freedom, and units consistent.

Intermediate 10 min read

What You'll Learn

  • Calculate a sample mean directly from raw observations.
  • Calculate sample standard deviation using deviations or a computational identity.
  • Find the degrees of freedom and the appropriate t critical value.
  • Construct a one-sample t interval from raw data.
  • Check calculations, units, assumptions, and common sources of error.

From Observations to an Interval

A confidence interval for a population mean is often reported using summary statistics, but an analysis may begin with a short list of measurements. In that case, the interval cannot be calculated correctly until the observations have been summarized: the sample mean locates the center, and the sample standard deviation measures the observed spread. The t critical value and standard error then determine how far to extend from that center.

This tutorial works through that process using small, hypothetical data sets. The emphasis is on moving carefully from the raw values to the final endpoints, while keeping track of what each calculation means and which assumptions make the interval appropriate.

Summary Statistics from Raw Data

Definition: For quantitative observations \(x_1,x_2,\ldots,x_n\), the sample mean is \(\bar{x}=\frac{\sum_{i=1}^{n}x_i}{n}\). The sample standard deviation is \(s=\sqrt{\frac{\sum_{i=1}^{n}(x_i-\bar{x})^2}{n-1}}\). The sample standard deviation describes the spread of the observations around their sample mean, in the same units as the data.

To calculate \(s\), subtract the mean from each observation, square those deviations, add the squared deviations, divide by \(n-1\), and take the square root. The denominator is \(n-1\), not \(n\). The resulting quantity before taking the square root is the sample variance, \(s^2\).

A useful alternative for calculating the sum of squared deviations is

$$ \sum_{i=1}^{n}(x_i-\bar{x})^2 = \sum_{i=1}^{n}x_i^2-\frac{\left(\sum_{i=1}^{n}x_i\right)^2}{n}. $$

This identity can reduce repeated subtraction when the data set is small. It gives the same sum of squared deviations as calculating each deviation from \(\bar{x}\), provided the arithmetic is carried out accurately.

Justification: Expand each squared deviation and use \(\sum_{i=1}^{n}x_i=n\bar{x}\):
$$ \begin{aligned} \sum_{i=1}^{n}(x_i-\bar{x})^2 &=\sum_{i=1}^{n}(x_i^2-2x_i\bar{x}+\bar{x}^2)\\ &=\sum_{i=1}^{n}x_i^2-2\bar{x}\sum_{i=1}^{n}x_i+n\bar{x}^2\\ &=\sum_{i=1}^{n}x_i^2-2n\bar{x}^2+n\bar{x}^2\\ &=\sum_{i=1}^{n}x_i^2-n\bar{x}^2\\ &=\sum_{i=1}^{n}x_i^2-\frac{\left(\sum_{i=1}^{n}x_i\right)^2}{n}. \end{aligned} $$

The identity is a calculation tool, not a different definition of standard deviation. In either form, \(s\) is measured in the original data units, while \(s^2\) is measured in squared units.

Model and Interval Formula

Before using the one-sample t procedure, specify the setting it is intended for. The data should be a random, independent sample from a population, and the measurements should be quantitative. For a small sample, the population distribution should be approximately normal; the interval can be sensitive to strong departures from this assumption. The specific checks for sampling and distribution shape are considered separately in the course.

When these conditions are appropriate, the one-sample t interval estimates the population mean \(\mu\). Its degrees of freedom are \(df=n-1\). For confidence level \(C\), let \(t^*\) be the positive critical value that leaves probability \((1-C)/2\) in each tail of a t distribution with \(n-1\) degrees of freedom. The standard error is \(SE=s/\sqrt{n}\), and the margin of error is \(t^*SE\).

Theorem: The one-sample t confidence interval for a population mean is
$$ \bar{x}\ \pm\ t^*\frac{s}{\sqrt{n}} \qquad\text{or equivalently}\qquad \left(\bar{x}-t^*\frac{s}{\sqrt{n}},\ \bar{x}+t^*\frac{s}{\sqrt{n}}\right). $$

For an independent sample from a normally distributed population, the statistic \((\bar{x}-\mu)/(s/\sqrt{n})\) follows a t distribution with \(n-1\) degrees of freedom. That result explains why the procedure uses a t critical value rather than a z critical value. In practice, once the assumptions are judged appropriate, the task is to calculate \(\bar{x}\) and \(s\) from the raw observations, select \(t^*\) using the confidence level and \(df\), and form the two endpoints.

Worked Calculations

Worked Example: Five Laboratory Measurements

Suppose five randomly selected, independent batches produce hypothetical measurements of a substance concentration, in milligrams per litre: \(8, 10, 9, 11, 7\). Assume the population distribution is approximately normal. Construct a 95% one-sample t interval for the population mean concentration.

Calculate the mean. The sum is \(8+10+9+11+7=45\), so

$$ \bar{x}=\frac{45}{5}=9\text{ mg/L}. $$

Calculate the sample standard deviation. The deviations from 9 are \(-1,1,0,2,-2\), so their squared deviations sum to \(1+1+0+4+4=10\). Thus

$$ s=\sqrt{\frac{10}{5-1}}=\sqrt{2.5}=1.581\text{ mg/L}. $$

Find the standard error and critical value. Here \(n=5\), so \(df=4\). For a two-sided 95% interval, \(t^*=2.776\). Therefore,

$$ SE=\frac{\sqrt{2.5}}{\sqrt{5}}=0.7071\text{ mg/L}, \qquad ME=2.776(0.7071)=1.963\text{ mg/L}. $$

Form the interval. Subtract and add the margin of error to the mean:

$$ 9\pm1.963=(7.037,\ 10.963)\text{ mg/L}. $$

The 95% t interval extends from about 7.037 to 10.963 mg/L. Its center is the observed sample mean, 9 mg/L, and its half-width is the calculated margin of error. The sampling setup and approximate-normality assumption stated above are what justify using this procedure for these small-sample data.

Worked Example: Using the Computational Identity

Suppose six hypothetical, independently sampled wait times, in minutes, are \(12,15,11,14,13,17\). Assume the population distribution is approximately normal. Construct a 90% t interval for the population mean wait time.

Calculate the mean. The observations sum to \(82\), so \(\bar{x}=82/6=13.6667\) minutes.

Calculate the sample standard deviation. The sum of the squared observations is \(12^2+15^2+11^2+14^2+13^2+17^2=1144\). By the computational identity, the squared deviations sum to

$$ 1144-\frac{82^2}{6} =1144-\frac{6724}{6} =23.3333. $$

Then

$$ s=\sqrt{\frac{23.3333}{6-1}} =\sqrt{4.6667} =2.160\text{ minutes}. $$

Calculate the standard error and margin of error. With \(n=6\), the degrees of freedom are \(df=5\). For a 90% interval, \(t^*=2.015\). Thus

$$ SE=\frac{2.160}{\sqrt{6}}=0.8819\text{ minutes}, \qquad ME=2.015(0.8819)=1.777\text{ minutes}. $$

Form the interval.

$$ 13.6667\pm1.777=(11.89,\ 15.44)\text{ minutes}. $$

The interval endpoints are about 11.89 and 15.44 minutes. The computational identity avoids rounding the mean before finding the squared deviations; using rounded intermediate values can shift the result slightly.

Worked Example: A Smaller Sample and a 90% Interval

Consider four hypothetical, independently selected specimens with thicknesses \(4,5,5,6\) millimetres. Suppose the population distribution is approximately normal. Calculate a 90% t interval for the population mean thickness.

Find the mean and spread. The observations sum to 20, so \(\bar{x}=20/4=5\) mm. The deviations are \(-1,0,0,1\), with squared deviations summing to 2. Therefore,

$$ s=\sqrt{\frac{2}{4-1}}=\sqrt{\frac{2}{3}}=0.8165\text{ mm}. $$

Find the critical value and margin of error. The degrees of freedom are \(df=3\). For a 90% interval, \(t^*=2.353\). The standard error and margin of error are

$$ SE=\frac{0.8165}{\sqrt{4}}=0.4082\text{ mm}, \qquad ME=2.353(0.40825)\approx0.9606\text{ mm}. $$

Calculate both endpoints.

$$ 5\pm0.9606=(4.039,\ 5.961)\text{ mm}. $$

The resulting 90% interval is about 4.039 to 5.961 mm. With only four observations, this calculation depends particularly strongly on the assumption that the population distribution is approximately normal; the numerical steps alone cannot establish that assumption.

Checks and Common Mistakes

A few quick checks can catch many arithmetic or setup errors before an interval is reported:

  • The sample mean and standard deviation should have the same units as the measurements; the variance has squared units.
  • The degrees of freedom should be \(n-1\), where \(n\) is the number of observations.
  • The standard error is \(s/\sqrt{n}\). For \(n>1\), \(SE\leq s\), with strict inequality when \(s>0\).
  • The interval should be centered on \(\bar{x}\), and its half-width should equal \(t^*SE\).

A common mistake is to divide the sum of squared deviations by \(n\) when calculating the sample standard deviation. For the first example, that would give a variance of \(10/5=2\), rather than the sample variance \(10/4=2.5\), and would make the estimated spread too small. The correction is to use \(n-1\) in the sample variance formula. Another mistake is to use a critical value for the wrong degrees of freedom: the confidence level alone does not determine \(t^*\); \(df\) matters too.

If all observations are identical, then \(s=0\) and \(SE=0\); the inequality \(SE\leq s\) is an equality in that case. The formula would produce a zero-width interval, but that result does not establish that the population mean is known exactly. It signals that the observed data provide no measured spread for the usual t procedure to reflect, so the data and the model should be examined rather than treating the degenerate interval as conclusive.

Key takeaway: For raw data, calculate \(\bar{x}\) and \(s\) from the individual observations before applying the one-sample t interval. Keep the \(n-1\) divisor, use \(df=n-1\) to choose \(t^*\), and calculate the margin of error as \(t^*s/\sqrt{n}\).

Check Your Understanding

For each question, show enough work to make your calculation checkable.

  1. For the observations \(3,5,4,6\), calculate \(\bar{x}\), the sum of squared deviations, and \(s\).
  2. A sample has \(n=8\). What are the degrees of freedom for its one-sample t interval?
  3. Explain why the sample variance divides the sum of squared deviations by \(n-1\), rather than \(n\), in the formula for \(s^2\).
  4. A sample has \(s=2.4\) units and \(n=9\). Calculate its standard error and state whether it is less than or equal to \(s\).
  5. What two pieces of information determine the t critical value for a two-sided confidence interval?