Importing Data
library(readxl)
data <- read_excel("D:/COLLEGE 4TH YEAR/1st SEMESTER/STAT 55 EXPERIMENTAL DESIGN/MIDTERM/data.xlsx")
data
Verify the Variables Structure
str(data)
tibble [16 × 4] (S3: tbl_df/tbl/data.frame)
$ Row : num [1:16] 1 1 1 1 2 2 2 2 3 3 ...
$ Column : num [1:16] 1 2 3 4 1 2 3 4 1 2 ...
$ Varieties: chr [1:16] "B" "D" "C" "A" ...
$ Yield : num [1:16] 1.64 1.21 1.42 1.34 1.48 ...
Changing Variables Structure into Factors
data$Row <- as.factor(data$Row)
data$Column <- as.factor(data$Column)
data$Varieties <- as.factor(data$Varieties)
str(data)
tibble [16 × 4] (S3: tbl_df/tbl/data.frame)
$ Row : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 2 2 2 2 3 3 ...
$ Column : Factor w/ 4 levels "1","2","3","4": 1 2 3 4 1 2 3 4 1 2 ...
$ Varieties: Factor w/ 4 levels "A","B","C","D": 2 4 3 1 3 1 4 2 1 3 ...
$ Yield : num [1:16] 1.64 1.21 1.42 1.34 1.48 ...
attach(data)
Applying Analysis of Variance Model
model <- lm(Yield ~ Row+Column+Varieties)
anova(model)
Analysis of Variance Table
Response: Yield
Df Sum Sq Mean Sq F value Pr(>F)
Row 3 0.03015 0.010052 0.4654 0.716972
Column 3 0.82734 0.275781 12.7692 0.005148 **
Varieties 3 0.42684 0.142281 6.5879 0.025092 *
Residuals 6 0.12958 0.021597
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Mean Comparison Test
library(agricolae)
# LSD test
LSD.test(y = model,
trt = "Varieties",
DFerror = model$df.residual,
MSerror = deviance(model)/model$df.residual,
alpha = 0.05,
group = TRUE,
console = TRUE)
Study: model ~ "Varieties"
LSD t Test for Yield
Mean Square Error: 0.0215974
Varieties, means and individual ( 95 %) CI
Yield std r LCL UCL Min Max
A 1.46375 0.2386900 4 1.2839503 1.64355 1.185 1.670
B 1.47125 0.2095382 4 1.2914503 1.65105 1.290 1.665
C 1.06750 0.4426153 4 0.8877003 1.24730 0.660 1.475
D 1.33875 0.1795538 4 1.1589503 1.51855 1.180 1.565
Alpha: 0.05 ; DF Error: 6
Critical Value of t: 2.446912
least Significant Difference: 0.2542752
Treatments with the same letter are not significantly different.
Yield groups
B 1.47125 a
A 1.46375 a
D 1.33875 a
C 1.06750 b
# SNK test
SNK.test(y = Yield,
trt = Varieties,
DFerror = model$df.residual,
MSerror = deviance(model)/model$df.residual,
alpha = 0.05,
group = TRUE,
console = TRUE)
Study: Yield ~ Varieties
Student Newman Keuls Test
for Yield
Mean Square Error: 0.0215974
Varieties, means
Yield std r Min Max
A 1.46375 0.2386900 4 1.185 1.670
B 1.47125 0.2095382 4 1.290 1.665
C 1.06750 0.4426153 4 0.660 1.475
D 1.33875 0.1795538 4 1.180 1.565
Alpha: 0.05 ; DF Error: 6
Critical Range
2 3 4
0.2542752 0.3188452 0.3597299
Means with the same letter are not significantly different.
Yield groups
B 1.47125 a
A 1.46375 a
D 1.33875 a
C 1.06750 b