Question 2 # Importing data

setwd("C:/Users/clemendeoliveira/Desktop/Homework3")
data=read.table("quest2.txt",header = T,check.names = F)
str(data)
## 'data.frame':    45 obs. of  4 variables:
##  $ Fungicide: Factor w/ 3 levels "A","B","C": 1 1 1 1 1 2 2 2 2 2 ...
##  $ Race     : int  1 2 3 4 5 1 2 3 4 5 ...
##  $ block    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ ndvi     : num  0.22 0.52 0.62 0.92 0.42 0.22 0.42 0.62 0.83 0.9 ...
data$Fungicide = as.factor(data$Fungicide)
data$Race = as.factor(data$Race)
data$block = as.factor(data$block)
summary(data)
##  Fungicide Race  block       ndvi       
##  A:15      1:9   1:15   Min.   :0.0200  
##  B:15      2:9   2:15   1st Qu.:0.3200  
##  C:15      3:9   3:15   Median :0.6200  
##            4:9          Mean   :0.5522  
##            5:9          3rd Qu.:0.7200  
##                         Max.   :0.9700
attach(data) 
data
##    Fungicide Race block ndvi
## 1          A    1     1 0.22
## 2          A    2     1 0.52
## 3          A    3     1 0.62
## 4          A    4     1 0.92
## 5          A    5     1 0.42
## 6          B    1     1 0.22
## 7          B    2     1 0.42
## 8          B    3     1 0.62
## 9          B    4     1 0.83
## 10         B    5     1 0.90
## 11         C    1     1 0.22
## 12         C    2     1 0.72
## 13         C    3     1 0.62
## 14         C    4     1 0.72
## 15         C    5     1 0.52
## 16         A    1     2 0.22
## 17         A    2     2 0.62
## 18         A    3     2 0.82
## 19         A    4     2 0.97
## 20         A    5     2 0.72
## 21         B    1     2 0.12
## 22         B    2     2 0.22
## 23         B    3     2 0.82
## 24         B    4     2 0.62
## 25         B    5     2 0.92
## 26         C    1     2 0.32
## 27         C    2     2 0.52
## 28         C    3     2 0.72
## 29         C    4     2 0.82
## 30         C    5     2 0.42
## 31         A    1     3 0.32
## 32         A    2     3 0.52
## 33         A    3     3 0.72
## 34         A    4     3 0.93
## 35         A    5     3 0.52
## 36         B    1     3 0.12
## 37         B    2     3 0.22
## 38         B    3     3 0.42
## 39         B    4     3 0.52
## 40         B    5     3 0.82
## 41         C    1     3 0.02
## 42         C    2     3 0.32
## 43         C    3     3 0.72
## 44         C    4     3 0.72
## 45         C    5     3 0.62

Including histogram and boxplot

hist(data$ndvi)

boxplot(data$ndvi~data$Fungicide)

boxplot(data$ndvi~data$Race)

Anova

library(agricolae)
## Warning: package 'agricolae' was built under R version 3.4.4
library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.4.4
## Loading required package: emmeans
## The 'lsmeans' package is now basically a front end for 'emmeans'.
## Users are encouraged to switch the rest of the way.
## See help('transition') for more information, including how to
## convert old 'lsmeans' objects and scripts to work with 'emmeans'.
outAOV<-aov(ndvi~block+Race+Fungicide+Race*Fungicide,data = data)
anova(outAOV)
## Analysis of Variance Table
## 
## Response: ndvi
##                Df  Sum Sq Mean Sq F value    Pr(>F)    
## block           2 0.06412 0.03206  2.5926  0.092684 .  
## Race            4 1.92431 0.48108 38.9002 4.736e-11 ***
## Fungicide       2 0.06179 0.03090  2.4982  0.100385    
## Race:Fungicide  8 0.45788 0.05723  4.6280  0.001103 ** 
## Residuals      28 0.34628 0.01237                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Test LSD

outfactorial<-LSD.test(outAOV, c ("Race","Fungicide"), main = "ndvi~block+Race+Fungicide+Race*Fungicide", console=TRUE)
## 
## Study: ndvi~block+Race+Fungicide+Race*Fungicide
## 
## LSD t Test for ndvi 
## 
## Mean Square Error:  0.01236698 
## 
## Race:Fungicide,  means and individual ( 95 %) CI
## 
##          ndvi        std r        LCL       UCL  Min  Max
## 1:A 0.2533333 0.05773503 3 0.12181462 0.3848520 0.22 0.32
## 1:B 0.1533333 0.05773503 3 0.02181462 0.2848520 0.12 0.22
## 1:C 0.1866667 0.15275252 3 0.05514795 0.3181854 0.02 0.32
## 2:A 0.5533333 0.05773503 3 0.42181462 0.6848520 0.52 0.62
## 2:B 0.2866667 0.11547005 3 0.15514795 0.4181854 0.22 0.42
## 2:C 0.5200000 0.20000000 3 0.38848129 0.6515187 0.32 0.72
## 3:A 0.7200000 0.10000000 3 0.58848129 0.8515187 0.62 0.82
## 3:B 0.6200000 0.20000000 3 0.48848129 0.7515187 0.42 0.82
## 3:C 0.6866667 0.05773503 3 0.55514795 0.8181854 0.62 0.72
## 4:A 0.9400000 0.02645751 3 0.80848129 1.0715187 0.92 0.97
## 4:B 0.6566667 0.15821926 3 0.52514795 0.7881854 0.52 0.83
## 4:C 0.7533333 0.05773503 3 0.62181462 0.8848520 0.72 0.82
## 5:A 0.5533333 0.15275252 3 0.42181462 0.6848520 0.42 0.72
## 5:B 0.8800000 0.05291503 3 0.74848129 1.0115187 0.82 0.92
## 5:C 0.5200000 0.10000000 3 0.38848129 0.6515187 0.42 0.62
## 
## Alpha: 0.05 ; DF Error: 28
## Critical Value of t: 2.048407 
## 
## least Significant Difference: 0.1859955 
## 
## Treatments with the same letter are not significantly different.
## 
##          ndvi groups
## 4:A 0.9400000      a
## 5:B 0.8800000     ab
## 4:C 0.7533333     bc
## 3:A 0.7200000    bcd
## 3:C 0.6866667    cde
## 4:B 0.6566667    cde
## 3:B 0.6200000    cde
## 2:A 0.5533333     de
## 5:A 0.5533333     de
## 2:C 0.5200000      e
## 5:C 0.5200000      e
## 2:B 0.2866667      f
## 1:A 0.2533333      f
## 1:C 0.1866667      f
## 1:B 0.1533333      f
outfactorial
## $statistics
##      MSerror Df      Mean       CV  t.value       LSD
##   0.01236698 28 0.5522222 20.13808 2.048407 0.1859955
## 
## $parameters
##         test p.ajusted         name.t ntr alpha
##   Fisher-LSD      none Race:Fungicide  15  0.05
## 
## $means
##          ndvi        std r        LCL       UCL  Min  Max   Q25  Q50   Q75
## 1:A 0.2533333 0.05773503 3 0.12181462 0.3848520 0.22 0.32 0.220 0.22 0.270
## 1:B 0.1533333 0.05773503 3 0.02181462 0.2848520 0.12 0.22 0.120 0.12 0.170
## 1:C 0.1866667 0.15275252 3 0.05514795 0.3181854 0.02 0.32 0.120 0.22 0.270
## 2:A 0.5533333 0.05773503 3 0.42181462 0.6848520 0.52 0.62 0.520 0.52 0.570
## 2:B 0.2866667 0.11547005 3 0.15514795 0.4181854 0.22 0.42 0.220 0.22 0.320
## 2:C 0.5200000 0.20000000 3 0.38848129 0.6515187 0.32 0.72 0.420 0.52 0.620
## 3:A 0.7200000 0.10000000 3 0.58848129 0.8515187 0.62 0.82 0.670 0.72 0.770
## 3:B 0.6200000 0.20000000 3 0.48848129 0.7515187 0.42 0.82 0.520 0.62 0.720
## 3:C 0.6866667 0.05773503 3 0.55514795 0.8181854 0.62 0.72 0.670 0.72 0.720
## 4:A 0.9400000 0.02645751 3 0.80848129 1.0715187 0.92 0.97 0.925 0.93 0.950
## 4:B 0.6566667 0.15821926 3 0.52514795 0.7881854 0.52 0.83 0.570 0.62 0.725
## 4:C 0.7533333 0.05773503 3 0.62181462 0.8848520 0.72 0.82 0.720 0.72 0.770
## 5:A 0.5533333 0.15275252 3 0.42181462 0.6848520 0.42 0.72 0.470 0.52 0.620
## 5:B 0.8800000 0.05291503 3 0.74848129 1.0115187 0.82 0.92 0.860 0.90 0.910
## 5:C 0.5200000 0.10000000 3 0.38848129 0.6515187 0.42 0.62 0.470 0.52 0.570
## 
## $comparison
## NULL
## 
## $groups
##          ndvi groups
## 4:A 0.9400000      a
## 5:B 0.8800000     ab
## 4:C 0.7533333     bc
## 3:A 0.7200000    bcd
## 3:C 0.6866667    cde
## 4:B 0.6566667    cde
## 3:B 0.6200000    cde
## 2:A 0.5533333     de
## 5:A 0.5533333     de
## 2:C 0.5200000      e
## 5:C 0.5200000      e
## 2:B 0.2866667      f
## 1:A 0.2533333      f
## 1:C 0.1866667      f
## 1:B 0.1533333      f
## 
## attr(,"class")
## [1] "group"

