#Loading Packages

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
Leaf<-read.csv("~/Biostats 2024/Data/LeafData_corrected.csv")
BP<-read.csv("~/Biostats 2024/Data/BP.csv")

#Working on Columns in a Data Frame

Leaf$Length
##   [1]  8.2  8.4  6.0  6.5  5.9 14.4 22.2 15.8 19.2 28.6  8.8  8.8  8.5  8.6  8.8
##  [16] 15.7 15.9 24.2 20.7 25.6  8.0  9.0  7.3  8.0  9.4 19.2 16.0 13.7 21.4 19.6
##  [31]  6.2  5.2  5.5  6.1  4.2 13.7 26.4 19.1 18.2 22.8  6.2  6.7  7.5  6.8  6.9
##  [46] 22.6 20.5 16.0 21.5 16.7 14.7 10.9 11.5 27.5 24.0  6.0  6.0  5.8  5.6  5.9
##  [61]  7.6  8.0  8.5  7.4  7.6 24.0 26.5 25.0 14.0 15.3  8.9  8.9  8.9  8.8  8.8
##  [76] 19.5 18.5 23.0 26.0 25.5 27.7 26.5 28.3 26.6 24.3  7.8  7.9  7.9  7.7  7.8
##  [91] 24.9 16.6 18.0 16.2 25.2  8.4  8.1  7.3  5.2  5.5  8.5  8.7  8.6  8.6  8.8
## [106] 24.9 18.0 25.1 23.2 21.7
Leaf$Size<-Leaf$Length*Leaf$Width
LfSize<-Leaf$Size
Leaf$Unique<-paste(Leaf$Name, Leaf$Leaf.ID, sep="_")
Leaf$Unique
##   [1] "MG_1"   "MG_2"   "MG_3"   "MG_4"   "MG_5"   "MG_6"   "MG_7"   "MG_8"  
##   [9] "MG_9"   "MG_10"  "SA_1"   "SA_2"   "SA_3"   "SA_4"   "SA_5"   "SA_6"  
##  [17] "SA_7"   "SA_8"   "SA_9"   "SA_10"  "MH_1"   "MH_2"   "MH_3"   "MH_4"  
##  [25] "MH_5"   "MH_6"   "MH_7"   "MH_8"   "MH_9"   "MH_10"  "IS_1"   "IS_2"  
##  [33] "IS_3"   "IS_4"   "IS_5"   "IS_6"   "IS_7"   "IS_8"   "IS_9"   "IS_10" 
##  [41] "AR_1"   "AR_2"   "AR_3"   "AR_4"   "AR_5"   "AR_6"   "AR_7"   "AR_8"  
##  [49] "AR_9"   "AR_10"  "JW_1"   "JW_2"   "JW_3"   "JW_4"   "JW_5"   "JW_6"  
##  [57] "JW_7"   "JW_8"   "JW_9"   "JW_10"  "AVB_1"  "AVB_2"  "AVB_3"  "AVB_4" 
##  [65] "AVB_5"  "AVB_6"  "AVB_7"  "AVB_8"  "AVB_9"  "AVB_10" "EO_1"   "EO_2"  
##  [73] "EO_3"   "EO_4"   "EO_5"   "EO_6"   "EO_7"   "EO_8"   "EO_9"   "EO_10" 
##  [81] "STA_1"  "STC_2"  "STA_3"  "STA_4"  "STA_5"  "STA_6"  "STA_7"  "STA_8" 
##  [89] "STA_9"  "STA_10" "BS_1"   "BS_2"   "BS_3"   "BS_4"   "BS_5"   "BS_6"  
##  [97] "BS_7"   "BS_8"   "BS_9"   "BS_10"  "AEW_1"  "AEW_2"  "AEW_3"  "AEW_4" 
## [105] "AEW_5"  "AEW_6"  "AEW_7"  "AEW_8"  "AEW_9"  "AEW_10"
SizeLeaf<-select(Leaf, Length, Width, Size)
Ratio<-mutate(SizeLeaf, ratio = "Lenth/Width")
Ratio
##     Length Width   Size       ratio
## 1      8.2   0.1   0.82 Lenth/Width
## 2      8.4   0.1   0.84 Lenth/Width
## 3      6.0   0.1   0.60 Lenth/Width
## 4      6.5   0.1   0.65 Lenth/Width
## 5      5.9   0.1   0.59 Lenth/Width
## 6     14.4   5.3  76.32 Lenth/Width
## 7     22.2   8.2 182.04 Lenth/Width
## 8     15.8   5.8  91.64 Lenth/Width
## 9     19.2   6.2 119.04 Lenth/Width
## 10    28.6   9.8 280.28 Lenth/Width
## 11     8.8   0.1   0.88 Lenth/Width
## 12     8.8   0.1   0.88 Lenth/Width
## 13     8.5   0.1   0.85 Lenth/Width
## 14     8.6   0.1   0.86 Lenth/Width
## 15     8.8   0.1   0.88 Lenth/Width
## 16    15.7   6.1  95.77 Lenth/Width
## 17    15.9   5.5  87.45 Lenth/Width
## 18    24.2   8.0 193.60 Lenth/Width
## 19    20.7   7.5 155.25 Lenth/Width
## 20    25.6   8.0 204.80 Lenth/Width
## 21     8.0   0.1   0.80 Lenth/Width
## 22     9.0   0.1   0.90 Lenth/Width
## 23     7.3   0.1   0.73 Lenth/Width
## 24     8.0   0.1   0.80 Lenth/Width
## 25     9.4   0.1   0.94 Lenth/Width
## 26    19.2   6.1 117.12 Lenth/Width
## 27    16.0   5.5  88.00 Lenth/Width
## 28    13.7   4.3  58.91 Lenth/Width
## 29    21.4   7.3 156.22 Lenth/Width
## 30    19.6   6.7 131.32 Lenth/Width
## 31     6.2   0.1   0.62 Lenth/Width
## 32     5.2   0.1   0.52 Lenth/Width
## 33     5.5   0.1   0.55 Lenth/Width
## 34     6.1   0.1   0.61 Lenth/Width
## 35     4.2   0.1   0.42 Lenth/Width
## 36    13.7   4.8  65.76 Lenth/Width
## 37    26.4   9.9 261.36 Lenth/Width
## 38    19.1   6.5 124.15 Lenth/Width
## 39    18.2   6.8 123.76 Lenth/Width
## 40    22.8   7.8 177.84 Lenth/Width
## 41     6.2   0.1   0.62 Lenth/Width
## 42     6.7   0.1   0.67 Lenth/Width
## 43     7.5   0.1   0.75 Lenth/Width
## 44     6.8   0.1   0.68 Lenth/Width
## 45     6.9   0.1   0.69 Lenth/Width
## 46    22.6   8.4 189.84 Lenth/Width
## 47    20.5   7.6 155.80 Lenth/Width
## 48    16.0   5.9  94.40 Lenth/Width
## 49    21.5   7.9 169.85 Lenth/Width
## 50    16.7   5.8  96.86 Lenth/Width
## 51    14.7   5.8  85.26 Lenth/Width
## 52    10.9   3.9  42.51 Lenth/Width
## 53    11.5   4.2  48.30 Lenth/Width
## 54    27.5   9.0 247.50 Lenth/Width
## 55    24.0   8.5 204.00 Lenth/Width
## 56     6.0   0.1   0.60 Lenth/Width
## 57     6.0   0.1   0.60 Lenth/Width
## 58     5.8   0.1   0.58 Lenth/Width
## 59     5.6   0.1   0.56 Lenth/Width
## 60     5.9   0.1   0.59 Lenth/Width
## 61     7.6   0.1   0.76 Lenth/Width
## 62     8.0   0.1   0.80 Lenth/Width
## 63     8.5   0.1   0.85 Lenth/Width
## 64     7.4   0.1   0.74 Lenth/Width
## 65     7.6   0.1   0.76 Lenth/Width
## 66    24.0   9.5 228.00 Lenth/Width
## 67    26.5  10.5 278.25 Lenth/Width
## 68    25.0   9.0 225.00 Lenth/Width
## 69    14.0   6.0  84.00 Lenth/Width
## 70    15.3   5.5  84.15 Lenth/Width
## 71     8.9   0.1   0.89 Lenth/Width
## 72     8.9   0.1   0.89 Lenth/Width
## 73     8.9   0.1   0.89 Lenth/Width
## 74     8.8   0.1   0.88 Lenth/Width
## 75     8.8   0.1   0.88 Lenth/Width
## 76    19.5   6.5 126.75 Lenth/Width
## 77    18.5   6.8 125.80 Lenth/Width
## 78    23.0   8.0 184.00 Lenth/Width
## 79    26.0   8.5 221.00 Lenth/Width
## 80    25.5   8.0 204.00 Lenth/Width
## 81    27.7   8.8 243.76 Lenth/Width
## 82    26.5   8.0 212.00 Lenth/Width
## 83    28.3   8.5 240.55 Lenth/Width
## 84    26.6   8.2 218.12 Lenth/Width
## 85    24.3   7.3 177.39 Lenth/Width
## 86     7.8   0.1   0.78 Lenth/Width
## 87     7.9   0.1   0.79 Lenth/Width
## 88     7.9   0.1   0.79 Lenth/Width
## 89     7.7   0.1   0.77 Lenth/Width
## 90     7.8   0.1   0.78 Lenth/Width
## 91    24.9   7.6 189.24 Lenth/Width
## 92    16.6   6.7 111.22 Lenth/Width
## 93    18.0   6.7 120.60 Lenth/Width
## 94    16.2   5.6  90.72 Lenth/Width
## 95    25.2   8.3 209.16 Lenth/Width
## 96     8.4   0.1   0.84 Lenth/Width
## 97     8.1   0.1   0.81 Lenth/Width
## 98     7.3   0.1   0.73 Lenth/Width
## 99     5.2   0.1   0.52 Lenth/Width
## 100    5.5   0.1   0.55 Lenth/Width
## 101    8.5   0.1   0.85 Lenth/Width
## 102    8.7   0.1   0.87 Lenth/Width
## 103    8.6   0.1   0.86 Lenth/Width
## 104    8.6   0.1   0.86 Lenth/Width
## 105    8.8   0.1   0.88 Lenth/Width
## 106   24.9   8.2 204.18 Lenth/Width
## 107   18.0   6.5 117.00 Lenth/Width
## 108   25.1   8.1 203.31 Lenth/Width
## 109   23.2   8.5 197.20 Lenth/Width
## 110   21.7   8.8 190.96 Lenth/Width
mean(BP$BMI)
## [1] 27.26
sd(BP$BMI)
## [1] 3.073977
#Y=27.26 S=3.07

