###12.1 Example with Wide Format Data

Cd.BeetBarley<- data.frame(
  redbeet= c(18, 5, 10, 8, 16, 12, 8, 8, 11, 5, 6, 8, 9, 21, 9),
  barley= c(8, 5, 10, 19, 15, 18, 11, 8, 9, 4, 5, 17, 7, 5, 7))
str(Cd.BeetBarley)
## 'data.frame':    15 obs. of  2 variables:
##  $ redbeet: num  18 5 10 8 16 12 8 8 11 5 ...
##  $ barley : num  8 5 10 19 15 18 11 8 9 4 ...
summary(Cd.BeetBarley)
##     redbeet          barley      
##  Min.   : 5.00   Min.   : 4.000  
##  1st Qu.: 8.00   1st Qu.: 6.000  
##  Median : 9.00   Median : 8.000  
##  Mean   :10.27   Mean   : 9.867  
##  3rd Qu.:11.50   3rd Qu.:13.000  
##  Max.   :21.00   Max.   :19.000
head(Cd.BeetBarley)
##   redbeet barley
## 1      18      8
## 2       5      5
## 3      10     10
## 4       8     19
## 5      16     15
## 6      12     18
with(Cd.BeetBarley, boxplot(redbeet, barley,
                            col= "lightgrey",
                              main= "Phytoremediation Efficiency of Crop Plants",
                            xlab= "Crop type", ylab= "Cadmium reduction (%)",
                            names= c("Redbeet","Barley"),
                            ylim= c(0,25), las= 1,
                            boxwex=0.6))

with(Cd.BeetBarley, var.test(redbeet, barley))
## 
##  F test to compare two variances
## 
## data:  redbeet and barley
## F = 0.86359, num df = 14, denom df = 14, p-value = 0.7876
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.2899312 2.5722651
## sample estimates:
## ratio of variances 
##          0.8635855
with(Cd.BeetBarley, t.test(redbeet, barley, var.qual = TRUE))
## 
##  Welch Two Sample t-test
## 
## data:  redbeet and barley
## t = 0.2245, df = 27.851, p-value = 0.824
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.250613  4.050613
## sample estimates:
## mean of x mean of y 
## 10.266667  9.866667

###12.2 Exxample with Long Format Data

Cd.CabbageMaize <- data.frame(remed.pcnt = c(46, 50, 44, 44, 43, 52, 48, 24, 51, 29, 53, 32, 61, 59, 35, 34, 26, 44, 17, 34, 19, 34, 34, 43, 18, 34, 27, 27, 53, 30), plt.typ = c(rep("cabbage", times = 15), rep("maize", times =15)))
str(Cd.CabbageMaize)
## 'data.frame':    30 obs. of  2 variables:
##  $ remed.pcnt: num  46 50 44 44 43 52 48 24 51 29 ...
##  $ plt.typ   : chr  "cabbage" "cabbage" "cabbage" "cabbage" ...
summary(Cd.CabbageMaize)
##    remed.pcnt      plt.typ         
##  Min.   :17.00   Length:30         
##  1st Qu.:29.25   Class :character  
##  Median :34.50   Mode  :character  
##  Mean   :38.17                     
##  3rd Qu.:47.50                     
##  Max.   :61.00
head(Cd.CabbageMaize)
##   remed.pcnt plt.typ
## 1         46 cabbage
## 2         50 cabbage
## 3         44 cabbage
## 4         44 cabbage
## 5         43 cabbage
## 6         52 cabbage
with(Cd.CabbageMaize, boxplot(remed.pcnt~plt.typ,
                               col= "lightgrey",
                               main= "Phytoremediation Efficiency of Crop Plants",
                               xlab= "Crop type", ylab= "Cadmium reduction (%)",
                               ylim= c(10, 70), las= 1, boxwex= .6))

with(Cd.CabbageMaize, var.test(remed.pcnt ~ plt.typ))
## 
##  F test to compare two variances
## 
## data:  remed.pcnt by plt.typ
## F = 1.1449, num df = 14, denom df = 14, p-value = 0.8037
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.3843653 3.4100823
## sample estimates:
## ratio of variances 
##           1.144866
with(Cd.CabbageMaize, t.test(remed.pcnt ~ plt.typ, var.equal = TRUE))
## 
##  Two Sample t-test
## 
## data:  remed.pcnt by plt.typ
## t = 3.4687, df = 28, p-value = 0.00171
## alternative hypothesis: true difference in means between group cabbage and group maize is not equal to 0
## 95 percent confidence interval:
##   5.377502 20.889165
## sample estimates:
## mean in group cabbage   mean in group maize 
##              44.73333              31.60000