typestar

t-tests in R

Comparing two group means for a significant difference.

set.seed(7)
control <- rnorm(30, mean = 100, sd = 15)
treatment <- rnorm(30, mean = 108, sd = 15)

result <- t.test(treatment, control, var.equal = FALSE)

p_value <- result$p.value
estimate <- result$estimate
interval <- result$conf.int
significant <- p_value < 0.05

paired <- t.test(treatment, control, paired = TRUE)

How it works

  1. t.test returns an object holding the whole result.
  2. $p.value and $conf.int read the key numbers.
  3. paired = TRUE handles before/after measurements.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
320
Tokens
76
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 48 seconds.

Type this snippet

Step 1 of 2 in Hypothesis tests, step 4 of 11 in Statistics.

← Previous Next →