Day 30

Math 216: Statistical Thinking

Bastola

One sample tests summary

graph LR
  A[Start] --> B{Paired?}
  B -->|Yes| C[Diffs] --> D{σ?}
  D -->|Yes| E[Z]:::green
  D -->|No| F{Normal?} -->|Yes| G[T]:::green
  F -->|No| H[Wilcoxon]:::orange
  B -->|No| I{σ?}
  I -->|Yes| J[Z]:::green
  I -->|No| K{n≥30?}
  K -->|Yes| L[T*]:::yellow
  K -->|No| M{Normal?} -->|Yes| N[T]:::green
  M -->|No| O[Sign/Wilcox]:::orange

  classDef green fill:#D5E8D4,stroke:#82B366;
  classDef yellow fill:#FFF2CC,stroke:#D6B656;
  classDef orange fill:#F8CECC,stroke:#B85450;
  linkStyle 0 stroke-width:2px;

Two samples tests summary

graph LR
  A[Two Samples] --> B{Paired?}
  B -->|Yes| C[Diffs] --> D{σ?}
  D -->|Yes| E[Z]:::green
  D -->|No| F{Norm?} -->|Yes| G[T]:::green
  F -->|No| H[Wilcoxon]:::orange
  B -->|No| I{σ?}
  I -->|Yes| J[Z]:::green
  I -->|No| K{n≥30?}
  K -->|Yes| L[T*]:::yellow
  K -->|No| M{Normal both?} -->|Yes| N[T]:::green
  M -->|No| O[Mann Whitney]:::orange

  classDef green fill:#D5E8D4,stroke:#82B366;
  classDef yellow fill:#FFF2CC,stroke:#D6B656;
  classDef orange fill:#F8CECD,stroke:#B85450;

Wilcoxon Test in R

One-Sample Wilcoxon Signed Rank Test

Non-parametric test of whether a single sample’s median differs from a hypothesized value.

wilcox.test(x, mu = 0, alternative = "two.sided", conf.level = 0.95)

Paired Wilcoxon Signed Rank Test

Tests median differences between paired measurements (non-parametric alternative to paired t-test).

wilcox.test(x, y, paired = TRUE, alternative = "two.sided")

Wilcoxon Rank Sum/Mann-Whitney U Test

Non-parametric comparison of two independent sample distributions (location).

wilcox.test(x ~ group, data = dataset, alternative = "two.sided")

Parametric Tests in R


z-Test (Known σ²)

Requires BSDA package. For known population variance:

BSDA::z.test(x, mu = 0, sigma.x = 1, alternative = "two.sided")

Student’s t-Test

Compare means (one-sample, two-sample, or paired). Default assumes unequal variances:

t.test(x, y = NULL, paired = FALSE, var.equal = FALSE, conf.level = 0.95)

Summary Statistics Tests (BSDA)

zsum.test

Z-test from summary statistics:

BSDA::zsum.test(mean.x, sigma.x, n.x, mu = 0, alternative = "two.sided")

tsum.test

t-test from summary statistics:

BSDA::tsum.test(mean.x, s.x, n.x, mu = 0, var.equal = FALSE)

Analysis of Exam Scores: Online vs Traditional Classroom

Two groups of students, one taking an online class and the other in a traditional classroom setting, were given the same final exam. Here are the scores:

  • Online: 78, 82, 83, 87, 75, 43, 78, 42, 94, 47, 98, 90, 97, 81
  • Traditional: 83, 82, 92, 100, 74, 90, 44, 84, 77, 89, 70, 34

We want to determine if there’s a statistically significant difference between the exam scores of the two groups using a non-parametric test.

Hypothesis Test Setup

We will perform a Mann-Whitney U test, which does not assume a normal distribution of the scores.

Hypotheses

  • Null hypothesis (\(H_0\)): There is no difference in the median scores between the two classes.
  • Alternative hypothesis (\(H_a\)): There is a difference in the median scores between the two classes.

Significance Level

  • \(\alpha = 0.05\): This is the threshold for determining statistical significance.

Mann-Whitney U Test in R

First, we’ll enter the exam scores into R and perform the test.

online_scores <- c(78, 82, 83, 87, 75, 43, 78, 42, 94, 47, 98, 90, 97, 81)
traditional_scores <- c(83, 82, 92, 100, 74, 90, 44, 84, 77, 89, 70, 34)

Next, we use the wilcox.test() function to conduct the Mann-Whitney U test.

wilcox.test(online_scores, traditional_scores, alternative = "two.sided", conf.level = 0.95)

    Wilcoxon rank sum test with continuity correction

data:  online_scores and traditional_scores
W = 85.5, p-value = 0.959
alternative hypothesis: true location shift is not equal to 0