Author: Levente L. Orbán
doi: 10.69642/5734
This document presents a structured overview of null hypothesis significance testing (NHST) and the t-test. Theoretical foundations, mathematical formulations, and base R implementations are provided to enhance understanding of statistical hypothesis testing in psychology.
Hypothesis testing is a fundamental component of statistical inference. It allows researchers to make probabilistic decisions regarding populations based on sample data. The process revolves around assessing whether an observed effect is likely due to chance.
A hypothesis is a predictive statement about an outcome in a study. The null hypothesis (H0) posits no effect or no difference, while the alternative hypothesis (Ha) suggests the presence of an effect. Statistical testing seeks to reject H0 in favor of Ha.
H₀: μ₁ = μ₂ Hₐ: μ₁ ≠ μ₂ (two-tailed) Hₐ: μ₁ > μ₂ or Hₐ: μ₁ < μ₂ (one-tailed)
The probability of a Type I error is typically set at α = 0.05, meaning there is a 5% chance of rejecting H0 when it is true.
The t-test compares two sample means to determine whether they likely come from the same population. There are three types of t-tests:
t = (X̄₁ - X̄₂) / (sₚ * sqrt(1/n₁ + 1/n₂))
sₚ = sqrt(((n₁ - 1)s₁² + (n₂ - 1)s₂²) / (n₁ + n₂ - 2))
# Sample data
data1 <- c(12, 15, 14, 10, 13)
data2 <- c(18, 17, 19, 15, 16)
# Sample sizes
n1 <- length(data1)
n2 <- length(data2)
# Sample means
mean1 <- mean(data1)
mean2 <- mean(data2)
# Sample variances
var1 <- var(data1)
var2 <- var(data2)
# Pooled variance
sp2 <- ((n1 - 1) * var1 + (n2 - 1) * var2) / (n1 + n2 - 2)
# Standard error of the mean difference
sem_pooled <- sqrt(sp2 * (1/n1 + 1/n2))
# t-statistic
t_value <- (mean1 - mean2) / sem_pooled
# Degrees of freedom
df <- n1 + n2 - 2
# p-value (two-tailed test)
p_value <- 2 * pt(-abs(t_value), df)
# Output results
cat("t-value:", t_value, "\n")
cat("p-value:", p_value, "\n")
The t-test is a powerful statistical tool for comparing means. Understanding the theoretical foundation and manually implementing it in R provides a deeper grasp of hypothesis testing, allowing for better critical evaluation of research findings.