O'Reilly logo

Data Analysis with R - Second Edition by Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 dataset that contains precipitation data from 70 US cities, using the code given below:

   > head(precip) 
       Mobile      Juneau     Phoenix Little Rock Los Angeles  
         67.0        54.7         7.0        48.5        14.0  
      Sacramento  
         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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required