MODULE 1310 QUESTIONS

Single Mean Inference

ADAPTIVE FLASHCARDS
Flashcard Study Mode
Study this module with spaced repetition. Wrong answers come back weighted heavier.

Single Mean Inference

Introduction

When we have a quantitative variable and want to make inferences about the population mean, we use the methods in this module. Whether we're estimating a confidence interval or testing a hypothesis about a population mean, the process relies on understanding the sampling distribution of the sample mean and the t-distribution.

1. The Sampling Distribution of the Sample Mean

Why the Sample Mean Follows a Normal Distribution

When we repeatedly sample from a population and calculate the sample mean (x) for each sample, those sample means follow a distribution. This sampling distribution has special properties:

If we take all possible samples of size n from a population:

  • The center of the sampling distribution is the true population mean (μ)
  • The spread of the sampling distribution is measured by the standard error
  • The sampling distribution is approximately normal

The second and third points are guaranteed by the Central Limit Theorem (CLT). The CLT states:

Key concept: If we take samples of size n from any population (with finite mean and standard deviation), the sampling distribution of x is approximately normal when n is large enough (typically n >= 30). If the population itself is normal, then the sampling distribution of x is normal regardless of sample size.

Standard Error: The Standard Deviation of x

The standard error (SE) measures how much sample means vary from sample to sample. It depends on two things:

1. The population standard deviation (σ): Larger σ means more variability in the data

2. The sample size (n): Larger samples give less variable sample means

The relationship is: SE = σ / √n

Notice that SE decreases as n increases. This is why larger samples give more precise estimates of the population mean.

In practice, we never know σ (the true population standard deviation), so we estimate it using the sample standard deviation s:

Estimated SE = s / √n

2. From Z-Distribution to T-Distribution: Why T When Sigma Is Unknown

The Problem: Estimation Introduces Uncertainty

If we knew the true population standard deviation σ, we could use the z-distribution (standard normal). The test statistic would be:

z = (x - μ) / (σ / √n)

However, in real life, we never know σ. We must estimate it using the sample standard deviation s. This introduces extra uncertainty.

The Solution: The T-Distribution

When we substitute s for σ, we no longer follow the standard normal (z) distribution. Instead, we follow the t-distribution:

t = (x - μ) / (s / √n)

The t-distribution has the following properties:

  • It is symmetric and bell-shaped, like the normal distribution
  • It has heavier tails than the normal distribution (more area in the tails)
  • The extra tail weight reflects the extra uncertainty from estimating σ
  • As degrees of freedom increase, the t-distribution approaches the normal distribution

Degrees of Freedom

The t-distribution is not a single distribution. Instead, it is a family of distributions, each determined by the degrees of freedom (df).

Key concept: For inference about a single population mean, df = n - 1. We lose one degree of freedom because we used the sample mean to estimate σ.

As df increases, the t-distribution has lighter tails and looks more like the standard normal. When df > 30, the t-distribution is very close to the normal distribution.

When to Use T vs Z

  • Use z-distribution: Only when σ is known (rare in practice)
  • Use t-distribution: When σ is unknown (almost always in practice)

3. Confidence Intervals for a Single Mean

The Formula

A confidence interval for the population mean μ is:

x ± t* × SE

Where:

  • x is the sample mean
  • t* is the critical value from the t-distribution with df = n - 1
  • SE = s / √n is the standard error
  • The margin of error is t* × SE

For a 95% confidence interval, t is the value such that 95% of the t-distribution lies between -t and t. This means 2.5% is in each tail. We use qt(0.975, df = n - 1) to find t.

Step-by-Step Example: Cat Sleep Time

Suppose we have data on adult male fixed Ragdoll cats:

  • Sample size: n = 135
  • Sample mean sleep time: x = 16.02 hours
  • Sample standard deviation: s = 2.87 hours

We want a 95% confidence interval for the mean sleep time.

Step 1: Calculate the standard error.