Test tukey (HSD)

library(agricolae)
outHSD<-HSD.test(outAOV, c ("Race","Fungicide"), main = "ndvi~block+Race+Fungicide+Race*Fungicide", console=TRUE)
## 
## Study: ndvi~block+Race+Fungicide+Race*Fungicide
## 
## HSD Test for ndvi 
## 
## Mean Square Error:  0.01236698 
## 
## Race:Fungicide,  means
## 
##          ndvi        std r  Min  Max
## 1:A 0.2533333 0.05773503 3 0.22 0.32
## 1:B 0.1533333 0.05773503 3 0.12 0.22
## 1:C 0.1866667 0.15275252 3 0.02 0.32
## 2:A 0.5533333 0.05773503 3 0.52 0.62
## 2:B 0.2866667 0.11547005 3 0.22 0.42
## 2:C 0.5200000 0.20000000 3 0.32 0.72
## 3:A 0.7200000 0.10000000 3 0.62 0.82
## 3:B 0.6200000 0.20000000 3 0.42 0.82
## 3:C 0.6866667 0.05773503 3 0.62 0.72
## 4:A 0.9400000 0.02645751 3 0.92 0.97
## 4:B 0.6566667 0.15821926 3 0.52 0.83
## 4:C 0.7533333 0.05773503 3 0.72 0.82
## 5:A 0.5533333 0.15275252 3 0.42 0.72
## 5:B 0.8800000 0.05291503 3 0.82 0.92
## 5:C 0.5200000 0.10000000 3 0.42 0.62
## 
## Alpha: 0.05 ; DF Error: 28 
## Critical Value of Studentized Range: 5.241876 
## 
## Minimun Significant Difference: 0.3365565 
## 
## Treatments with the same letter are not significantly different.
## 
##          ndvi groups
## 4:A 0.9400000      a
## 5:B 0.8800000     ab
## 4:C 0.7533333    abc
## 3:A 0.7200000    abc
## 3:C 0.6866667    abc
## 4:B 0.6566667    abc
## 3:B 0.6200000   abcd
## 2:A 0.5533333   bcde
## 5:A 0.5533333   bcde
## 2:C 0.5200000   cdef
## 5:C 0.5200000   cdef
## 2:B 0.2866667   defg
## 1:A 0.2533333    efg
## 1:C 0.1866667     fg
## 1:B 0.1533333      g
outHSD
## $statistics
##      MSerror Df      Mean       CV       MSD
##   0.01236698 28 0.5522222 20.13808 0.3365565
## 
## $parameters
##    test         name.t ntr StudentizedRange alpha
##   Tukey Race:Fungicide  15         5.241876  0.05
## 
## $means
##          ndvi        std r  Min  Max   Q25  Q50   Q75
## 1:A 0.2533333 0.05773503 3 0.22 0.32 0.220 0.22 0.270
## 1:B 0.1533333 0.05773503 3 0.12 0.22 0.120 0.12 0.170
## 1:C 0.1866667 0.15275252 3 0.02 0.32 0.120 0.22 0.270
## 2:A 0.5533333 0.05773503 3 0.52 0.62 0.520 0.52 0.570
## 2:B 0.2866667 0.11547005 3 0.22 0.42 0.220 0.22 0.320
## 2:C 0.5200000 0.20000000 3 0.32 0.72 0.420 0.52 0.620
## 3:A 0.7200000 0.10000000 3 0.62 0.82 0.670 0.72 0.770
## 3:B 0.6200000 0.20000000 3 0.42 0.82 0.520 0.62 0.720
## 3:C 0.6866667 0.05773503 3 0.62 0.72 0.670 0.72 0.720
## 4:A 0.9400000 0.02645751 3 0.92 0.97 0.925 0.93 0.950
## 4:B 0.6566667 0.15821926 3 0.52 0.83 0.570 0.62 0.725
## 4:C 0.7533333 0.05773503 3 0.72 0.82 0.720 0.72 0.770
## 5:A 0.5533333 0.15275252 3 0.42 0.72 0.470 0.52 0.620
## 5:B 0.8800000 0.05291503 3 0.82 0.92 0.860 0.90 0.910
## 5:C 0.5200000 0.10000000 3 0.42 0.62 0.470 0.52 0.570
## 
## $comparison
## NULL
## 
## $groups
##          ndvi groups
## 4:A 0.9400000      a
## 5:B 0.8800000     ab
## 4:C 0.7533333    abc
## 3:A 0.7200000    abc
## 3:C 0.6866667    abc
## 4:B 0.6566667    abc
## 3:B 0.6200000   abcd
## 2:A 0.5533333   bcde
## 5:A 0.5533333   bcde
## 2:C 0.5200000   cdef
## 5:C 0.5200000   cdef
## 2:B 0.2866667   defg
## 1:A 0.2533333    efg
## 1:C 0.1866667     fg
## 1:B 0.1533333      g
## 
## attr(,"class")
## [1] "group"

Computing graph bar

library(ggplot2)
graph<-lsmeans(outAOV, ~Race*Fungicide, adjust='Tukey')
graph<-summary(graph)
graph$Race <- factor(graph$Race, levels = c( "1","2","3","4","5"))
ggplot(graph, aes(x=Race, y=lsmean, fill=Fungicide)) + 
  geom_bar(position=position_dodge(0.9), stat="identity",
           colour="black", # Use black outlines
           size=.3) + scale_fill_brewer() +
  geom_errorbar(aes(ymin=lsmean-SE, ymax=lsmean+SE), 
                size=.5,    # Thinner lines
                colour="black",
                width=.2,
                position=position_dodge(.9)) +
   xlab("Race") +
  ylab("NDVI") +
  ggtitle("ndvi homework3") +
  annotate("text",x=0.65,y=0.4,label="a", size=6)+
  annotate("text",x=1,y=0.4,label="ab", size=6)+
  annotate("text",x=1.4,y=0.4,label="abc", size=6)+
  annotate("text",x=1.78,y=0.7,label="abc", size=6)+
  annotate("text",x=2,y=0.5,label="abc", size=6)+
  annotate("text",x=2.3,y=0.7,label="abc", size=6)+
  annotate("text",x=2.7,y=0.95,label="abcd", size=6)+
  annotate("text",x=3,y=0.75,label="bcde", size=6)+
  annotate("text",x=3.3,y=0.85,label="bcde", size=6)+
  annotate("text",x=3.6,y=1.05,label="cdef", size=6)+
   annotate("text",x=4,y=0.8,label="cdef", size=6)+
  annotate("text",x=4.3,y=0.9,label="defg", size=6)+
  annotate("text",x=4.3,y=0.8,label="efg", size=6)+
  annotate("text",x=5,y=1,label="fg", size=6)+
  annotate("text",x=5.2,y=0.74,label=" g", size=6)+
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  theme(axis.title=element_text( size = rel(2.1) , color="black")) +
  theme(axis.text = element_text(colour = "black", size="20")) +
  theme(legend.title = element_text(size = "14"))+ 
  theme(legend.position = "none")+ 
  theme(plot.title = element_text(size = rel(2)))

Question 3

