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
t.testreturns an object holding the whole result.$p.valueand$conf.intread the key numbers.paired = TRUEhandles before/after measurements.
Keywords and builtins used here
rnorm
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.
Step 1 of 2 in Hypothesis tests, step 4 of 11 in Statistics.