SE = s / √n = 2.87 / √135 = 2.87 / 11.62 = 0.247 hours

Step 2: Find the critical value t*.

With df = 135 - 1 = 134, we look up qt(0.975, df = 134). This gives t* = 1.978.

Step 3: Calculate the margin of error.

Margin of error = t × SE = 1.978 0.247 = 0.489 hours

Step 4: Calculate the confidence interval.

CI = 16.02 ± 0.489 = [15.531, 16.509] hours

Interpretation of a 95% Confidence Interval

Key concept: If we repeated our sampling procedure infinitely many times and calculated a 95% CI each time, approximately 95% of those intervals would contain the true population mean.

This does NOT mean:

  • The probability that μ is in this specific interval is 0.95 (once we calculate an interval, either μ is in it or it isn't)
  • There is a 95% probability that the population mean is in the interval

It DOES mean:

  • We used a method that captures the true mean 95% of the time in the long run
  • We have confidence in our procedure, not in a particular interval

R Code for Confidence Intervals

Calculating by hand:

R
1cats <- read_csv("cat_breeds_clean.csv")
2cats_small <- cats %>%
3 filter(Age_in_years >= 1, Sex == "male", Breed == "Ragdoll", Fixed == TRUE)
4
5# Calculate summary statistics
6cats_summary <- cats_small %>%
7 summarize(xbar = mean(Sleep_time_hours),
8 s = sd(Sleep_time_hours),
9 n = n())
10
11xbar <- cats_summary$xbar
12s <- cats_summary$s
13n <- cats_summary$n
14se <- s / sqrt(n)
15t_star <- qt(0.975, df = n - 1)
16margin_error <- t_star * se
17
18c(xbar - margin_error, xbar + margin_error)
OUTPUT
1[1] 15.531 16.509

Using the t.test() function (much simpler):

R
1t.test(cats_small$Sleep_time_hours, conf.level = 0.95)
OUTPUT
1 One Sample t-test
2
3data: cats_small$Sleep_time_hours
4t = 64.84, df = 134, p-value < 2.2e-16
5alternative hypothesis: true mean is not equal to 0
695 percent confidence interval:
7 15.531 16.509
8
9statistic:
10 t = 64.84
11df = 134
12mean of x = 16.02

Confidence Level and Critical Values

Different confidence levels use different critical values:

  • 90% CI: t* = qt(0.95, df = n - 1)
  • 95% CI: t* = qt(0.975, df = n - 1)
  • 99% CI: t* = qt(0.995, df = n - 1)

Higher confidence levels result in wider intervals.

4. Hypothesis Tests for a Single Mean

Setting Up the Hypothesis Test

A hypothesis test for a population mean has the form:

  • H₀: μ = μ₀ (null hypothesis - the claim we are testing)
  • Hₐ: The alternative hypothesis, which can be:

- Hₐ: μ != μ₀ (two-sided test)

- Hₐ: μ > μ₀ (right-tailed test)

- Hₐ: μ < μ₀ (left-tailed test)

We also set a significance level, usually α = 0.05.

The Test Statistic

The test statistic for testing a single mean is:

t = (x - μ₀) / (s / √n)

with df = n - 1.

The test statistic measures how many standard errors the sample mean is from the null hypothesis value.

P-Value Calculation

The p-value is the probability of observing a test statistic as extreme as (or more extreme than) the one we calculated, assuming the null hypothesis is true.

For a two-sided test (Hₐ: μ != μ₀):

p-value = 2 * P(t < -|t_obs|)

Using R: 2 * pt(-abs(t_obs), df = n - 1)

For a right-tailed test (Hₐ: μ > μ₀):

p-value = P(t > t_obs)

Using R: 1 - pt(t_obs, df = n - 1)

For a left-tailed test (Hₐ: μ < μ₀):

p-value = P(t < t_obs)

Using R: pt(t_obs, df = n - 1)

Decision Rule

  • If p-value < α, reject H0 (conclude that Ha is supported by the data)
  • If p-value >= α, fail to reject H0 (we do not have sufficient evidence to reject H0)

Example: Two-Sided Test

Question: Is the mean sleep time of adult male fixed Ragdoll cats different from 17 hours?

H₀: μ = 17

Hₐ: μ != 17

α = 0.05

From our data: x = 16.02, s = 2.87, n = 135, SE = 0.247

Test statistic:

t = (16.02 - 17) / 0.247 = -0.98 / 0.247 = -3.96

P-value (two-sided):

p-value = 2 * P(t < -3.96) with df = 134

p-value = 2 pt(-3.96, df = 134) = 2 0.000065 = 0.00013

Conclusion:

Since p-value (0.00013) < α (0.05), we reject H0. We have strong evidence that the mean sleep time of adult male fixed Ragdoll cats is different from 17 hours.

R code:

R
1t_stat <- (16.02 - 17) / (2.87 / sqrt(135))
2p_value <- 2 * pt(-abs(t_stat), df = 134)
3cat("Test statistic:", t_stat, "\n")
4cat("P-value:", p_value, "\n")
OUTPUT
1Test statistic: -3.96
2P-value: 0.000127

Or using the t.test() function:

R
1t.test(cats_small$Sleep_time_hours, mu = 17, conf.level = 0.95)
OUTPUT
1 One Sample t-test
2
3data: cats_small$Sleep_time_hours
4t = -3.96, df = 134, p-value = 0.000127
5alternative hypothesis: true mean is not equal to 17
695 percent confidence interval:
7 15.531 16.509
8
9statistic:
10 t = -3.96
11df = 134
12mean of x = 16.02

In t.test(), the μ argument specifies the null hypothesis value.

Example: One-Sided (Right-Tailed) Test

Question: Is the mean sleep time greater than 15.5 hours?

H₀: μ = 15.5

Hₐ: μ > 15.5

α = 0.05

Test statistic:

t = (16.02 - 15.5) / 0.247 = 0.52 / 0.247 = 2.11

P-value (right-tailed):

p-value = P(t > 2.11) = 1 - pt(2.11, df = 134) = 0.0184

Conclusion:

Since p-value (0.0184) < α (0.05), we reject H0. We have evidence that the mean sleep time is greater than 15.5 hours.

5. Rejection Region Approach

An alternative to the p-value approach is the rejection region (or critical value) approach.

In this approach:

1. Calculate the critical value(s) from the t-distribution

2. Reject H0 if the test statistic falls in the rejection region

Two-Sided Test Rejection Region

For a two-sided test with α = 0.05 and df = 134:

Reject H0 if t < qt(0.025, df = 134) or t > qt(0.975, df = 134)

R code:

R
1lower_crit <- qt(0.025, df = 134)
2upper_crit <- qt(0.975, df = 134)
3cat("Lower critical value:", lower_crit, "\n")
4cat("Upper critical value:", upper_crit, "\n")
OUTPUT
1Lower critical value: -1.978
2Upper critical value: 1.978

Since our test statistic t = -3.96 is less than -1.978, we reject H0.

One-Sided Test Rejection Region

For a right-tailed test (Hₐ: μ > μ₀) with α = 0.05:

Reject H0 if t > qt(0.95, df = 134) = 1.656

For a left-tailed test (Hₐ: μ < μ₀) with α = 0.05:

Reject H0 if t < qt(0.05, df = 134) = -1.656

6. Connection Between Confidence Intervals and Hypothesis Tests

There is a direct relationship between a (1 - α) * 100% confidence interval and a hypothesis test with significance level α.

Key concept: For a two-sided hypothesis test with significance level α, we reject H₀: μ = μ₀ if and only if μ₀ lies outside the (1 - α) * 100% confidence interval.

Example

We calculated a 95% CI for mean sleep time: [15.531, 16.509]

For the test H₀: μ = 17 vs Hₐ: μ != 17 with α = 0.05:

Since 17 is outside the 95% CI, we reject H0.

This matches our p-value result.

For the test H₀: μ = 16 vs Hₐ: μ != 16 with α = 0.05:

Since 16 is inside the 95% CI, we fail to reject H0.

This provides an intuitive way to understand hypothesis tests: if the hypothesized mean is outside the confidence interval, it's an implausible value for the true mean.

7. Checking Conditions for Valid T-Tests

Before conducting a t-test, we should verify certain conditions:

Condition 1: Quantitative Data

The variable should be quantitative (numerical), not categorical.

Condition 2: Random Sample

The data should come from a random sample of the population. If it doesn't, our inference may be biased.

Condition 3: Normality or Large Sample Size

One of the following should be true:

  • The population distribution is approximately normal (check by making a histogram or Q-Q plot of the sample), OR
  • The sample size is large (n >= 30)

The t-test is robust to moderate violations of normality when n is large.

Example: Checking Conditions

For the cat sleep data:

  • Quantitative: Yes, sleep time in hours is numerical
  • Random sample: The data should come from a random sample of the population of interest
  • Sample size: n = 135, which is much larger than 30, so normality is not a major concern

R code to check normality with a histogram:

R
1histogram <- ggplot(cats_small, aes(x = Sleep_time_hours)) +
2 geom_histogram(binwidth = 1) +
3 labs(title = "Distribution of Sleep Time",
4 x = "Sleep time (hours)",
5 y = "Frequency")
6print(histogram)

If the histogram is roughly symmetric and unimodal, the normality condition is reasonably satisfied.

8. Common Interpretation Pitfalls

Pitfall 1: Misinterpreting the Confidence Interval

Incorrect: "There is a 95% probability that the true mean is in the interval [15.531, 16.509]."

Correct: "If we repeated our sampling procedure many times and calculated a 95% CI each time, about 95% of those intervals would contain the true mean."

Once we compute an interval, the true mean either is or is not in it. The probability is either 0 or 1, not 0.95.

Pitfall 2: Confusing P-Value with the Probability H0 Is True

Incorrect: "The p-value is the probability that H0 is true."

Correct: "The p-value is the probability of observing data as extreme as (or more extreme than) what we observed, assuming H0 is true."

A small p-value suggests the data is incompatible with H0, but it does not directly tell us the probability that H0 is true.

Pitfall 3: Failing to Reject Doesn't Mean Accept

Incorrect: "We fail to reject H0, so H0 is true."

Correct: "We fail to reject H0, so we don't have sufficient evidence to reject it. This doesn't mean H0 is true; it means the data don't provide strong evidence against it."

Pitfall 4: Ignoring Practical Significance

A small p-value indicates statistical significance (the effect is unlikely to be due to chance), but the effect might still be small in practical terms.

Example: Suppose we test H₀: μ = 16 hours vs Hₐ: μ != 16 hours, and our sample mean is 16.02 hours with p-value = 0.01.

We reject H0 (statistically significant), but the difference of 0.02 hours (about 1 minute) is negligible in practical terms.

Pitfall 5: Type I and Type II Errors

A Type I error occurs when we reject H0 when it is actually true. The probability of a Type I error is α (the significance level).

A Type II error occurs when we fail to reject H0 when it is actually false. The probability of a Type II error is β.

We control α by setting it before the analysis, but β depends on the true mean, the sample size, and the variability of the data. Larger sample sizes reduce β.

Summary

To conduct inference about a single population mean:

1. Check the conditions (quantitative data, random sample, normality or n >= 30)

2. Calculate the sample mean, sample standard deviation, and standard error

3. For a confidence interval, use *x ± t × SE**

4. For a hypothesis test, calculate t = (x - μ₀) / SE and find the p-value

5. Interpret results carefully, keeping practical significance in mind

6. Remember that confidence intervals and p-values are tools for inference, not statements about the true parameters