setwd("C:/Users/clemendeoliveira/Desktop/Homework3")
data3=read.table("quest3.txt",header = T,check.names = F)
str(data3)
## 'data.frame':    90 obs. of  5 variables:
##  $ fungicide: Factor w/ 3 levels "A","B","C": 1 1 1 1 1 2 2 2 2 2 ...
##  $ race     : int  1 2 3 4 5 1 2 3 4 5 ...
##  $ block    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ year     : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ ndvi     : num  0.22 0.52 0.62 0.92 0.42 0.22 0.42 0.62 0.83 0.9 ...
data3$race=as.factor(data3$race)
data3$fungicide=as.factor(data3$fungicide)
data3$block = as.factor(data3$block)
data3$year= as.factor(data3$year)
summary(data3)
##  fungicide race   block  year        ndvi       
##  A:30      1:18   1:30   1:45   Min.   :0.0200  
##  B:30      2:18   2:30   2:45   1st Qu.:0.3200  
##  C:30      3:18   3:30          Median :0.5300  
##            4:18                 Mean   :0.5176  
##            5:18                 3rd Qu.:0.7200  
##                                 Max.   :0.9700
attach(data3) 
## The following objects are masked from data:
## 
##     block, ndvi
data3
##    fungicide race block year ndvi
## 1          A    1     1    1 0.22
## 2          A    2     1    1 0.52
## 3          A    3     1    1 0.62
## 4          A    4     1    1 0.92
## 5          A    5     1    1 0.42
## 6          B    1     1    1 0.22
## 7          B    2     1    1 0.42
## 8          B    3     1    1 0.62
## 9          B    4     1    1 0.83
## 10         B    5     1    1 0.90
## 11         C    1     1    1 0.22
## 12         C    2     1    1 0.72
## 13         C    3     1    1 0.62
## 14         C    4     1    1 0.72
## 15         C    5     1    1 0.52
## 16         A    1     2    1 0.22
## 17         A    2     2    1 0.62
## 18         A    3     2    1 0.82
## 19         A    4     2    1 0.97
## 20         A    5     2    1 0.72
## 21         B    1     2    1 0.12
## 22         B    2     2    1 0.22
## 23         B    3     2    1 0.82
## 24         B    4     2    1 0.62
## 25         B    5     2    1 0.92
## 26         C    1     2    1 0.32
## 27         C    2     2    1 0.52
## 28         C    3     2    1 0.72
## 29         C    4     2    1 0.82
## 30         C    5     2    1 0.42
## 31         A    1     3    1 0.32
## 32         A    2     3    1 0.52
## 33         A    3     3    1 0.72
## 34         A    4     3    1 0.93
## 35         A    5     3    1 0.52
## 36         B    1     3    1 0.12
## 37         B    2     3    1 0.22
## 38         B    3     3    1 0.42
## 39         B    4     3    1 0.52
## 40         B    5     3    1 0.82
## 41         C    1     3    1 0.02
## 42         C    2     3    1 0.32
## 43         C    3     3    1 0.72
## 44         C    4     3    1 0.72
## 45         C    5     3    1 0.62
## 46         A    1     1    2 0.13
## 47         A    2     1    2 0.43
## 48         A    3     1    2 0.53
## 49         A    4     1    2 0.93
## 50         A    5     1    2 0.33
## 51         B    1     1    2 0.13
## 52         B    2     1    2 0.33
## 53         B    3     1    2 0.53
## 54         B    4     1    2 0.74
## 55         B    5     1    2 0.92
## 56         C    1     1    2 0.13
## 57         C    2     1    2 0.63
## 58         C    3     1    2 0.53
## 59         C    4     1    2 0.63
## 60         C    5     1    2 0.43
## 61         A    1     2    2 0.15
## 62         A    2     2    2 0.53
## 63         A    3     2    2 0.73
## 64         A    4     2    2 0.94
## 65         A    5     2    2 0.63
## 66         B    1     2    2 0.10
## 67         B    2     2    2 0.13
## 68         B    3     2    2 0.73
## 69         B    4     2    2 0.53
## 70         B    5     2    2 0.93
## 71         C    1     2    2 0.23
## 72         C    2     2    2 0.43
## 73         C    3     2    2 0.63
## 74         C    4     2    2 0.73
## 75         C    5     2    2 0.33
## 76         A    1     3    2 0.23
## 77         A    2     3    2 0.43
## 78         A    3     3    2 0.63
## 79         A    4     3    2 0.96
## 80         A    5     3    2 0.43
## 81         B    1     3    2 0.09
## 82         B    2     3    2 0.13
## 83         B    3     3    2 0.33
## 84         B    4     3    2 0.43
## 85         B    5     3    2 0.87
## 86         C    1     3    2 0.08
## 87         C    2     3    2 0.23
## 88         C    3     3    2 0.63
## 89         C    4     3    2 0.63
## 90         C    5     3    2 0.53

Including histogram and boxplot

hist(data3$ndvi)

boxplot(data3$ndvi~data3$fungicide)

boxplot(data3$ndvi~data3$race)

###Anova without transform the data

library(agricolae)
outANOVA<-aov(ndvi~block+year+race+fungicide+race*fungicide+year*race*fungicide, data = data3)##wrong way to do it because i am assuming the data was colected from the same experimental unit
anova(outANOVA)
## Analysis of Variance Table
## 
## Response: ndvi
##                     Df Sum Sq Mean Sq F value    Pr(>F)    
## block                2 0.1058 0.05288  4.5870  0.014144 *  
## year                 1 0.1082 0.10816  9.3813  0.003321 ** 
## race                 4 3.8412 0.96029 83.2913 < 2.2e-16 ***
## fungicide            2 0.1192 0.05961  5.1707  0.008582 ** 
## race:fungicide       8 1.1793 0.14742 12.7865 2.148e-10 ***
## year:race            4 0.0066 0.00164  0.1421  0.965789    
## year:fungicide       2 0.0018 0.00091  0.0789  0.924204    
## year:race:fungicide  8 0.0221 0.00277  0.2400  0.981470    
## Residuals           58 0.6687 0.01153                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(outANOVA)

model <- aov(ndvi~block+fungicide*race*year+Error(block:race:fungicide/year),data=data3)##correct way, year is a split plot
## Warning in aov(ndvi ~ block + fungicide * race * year +
## Error(block:race:fungicide/year), : Error() model is singular
summary(model)
## 
## Error: block:race:fungicide
##                Df Sum Sq Mean Sq F value   Pr(>F)    
## block           2  0.106  0.0529   2.249 0.124175    
## fungicide       2  0.119  0.0596   2.536 0.097242 .  
## race            4  3.841  0.9603  40.847 2.67e-11 ***
## fungicide:race  8  1.179  0.1474   6.271 0.000115 ***
## Residuals      28  0.658  0.0235                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: block:race:fungicide:year
##                     Df  Sum Sq Mean Sq F value   Pr(>F)    
## year                 1 0.10816 0.10816 311.003  < 2e-16 ***
## fungicide:year       2 0.00182 0.00091   2.617  0.08965 .  
## race:year            4 0.00655 0.00164   4.709  0.00454 ** 
## fungicide:race:year  8 0.02214 0.00277   7.956 1.08e-05 ***
## Residuals           30 0.01043 0.00035                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Test LSD with non-transformed data

