Chapter 10: Single Sample t-Test

10.1 Preliminary Data Exploration

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

# gives us the 6 num. summary (mean, min, max, etc.) for the variable 'x'
summary(co2) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   313.2   323.5   335.2   337.1   350.3   366.8
str(co2)  
##  Time-Series [1:468] from 1959 to 1998: 315 316 316 318 318 ...
# we have a time-series; [1 var and 468 obs] from 1959 to 1998
temp.data <-as.data.frame(co2)     # change the data set to be the same as typical
names(temp.data) <- c("co2")

# plot histogram
with(temp.data, hist(co2, col= 'lightgrey', border= 'black',      # set optional parameters   
      main= "Histogram of Mauna Loa CO2 Concentrations",                                        
      xlab= "CO2 (ppm)", xlim= c(300,380), ylim= c(0,80)))

## 10.2 Conducting a One Sample t-test ### 10.2.1 Example: Fail to Reject the Null

Step 1: Set the Null and Alternate Hypotheses

Step 2: Set the Alpha Level

Step 3: Implement the Single Sample t-test

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

Step 4: Interpret the Results