One-sample t-Test using R

 

Still using the mpg data file and also test whether the average highway mpg (hwy) significantly differs from 25.  We can do this as shown below.

> t.test(mpg$hwy, mu=25)
One Sample t-test

data: mpg$hwy
t = -4.0071, df = 233, p-value = 8.274e-05
alternative hypothesis: true mean is not equal to 25
95 percent confidence interval:
 22.67324 24.20710
sample estimates:
mean of x 
 23.44017

Similarly, one side test can be simply conducted using alternative= option.

> t.test(mpg$hwy, mu=23, alternative = 'greater')
One Sample t-test

data: mpg$hwy
t = 1.1308, df = 233, p-value = 0.1297
alternative hypothesis: true mean is greater than 23
95 percent confidence interval:
 22.79733 Inf
sample estimates:
mean of x 
 23.44017

 

See Also:

Do the same test in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *