Understanding Hypothesis Testing and the t-Test

Levente L. Orbán
School of Psychology, University of the South Pacific, Suva, Fiji
levente.orban@usp.ac.fj
doi: 10.69642/9543

Abstract

This lecture note provides an accessible and pedagogically informed walkthrough of null hypothesis significance testing (NHST) and the \emph{t}-test, based on a live undergraduate statistics lecture. I discuss both independent and related samples \emph{t}-tests, common assumptions and their verification, and show how to manually implement these tests using R. Emphasis is placed on conceptual clarity, mathematical underpinnings, and hands-on implementation.

Introduction

Statistics forms the backbone of modern psychological research. The ability to test hypotheses and make data-driven inferences is crucial for both academic and applied psychologists. This page distills the core elements of a live lecture delivered in an undergraduate psychology course (Statistics 300), focusing on null hypothesis testing and the t-test, including independent and related samples designs.

We integrate assumption checks, diagnostic visualizations, and show how these procedures can be conducted manually using base R.

Null Hypothesis Testing Framework

Compare the p-value against a threshold α = 0.05. If p < α, reject H₀.

Assumption Checks

Normality: Use histograms, skewness, kurtosis. Acceptable skew < 2, kurtosis ≈ 3.

library(psych)
hist(screen_time_f2f)
skew(screen_time_f2f)
kurtosi(screen_time_f2f)

Homogeneity of Variance: Hartley’s F-max Test

var1 <- var(screen_time_f2f)
var2 <- var(screen_time_online)
F_max <- max(var1, var2) / min(var1, var2)

Independent Samples t-Test

t = (X̄₁ - X̄₂) / √(s²ₚ/n₁ + s²ₚ/n₂)

mean1 <- mean(group1)
mean2 <- mean(group2)
var1 <- var(group1)
var2 <- var(group2)
n1 <- length(group1)
n2 <- length(group2)
sp2 <- ((n1 - 1)*var1 + (n2 - 1)*var2) / (n1 + n2 - 2)
sem <- sqrt(sp2/n1 + sp2/n2)
t <- (mean1 - mean2) / sem

Related Samples t-Test

t = ȲD / (sD / √n)

diff_scores <- group1 - group2
mean_diff <- mean(diff_scores)
var_diff <- var(diff_scores)
n <- length(diff_scores)
sem <- sqrt(var_diff / n)
t <- mean_diff / sem

p-Value Calculation

df <- n1 + n2 - 2
p_value <- 2 * pt(-abs(t), df)

Cohen's d

d = (X̄₁ - X̄₂) / sₚ

d <- (mean1 - mean2) / sqrt(sp2)

Visualization

means <- c(mean1, mean2)
names <- c("Group 1", "Group 2")
bar <- barplot(means, names.arg=names, ylim=c(0, max(means) + 5))
arrows(bar, means - sem, bar, means + sem, angle=90, code=3, length=0.1)

Conclusion

This guide demonstrated how to manually compute and interpret t-tests using base R, supported by mathematical reasoning. Independent and related samples tests were examined, along with diagnostics, effect sizes, and visualizations.

Appendix

Complete annotated R scripts available upon request for lab and exam preparation.