outtestLSD<-LSD.test(outANOVA, c ("race","fungicide","year"), main = "ndvi~block+year+race+fungicide+race*fungicide+year*race*fungicide", console=TRUE)
## 
## Study: ndvi~block+year+race+fungicide+race*fungicide+year*race*fungicide
## 
## LSD t Test for ndvi 
## 
## Mean Square Error:  0.01152927 
## 
## race:fungicide:year,  means and individual ( 95 %) CI
## 
##            ndvi        std r         LCL       UCL  Min  Max
## 1:A:1 0.2533333 0.05773503 3  0.12924153 0.3774251 0.22 0.32
## 1:A:2 0.1700000 0.05291503 3  0.04590820 0.2940918 0.13 0.23
## 1:B:1 0.1533333 0.05773503 3  0.02924153 0.2774251 0.12 0.22
## 1:B:2 0.1066667 0.02081666 3 -0.01742514 0.2307585 0.09 0.13
## 1:C:1 0.1866667 0.15275252 3  0.06257486 0.3107585 0.02 0.32
## 1:C:2 0.1466667 0.07637626 3  0.02257486 0.2707585 0.08 0.23
## 2:A:1 0.5533333 0.05773503 3  0.42924153 0.6774251 0.52 0.62
## 2:A:2 0.4633333 0.05773503 3  0.33924153 0.5874251 0.43 0.53
## 2:B:1 0.2866667 0.11547005 3  0.16257486 0.4107585 0.22 0.42
## 2:B:2 0.1966667 0.11547005 3  0.07257486 0.3207585 0.13 0.33
## 2:C:1 0.5200000 0.20000000 3  0.39590820 0.6440918 0.32 0.72
## 2:C:2 0.4300000 0.20000000 3  0.30590820 0.5540918 0.23 0.63
## 3:A:1 0.7200000 0.10000000 3  0.59590820 0.8440918 0.62 0.82
## 3:A:2 0.6300000 0.10000000 3  0.50590820 0.7540918 0.53 0.73
## 3:B:1 0.6200000 0.20000000 3  0.49590820 0.7440918 0.42 0.82
## 3:B:2 0.5300000 0.20000000 3  0.40590820 0.6540918 0.33 0.73
## 3:C:1 0.6866667 0.05773503 3  0.56257486 0.8107585 0.62 0.72
## 3:C:2 0.5966667 0.05773503 3  0.47257486 0.7207585 0.53 0.63
## 4:A:1 0.9400000 0.02645751 3  0.81590820 1.0640918 0.92 0.97
## 4:A:2 0.9433333 0.01527525 3  0.81924153 1.0674251 0.93 0.96
## 4:B:1 0.6566667 0.15821926 3  0.53257486 0.7807585 0.52 0.83
## 4:B:2 0.5666667 0.15821926 3  0.44257486 0.6907585 0.43 0.74
## 4:C:1 0.7533333 0.05773503 3  0.62924153 0.8774251 0.72 0.82
## 4:C:2 0.6633333 0.05773503 3  0.53924153 0.7874251 0.63 0.73
## 5:A:1 0.5533333 0.15275252 3  0.42924153 0.6774251 0.42 0.72
## 5:A:2 0.4633333 0.15275252 3  0.33924153 0.5874251 0.33 0.63
## 5:B:1 0.8800000 0.05291503 3  0.75590820 1.0040918 0.82 0.92
## 5:B:2 0.9066667 0.03214550 3  0.78257486 1.0307585 0.87 0.93
## 5:C:1 0.5200000 0.10000000 3  0.39590820 0.6440918 0.42 0.62
## 5:C:2 0.4300000 0.10000000 3  0.30590820 0.5540918 0.33 0.53
## 
## Alpha: 0.05 ; DF Error: 58
## Critical Value of t: 2.001717 
## 
## least Significant Difference: 0.1754923 
## 
## Treatments with the same letter are not significantly different.
## 
##            ndvi groups
## 4:A:2 0.9433333      a
## 4:A:1 0.9400000      a
## 5:B:2 0.9066667     ab
## 5:B:1 0.8800000    abc
## 4:C:1 0.7533333    bcd
## 3:A:1 0.7200000    cde
## 3:C:1 0.6866667    def
## 4:C:2 0.6633333    def
## 4:B:1 0.6566667    def
## 3:A:2 0.6300000   defg
## 3:B:1 0.6200000   defg
## 3:C:2 0.5966667  defgh
## 4:B:2 0.5666667   efgh
## 2:A:1 0.5533333   efgh
## 5:A:1 0.5533333   efgh
## 3:B:2 0.5300000    fgh
## 2:C:1 0.5200000    fgh
## 5:C:1 0.5200000    fgh
## 2:A:2 0.4633333     gh
## 5:A:2 0.4633333     gh
## 2:C:2 0.4300000     hi
## 5:C:2 0.4300000     hi
## 2:B:1 0.2866667     ij
## 1:A:1 0.2533333     jk
## 2:B:2 0.1966667     jk
## 1:C:1 0.1866667     jk
## 1:A:2 0.1700000     jk
## 1:B:1 0.1533333     jk
## 1:C:2 0.1466667     jk
## 1:B:2 0.1066667      k
outtestLSD
## $statistics
##      MSerror Df      Mean       CV  t.value       LSD
##   0.01152927 58 0.5175556 20.74646 2.001717 0.1754923
## 
## $parameters
##         test p.ajusted              name.t ntr alpha
##   Fisher-LSD      none race:fungicide:year  30  0.05
## 
## $means
##            ndvi        std r         LCL       UCL  Min  Max   Q25  Q50
## 1:A:1 0.2533333 0.05773503 3  0.12924153 0.3774251 0.22 0.32 0.220 0.22
## 1:A:2 0.1700000 0.05291503 3  0.04590820 0.2940918 0.13 0.23 0.140 0.15
## 1:B:1 0.1533333 0.05773503 3  0.02924153 0.2774251 0.12 0.22 0.120 0.12
## 1:B:2 0.1066667 0.02081666 3 -0.01742514 0.2307585 0.09 0.13 0.095 0.10
## 1:C:1 0.1866667 0.15275252 3  0.06257486 0.3107585 0.02 0.32 0.120 0.22
## 1:C:2 0.1466667 0.07637626 3  0.02257486 0.2707585 0.08 0.23 0.105 0.13
## 2:A:1 0.5533333 0.05773503 3  0.42924153 0.6774251 0.52 0.62 0.520 0.52
## 2:A:2 0.4633333 0.05773503 3  0.33924153 0.5874251 0.43 0.53 0.430 0.43
## 2:B:1 0.2866667 0.11547005 3  0.16257486 0.4107585 0.22 0.42 0.220 0.22
## 2:B:2 0.1966667 0.11547005 3  0.07257486 0.3207585 0.13 0.33 0.130 0.13
## 2:C:1 0.5200000 0.20000000 3  0.39590820 0.6440918 0.32 0.72 0.420 0.52
## 2:C:2 0.4300000 0.20000000 3  0.30590820 0.5540918 0.23 0.63 0.330 0.43
## 3:A:1 0.7200000 0.10000000 3  0.59590820 0.8440918 0.62 0.82 0.670 0.72
## 3:A:2 0.6300000 0.10000000 3  0.50590820 0.7540918 0.53 0.73 0.580 0.63
## 3:B:1 0.6200000 0.20000000 3  0.49590820 0.7440918 0.42 0.82 0.520 0.62
## 3:B:2 0.5300000 0.20000000 3  0.40590820 0.6540918 0.33 0.73 0.430 0.53
## 3:C:1 0.6866667 0.05773503 3  0.56257486 0.8107585 0.62 0.72 0.670 0.72
## 3:C:2 0.5966667 0.05773503 3  0.47257486 0.7207585 0.53 0.63 0.580 0.63
## 4:A:1 0.9400000 0.02645751 3  0.81590820 1.0640918 0.92 0.97 0.925 0.93
## 4:A:2 0.9433333 0.01527525 3  0.81924153 1.0674251 0.93 0.96 0.935 0.94
## 4:B:1 0.6566667 0.15821926 3  0.53257486 0.7807585 0.52 0.83 0.570 0.62
## 4:B:2 0.5666667 0.15821926 3  0.44257486 0.6907585 0.43 0.74 0.480 0.53
## 4:C:1 0.7533333 0.05773503 3  0.62924153 0.8774251 0.72 0.82 0.720 0.72
## 4:C:2 0.6633333 0.05773503 3  0.53924153 0.7874251 0.63 0.73 0.630 0.63
## 5:A:1 0.5533333 0.15275252 3  0.42924153 0.6774251 0.42 0.72 0.470 0.52
## 5:A:2 0.4633333 0.15275252 3  0.33924153 0.5874251 0.33 0.63 0.380 0.43
## 5:B:1 0.8800000 0.05291503 3  0.75590820 1.0040918 0.82 0.92 0.860 0.90
## 5:B:2 0.9066667 0.03214550 3  0.78257486 1.0307585 0.87 0.93 0.895 0.92
## 5:C:1 0.5200000 0.10000000 3  0.39590820 0.6440918 0.42 0.62 0.470 0.52
## 5:C:2 0.4300000 0.10000000 3  0.30590820 0.5540918 0.33 0.53 0.380 0.43
##         Q75
## 1:A:1 0.270
## 1:A:2 0.190
## 1:B:1 0.170
## 1:B:2 0.115
## 1:C:1 0.270
## 1:C:2 0.180
## 2:A:1 0.570
## 2:A:2 0.480
## 2:B:1 0.320
## 2:B:2 0.230
## 2:C:1 0.620
## 2:C:2 0.530
## 3:A:1 0.770
## 3:A:2 0.680
## 3:B:1 0.720
## 3:B:2 0.630
## 3:C:1 0.720
## 3:C:2 0.630
## 4:A:1 0.950
## 4:A:2 0.950
## 4:B:1 0.725
## 4:B:2 0.635
## 4:C:1 0.770
## 4:C:2 0.680
## 5:A:1 0.620
## 5:A:2 0.530
## 5:B:1 0.910
## 5:B:2 0.925
## 5:C:1 0.570
## 5:C:2 0.480
## 
## $comparison
## NULL
## 
## $groups
##            ndvi groups
## 4:A:2 0.9433333      a
## 4:A:1 0.9400000      a
## 5:B:2 0.9066667     ab
## 5:B:1 0.8800000    abc
## 4:C:1 0.7533333    bcd
## 3:A:1 0.7200000    cde
## 3:C:1 0.6866667    def
## 4:C:2 0.6633333    def
## 4:B:1 0.6566667    def
## 3:A:2 0.6300000   defg
## 3:B:1 0.6200000   defg
## 3:C:2 0.5966667  defgh
## 4:B:2 0.5666667   efgh
## 2:A:1 0.5533333   efgh
## 5:A:1 0.5533333   efgh
## 3:B:2 0.5300000    fgh
## 2:C:1 0.5200000    fgh
## 5:C:1 0.5200000    fgh
## 2:A:2 0.4633333     gh
## 5:A:2 0.4633333     gh
## 2:C:2 0.4300000     hi
## 5:C:2 0.4300000     hi
## 2:B:1 0.2866667     ij
## 1:A:1 0.2533333     jk
## 2:B:2 0.1966667     jk
## 1:C:1 0.1866667     jk
## 1:A:2 0.1700000     jk
## 1:B:1 0.1533333     jk
## 1:C:2 0.1466667     jk
## 1:B:2 0.1066667      k
## 
## attr(,"class")
## [1] "group"

Test Tukey’s HSD

