To perform a hypothesis test for a single mean you need to use the t.test()
function and specify the variable, x
, the value of the population parameter, mu
, and the alternative hypothesis. By default the alternative hypothesis is "two.sided", but you can also use "less", or "greater".
t.test(x = variable, mu = mu_0, alternative="less")
To calculate a confidence interval for a single mean you need to use the t.test()
function and specify the variable, x
, and set the confidence level, conf.level = .95
. You may also set the population parameter, but it is not necessary for a hypothesis test. Adding $conf.int
to the end of the t.test()
function will display only the confidence interval.
t.test(x = variable, conf.level = .95)$conf.int
The data for this example comes from the sleep
dataset. Suppose 20 individuals recorded the amount of "extra" sleep they got on a particular weekend. Is the amount of extra sleep significantly greater than 1.5?
# Hypothesis Test
t.test(sleep$extra, mu = 1.5, alternative = "greater" )
##
## One Sample t-test
##
## data: sleep$extra
## t = 0.088648, df = 19, p-value = 0.4651
## alternative hypothesis: true mean is greater than 1.5
## 95 percent confidence interval:
## 0.7597797 Inf
## sample estimates:
## mean of x
## 1.54
# Confidence Interval
t.test(sleep$extra, conf.level = .95 )$conf.int
## [1] 0.5955845 2.4844155
## attr(,"conf.level")
## [1] 0.95
Mathematicss, Computer Science, and Statistics Department Gustavus Adolphus College