One-Sample t-Test Using Python

Model group-report output for Statistical Inference and Correlation Analysis

Model Presentation

Purpose of the One-Sample t-Test

The one-sample t-test is used to determine whether the mean of one sample is significantly different from a known, expected, or hypothesized reference mean.

1. State the Research Problem or Question
2. Identify the Variables
3. State the Hypotheses
4. Set the Level of Significance
5. Explain Why the Test Is Appropriate
6. Present the Python Results
7. Make the Statistical Decision
8. Interpret the Result

When is it appropriate?

  • There is one sample.
  • The dependent variable is continuous.
  • The sample mean is compared with a specified value.
  • Observations are independent.
  • There are no serious outliers.
  • The variable is approximately normally distributed.

Level of Significance

α = 0.05

For this model, lengthy manual computations are not shown. Only the test statistic, p-value, decision, and contextual interpretation are presented.

Example 1 — Test Anxiety Score

1. State the Research Problem or Question

Research question: Is the mean test-anxiety score of the students significantly different from the reference score of 8?

This investigates whether the average test-anxiety score observed in one group of students differs from a specified benchmark.

2. Identify the Variables

VariableTest Anxiety Score
RoleDependent / outcome variable being compared with a benchmark
Measurement LevelContinuous
Number of Groups or ConditionsOne sample
Reference Valueμ₀ = 8

3. State the Hypotheses

H₀: μ = 8

H₁: μ ≠ 8

This is a two-tailed test because the question asks whether the mean is different from 8.

4. Set the Level of Significance

α = 0.05

5. Explain Why the Statistical Test Is Appropriate

  • Number of groups/conditions: One sample is compared with one reference mean.
  • Independent or related observations: Observations are independent because each score belongs to a different student.
  • Measurement level: Test-anxiety score is treated as a continuous variable.
  • Important assumptions: No significant outliers are observed, and the distribution is approximately normal.
  • Normality evidence: Shapiro–Wilk W = 0.961, p = 0.560, so there is no significant evidence of non-normality.
Therefore, the one-sample t-test is appropriate.

6. Present the Python Results

Only the important output is presented. Lengthy manual computations are not required.

Sample Sizen = 20
Sample Mean8.53
Standard Deviation0.61
Reference Mean8.00
Test Statistict = 3.916
p-valuep = 0.0009

7. Make the Statistical Decision

Because p = 0.0009 < α = 0.05, reject H₀.

8. Interpret the Result

There is sufficient evidence to conclude that the students' mean test-anxiety score is different from the reference score of 8. Since the sample mean is 8.53, the students in this sample have a higher average test-anxiety score than the benchmark.

Example 2 — Programming Examination Score

1. State the Research Problem or Question

Research question: Is the mean programming examination score of the students significantly different from 85?

This investigates whether the average score of one group of BSIT students differs from the expected benchmark score of 85.

2. Identify the Variables

VariableProgramming Examination Score
RoleDependent / outcome variable being compared with a benchmark
Measurement LevelContinuous
Number of Groups or ConditionsOne sample
Reference Valueμ₀ = 85

3. State the Hypotheses

H₀: μ = 85

H₁: μ ≠ 85

4. Set the Level of Significance

α = 0.05

5. Explain Why the Statistical Test Is Appropriate

  • Number of groups/conditions: One sample is compared with a reference mean of 85.
  • Independent or related observations: Each score comes from a different student, so the observations are independent.
  • Measurement level: Examination score is treated as continuous.
  • Important assumptions: No serious outliers are observed, and the scores are approximately normally distributed.
  • Normality evidence: Shapiro–Wilk W = 0.965, p = 0.419.
Therefore, the one-sample t-test is appropriate.

6. Present the Python Results

Sample Sizen = 30
Sample Mean88.20
Standard Deviation2.23
Reference Mean85.00
Test Statistict = 7.844
p-valuep < 0.001

7. Make the Statistical Decision

Because p < α = 0.05, reject H₀.

8. Interpret the Result

There is sufficient evidence to conclude that the students' mean programming examination score differs from 85. Since the sample mean is 88.20, the students scored higher on average than the expected benchmark.

Example 3 — Information-System Response Time

1. State the Research Problem or Question

Research question: Is the average system response time significantly different from 250 milliseconds?

This investigates whether the observed average response time of the system differs from the specified performance benchmark.

2. Identify the Variables

VariableSystem Response Time
RoleDependent / outcome variable being compared with a benchmark
Measurement LevelContinuous
Number of Groups or ConditionsOne sample
Reference Valueμ₀ = 250 ms

3. State the Hypotheses

H₀: μ = 250 ms

H₁: μ ≠ 250 ms

4. Set the Level of Significance

α = 0.05

5. Explain Why the Statistical Test Is Appropriate

  • Number of groups/conditions: One set of response-time observations is compared with a benchmark of 250 ms.
  • Independent or related observations: Each recorded response is treated as an independent observation.
  • Measurement level: Response time measured in milliseconds is continuous.
  • Important assumptions: No significant outliers are observed, and the response times are approximately normal.
  • Normality evidence: Shapiro–Wilk W = 0.979, p = 0.872.
Therefore, the one-sample t-test is appropriate.

6. Present the Python Results

Sample Sizen = 25
Sample Mean245.96 ms
Standard Deviation3.54 ms
Reference Mean250 ms
Test Statistict = −5.704
p-valuep < 0.001

7. Make the Statistical Decision

Because p < α = 0.05, reject H₀.

8. Interpret the Result

There is sufficient evidence to conclude that the system's mean response time differs from 250 ms. Since the sample mean is 245.96 ms, the system responds faster on average than the specified benchmark.

Suggested Python Code

import pandas as pd
from scipy.stats import ttest_1samp, shapiro

data = pd.read_csv("data.csv")
scores = data["Score"]

print("Mean:", scores.mean())
print("Standard deviation:", scores.std())
print("Sample size:", len(scores))

w, p_normal = shapiro(scores)
print("Shapiro-Wilk W:", w)
print("Normality p-value:", p_normal)

t_stat, p_value = ttest_1samp(scores, popmean=85)

print("t-statistic:", t_stat)
print("p-value:", p_value)
During the report, explain what the output means. Do not spend presentation time explaining every line of Python code unless asked.

Required Presentation Sequence

StepWhat Students Should Present
1. State the research problem or questionClearly explain what is being investigated.
2. Identify the variablesIdentify the relevant variables and their measurement levels. For comparison tests, indicate the groups or conditions being compared.
3. State the hypothesesPresent the null hypothesis (H₀) and alternative hypothesis (H₁).
4. Set the level of significanceUse α = 0.05, unless another level is justified.
5. Explain why the statistical test is appropriateDiscuss the number of groups or conditions, whether observations are independent or related, the measurement level of the variables, and the important assumptions. Explain whether the assumptions are reasonably satisfied.
6. Present the Python resultsReport at least the test statistic and p-value. Include other useful values such as descriptive statistics, means, medians, or correlation coefficients when needed. Do not show lengthy manual computations.
7. Make the statistical decisionCompare the p-value with α = 0.05 and state whether H₀ is rejected or not rejected.
8. Interpret the resultExplain the result in ordinary language and in the context of the research problem. Do not simply say “significant” or “not significant.”
Model reminder: The one-sample t-test is used here only to demonstrate the required presentation structure. Student groups should apply the same 8-step sequence to their assigned statistical test.

Quick Check

1. When is a one-sample t-test appropriate?
2. If p = 0.012 and α = 0.05, what is the decision?
3. Which is NOT normally required for this test?