Testing the mean of one sample

An illustrative and fairly common statistical hypothesis test is the one sample t-test. You use it when you have one sample and you want to test whether that sample likely came from a population by comparing the mean against the known population mean. For this test to work, you have to know the population mean.

In this example, we'll be using R's built-in precip data set that contains precipitation data from 70 US cities.

  > head(precip)
  Mobile    Juneau   Phoenix   Little Rock   Los Angeles   Sacramento
   67.0      54.7      7.0        48.5           14.0        17.2

Don't be fooled by the fact that there are city names in there—this is a regular old vector - it's just that the elements are labeled. We can directly take the mean of this vector, just like a normal ...

Get R: Predictive Analysis now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.