TLDR
Off-setting this newsletter by a day so that I’m not hitting your inbox twice on a Friday.
The t.test()
function in R implements both the one-sample and two-sample t-tests. It knows which one to implement based on what kinds of data you provide to it.
# Set random seed for reproducible randomness
set.seed(1)
# Generate data where one group actually has a different mean
placebo = rnorm(30, mean = 0, sd = 1)
treatment = rnorm(30, mean = 2, sd = 1)
# Run the test to see nicely formatted results in the console
t.test(x = placebo, y = treatment)
# Store the result to a variable so you can access different elements
result = t.test(x = placebo, y = treatment)
Instead of needing to do any calculations, the t.test()
function asks you to specify what you want from the it:
Assumptions on variance?
How much are you willing to tolerate Type-I error? (aka the level)
Is it a paired t-test?
But keep in mind that the function only implements the test, it has no built in capability for knowing whether or not the results it produces are valid. It’s up to the human statistician to make or check the relevant assumptions.