Chapter 10 - Single Sample t-Test

10.1 Preliminary Data Exploration

par(mar=c(5,4,3,4))
# get summary and structure

summary(co2) # gives us the 6 num. summary (mean, min, max, etc.) for the variable 'x'
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   313.2   323.5   335.2   337.1   350.3   366.8
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>     313     324     335     337     350     367
str(co2)     # we have a time-series; [1 var and 468 obs] from 1959 to 1998
##  Time-Series [1:468] from 1959 to 1998: 315 316 316 318 318 ...
#>  Time-Series [1:468] from 1959 to 1998: 315 316 316 318 318 ...
temp.data <-as.data.frame(co2) # let me change the data set to be the same as typical
names(temp.data) <- c("co2")
# plot histogram
with(temp.data, hist(co2, col= 'black', border= 'red',      # set optional parameters   
      main= "Histogram of Mauna Loa CO2 Concentrations",                                        
      xlab= "CO2 (ppm)", xlim= c(300,380), ylim= c(0,80)))

Figure 10.1: Histogram of Mauna Loa carbon dioxide concentrations between 1959 and 1997.

10.2 Conducting a One Sample t-test

10.2.1 Example: Fail to Reject the Null

with(temp.data, t.test(co2, mu = 338))
## 
##  One Sample t-test
## 
## data:  co2
## t = -1.3681, df = 467, p-value = 0.1719
## alternative hypothesis: true mean is not equal to 338
## 95 percent confidence interval:
##  335.6941 338.4130
## sample estimates:
## mean of x 
##  337.0535
#> 
#>  One Sample t-test
#> 
#> data:  co2
#> t = -1, df = 467, p-value = 0.2
#> alternative hypothesis: true mean is not equal to 338
#> 95 percent confidence interval:
#>  336 338
#> sample estimates:
#> mean of x 
#>       337