#More Practice with Data

data("iris")
flower<-iris
Sepal<-select(flower, Sepal.Length, Sepal.Width)
Sepal
##     Sepal.Length Sepal.Width
## 1            5.1         3.5
## 2            4.9         3.0
## 3            4.7         3.2
## 4            4.6         3.1
## 5            5.0         3.6
## 6            5.4         3.9
## 7            4.6         3.4
## 8            5.0         3.4
## 9            4.4         2.9
## 10           4.9         3.1
## 11           5.4         3.7
## 12           4.8         3.4
## 13           4.8         3.0
## 14           4.3         3.0
## 15           5.8         4.0
## 16           5.7         4.4
## 17           5.4         3.9
## 18           5.1         3.5
## 19           5.7         3.8
## 20           5.1         3.8
## 21           5.4         3.4
## 22           5.1         3.7
## 23           4.6         3.6
## 24           5.1         3.3
## 25           4.8         3.4
## 26           5.0         3.0
## 27           5.0         3.4
## 28           5.2         3.5
## 29           5.2         3.4
## 30           4.7         3.2
## 31           4.8         3.1
## 32           5.4         3.4
## 33           5.2         4.1
## 34           5.5         4.2
## 35           4.9         3.1
## 36           5.0         3.2
## 37           5.5         3.5
## 38           4.9         3.6
## 39           4.4         3.0
## 40           5.1         3.4
## 41           5.0         3.5
## 42           4.5         2.3
## 43           4.4         3.2
## 44           5.0         3.5
## 45           5.1         3.8
## 46           4.8         3.0
## 47           5.1         3.8
## 48           4.6         3.2
## 49           5.3         3.7
## 50           5.0         3.3
## 51           7.0         3.2
## 52           6.4         3.2
## 53           6.9         3.1
## 54           5.5         2.3
## 55           6.5         2.8
## 56           5.7         2.8
## 57           6.3         3.3
## 58           4.9         2.4
## 59           6.6         2.9
## 60           5.2         2.7
## 61           5.0         2.0
## 62           5.9         3.0
## 63           6.0         2.2
## 64           6.1         2.9
## 65           5.6         2.9
## 66           6.7         3.1
## 67           5.6         3.0
## 68           5.8         2.7
## 69           6.2         2.2
## 70           5.6         2.5
## 71           5.9         3.2
## 72           6.1         2.8
## 73           6.3         2.5
## 74           6.1         2.8
## 75           6.4         2.9
## 76           6.6         3.0
## 77           6.8         2.8
## 78           6.7         3.0
## 79           6.0         2.9
## 80           5.7         2.6
## 81           5.5         2.4
## 82           5.5         2.4
## 83           5.8         2.7
## 84           6.0         2.7
## 85           5.4         3.0
## 86           6.0         3.4
## 87           6.7         3.1
## 88           6.3         2.3
## 89           5.6         3.0
## 90           5.5         2.5
## 91           5.5         2.6
## 92           6.1         3.0
## 93           5.8         2.6
## 94           5.0         2.3
## 95           5.6         2.7
## 96           5.7         3.0
## 97           5.7         2.9
## 98           6.2         2.9
## 99           5.1         2.5
## 100          5.7         2.8
## 101          6.3         3.3
## 102          5.8         2.7
## 103          7.1         3.0
## 104          6.3         2.9
## 105          6.5         3.0
## 106          7.6         3.0
## 107          4.9         2.5
## 108          7.3         2.9
## 109          6.7         2.5
## 110          7.2         3.6
## 111          6.5         3.2
## 112          6.4         2.7
## 113          6.8         3.0
## 114          5.7         2.5
## 115          5.8         2.8
## 116          6.4         3.2
## 117          6.5         3.0
## 118          7.7         3.8
## 119          7.7         2.6
## 120          6.0         2.2
## 121          6.9         3.2
## 122          5.6         2.8
## 123          7.7         2.8
## 124          6.3         2.7
## 125          6.7         3.3
## 126          7.2         3.2
## 127          6.2         2.8
## 128          6.1         3.0
## 129          6.4         2.8
## 130          7.2         3.0
## 131          7.4         2.8
## 132          7.9         3.8
## 133          6.4         2.8
## 134          6.3         2.8
## 135          6.1         2.6
## 136          7.7         3.0
## 137          6.3         3.4
## 138          6.4         3.1
## 139          6.0         3.0
## 140          6.9         3.1
## 141          6.7         3.1
## 142          6.9         3.1
## 143          5.8         2.7
## 144          6.8         3.2
## 145          6.7         3.3
## 146          6.7         3.0
## 147          6.3         2.5
## 148          6.5         3.0
## 149          6.2         3.4
## 150          5.9         3.0
#there are 150 rows
Setosa<- filter(flower, Species =="setosa")
Setosa
##    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1           5.1         3.5          1.4         0.2  setosa
## 2           4.9         3.0          1.4         0.2  setosa
## 3           4.7         3.2          1.3         0.2  setosa
## 4           4.6         3.1          1.5         0.2  setosa
## 5           5.0         3.6          1.4         0.2  setosa
## 6           5.4         3.9          1.7         0.4  setosa
## 7           4.6         3.4          1.4         0.3  setosa
## 8           5.0         3.4          1.5         0.2  setosa
## 9           4.4         2.9          1.4         0.2  setosa
## 10          4.9         3.1          1.5         0.1  setosa
## 11          5.4         3.7          1.5         0.2  setosa
## 12          4.8         3.4          1.6         0.2  setosa
## 13          4.8         3.0          1.4         0.1  setosa
## 14          4.3         3.0          1.1         0.1  setosa
## 15          5.8         4.0          1.2         0.2  setosa
## 16          5.7         4.4          1.5         0.4  setosa
## 17          5.4         3.9          1.3         0.4  setosa
## 18          5.1         3.5          1.4         0.3  setosa
## 19          5.7         3.8          1.7         0.3  setosa
## 20          5.1         3.8          1.5         0.3  setosa
## 21          5.4         3.4          1.7         0.2  setosa
## 22          5.1         3.7          1.5         0.4  setosa
## 23          4.6         3.6          1.0         0.2  setosa
## 24          5.1         3.3          1.7         0.5  setosa
## 25          4.8         3.4          1.9         0.2  setosa
## 26          5.0         3.0          1.6         0.2  setosa
## 27          5.0         3.4          1.6         0.4  setosa
## 28          5.2         3.5          1.5         0.2  setosa
## 29          5.2         3.4          1.4         0.2  setosa
## 30          4.7         3.2          1.6         0.2  setosa
## 31          4.8         3.1          1.6         0.2  setosa
## 32          5.4         3.4          1.5         0.4  setosa
## 33          5.2         4.1          1.5         0.1  setosa
## 34          5.5         4.2          1.4         0.2  setosa
## 35          4.9         3.1          1.5         0.2  setosa
## 36          5.0         3.2          1.2         0.2  setosa
## 37          5.5         3.5          1.3         0.2  setosa
## 38          4.9         3.6          1.4         0.1  setosa
## 39          4.4         3.0          1.3         0.2  setosa
## 40          5.1         3.4          1.5         0.2  setosa
## 41          5.0         3.5          1.3         0.3  setosa
## 42          4.5         2.3          1.3         0.3  setosa
## 43          4.4         3.2          1.3         0.2  setosa
## 44          5.0         3.5          1.6         0.6  setosa
## 45          5.1         3.8          1.9         0.4  setosa
## 46          4.8         3.0          1.4         0.3  setosa
## 47          5.1         3.8          1.6         0.2  setosa
## 48          4.6         3.2          1.4         0.2  setosa
## 49          5.3         3.7          1.5         0.2  setosa
## 50          5.0         3.3          1.4         0.2  setosa
#there are 50 rows
head(Sepal)
##   Sepal.Length Sepal.Width
## 1          5.1         3.5
## 2          4.9         3.0
## 3          4.7         3.2
## 4          4.6         3.1
## 5          5.0         3.6
## 6          5.4         3.9
head(Setosa)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
stats<-flower%>%
  group_by(Species) %>%
  summarize(average=mean(Petal.Width))
