A car company claims that their Super Spiffy Sedan averages 31 mpg. You randomly select 8 Super Spifies from local car dealerships and test their gas mileage under similar conditions.

you get the MPG scores:
MPG: 30, 28, 32, 26, 33, 25, 28, 30

Does the actual gas mileage for these cars deviate significantly from 31 (alpha = .05)?


The goal of your analysis is to test for a significant deviation between your sample mean and the proposed population mean.

We will test the mean of these data against the value of 31 with a one-sample t test of the mean.

Find the critical value:

#this function finds the absolute value of the  t-critical corresponding to a given area and degrees of freedom. 
criticalValue <- abs(qt(.05/2, 7))

criticalValue
[1] 2.364624

Compute Test Statistic:

#load the data for mpg.    
mpg <- c(30, 28, 32, 26, 33, 25, 28, 30)
#the 'c' before the group of numbers stands for  
#concatenate, or to link them together. 

#now input the data into the t.test 
#function with a 5% confidence level and the supposed mean of 31 mpg.
t.test(x = mpg, conf.level = .05, mu = 31)

    One Sample t-test

data:  mpg
t = -2.0367, df = 7, p-value = 0.08111
alternative hypothesis: true mean is not equal to 31
5 percent confidence interval:
 28.93618 29.06382
sample estimates:
mean of x 
       29 

The test statistic is less than the critical value. Fail to reject the null hypothesis that the Super Spify sedan averages 31 mpg, at a 5% significance level.

example from :
https://sites.berry.edu/vbissonnette/index/stats-homework/documentation/one-sample-t-test/one-sample-t-test-solution/

LS0tDQp0aXRsZTogIkh5cG90aGVzaXMgVGVzdGluZyBFeGFtcGxlIg0Kb3V0cHV0Og0KICBodG1sX25vdGVib29rOiBkZWZhdWx0DQogIHdvcmRfZG9jdW1lbnQ6IGRlZmF1bHQNCi0tLQ0KDQpBIGNhciBjb21wYW55IGNsYWltcyB0aGF0IHRoZWlyIFN1cGVyIFNwaWZmeSBTZWRhbiBhdmVyYWdlcyAzMSBtcGcuIFlvdSByYW5kb21seSBzZWxlY3QgOCBTdXBlciBTcGlmaWVzIGZyb20gbG9jYWwgY2FyIGRlYWxlcnNoaXBzIGFuZCB0ZXN0IHRoZWlyIGdhcyBtaWxlYWdlIHVuZGVyIHNpbWlsYXIgY29uZGl0aW9ucy4gICANCiAgDQ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