library(readxl)
CRDEqual <- read_excel("D:/COLLEGE 4TH YEAR/1st SEMESTER/STAT 55 EXPERIMENTAL DESIGN/MIDTERM/CRDEqual.xlsx",
col_types = c("text", "numeric"))
CRDEqual
Fittinf of linear model
model <- lm(CRDEqual$Yield ~ CRDEqual$Treatment)
Obtains R square and other statistics of fitted model
summary <- summary(model)
Carryout ANOVA
anova <- anova(model)
anova
Analysis of Variance Table
Response: CRDEqual$Yield
Df Sum Sq Mean Sq F value Pr(>F)
CRDEqual$Treatment 4 331.30 82.825 13.043 8.93e-05 ***
Residuals 15 95.25 6.350
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Below codes are used to obtain of fitted vs Residuals and Normal QQ
plots
par(mfrow=c(1,2))
plot(model, which = 1)
plot(model, which = 2)

Carry out LSD test
library(agricolae)
LSD <- LSD.test(CRDEqual$Yield,CRDEqual$Treatment,anova$`Df`[2],anova$`Mean Sq`[2])
LSD
$statistics
MSerror Df Mean CV t.value LSD
6.35 15 19.85 12.69481 2.13145 3.79793
$parameters
test p.ajusted name.t ntr alpha
Fisher-LSD none CRDEqual$Treatment 5 0.05
$means
CRDEqual$Yield std r LCL UCL Min Max Q25 Q50 Q75
1.0 21.25 2.872281 4 18.56446 23.93554 18 25 20.25 21.0 22.00
2.0 25.50 1.732051 4 22.81446 28.18554 24 28 24.75 25.0 25.75
3.0 21.25 3.774917 4 18.56446 23.93554 16 24 19.75 22.5 24.00
4.0 18.00 1.825742 4 15.31446 20.68554 16 20 16.75 18.0 19.25
5.0 13.25 1.707825 4 10.56446 15.93554 11 15 12.50 13.5 14.25
$comparison
NULL
$groups
CRDEqual$Yield groups
2.0 25.50 a
1.0 21.25 b
3.0 21.25 b
4.0 18.00 b
5.0 13.25 c
attr(,"class")
[1] "group"
Generate the txt file of analysis
sink("CRDEqualanalysis.txt")
print("ANOVA of CRDEqual")
[1] "ANOVA of CRDEqual"
print(anova)
Analysis of Variance Table
Response: CRDEqual$Yield
Df Sum Sq Mean Sq F value Pr(>F)
CRDEqual$Treatment 4 331.30 82.825 13.043 8.93e-05 ***
Residuals 15 95.25 6.350
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print("LSD ANALYSIS")
[1] "LSD ANALYSIS"
print(LSD$statistics)
MSerror Df Mean CV t.value LSD
6.35 15 19.85 12.69481 2.13145 3.79793
print(LSD$groups)
CRDEqual$Yield groups
2.0 25.50 a
1.0 21.25 b
3.0 21.25 b
4.0 18.00 b
5.0 13.25 c
sink()