outtestHSD<-HSD.test(outANOVA, c ("race","fungicide","year"), main = "ndvi~block+year+race+fungicide+race*fungicide+year*race*fungicide", console=TRUE)
## 
## Study: ndvi~block+year+race+fungicide+race*fungicide+year*race*fungicide
## 
## HSD Test for ndvi 
## 
## Mean Square Error:  0.01152927 
## 
## race:fungicide:year,  means
## 
##            ndvi        std r  Min  Max
## 1:A:1 0.2533333 0.05773503 3 0.22 0.32
## 1:A:2 0.1700000 0.05291503 3 0.13 0.23
## 1:B:1 0.1533333 0.05773503 3 0.12 0.22
## 1:B:2 0.1066667 0.02081666 3 0.09 0.13
## 1:C:1 0.1866667 0.15275252 3 0.02 0.32
## 1:C:2 0.1466667 0.07637626 3 0.08 0.23
## 2:A:1 0.5533333 0.05773503 3 0.52 0.62
## 2:A:2 0.4633333 0.05773503 3 0.43 0.53
## 2:B:1 0.2866667 0.11547005 3 0.22 0.42
## 2:B:2 0.1966667 0.11547005 3 0.13 0.33
## 2:C:1 0.5200000 0.20000000 3 0.32 0.72
## 2:C:2 0.4300000 0.20000000 3 0.23 0.63
## 3:A:1 0.7200000 0.10000000 3 0.62 0.82
## 3:A:2 0.6300000 0.10000000 3 0.53 0.73
## 3:B:1 0.6200000 0.20000000 3 0.42 0.82
## 3:B:2 0.5300000 0.20000000 3 0.33 0.73
## 3:C:1 0.6866667 0.05773503 3 0.62 0.72
## 3:C:2 0.5966667 0.05773503 3 0.53 0.63
## 4:A:1 0.9400000 0.02645751 3 0.92 0.97
## 4:A:2 0.9433333 0.01527525 3 0.93 0.96
## 4:B:1 0.6566667 0.15821926 3 0.52 0.83
## 4:B:2 0.5666667 0.15821926 3 0.43 0.74
## 4:C:1 0.7533333 0.05773503 3 0.72 0.82
## 4:C:2 0.6633333 0.05773503 3 0.63 0.73
## 5:A:1 0.5533333 0.15275252 3 0.42 0.72
## 5:A:2 0.4633333 0.15275252 3 0.33 0.63
## 5:B:1 0.8800000 0.05291503 3 0.82 0.92
## 5:B:2 0.9066667 0.03214550 3 0.87 0.93
## 5:C:1 0.5200000 0.10000000 3 0.42 0.62
## 5:C:2 0.4300000 0.10000000 3 0.33 0.53
## 
## Alpha: 0.05 ; DF Error: 58 
## Critical Value of Studentized Range: 5.575498 
## 
## Minimun Significant Difference: 0.34564 
## 
## Treatments with the same letter are not significantly different.
## 
##            ndvi groups
## 4:A:2 0.9433333      a
## 4:A:1 0.9400000     ab
## 5:B:2 0.9066667    abc
## 5:B:1 0.8800000   abcd
## 4:C:1 0.7533333  abcde
## 3:A:1 0.7200000  abcde
## 3:C:1 0.6866667  abcde
## 4:C:2 0.6633333  abcde
## 4:B:1 0.6566667  abcde
## 3:A:2 0.6300000 abcdef
## 3:B:1 0.6200000 abcdef
## 3:C:2 0.5966667 bcdefg
## 4:B:2 0.5666667  cdefg
## 2:A:1 0.5533333   defg
## 5:A:1 0.5533333   defg
## 3:B:2 0.5300000   efgh
## 2:C:1 0.5200000   efgh
## 5:C:1 0.5200000   efgh
## 2:A:2 0.4633333  efghi
## 5:A:2 0.4633333  efghi
## 2:C:2 0.4300000 efghij
## 5:C:2 0.4300000 efghij
## 2:B:1 0.2866667  fghij
## 1:A:1 0.2533333   ghij
## 2:B:2 0.1966667    hij
## 1:C:1 0.1866667    hij
## 1:A:2 0.1700000     ij
## 1:B:1 0.1533333     ij
## 1:C:2 0.1466667     ij
## 1:B:2 0.1066667      j
outtestHSD
## $statistics
##      MSerror Df      Mean       CV     MSD
##   0.01152927 58 0.5175556 20.74646 0.34564
## 
## $parameters
##    test              name.t ntr StudentizedRange alpha
##   Tukey race:fungicide:year  30         5.575498  0.05
## 
## $means
##            ndvi        std r  Min  Max   Q25  Q50   Q75
## 1:A:1 0.2533333 0.05773503 3 0.22 0.32 0.220 0.22 0.270
## 1:A:2 0.1700000 0.05291503 3 0.13 0.23 0.140 0.15 0.190
## 1:B:1 0.1533333 0.05773503 3 0.12 0.22 0.120 0.12 0.170
## 1:B:2 0.1066667 0.02081666 3 0.09 0.13 0.095 0.10 0.115
## 1:C:1 0.1866667 0.15275252 3 0.02 0.32 0.120 0.22 0.270
## 1:C:2 0.1466667 0.07637626 3 0.08 0.23 0.105 0.13 0.180
## 2:A:1 0.5533333 0.05773503 3 0.52 0.62 0.520 0.52 0.570
## 2:A:2 0.4633333 0.05773503 3 0.43 0.53 0.430 0.43 0.480
## 2:B:1 0.2866667 0.11547005 3 0.22 0.42 0.220 0.22 0.320
## 2:B:2 0.1966667 0.11547005 3 0.13 0.33 0.130 0.13 0.230
## 2:C:1 0.5200000 0.20000000 3 0.32 0.72 0.420 0.52 0.620
## 2:C:2 0.4300000 0.20000000 3 0.23 0.63 0.330 0.43 0.530
## 3:A:1 0.7200000 0.10000000 3 0.62 0.82 0.670 0.72 0.770
## 3:A:2 0.6300000 0.10000000 3 0.53 0.73 0.580 0.63 0.680
## 3:B:1 0.6200000 0.20000000 3 0.42 0.82 0.520 0.62 0.720
## 3:B:2 0.5300000 0.20000000 3 0.33 0.73 0.430 0.53 0.630
## 3:C:1 0.6866667 0.05773503 3 0.62 0.72 0.670 0.72 0.720
## 3:C:2 0.5966667 0.05773503 3 0.53 0.63 0.580 0.63 0.630
## 4:A:1 0.9400000 0.02645751 3 0.92 0.97 0.925 0.93 0.950
## 4:A:2 0.9433333 0.01527525 3 0.93 0.96 0.935 0.94 0.950
## 4:B:1 0.6566667 0.15821926 3 0.52 0.83 0.570 0.62 0.725
## 4:B:2 0.5666667 0.15821926 3 0.43 0.74 0.480 0.53 0.635
## 4:C:1 0.7533333 0.05773503 3 0.72 0.82 0.720 0.72 0.770
## 4:C:2 0.6633333 0.05773503 3 0.63 0.73 0.630 0.63 0.680
## 5:A:1 0.5533333 0.15275252 3 0.42 0.72 0.470 0.52 0.620
## 5:A:2 0.4633333 0.15275252 3 0.33 0.63 0.380 0.43 0.530
## 5:B:1 0.8800000 0.05291503 3 0.82 0.92 0.860 0.90 0.910
## 5:B:2 0.9066667 0.03214550 3 0.87 0.93 0.895 0.92 0.925
## 5:C:1 0.5200000 0.10000000 3 0.42 0.62 0.470 0.52 0.570
## 5:C:2 0.4300000 0.10000000 3 0.33 0.53 0.380 0.43 0.480
## 
## $comparison
## NULL
## 
## $groups
##            ndvi groups
## 4:A:2 0.9433333      a
## 4:A:1 0.9400000     ab
## 5:B:2 0.9066667    abc
## 5:B:1 0.8800000   abcd
## 4:C:1 0.7533333  abcde
## 3:A:1 0.7200000  abcde
## 3:C:1 0.6866667  abcde
## 4:C:2 0.6633333  abcde
## 4:B:1 0.6566667  abcde
## 3:A:2 0.6300000 abcdef
## 3:B:1 0.6200000 abcdef
## 3:C:2 0.5966667 bcdefg
## 4:B:2 0.5666667  cdefg
## 2:A:1 0.5533333   defg
## 5:A:1 0.5533333   defg
## 3:B:2 0.5300000   efgh
## 2:C:1 0.5200000   efgh
## 5:C:1 0.5200000   efgh
## 2:A:2 0.4633333  efghi
## 5:A:2 0.4633333  efghi
## 2:C:2 0.4300000 efghij
## 5:C:2 0.4300000 efghij
## 2:B:1 0.2866667  fghij
## 1:A:1 0.2533333   ghij
## 2:B:2 0.1966667    hij
## 1:C:1 0.1866667    hij
## 1:A:2 0.1700000     ij
## 1:B:1 0.1533333     ij
## 1:C:2 0.1466667     ij
## 1:B:2 0.1066667      j
## 
## attr(,"class")
## [1] "group"

Question 4

setwd("C:/Users/clemendeoliveira/Desktop/Homework3")
data4=read.csv("quest4.csv",header = T,check.names = F,na.strings = -9,sep = ",")
str(data4)
## 'data.frame':    48 obs. of  6 variables:
##  $ Block    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ wplot    : int  1 1 1 1 2 2 2 2 3 3 ...
##  $ splot    : int  1 2 3 4 1 2 3 4 1 2 ...
##  $ Herbicide: Factor w/ 4 levels "A","B","C","D": 1 1 1 1 2 2 2 2 3 3 ...
##  $ Variety  : int  1 2 3 4 1 2 3 4 1 2 ...
##  $ Humidity : num  10.9 11.5 13 14.3 9 10 12.1 16 9.6 10.2 ...
data4$Block=as.factor(data4$Block)
data4$wplot=as.factor(data4$wplot)
data4$splot=as.factor(data4$splot)
data4$Herbicide=as.factor(data4$Herbicide)
data4$Variety = as.factor(data4$Variety)
summary(data4)
##  Block  wplot  splot  Herbicide Variety    Humidity    
##  1:16   1:12   1:12   A:12      1:12    Min.   : 6.60  
##  2:16   2:12   2:12   B:12      2:12    1st Qu.:10.97  
##  3:16   3:12   3:12   C:12      3:12    Median :12.85  
##         4:12   4:12   D:12      4:12    Mean   :13.13  
##                                         3rd Qu.:15.53  
##                                         Max.   :18.40
attach(data4) 
data4
##    Block wplot splot Herbicide Variety Humidity
## 1      1     1     1         A       1     10.9
## 2      1     1     2         A       2     11.5
## 3      1     1     3         A       3     13.0
## 4      1     1     4         A       4     14.3
## 5      1     2     1         B       1      9.0
## 6      1     2     2         B       2     10.0
## 7      1     2     3         B       3     12.1
## 8      1     2     4         B       4     16.0
## 9      1     3     1         C       1      9.6
## 10     1     3     2         C       2     10.2
## 11     1     3     3         C       3     11.7
## 12     1     3     4         C       4     13.0
## 13     1     4     1         D       1      6.6
## 14     1     4     2         D       2      8.7
## 15     1     4     3         D       3     10.8
## 16     1     4     4         D       4     14.7
## 17     2     1     1         A       1     12.3
## 18     2     1     2         A       2     11.4
## 19     2     1     3         A       3     15.4
## 20     2     1     4         A       4     17.2
## 21     2     2     1         B       1     10.3
## 22     2     2     2         B       2     12.5
## 23     2     2     3         B       3     16.1
## 24     2     2     4         B       4     16.5
## 25     2     3     1         C       1     11.0
## 26     2     3     2         C       2     10.1
## 27     2     3     3         C       3     14.1
## 28     2     3     4         C       4     15.9
## 29     2     4     1         D       1      9.0
## 30     2     4     2         D       2     11.2
## 31     2     4     3         D       3     14.8
## 32     2     4     4         D       4     15.2
## 33     3     1     1         A       1     14.3
## 34     3     1     2         A       2     13.3
## 35     3     1     3         A       3     18.1
## 36     3     1     4         A       4     16.5
## 37     3     2     1         B       1     12.1
## 38     3     2     2         B       2     12.7
## 39     3     2     3         B       3     17.3
## 40     3     2     4         B       4     18.4
## 41     3     3     1         C       1     13.0
## 42     3     3     2         C       2     12.0
## 43     3     3     3         C       3     16.8
## 44     3     3     4         C       4     15.2
## 45     3     4     1         D       1     10.8
## 46     3     4     2         D       2     11.4
## 47     3     4     3         D       3     16.0
## 48     3     4     4         D       4     17.1

