Hi! I Mike Marin and in this video
we'll talk about how to conduct the one sample t-test
and construct a one sample confidence interval for the mean
using R (programming language) . the one sample t-test
and confidence interval are parametric methods appropriate for examining a
single numeric variable.
we will be working with the lung capacity dataset
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 examine the variable
Lung Capacity. We can conduct the t-test
and the confidence interval using the "t.test" command.
to access the Help menu in R statistics software, type "help"
and in brackets the name of the command we would like help for
or simply throw a question mark (?) in front of the name of the command.
Before beginning any analysis
it's useful to examine a plot of the data. One may produce a box plot
or a histogram for the variable.
Now let's get started with the "t.test" command. Suppose we would like to test
the null hypothesis that the mean is less than 8,
further
we would also like to have a one-sided 95% confidence
interval produced
for the mean. this can be done
using the "t.test" command (function). Here we would like to do the test
on the variable Lung Capacity. Our null hypothesis
is that the mean is equal to 8. the alternative
is a one-sided specifically less than,
the confidence level that we would like to use
is 95%. here is the output that R programming language
returns to us. we can see the test statistic of
-1.384, the p-value
of 0.083, the 95 percent confidence interval
running from negative infinity to 8.026
and recall this was a one-sided confidence interval.
and we are also returned the sample mean Lung Capacity
of 7.86. for most arguments within
R we often only need to include the first few letters
and R will know which argument we are calling on; for example
it's enough to only include "conf" and for the alternative
"alt". if
instead we wanted to produce a two-sided hypothesis test
or confidence interval, we can achieve this
by setting the alternative to
"two.sided", here are the results
for two-sided hypothesis test and two-sided confidence interval
it's also worth noting that a two-sided test
is the default in R. so if we do not include this argument
by default R will produce a two-sided test
suppose we would like to create a 99 percent confidence interval. this can be achieved
by setting the "conf" argument equal to 0.99
as we have seen
earlier in this series of videos. we can store
results of the test in an object. I'm gonna go ahead
and store the results in an object called TEST using capital letters;
here we can see the result of this t-test are stored in this object.
one final thing we can discuss
in this video is the attributes of an object;
the "attributes" command will allow us to see
what attributes are stored within this object TEST
any of these attributes can be extracted
from the object TEST using the dollar sign ($), for example
we may like pull out only the confidence interval
or we may want to pull out
only the p-value. while these last few steps
are not completely necessary for performing simple tests,
it can be useful when conducting more advanced coding or analysis.
in the next video in this series
we will discuss the two-sample t-test.
thanks for watching this video! Make sure to subscribe to marinstatslectures for more videos and tutorials.