stats
## # A tibble: 3 × 2
##   Species    average
##   <fct>        <dbl>
## 1 setosa       0.246
## 2 versicolor   1.33 
## 3 virginica    2.03
t.test(Leaf$Length)$conf.int
## [1] 12.70252 15.54839
## attr(,"conf.level")
## [1] 0.95
#95% of the Leaf Length data falls between 12.7cm and 15.5cm
pine<-filter(Leaf, Species == "pine")
pine
##    Leaf.ID Name Species Deciduous Length Width Damage Size Unique
## 1        1   MG    pine        no    8.2   0.1      2 0.82   MG_1
## 2        2   MG    pine        no    8.4   0.1      2 0.84   MG_2
## 3        3   MG    pine        no    6.0   0.1      1 0.60   MG_3
## 4        4   MG    pine        no    6.5   0.1      1 0.65   MG_4
## 5        5   MG    pine        no    5.9   0.1      2 0.59   MG_5
## 6        1   SA    pine        no    8.8   0.1      0 0.88   SA_1
## 7        2   SA    pine        no    8.8   0.1      1 0.88   SA_2
## 8        3   SA    pine        no    8.5   0.1      0 0.85   SA_3
## 9        4   SA    pine        no    8.6   0.1      0 0.86   SA_4
## 10       5   SA    pine        no    8.8   0.1      0 0.88   SA_5
## 11       1   MH    pine        no    8.0   0.1      0 0.80   MH_1
## 12       2   MH    pine        no    9.0   0.1      0 0.90   MH_2
## 13       3   MH    pine        no    7.3   0.1      0 0.73   MH_3
## 14       4   MH    pine        no    8.0   0.1      0 0.80   MH_4
## 15       5   MH    pine        no    9.4   0.1      0 0.94   MH_5
## 16       1   IS    pine        no    6.2   0.1      0 0.62   IS_1
## 17       2   IS    pine        no    5.2   0.1      0 0.52   IS_2
## 18       3   IS    pine        no    5.5   0.1      0 0.55   IS_3
## 19       4   IS    pine        no    6.1   0.1      0 0.61   IS_4
## 20       5   IS    pine        no    4.2   0.1      0 0.42   IS_5
## 21       1   AR    pine        no    6.2   0.1      0 0.62   AR_1
## 22       2   AR    pine        no    6.7   0.1      0 0.67   AR_2
## 23       3   AR    pine        no    7.5   0.1      0 0.75   AR_3
## 24       4   AR    pine        no    6.8   0.1      0 0.68   AR_4
## 25       5   AR    pine        no    6.9   0.1      0 0.69   AR_5
## 26       6   JW    pine        no    6.0   0.1      0 0.60   JW_6
## 27       7   JW    pine        no    6.0   0.1      0 0.60   JW_7
## 28       8   JW    pine        no    5.8   0.1      0 0.58   JW_8
## 29       9   JW    pine        no    5.6   0.1      0 0.56   JW_9
## 30      10   JW    pine        no    5.9   0.1      0 0.59  JW_10
## 31       1  AVB    pine        no    7.6   0.1      1 0.76  AVB_1
## 32       2  AVB    pine        no    8.0   0.1      1 0.80  AVB_2
## 33       3  AVB    pine        no    8.5   0.1      0 0.85  AVB_3
## 34       4  AVB    pine        no    7.4   0.1      1 0.74  AVB_4
## 35       5  AVB    pine        no    7.6   0.1      1 0.76  AVB_5
## 36       1   EO    pine        no    8.9   0.1      0 0.89   EO_1
## 37       2   EO    pine        no    8.9   0.1      0 0.89   EO_2
## 38       3   EO    pine        no    8.9   0.1      0 0.89   EO_3
## 39       4   EO    pine        no    8.8   0.1      0 0.88   EO_4
## 40       5   EO    pine        no    8.8   0.1      0 0.88   EO_5
## 41       6  STA    pine        no    7.8   0.1      0 0.78  STA_6
## 42       7  STA    pine        no    7.9   0.1      0 0.79  STA_7
## 43       8  STA    pine        no    7.9   0.1      0 0.79  STA_8
## 44       9  STA    pine        no    7.7   0.1      0 0.77  STA_9
## 45      10  STA    pine        no    7.8   0.1      0 0.78 STA_10
## 46       6   BS    pine        no    8.4   0.1      0 0.84   BS_6
## 47       7   BS    pine        no    8.1   0.1      0 0.81   BS_7
## 48       8   BS    pine        no    7.3   0.1      0 0.73   BS_8
## 49       9   BS    pine        no    5.2   0.1      0 0.52   BS_9
## 50      10   BS    pine        no    5.5   0.1      0 0.55  BS_10
## 51       1  AEW    pine        no    8.5   0.1      0 0.85  AEW_1
## 52       2  AEW    pine        no    8.7   0.1      0 0.87  AEW_2
## 53       3  AEW    pine        no    8.6   0.1      0 0.86  AEW_3
## 54       4  AEW    pine        no    8.6   0.1      0 0.86  AEW_4
## 55       5  AEW    pine        no    8.8   0.1      0 0.88  AEW_5
notPine<-filter(Leaf,Species == "buckeye")
notPine
##    Leaf.ID Name Species Deciduous Length Width Damage   Size Unique
## 1        6   MH buckeye       yes   19.2   6.1      2 117.12   MH_6
## 2        7   MH buckeye       yes   16.0   5.5      2  88.00   MH_7
## 3        8   MH buckeye       yes   13.7   4.3      1  58.91   MH_8
## 4        9   MH buckeye       yes   21.4   7.3      2 156.22   MH_9
## 5       10   MH buckeye       yes   19.6   6.7      1 131.32  MH_10
## 6        6   IS buckeye       yes   13.7   4.8      3  65.76   IS_6
## 7        7   IS buckeye       yes   26.4   9.9      4 261.36   IS_7
## 8        8   IS buckeye       yes   19.1   6.5      1 124.15   IS_8
## 9        9   IS buckeye       yes   18.2   6.8      2 123.76   IS_9
## 10      10   IS buckeye       yes   22.8   7.8      3 177.84  IS_10
## 11       6   AR buckeye       yes   22.6   8.4      1 189.84   AR_6
## 12       7   AR buckeye       yes   20.5   7.6      3 155.80   AR_7
## 13       8   AR buckeye       yes   16.0   5.9      1  94.40   AR_8
## 14       9   AR buckeye       yes   21.5   7.9      1 169.85   AR_9
## 15      10   AR buckeye       yes   16.7   5.8      1  96.86  AR_10
## 16       1   JW buckeye       yes   14.7   5.8      2  85.26   JW_1
## 17       2   JW buckeye       yes   10.9   3.9      0  42.51   JW_2
## 18       3   JW buckeye       yes   11.5   4.2      2  48.30   JW_3
## 19       4   JW buckeye       yes   27.5   9.0      1 247.50   JW_4
## 20       5   JW buckeye       yes   24.0   8.5      1 204.00   JW_5
## 21       6  AVB buckeye       yes   24.0   9.5      1 228.00  AVB_6
## 22       7  AVB buckeye       yes   26.5  10.5      3 278.25  AVB_7
## 23       8  AVB buckeye       yes   25.0   9.0      4 225.00  AVB_8
## 24       9  AVB buckeye       yes   14.0   6.0      3  84.00  AVB_9
## 25      10  AVB buckeye       yes   15.3   5.5      2  84.15 AVB_10
## 26       6   EO buckeye       yes   19.5   6.5      2 126.75   EO_6
## 27       7   EO buckeye       yes   18.5   6.8      1 125.80   EO_7
## 28       8   EO buckeye       yes   23.0   8.0      0 184.00   EO_8
## 29       9   EO buckeye       yes   26.0   8.5      0 221.00   EO_9
## 30      10   EO buckeye       yes   25.5   8.0      1 204.00  EO_10
## 31       1  STA buckeye       yes   27.7   8.8      5 243.76  STA_1
## 32       2  STC buckeye       yes   26.5   8.0      1 212.00  STC_2
## 33       3  STA buckeye       yes   28.3   8.5      1 240.55  STA_3
## 34       4  STA buckeye       yes   26.6   8.2      2 218.12  STA_4
## 35       5  STA buckeye       yes   24.3   7.3      1 177.39  STA_5
## 36       1   BS buckeye       yes   24.9   7.6      1 189.24   BS_1
## 37       2   BS buckeye       yes   16.6   6.7      2 111.22   BS_2
## 38       3   BS buckeye       yes   18.0   6.7      0 120.60   BS_3
## 39       4   BS buckeye       yes   16.2   5.6      2  90.72   BS_4
## 40       5   BS buckeye       yes   25.2   8.3      0 209.16   BS_5
## 41       6  AEW buckeye       yes   24.9   8.2      1 204.18  AEW_6
## 42       7  AEW buckeye       yes   18.0   6.5      1 117.00  AEW_7
## 43       8  AEW buckeye       yes   25.1   8.1      1 203.31  AEW_8
## 44       9  AEW buckeye       yes   23.2   8.5      1 197.20  AEW_9
## 45      10  AEW buckeye       yes   21.7   8.8      3 190.96 AEW_10
t.test(pine$Length)$conf.int
## [1] 7.124792 7.820662
## attr(,"conf.level")
## [1] 0.95
# we are 95% confident that the interval between 7.12cm and 7.82cm contains the population parameter 
t.test(notPine$Length)$conf.int
## [1] 19.46355 22.33645
## attr(,"conf.level")
## [1] 0.95
# we are 95% confident that the interval between 19.5cm and 22.3cm contains the population parameter 

