Hi! I am Mike Marin and in this video
we'll talk about how to conduct the paired t-test and confidence interval using R Programming Language.
The paired t-test and
confidence interval in statistics are parametric methods appropriate
for examining the difference in means
for two populations that are paired or dependent on one another.
We will work with data involving measurements on systolic blood pressure
before and then after receiving some treatment.
We can see that the data consists of 25 paired observations
with subject numbers, before measurements, and after measurements.
I've already imported the data into R and attached it.
We will explore
the change in systolic blood pressure from before treatment
to after treatment. We can use the "t.test" command/function in R
to conduct the paired t-test. To access the Help menu
type "help" and in brackets the name of the command you would like help for,
or simply place a question mark (?) in front of the name of the command.
Before performing the test
we can go ahead and examine a boxplot of the data
comparing the before and the after measurements.
We can see some evidence that the blood pressure
after treatment is lower on average. We may want to look at a plot
that allows us to see the data as paired or the changes in individuals.
There are many ways that one can do this; here is one of them:
we may produce a scatterplot of the before
and the after measurements. We may also
add a 45-degree line to this plot using the "abline" argument in R.
Here we will add a line that has an intercept of 0 and a slope of 1.
This 45-degree line
is a line for X equal to Y or before equal to after.
If there is no change in blood pressure
points should fall on this diagonal line and be equally scattered above
or below the line. If there is a decrease in blood pressure
after treatment, more points should fall below the line
than above. Now let's go ahead and conduct a paired t-test.
We can use the null hypothesis
that the mean difference in systolic blood pressure
is zero and let's use a two-sided alternative.
We can do the paired t-test
using the "t.test" command/funtion in R Here we would like to compare the before
and the after measurements. We can set the mu argument equal to 0
to let R statistical software know we would like to test if the mean difference is 0.
We can set the "alt" argument in R
equal to "two.sided", to have a two-sided test.
We can set the "paired" argument equal to TRUE
to let R know the data is paired, and we would like the paired t-test.
We can use the "conf.level" argument
to let R know the level of confidence we would like,
here let's use a 99 percent (99%) confidence level.
We can see the test statistic of 3.88
the p-value of 0.000698
our 99 percent confidence interval that runs from 2.245 up to 13.754
and the sample mean difference of 8.
It's worth noting that the order we enter the before
and the after in, will not change things significantly
although, we should still make sure to pay attention to the order we have
entered them in. For example if instead we entered
after and then before our results will involve after measurements
minus before measurements, the only thing that will change
is the sign of things. We can see the sample mean difference is -8
instead of 8. The next video in this series
we will discuss the Wilcoxon Signed Rank test
a nonparametric equivalent to the paired t-test.
Thanks for watching this video; Please subscribe to marinstatslectures for more videos and tutorials in Statistics and R programming language