Hi! I am Mike Marin and in this video
we'll talk about how to conduct the "independent two sample t-test"
and "confidence interval" using R Statistical Software.
The independent two sample t-test and confidence interval
are parametric methods appropriate for examining the difference in means
for two populations. They can also be thought of
as a way of examining the relationship between a numeric
outcome or Y variable and a categorical
explanatory or X variable. We'll be working with the Lung Capacity data
that was introduced earlier in this series of videos. I've already gone ahead
and imported the data into R and attached it.
We will be exploring the relationship between Smoking and Lung Capacity.
We can use the "t.test" command/function
to conduct the t-test. To access the Help menus in R programming language
type "help" and the name of the command you would like help for, or simply place a
question mark (?)
in front of the name of the command/function you would like help for.
Before conducting the test it can be useful to examine a plot of the data.
We will produce a Boxplot in R to examine the relationship between
Lung Capacity and Smoking.
Now let's go ahead and test the hypothesis
that the mean Lung Capacity of Smokers
is equal to that of Non-Smokers.
Let's also go ahead
and do a two-sided test in R.
Here we'll assume non-equal variances.
We can do
the independent two sample t-test in R using the "t.test" command/function.
Here we would like to compare the Lung Capacities separated
on groups formed by the variable Smoking. Our null hypothesis
is that the mean difference is 0, the alternative we are using
is a two-sided. We will use confidence
of 95 percent for our confidence interval. We are assuming
that variances are not equal and that
these two groups are not paired, they are independent.
We can see in the output
returned by R the test statistic of negative 3.65,
the p-value of 0.00039,
the 95 percent confidence interval
for the difference in means running from
negative 1.35 to negative 0.40,
as well we also see the sample group means of 7.77 and 8.65.
It is worth noting
that all of the arguments entered above are the default values in R
and none of these need to be entered if we'd like to use all these default values.
We may change the
"mu" argument if you would like to test for a difference other than 0
we may change the "alt" argument
if we'd like to do a one-sided test less than or greater than,
we can change the "conf" argument if we'd like to change the confidence level,
we can change the "var.eq" argument
if you'd like to assume equal variances, and we can change the "paired" argument
and set this equal to TRUE when we have paired group or
dependent groups.
We should also make a note here that instead of separating the groups
using the tilda (~),
we can also enter into R the two separate groups we would like compared.
Here we would like to compare the Lung Capacity for those
who do not Smoke and compare this
to the mean Lung Capacity for those who do smoke.
If we would like to go ahead
and make the assumption that the population variances are equal,
we can do this by changing the
"var.eq" argument and setting this
equal to TRUE.
Now we should discuss how we can decide if we want to assume
equal or non equal variances.
The simplest way is we can examine the boxplot that we produced earlier:
looking at this, we can see the Non-Smoking group
seems to have a larger variation in Lung Capacities than the Smoking group.
Second way is that we can compare the actual variance
of Lung Capacities for those who Smoke
and compare this with the variance in Lung Capacities for those who do not Smoke.
Again we can see the variance for the Non-Smoking group
is almost double that of the Smoking group.
One final option is we can use Levene's test.
This test is used to test the null hypothesis
that the population variances are equal.
To use this test one must have the CAR,
the companion to applied regression package installed.
For help on installing packages see my earlier video
on installing packages in R. I've already installed this package;
the next thing to do is go ahead and load the library.
Once we have loaded this package we can then conduct this test
using the "leveneTest" command.
Here again we would like to compare
variations in Lung Capacities separated by the Smoking status.
Here we can see that with a small P value we should reject
the null hypothesis
and conclude that we have evidence to believe population variances
are not equal and use the non-equal assumption.
In the next video in this series we'll discuss the "Wilcoxon Rank Sum test"
also known as the "Mann-Whitney u-test", this is a nonparametric equivalent
to the "independent two sample t-test".
Thanks for watching this video and make sure to check out my other instructional videos