#GGplot2 Demo

ggplot(flower, aes(x=Species)) + geom_bar(stat="count")

ggplot(flower, aes(x=Species, y=Petal.Width)) + geom_boxplot()

ggplot(flower, aes(x=Species, y=Petal.Width)) + geom_jitter()

ggplot(flower, aes(x=Species, y=Petal.Width)) + geom_jitter(position=position_jitter(0.1))

ggplot(flower, aes(x=Petal.Width, y=Petal.Length)) + geom_point() + xlab("Petal Width (cm)") + ylab("Petal Length (cm)") + theme_bw() + facet_grid(~Species)

ggplot(flower, aes(x=Sepal.Width, y=Sepal.Length)) + geom_point() + xlab("Petal Width (cm)") + ylab("Petal Length (cm)") + theme_bw() + facet_grid(~Species)

ggplot(Leaf, aes(x=Length, y=Width))+ geom_point() + xlab("Leaf Length (cm)") + ylab("Leaf Width (cm)") + theme_bw() + facet_grid(~Species)

#Density Plots

?sleep()
## starting httpd help server ... done
honkshoo<-sleep
honkshoo
##    extra group ID
## 1    0.7     1  1
## 2   -1.6     1  2
## 3   -0.2     1  3
## 4   -1.2     1  4
## 5   -0.1     1  5
## 6    3.4     1  6
## 7    3.7     1  7
## 8    0.8     1  8
## 9    0.0     1  9
## 10   2.0     1 10
## 11   1.9     2  1
## 12   0.8     2  2
## 13   1.1     2  3
## 14   0.1     2  4
## 15  -0.1     2  5
## 16   4.4     2  6
## 17   5.5     2  7
## 18   1.6     2  8
## 19   4.6     2  9
## 20   3.4     2 10
ggplot(honkshoo, aes(x=extra)) + geom_density()

ggplot(honkshoo, aes(x=extra)) + geom_density() + xlim(c(-10,10))

ggplot(honkshoo, aes(extra, fill=group)) + geom_density(alpha = 0.5) + xlim(c(-10,10))

#Density Plots for Our Data

ggplot(Leaf, aes(x=Length)) + geom_density()

ggplot(pine, aes(x=Length)) + geom_density()

ggplot(notPine, aes(x=Length)) + geom_density()

shapiro.test(pine$Length)
## 
##  Shapiro-Wilk normality test
## 
## data:  pine$Length
## W = 0.91832, p-value = 0.001152
shapiro.test(notPine$Length)
## 
##  Shapiro-Wilk normality test
## 
## data:  notPine$Length
## W = 0.95147, p-value = 0.05776
# the p-values are incredibly low which means the data is not normally distributed. 

#QQ Plots

normal_vector<-rnorm(n=100, mean=13, sd=4)
qqnorm(normal_vector, pch=1)

qqnorm(normal_vector, pch=2)

qqnorm(normal_vector, pch=3)

qqnorm(pine$Length, pch=1)

qqnorm(pine$Width, pch=1)

qqnorm(notPine$Length, pch=1)

qqnorm(notPine$Width, pch=1)