Including histogram and boxplot

hist(data4$Humidity)

boxplot(data4$Humidity~data4$Herbicide)

boxplot(data4$Humidity~data4$Variety)

###Anova without transform the data

splitplot4 <- aov(Humidity~Block+Herbicide*Variety+Error(Block/wplot/splot),data = data4)
summary(splitplot4)
## 
## Error: Block
##       Df Sum Sq Mean Sq
## Block  2  88.28   44.14
## 
## Error: Block:wplot
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## Herbicide  3 24.516   8.172   65.27 5.69e-05 ***
## Residuals  6  0.751   0.125                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: Block:wplot:splot
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## Variety            3 227.51   75.84  85.558 5.91e-13 ***
## Herbicide:Variety  9  15.61    1.73   1.956   0.0915 .  
## Residuals         24  21.27    0.89                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
splitplotwrongway <- aov(Humidity~Block+Herbicide+Block*Herbicide+Variety+Herbicide*Variety,data = data4)
summary(splitplotwrongway)
##                   Df Sum Sq Mean Sq F value   Pr(>F)    
## Block              2  88.28   44.14  49.795 2.88e-09 ***
## Herbicide          3  24.52    8.17   9.219 0.000308 ***
## Variety            3 227.51   75.84  85.558 5.91e-13 ***
## Block:Herbicide    6   0.75    0.13   0.141 0.989110    
## Herbicide:Variety  9  15.61    1.73   1.956 0.091525 .  
## Residuals         24  21.27    0.89                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
model_1=with(data4,sp.plot(Block,Herbicide,Variety,Humidity))
## 
## ANALYSIS SPLIT PLOT:  Humidity 
## Class level information
## 
## Herbicide    :  A B C D 
## Variety  :  1 2 3 4 
## Block    :  1 2 3 
## 
## Number of observations:  48 
## 
## Analysis of Variance Table
## 
## Response: Humidity
##                   Df  Sum Sq Mean Sq  F value    Pr(>F)    
## Block              2  88.275  44.138 352.5141 6.009e-07 ***
## Herbicide          3  24.516   8.172  65.2662 5.685e-05 ***
## Ea                 6   0.751   0.125                       
## Variety            3 227.512  75.837  85.5577 5.909e-13 ***
## Herbicide:Variety  9  15.607   1.734   1.9564   0.09152 .  
## Eb                24  21.273   0.886                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## cv(a) = 2.7 %, cv(b) = 7.2 %, Mean = 13.12708
gla= model_1$gl.a
glb= model_1$gl.b
Ea= model_1$Ea
Eb= model_1$Eb

out1= with(data4,HSD.test(Humidity, Herbicide, gla, Ea, console=TRUE))
## 
## Study: Humidity ~ Herbicide
## 
## HSD Test for Humidity 
## 
## Mean Square Error:  0.1252083 
## 
## Herbicide,  means
## 
##   Humidity      std  r  Min  Max
## A 14.01667 2.382448 12 10.9 18.1
## B 13.58333 3.143199 12  9.0 18.4
## C 12.71667 2.382448 12  9.6 16.8
## D 12.19167 3.301090 12  6.6 17.1
## 
## Alpha: 0.05 ; DF Error: 6 
## Critical Value of Studentized Range: 4.895599 
## 
## Minimun Significant Difference: 0.5000712 
## 
## Treatments with the same letter are not significantly different.
## 
##   Humidity groups
## A 14.01667      a
## B 13.58333      a
## C 12.71667      b
## D 12.19167      c
out2= with(data4,HSD.test(Humidity, Variety, glb, Eb, console=TRUE))
## 
## Study: Humidity ~ Variety
## 
## HSD Test for Humidity 
## 
## Mean Square Error:  0.8863889 
## 
## Variety,  means
## 
##   Humidity      std  r  Min  Max
## 1 10.74167 2.063738 12  6.6 14.3
## 2 11.25000 1.315295 12  8.7 13.3
## 3 14.68333 2.356744 12 10.8 18.1
## 4 15.83333 1.459971 12 13.0 18.4
## 
## Alpha: 0.05 ; DF Error: 24 
## Critical Value of Studentized Range: 3.901262 
## 
## Minimun Significant Difference: 1.060295 
## 
## Treatments with the same letter are not significantly different.
## 
##   Humidity groups
## 4 15.83333      a
## 3 14.68333      b
## 2 11.25000      c
## 1 10.74167      c
out3= with(data4,HSD.test(Humidity, Herbicide:Variety, glb, Eb, console=TRUE))
## 
## Study: Humidity ~ Herbicide:Variety
## 
## HSD Test for Humidity 
## 
## Mean Square Error:  0.8863889 
## 
## Herbicide:Variety,  means
## 
##     Humidity      std r  Min  Max
## A:1 12.50000 1.708801 3 10.9 14.3
## A:2 12.06667 1.069268 3 11.4 13.3
## A:3 15.50000 2.551470 3 13.0 18.1
## A:4 16.00000 1.513275 3 14.3 17.2
## B:1 10.46667 1.556706 3  9.0 12.1
## B:2 11.73333 1.504438 3 10.0 12.7
## B:3 15.16667 2.722744 3 12.1 17.3
## B:4 16.96667 1.266228 3 16.0 18.4
## C:1 11.20000 1.708801 3  9.6 13.0
## C:2 10.76667 1.069268 3 10.1 12.0
## C:3 14.20000 2.551470 3 11.7 16.8
## C:4 14.70000 1.513275 3 13.0 15.9
## D:1  8.80000 2.107131 3  6.6 10.8
## D:2 10.43333 1.504438 3  8.7 11.4
## D:3 13.86667 2.722744 3 10.8 16.0
## D:4 15.66667 1.266228 3 14.7 17.1
## 
## Alpha: 0.05 ; DF Error: 24 
## Critical Value of Studentized Range: 5.381037 
## 
## Minimun Significant Difference: 2.924944 
## 
## Treatments with the same letter are not significantly different.
## 
##     Humidity groups
## B:4 16.96667      a
## A:4 16.00000     ab
## D:4 15.66667     ab
## A:3 15.50000     ab
## B:3 15.16667    abc
## C:4 14.70000   abcd
## C:3 14.20000  abcde
## D:3 13.86667  bcdef
## A:1 12.50000  cdefg
## A:2 12.06667   defg
## B:2 11.73333    efg
## C:1 11.20000    fgh
## C:2 10.76667     gh
## B:1 10.46667     gh
## D:2 10.43333     gh
## D:1  8.80000      h
library(lsmeans)
meanseparation<-lsmeans(splitplotwrongway, ~Herbicide, adjust='Tukey')
## NOTE: Results may be misleading due to involvement in interactions
meanseparation<-summary(meanseparation)
HSD.test(splitplotwrongway,c("Herbicide"),console=TRUE)
## 
## Study: splitplotwrongway ~ c("Herbicide")
## 
## HSD Test for Humidity 
## 
## Mean Square Error:  0.8863889 
## 
## Herbicide,  means
## 
##   Humidity      std  r  Min  Max
## A 14.01667 2.382448 12 10.9 18.1
## B 13.58333 3.143199 12  9.0 18.4
## C 12.71667 2.382448 12  9.6 16.8
## D 12.19167 3.301090 12  6.6 17.1
## 
## Alpha: 0.05 ; DF Error: 24 
## Critical Value of Studentized Range: 3.901262 
## 
## Minimun Significant Difference: 1.060295 
## 
## Treatments with the same letter are not significantly different.
## 
##   Humidity groups
## A 14.01667      a
## B 13.58333     ab
## C 12.71667     bc
## D 12.19167      c
library(lsmeans)
meanseparation2<-lsmeans(splitplotwrongway, ~Variety, adjust='Tukey')
## NOTE: Results may be misleading due to involvement in interactions
meanseparation2<-summary(meanseparation2)
HSD.test(splitplotwrongway,c("Variety"),console=TRUE)
## 
## Study: splitplotwrongway ~ c("Variety")
## 
## HSD Test for Humidity 
## 
## Mean Square Error:  0.8863889 
## 
## Variety,  means
## 
##   Humidity      std  r  Min  Max
## 1 10.74167 2.063738 12  6.6 14.3
## 2 11.25000 1.315295 12  8.7 13.3
## 3 14.68333 2.356744 12 10.8 18.1
## 4 15.83333 1.459971 12 13.0 18.4
## 
## Alpha: 0.05 ; DF Error: 24 
## Critical Value of Studentized Range: 3.901262 
## 
## Minimun Significant Difference: 1.060295 
## 
## Treatments with the same letter are not significantly different.
## 
##   Humidity groups
## 4 15.83333      a
## 3 14.68333      b
## 2 11.25000      c
## 1 10.74167      c

