Tech Tutorial: Compute

Tech Tutorial — Compute. This unit uses formulas and theoretical distributions (the t and the normal) instead of resampling. Pick one tool and follow its tab — all three handle this unit well.

We reuse class_survey.csv.

What you’ll do

  1. A two-sample t-test — do On- and Off-campus students differ in mean sleep_hours?
  2. A confidence interval for one proportion — what fraction of students live on campus?

1. Two-sample t-test for a difference in means

This is the formula-based counterpart to the randomization test from the Simulate unit. It assumes roughly normal data (or a large enough sample) and reports a t statistic, degrees of freedom, and a p-value.

  1. Open the Two-Means Inference tool.
  2. Confirm the grouping variable is housing and the response is sleep_hours.
  3. Read the t statistic, df, p-value, and the confidence interval for the difference.
  1. Open class_survey.csv.
  2. T-Tests → Independent Samples T-Test. Dependent: sleep_hours; Grouping: housing.
  3. Tick Welch’s (unequal variances), Mean difference, and Confidence interval.

(Jamovi screenshots to be added.)

library(readr)
library(dplyr)
library(infer)

survey <- read_csv("../datasets/class_survey.csv")

# Two-sample t-test (Welch); order sets the sign of the difference
survey |>
  t_test(sleep_hours ~ housing,
         order = c("On-campus", "Off-campus"))
# A tibble: 1 × 7
  statistic  t_df p_value alternative estimate lower_ci upper_ci
      <dbl> <dbl>   <dbl> <chr>          <dbl>    <dbl>    <dbl>
1     0.204  47.8   0.839 two.sided     0.0516   -0.458    0.561

2. Confidence interval for one proportion

Here the variable is categorical: each student lives on campus or not. We estimate the population proportion living on campus with a normal-based (Wald/score) confidence interval.

  1. Open the One-Proportion Inference tool.
  2. Choose housing and set the success category to On-campus.
  3. Read the sample proportion and its 95% confidence interval.
  1. Frequencies → 2 Outcomes (Binomial test). Variable: housing.
  2. Set the test value and read the proportion and its confidence interval (Jamovi reports the CI for the level you select).

(Jamovi screenshots to be added.)

# Count on-campus students and form a one-proportion z interval
on <- sum(survey$housing == "On-campus")
n  <- nrow(survey)

prop.test(on, n)$conf.int        # 95% CI for the proportion on campus
[1] 0.3026605 0.5865007
attr(,"conf.level")
[1] 0.95
round(on / n, 3)                 # sample proportion
[1] 0.44

Check yourself