Comparing two means for paired samples (4)
Did you see how cumbersome this was? Calculating the 95% confidence interval, the t values and the p value can be done a lot easier using the built-in R function t.test()
. This function outputs all these statistics in one go.
We have already used the function t.test()
when working with independent group means. The function however works similar when working with paired samples. The main difference is that we need to set the argument pairs paired = TRUE
because we are working with paired data. Also, as we are dealing with a dataframe that contains two vectors pre_weight
and post_weight
, you would need to specify the x and y arguments of the t.test()
function, like so: t.test(x = pre_variable, y = post_variable)
This exercise is part of the course
Inferential Statistics
Exercise instructions
- Your console once again contains the
weight
dataframe which contains the variablespre_weight
andpost_weight
. Use the functiont.test()
to perform a paired samples t.test. Don't forget to set the argument pairspaired = TRUE
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# perform a paired samples t test