Computing graph bar for Herbicide

library(ggplot2)
graph<-lsmeans(splitplot4, ~Herbicide, adjust='Tukey')
## Note: re-fitting model with sum-to-zero contrasts
## NOTE: Results may be misleading due to involvement in interactions
graph<-summary(graph)
graph$Herbicide <- factor(graph$Herbicide, levels = c( "A","B","C","D"))
ggplot(graph, aes(x=Herbicide, y=lsmean, fill=Herbicide)) + 
  geom_bar(position=position_dodge(0.9), stat="identity",
           colour="black", # Use black outlines
           size=.3) + scale_fill_brewer() +
  geom_errorbar(aes(ymin=lsmean-SE, ymax=lsmean+SE), 
                size=.5,    # Thinner lines
                colour="black",
                width=.2,
                position=position_dodge(.9)) +
   xlab("Herbicide") +
  ylab("Humidity") +
  ggtitle("Humidity Question 4 - Herbicide") +
  annotate("text",x=1,y=16,label="a", size=10)+
  annotate("text",x=2,y=16,label="ab", size=10)+
  annotate("text",x=3,y=16,label="bc", size=10)+
  annotate("text",x=4,y=16,label="c", size=10)+
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  theme(axis.title=element_text( size = rel(2.1) , color="black")) +
  theme(axis.text = element_text(colour = "black", size="20")) +
  theme(legend.title = element_text(size = "14"))+ 
  theme(legend.position = "none")+ 
  theme(plot.title = element_text(size = rel(2)))
## Warning: Removed 4 rows containing missing values (geom_errorbar).

###Computing graph bar for Variety

library(ggplot2)
graph<-lsmeans(splitplot4, ~Variety, adjust='Tukey')
## Note: re-fitting model with sum-to-zero contrasts
## NOTE: Results may be misleading due to involvement in interactions
graph<-summary(graph)
graph$Variety <- factor(graph$Variety, levels = c( "1","2","3","4"))
ggplot(graph, aes(x=Variety, y=lsmean, fill=Variety)) + 
  geom_bar(position=position_dodge(0.9), stat="identity",
           colour="black", # Use black outlines
           size=.3) + scale_fill_brewer() +
  geom_errorbar(aes(ymin=lsmean-SE, ymax=lsmean+SE), 
                size=.5,    # Thinner lines
                colour="black",
                width=.2,
                position=position_dodge(.9)) +
   xlab("Variety") +
  ylab("Humidity") +
  ggtitle("Humidity Question 4 - Variety") +
  annotate("text",x=1,y=16,label="a", size=10)+
  annotate("text",x=2,y=16,label="b", size=10)+
  annotate("text",x=3,y=18,label="c", size=10)+
  annotate("text",x=4,y=19,label="c", size=10)+
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))+
  theme(axis.title=element_text( size = rel(2.1) , color="black")) +
  theme(axis.text = element_text(colour = "black", size="20")) +
  theme(legend.title = element_text(size = "14"))+ 
  theme(legend.position = "none")+ 
  theme(plot.title = element_text(size = rel(2)))
## Warning: Removed 4 rows containing missing values (geom_errorbar).

###bONUS

setwd("C:/Users/clemendeoliveira/Desktop/Homework3")
data5=read.table("quest5.txt",header = T,check.names = F)
str(data5)
## 'data.frame':    48 obs. of  8 variables:
##  $ Block     : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ wplot     : int  1 1 1 1 1 1 2 2 2 2 ...
##  $ subplot   : int  1 1 1 2 2 2 1 1 1 2 ...
##  $ subsubplot: int  1 2 3 1 2 3 1 2 3 1 ...
##  $ Soil      : Factor w/ 2 levels "Conventional",..: 1 1 1 1 1 1 2 2 2 2 ...
##  $ Cultivar  : Factor w/ 2 levels "Susceptible",..: 2 2 2 1 1 1 2 2 2 1 ...
##  $ Nitrogen  : Factor w/ 3 levels "High","Low","Medium": 2 3 1 2 3 1 2 3 1 2 ...
##  $ Yield     : int  140 145 150 136 140 145 142 146 148 132 ...
data5$Block=as.factor(data5$Block)
data5$wplot=as.factor(data5$wplot)
data5$subplot=as.factor(data5$subplot)
data5$subsubplot=as.factor(data5$subsubplot)
data5$Soil=as.factor(data5$Soil)
data5$Cultivar = as.factor(data5$Cultivar)
data5$Nitrogen=as.factor(data5$Nitrogen)
summary(data5)
##  Block  wplot  subplot subsubplot           Soil           Cultivar 
##  1:12   1:24   1:24    1:16       Conventional:24   Susceptible:24  
##  2:12   2:24   2:24    2:16       Non_Till    :24   Tolerant   :24  
##  3:12                  3:16                                         
##  4:12                                                               
##                                                                     
##                                                                     
##    Nitrogen      Yield      
##  High  :16   Min.   :130.0  
##  Low   :16   1st Qu.:136.0  
##  Medium:16   Median :140.0  
##              Mean   :139.5  
##              3rd Qu.:142.0  
##              Max.   :150.0
attach(data5) 
## The following objects are masked from data4:
## 
##     Block, wplot
data5
##    Block wplot subplot subsubplot         Soil    Cultivar Nitrogen Yield
## 1      1     1       1          1 Conventional    Tolerant      Low   140
## 2      1     1       1          2 Conventional    Tolerant   Medium   145
## 3      1     1       1          3 Conventional    Tolerant     High   150
## 4      1     1       2          1 Conventional Susceptible      Low   136
## 5      1     1       2          2 Conventional Susceptible   Medium   140
## 6      1     1       2          3 Conventional Susceptible     High   145
## 7      1     2       1          1     Non_Till    Tolerant      Low   142
## 8      1     2       1          2     Non_Till    Tolerant   Medium   146
## 9      1     2       1          3     Non_Till    Tolerant     High   148
## 10     1     2       2          1     Non_Till Susceptible      Low   132
## 11     1     2       2          2     Non_Till Susceptible   Medium   138
## 12     1     2       2          3     Non_Till Susceptible     High   140
## 13     2     1       1          1 Conventional    Tolerant      Low   138
## 14     2     1       1          2 Conventional    Tolerant   Medium   146
## 15     2     1       1          3 Conventional    Tolerant     High   149
## 16     2     1       2          1 Conventional Susceptible      Low   136
## 17     2     1       2          2 Conventional Susceptible   Medium   134
## 18     2     1       2          3 Conventional Susceptible     High   138
## 19     2     2       1          1     Non_Till    Tolerant      Low   135
## 20     2     2       1          2     Non_Till    Tolerant   Medium   136
## 21     2     2       1          3     Non_Till    Tolerant     High   140
## 22     2     2       2          1     Non_Till Susceptible      Low   130
## 23     2     2       2          2     Non_Till Susceptible   Medium   132
## 24     2     2       2          3     Non_Till Susceptible     High   134
## 25     3     1       1          1 Conventional    Tolerant      Low   142
## 26     3     1       1          2 Conventional    Tolerant   Medium   150
## 27     3     1       1          3 Conventional    Tolerant     High   146
## 28     3     1       2          1 Conventional Susceptible      Low   134
## 29     3     1       2          2 Conventional Susceptible   Medium   136
## 30     3     1       2          3 Conventional Susceptible     High   138
## 31     3     2       1          1     Non_Till    Tolerant      Low   137
## 32     3     2       1          2     Non_Till    Tolerant   Medium   140
## 33     3     2       1          3     Non_Till    Tolerant     High   142
## 34     3     2       2          1     Non_Till Susceptible      Low   136
## 35     3     2       2          2     Non_Till Susceptible   Medium   130
## 36     3     2       2          3     Non_Till Susceptible     High   130
## 37     4     1       1          1 Conventional    Tolerant      Low   142
## 38     4     1       1          2 Conventional    Tolerant   Medium   147
## 39     4     1       1          3 Conventional    Tolerant     High   150
## 40     4     1       2          1 Conventional Susceptible      Low   139
## 41     4     1       2          2 Conventional Susceptible   Medium   140
## 42     4     1       2          3 Conventional Susceptible     High   142
## 43     4     2       1          1     Non_Till    Tolerant      Low   140
## 44     4     2       1          2     Non_Till    Tolerant   Medium   141
## 45     4     2       1          3     Non_Till    Tolerant     High   140
## 46     4     2       2          1     Non_Till Susceptible      Low   134
## 47     4     2       2          2     Non_Till Susceptible   Medium   132
## 48     4     2       2          3     Non_Till Susceptible     High   136
hist(data5$Yield)

