library(readxl)
Yield <- read_excel("C:/Users/admin/Downloads/Yield.xlsx")
View(Yield)
str(Yield)
## tibble [20 x 3] (S3: tbl_df/tbl/data.frame)
##  $ Replication: num [1:20] 1 1 1 1 1 2 2 2 2 2 ...
##  $ Variety    : chr [1:20] "African tall" "Co-11" "FS-1" "K-7" ...
##  $ Yield      : num [1:20] 22.9 29.5 28.8 47 28.9 25.9 30.4 24.4 40.9 20.4 ...
Yield$Replication = factor(Yield$Replication)

#Fitting of linear model Ho:African tall=Co-11=FS-1=K-7=Co-24, Ha: Atleast one variety is different

model <- lm(Yield ~ Replication + Variety, data = Yield)
anova <-anova(model)
anova
## Analysis of Variance Table
## 
## Response: Yield
##             Df Sum Sq Mean Sq F value  Pr(>F)  
## Replication  3  80.80  26.934  0.9205 0.46033  
## Variety      4 520.53 130.133  4.4476 0.01958 *
## Residuals   12 351.11  29.259                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

As we can observe from the table, “Variety” have a p-value of 0.01958 which is a significant value. Hence, we reject the null hypothesis. We can conclude that, atleast one variety either African tall, Co-11, FS-1, K-7, or Co-24 is different.

Model assumptions The model assumes: 1 Errors ei are independent, have homogeneous variance, and a normal distribution. 2 Additivity: means are µ + αj + βk, i.e. the trt differences are the same for every block and the block differences are the same for every trt. No interaction.

#Below codes are used to obtain plots of fitted vs Residuals and Normal QQ plots

par(mfrow=c(1,2))
plot(model, which=1)
plot(model, which=2)

As we observe in the Normal Q-Q plot, almost all of the yields are close to the line and on the line. So, the residuals are normally distributed. Normality is met.

with(Yield,
interaction.plot(Variety, Replication, Yield, col=1:4) )

with(Yield,
interaction.plot(Replication, Variety, Yield, col=1:4) )

The Variety differences are the same for every Replication and the Replication differences are the same for every Variety. Thus, no interaction.

library(agricolae)

#Duncan test

DNMRT <-duncan.test(Yield$Yield, Yield$Variety,12,29.259)
DNMRT
## $statistics
##   MSerror Df   Mean       CV
##    29.259 12 31.275 17.29547
## 
## $parameters
##     test        name.t ntr alpha
##   Duncan Yield$Variety   5  0.05
## 
## $duncan
##      Table CriticalRange
## 2 3.081307      8.333639
## 3 3.225244      8.722927
## 4 3.312453      8.958792
## 5 3.370172      9.114897
## 
## $means
##              Yield$Yield      std r  Min  Max    Q25   Q50    Q75
## African tall      30.450 7.403378 4 22.9 39.1 25.150 29.90 35.200
## Co-11             31.200 2.762849 4 29.5 35.3 29.575 30.00 31.625
## Co-24             25.550 5.674798 4 20.4 31.8 20.925 25.00 29.625
## FS-1              28.475 3.155287 4 24.4 32.1 27.550 28.70 29.625
## K-7               40.700 6.274286 4 32.1 47.0 38.700 41.85 43.850
## 
## $comparison
## NULL
## 
## $groups
##              Yield$Yield groups
## K-7               40.700      a
## Co-11             31.200      b
## African tall      30.450      b
## FS-1              28.475      b
## Co-24             25.550      b
## 
## attr(,"class")
## [1] "group"

By the Duncan test, we will be able to know which of the variety is different. So in this experiment, we know that the variety ‘K-7’ is significantly different form the other variety. While the the variety ‘Co-11’, ‘African tall’, ‘FS-1’, and ‘Co-24’ are not significantly different from each other.

#LSD test

LSD <-LSD.test(Yield$Yield, Yield$Variety,12,29.259)
LSD
## $statistics
##   MSerror Df   Mean       CV  t.value      LSD
##    29.259 12 31.275 17.29547 2.178813 8.333639
## 
## $parameters
##         test p.ajusted        name.t ntr alpha
##   Fisher-LSD      none Yield$Variety   5  0.05
## 
## $means
##              Yield$Yield      std r      LCL      UCL  Min  Max    Q25   Q50
## African tall      30.450 7.403378 4 24.55723 36.34277 22.9 39.1 25.150 29.90
## Co-11             31.200 2.762849 4 25.30723 37.09277 29.5 35.3 29.575 30.00
## Co-24             25.550 5.674798 4 19.65723 31.44277 20.4 31.8 20.925 25.00
## FS-1              28.475 3.155287 4 22.58223 34.36777 24.4 32.1 27.550 28.70
## K-7               40.700 6.274286 4 34.80723 46.59277 32.1 47.0 38.700 41.85
##                 Q75
## African tall 35.200
## Co-11        31.625
## Co-24        29.625
## FS-1         29.625
## K-7          43.850
## 
## $comparison
## NULL
## 
## $groups
##              Yield$Yield groups
## K-7               40.700      a
## Co-11             31.200      b
## African tall      30.450      b
## FS-1              28.475      b
## Co-24             25.550      b
## 
## attr(,"class")
## [1] "group"

#Save the file in txt

sink("Yield.txt")
print(anova)
## Analysis of Variance Table
## 
## Response: Yield
##             Df Sum Sq Mean Sq F value  Pr(>F)  
## Replication  3  80.80  26.934  0.9205 0.46033  
## Variety      4 520.53 130.133  4.4476 0.01958 *
## Residuals   12 351.11  29.259                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print("DNMRT Result")
## [1] "DNMRT Result"
print(DNMRT$statistics)
##   MSerror Df   Mean       CV
##    29.259 12 31.275 17.29547
print(DNMRT$groups)
##              Yield$Yield groups
## K-7               40.700      a
## Co-11             31.200      b
## African tall      30.450      b
## FS-1              28.475      b
## Co-24             25.550      b
print("LSD Result")
## [1] "LSD Result"
print(LSD$statistics)
##   MSerror Df   Mean       CV  t.value      LSD
##    29.259 12 31.275 17.29547 2.178813 8.333639
print(LSD$groups)
##              Yield$Yield groups
## K-7               40.700      a
## Co-11             31.200      b
## African tall      30.450      b
## FS-1              28.475      b
## Co-24             25.550      b
sink()

#Script Prepared by Raj Popat, PhD scholar, Department of Agricultural Statistics, Anand Agricultural University, Anand