boxplot(data5$Yield~data5$Soil)

boxplot(data5$Yield~data5$Cultivar)

boxplot(data5$Yield~data5$Nitrogen)

splitplot5 <- aov(Yield~Block+Soil*Cultivar*Nitrogen+Error(Block/wplot/subplot/subsubplot),data = data5)
summary(splitplot5)
## 
## Error: Block
##       Df Sum Sq Mean Sq
## Block  3  142.4   47.47
## 
## Error: Block:wplot
##           Df Sum Sq Mean Sq F value Pr(>F)  
## Soil       1  261.3   261.3   20.91 0.0196 *
## Residuals  3   37.5    12.5                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: Block:wplot:subplot
##               Df Sum Sq Mean Sq F value   Pr(>F)    
## Cultivar       1  602.1   602.1  97.856 6.16e-05 ***
## Soil:Cultivar  1    0.3     0.3   0.054    0.824    
## Residuals      6   36.9     6.2                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: Block:wplot:subplot:subsubplot
##                        Df Sum Sq Mean Sq F value   Pr(>F)    
## Nitrogen                2 176.04   88.02  17.013 2.51e-05 ***
## Soil:Nitrogen           2  25.79   12.90   2.493   0.1039    
## Cultivar:Nitrogen       2  30.79   15.40   2.976   0.0701 .  
## Soil:Cultivar:Nitrogen  2   4.54    2.27   0.439   0.6498    
## Residuals              24 124.17    5.17                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model_2=with(data5,ssp.plot(Block,Soil,Cultivar,Nitrogen,Yield))
## 
## ANALYSIS SPLIT-SPLIT PLOT:  Yield 
## Class level information
## 
## Soil     :  Conventional Non_Till 
## Cultivar     :  Tolerant Susceptible 
## Nitrogen     :  Low Medium High 
## Block    :  1 2 3 4 
## 
## Number of observations:  48 
## 
## Analysis of Variance Table
## 
## Response: Yield
##                        Df Sum Sq Mean Sq F value    Pr(>F)    
## Block                   3 142.42   47.47  3.7978   0.15103    
## Soil                    1 261.33  261.33 20.9067   0.01963 *  
## Ea                      3  37.50   12.50                      
## Cultivar                1 602.08  602.08 97.8555 6.161e-05 ***
## Soil:Cultivar           1   0.33    0.33  0.0542   0.82369    
## Eb                      6  36.92    6.15                      
## Nitrogen                2 176.04   88.02 17.0134 2.506e-05 ***
## Nitrogen:Soil           2  25.79   12.90  2.4926   0.10385    
## Nitrogen:Cultivar       2  30.79   15.40  2.9758   0.07006 .  
## Nitrogen:Soil:Cultivar  2   4.54    2.27  0.4389   0.64980    
## Ec                     24 124.17    5.17                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## cv(a) = 2.5 %, cv(b) = 1.8 %, cv(c) = 1.6 %, Mean = 139.4583
gla= model_2$gl.a
glb= model_2$gl.b
glc= model_2$gl.c
Ea= model_2$Ea
Eb= model_2$Eb
Ec= model_2$Ec
out1= with(data5,HSD.test(Yield, Soil, gla, Ea, console=TRUE))
## 
## Study: Yield ~ Soil
## 
## HSD Test for Yield 
## 
## Mean Square Error:  12.5 
## 
## Soil,  means
## 
##                 Yield      std  r Min Max
## Conventional 141.7917 5.191793 24 134 150
## Non_Till     137.1250 4.937104 24 130 148
## 
## Alpha: 0.05 ; DF Error: 3 
## Critical Value of Studentized Range: 4.500659 
## 
## Minimun Significant Difference: 3.248071 
## 
## Treatments with the same letter are not significantly different.
## 
##                 Yield groups
## Conventional 141.7917      a
## Non_Till     137.1250      b
out2= with(data5,HSD.test(Yield, Cultivar, glb, Eb, console=TRUE))
## 
## Study: Yield ~ Cultivar
## 
## HSD Test for Yield 
## 
## Mean Square Error:  6.152778 
## 
## Cultivar,  means
## 
##                Yield      std  r Min Max
## Susceptible 135.9167 3.944359 24 130 145
## Tolerant    143.0000 4.577829 24 135 150
## 
## Alpha: 0.05 ; DF Error: 6 
## Critical Value of Studentized Range: 3.460456 
## 
## Minimun Significant Difference: 1.752118 
## 
## Treatments with the same letter are not significantly different.
## 
##                Yield groups
## Tolerant    143.0000      a
## Susceptible 135.9167      b
out3= with(data5,HSD.test(Yield, Nitrogen, glc, Ec, console=TRUE))
## 
## Study: Yield ~ Nitrogen
## 
## HSD Test for Yield 
## 
## Mean Square Error:  5.173611 
## 
## Nitrogen,  means
## 
##           Yield      std  r Min Max
## High   141.7500 5.916080 16 130 150
## Low    137.0625 3.623419 16 130 142
## Medium 139.5625 6.021835 16 130 150
## 
## Alpha: 0.05 ; DF Error: 24 
## Critical Value of Studentized Range: 3.531697 
## 
## Minimun Significant Difference: 2.008262 
## 
## Treatments with the same letter are not significantly different.
## 
##           Yield groups
## High   141.7500      a
## Medium 139.5625      b
## Low    137.0625      c
splitplotwrongway5 <- aov(Yield~Block+Soil+Block*Soil+Cultivar+Soil*Cultivar+Nitrogen+Nitrogen*Cultivar*Soil,data = data5)
summary(splitplotwrongway5)
##                        Df Sum Sq Mean Sq F value   Pr(>F)    
## Block                   3  142.4    47.5   8.841 0.000237 ***
## Soil                    1  261.3   261.3  48.670 9.45e-08 ***
## Cultivar                1  602.1   602.1 112.131 1.19e-11 ***
## Nitrogen                2  176.0    88.0  16.393 1.54e-05 ***
## Block:Soil              3   37.5    12.5   2.328 0.094517 .  
## Soil:Cultivar           1    0.3     0.3   0.062 0.804937    
## Cultivar:Nitrogen       2   30.8    15.4   2.867 0.072524 .  
## Soil:Nitrogen           2   25.8    12.9   2.402 0.107768    
## Soil:Cultivar:Nitrogen  2    4.5     2.3   0.423 0.658978    
## Residuals              30  161.1     5.4                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(lsmeans)
meanseparation5<-lsmeans(splitplotwrongway5, ~Soil, adjust='Tukey')
## NOTE: Results may be misleading due to involvement in interactions
meanseparation2<-summary(meanseparation5)
HSD.test(splitplotwrongway5,c("Soil"),console=TRUE)
## 
## Study: splitplotwrongway5 ~ c("Soil")
## 
## HSD Test for Yield 
## 
## Mean Square Error:  5.369444 
## 
## Soil,  means
## 
##                 Yield      std  r Min Max
## Conventional 141.7917 5.191793 24 134 150
## Non_Till     137.1250 4.937104 24 130 148
## 
## Alpha: 0.05 ; DF Error: 30 
## Critical Value of Studentized Range: 2.888209 
## 
## Minimun Significant Difference: 1.366116 
## 
## Treatments with the same letter are not significantly different.
## 
##                 Yield groups
## Conventional 141.7917      a
## Non_Till     137.1250      b
library(lsmeans)
meanseparation5.1<-lsmeans(splitplotwrongway5, ~Cultivar, adjust='Tukey')
## NOTE: Results may be misleading due to involvement in interactions
meanseparation5.1<-summary(meanseparation5.1)
HSD.test(splitplotwrongway5,c("Cultivar"),console=TRUE)
## 
## Study: splitplotwrongway5 ~ c("Cultivar")
## 
## HSD Test for Yield 
## 
## Mean Square Error:  5.369444 
## 
## Cultivar,  means
## 
##                Yield      std  r Min Max
## Susceptible 135.9167 3.944359 24 130 145
## Tolerant    143.0000 4.577829 24 135 150
## 
## Alpha: 0.05 ; DF Error: 30 
## Critical Value of Studentized Range: 2.888209 
## 
## Minimun Significant Difference: 1.366116 
## 
## Treatments with the same letter are not significantly different.
## 
##                Yield groups
## Tolerant    143.0000      a
## Susceptible 135.9167      b
library(lsmeans)
meanseparation5.2<-lsmeans(splitplotwrongway5, ~Nitrogen, adjust='Tukey')
## NOTE: Results may be misleading due to involvement in interactions
meanseparation5.2<-summary(meanseparation5.2)
HSD.test(splitplotwrongway5,c("Nitrogen"),console=TRUE)
## 
## Study: splitplotwrongway5 ~ c("Nitrogen")
## 
## HSD Test for Yield 
## 
## Mean Square Error:  5.369444 
## 
## Nitrogen,  means
## 
##           Yield      std  r Min Max
## High   141.7500 5.916080 16 130 150
## Low    137.0625 3.623419 16 130 142
## Medium 139.5625 6.021835 16 130 150
## 
## Alpha: 0.05 ; DF Error: 30 
## Critical Value of Studentized Range: 3.48642 
## 
## Minimun Significant Difference: 2.019689 
## 
## Treatments with the same letter are not significantly different.
## 
##           Yield groups
## High   141.7500      a
## Medium 139.5625      b
## Low    137.0625      c