Escolar Documentos
Profissional Documentos
Cultura Documentos
Compiled by
Rajender Parsad , B.N. Mandal , A. Dhandapani2, Sukanta Dash1, Eldho Varghese1 and
1 1
D.C. Mishra1
1
ICAR-I.A.S.R.I., Library Avenue, Pusa, New Delhi
2
ICAR-N.A.A.R.M, Rajendra Nagar, Hyderabad
A. Statistical Methods
A.1. Descriptive statistics
Datafile: descriptive.txt
v1 v2 v3 v4
12.4 45.15 1.25 1115.2
13.5 26.15 0.99 1216.4
16.3 78.14 1.63 1426.1
14.9 56.35 1.34 1635.2
14.5 65.21 0.96 1345.6
13.9 63.15 1.26 1248.3
18.2 46.15 0.64 1632.5
16.7 48.23 1.54 1458.6
23.2 86.35 1.48 1752.6
10.9 46.15 1.78 1496.8
23.9 31.25 0.69 1835.6
24.8 48.26 1.16 1934.6
26.1 46.23 1.49 1536.4
24.7 32.56 1.25 1269.7
1
sd(v1)
var(v1)
CoefVar(v1)
Skew(v1)
Kurt(v1)
Desc(descriptive)
# Histogram
library(Hmisc)
hist(descriptive,col="red")
# Density Plot
dens =density(descriptive)
plot(dens)
#Box Plot
boxplot(descriptive)
2
# R-Script for tests of significance
# Single Sample t-test (two-tailed)
attach(test)
names(test)
t.test(X, mu=7)
# t-test for comparing means of two independent populations with unequal variances
t.test(group~X)
# t-test for comparing means of two independent populations with equal variances
t.test(group~Y,var.equal=TRUE)
# Paired t-test
t.test(X,Y,paired=TRUE)
detach(test)
A.3. Correlation
Datafile: correlation.txt
pp ph ngl yld
142 0.525 8.2 2.47
143 0.64 9.5 4.76
107 0.66 9.3 3.31
78 0.66 7.5 1.97
100 0.46 5.9 1.34
86.5 0.345 6.4 1.14
103.5 0.86 6.4 1.5
155.99 0.33 7.5 2.03
80.88 0.285 8.4 2.54
109.77 0.59 10.6 4.9
61.77 0.265 8.3 2.91
79.11 0.66 11.6 2.76
155.99 0.42 8.1 0.59
61.81 0.34 9.4 0.84
74.5 0.63 8.4 3.87
97 0.705 7.2 4.47
93.14 0.68 6.4 3.31
37.43 0.665 8.4 1.57
36.44 0.275 7.4 0.53
51 0.28 7.4 1.15
104 0.28 9.8 1.08
49 0.49 4.8 1.83
54.66 0.385 5.5 0.76
55.55 0.265 5 0.43
88.44 0.98 5 4.08
99.55 0.645 9.6 2.83
63.99 0.635 5.6 2.57
101.77 0.29 8.2 7.42
138.66 0.72 9.9 2.62
90.22 0.63 8.4 2
3
76.92 1.25 7.3 1.99
126.22 0.58 6.9 1.36
80.36 0.605 6.8 0.68
150.23 1.19 8.8 5.36
56.5 0.355 9.7 2.12
136 0.59 10.2 4.16
144.5 0.61 9.8 3.12
157.33 0.605 8.8 2.07
91.99 0.38 7.7 1.17
121.5 0.55 7.7 3.62
64.5 0.32 5.7 0.67
116 0.455 6.8 3.05
77.5 0.72 11.8 1.7
70.43 0.625 10 1.55
133.77 0.535 9.3 3.28
89.99 0.49 9.8 2.69
0.43 55.55 0.265 5
4.08 88.44 0.98 5
2.83 99.55 0.645 9.6
2.57 63.99 0.635 5.6
7.42 101.77 0.29 8.2
2.62 138.66 0.72 9.9
2 90.22 0.63 8.4
1.99 76.92 1.25 7.3
1.36 126.22 0.58 6.9
0.68 80.36 0.605 6.8
5.36 150.23 1.19 8.8
2.12 56.5 0.355 9.7
4.16 136 0.59 10.2
3.12 144.5 0.61 9.8
2.07 157.33 0.605 8.8
1.17 91.99 0.38 7.7
3.62 121.5 0.55 7.7
0.67 64.5 0.32 5.7
3.05 116 0.455 6.8
1.7 77.5 0.72 11.8
1.55 70.43 0.625 10
#Test for Non-Constant Variance - quick way from fitted values as in lm1
summary(lm(abs(residuals(lm1)) ~ fitted(lm1)))
5
# Looking for multi-collinearity
library(car)
vif(lm1)
detach(reg)
B. Design of Experiments
B.1. Completely Randomized Designs
datafile: crd.txt
trt yield
1 850.5
1 453.6
1 878.85
1 623.7
1 510.3
1 765.45
1 680.4
1 595.35
1 538.65
1 850.5
1 850.5
1 793.8
1 1020.6
1 708.75
1 652.05
1 623.7
1 396.9
1 822.15
1 680.4
1 652.05
1 538.65
1 850.5
1 680.4
2 510.3
2 963.9
2 652.05
2 1020.6
2 878.85
2 567
2 680.4
2 538.65
2 567
2 510.3
2 425.25
2 567
2 623.7
2 538.65
2 737.1
2 453.6
6
2 481.95
2 368.55
2 567
2 595.35
2 567
2 595.35
3 992.25
3 850.5
3 1474.2
3 510.3
3 850.5
3 793.8
3 453.6
3 935.55
3 1190.7
3 481.95
3 623.7
3 878.85
3 1077.3
3 850.5
3 680.4
3 737.1
3 737.1
3 708.75
3 708.75
3 652.05
3 567
3 453.6
3 652.05
3 567
# R-Script for CRD
attach(crd)
names(crd)
trt=factor(trt)
lm1=lm(yield~trt)
anova(lm1)
library(lsmeans)
lsm=lsmeans(lm1,"trt")
lsm
pairs(lsm)
#pairs statement is an optional statement
#to provide letters for groups, need to install multcompView
library(multcompView)
cld(lsm,Letters="abc")
detach(crd)
7
B.2. Randomized Complete Block Designs
Datafile: rbd.txt
trt blk yield
1 1 1539.69
2 1 1261.85
3 1 1389.19
4 1 1192.39
5 1 1250.27
6 1 1296.58
7 1 1227.12
8 1 1273.43
9 1 1180.82
10 1 1296.58
11 1 1122.93
12 1 1250.27
13 1 1180.82
14 1 1146.09
15 1 1574.42
16 1 914.55
17 1 891.4
18 1 1227.12
19 1 1389.19
20 1 1331.31
21 1 1250.27
22 1 717.75
23 1 1169.24
24 1 1203.97
1 2 1412.35
2 2 1065.05
3 2 1516.54
4 2 1215.55
5 2 1203.97
6 2 1273.43
7 2 1018.74
8 2 1157.66
9 2 1203.97
10 2 1458.65
11 2 1065.05
12 2 926.13
13 2 1053.47
14 2 1180.82
15 2 1412.35
16 2 972.44
17 2 937.71
18 2 1203.97
19 2 1180.82
20 2 1157.66
21 2 1250.27
22 2 740.9
8
23 2 1157.66
24 2 1296.58
1 3 1319.73
2 3 1111.36
3 3 1203.97
4 3 1157.66
5 3 1366.04
6 3 1308.16
7 3 937.71
8 3 1088.2
9 3 1041.9
10 3 1250.27
11 3 1018.74
12 3 1030.32
13 3 717.75
14 3 856.67
15 3 1597.57
16 3 659.87
17 3 798.79
18 3 1389.19
19 3 1273.43
20 3 1180.82
21 3 1296.58
22 3 578.83
23 3 1111.36
24 3 1250.27
# R-Script for RCB Design (it is same for any block design)
attach(rbd)
names(rbd)
trt=factor(trt)
blk=factor(blk)
lm1=lm(yield~trt+blk)
anova(lm1)
library(lsmeans)
lsm=lsmeans(lm1,"trt")
lsm
pairs(lsm)
#pairs statement is an optional statement
#to provide letters for groups, need to install multcompView
library(multcompView)
cld(lsm, Letters="abcdefghij")
detach(rbd)
9
B.3. Resolvable Block Designs
datafile: resolvable.txt
rep blk trt syield
1 1 1 1555.6
1 1 5 1160.5
1 1 9 1308.6
1 1 13 1382.7
1 1 17 987.7
1 1 21 1135.8
1 2 2 1284
1 2 6 1086.4
1 2 10 1284
1 2 14 1111.1
1 2 18 938.3
1 2 22 1308.6
1 3 3 1234.6
1 3 7 419.8
1 3 11 1308.6
1 3 15 963
1 3 19 963
1 3 23 987.7
1 4 4 1234.6
1 4 8 987.7
1 4 12 1284
1 4 16 913.6
1 4 20 1160.5
1 4 24 790.1
2 1 1 1481.5
2 1 6 1086.4
2 1 11 1308.6
2 1 16 1284
2 1 19 1111.1
2 1 22 1185.2
2 2 2 987.7
2 2 7 308.6
2 2 12 1234.6
2 2 13 1308.6
2 2 20 765.4
2 2 23 938.3
2 3 3 1012.3
2 3 8 864.2
2 3 9 1234.6
2 3 14 938.3
2 3 17 913.6
2 3 24 864.2
2 4 4 1135.8
2 4 5 987.7
2 4 10 987.7
2 4 15 740.7
10
2 4 18 963
2 4 21 1135.8
3 1 1 1284
3 1 7 333.3
3 1 12 1135.8
3 1 15 839.5
3 1 18 814.8
3 1 24 888.9
3 2 2 1135.8
3 2 8 913.6
3 2 9 1456.8
3 2 16 1037
3 2 19 938.3
3 2 21 1037
3 3 3 963
3 3 5 1209.9
3 3 10 1259.3
3 3 13 1234.6
3 3 20 963
3 3 22 1111.1
3 4 4 1086.4
3 4 6 765.4
3 4 11 1111.1
3 4 14 1037
3 4 17 938.3
3 4 23 938.3
# R-Script for Resolvable block design or alpha design (infact similar steps can be used
for nested block designs)
attach(resolvable)
names(resolvable)
trt=factor(trt)
rep=factor(rep)
blk=factor(blk)
lm1=lm(syield~trt+blk+rep/blk-blk)
#anova(lm1)
library(car)
Anova(lm1,type="III")
library(lsmeans)
lsm=lsmeans(lm1,"trt")
lsm
pairs(lsm)
#pairs statement is an optional statement
#to provide letters for groups, need to install multcompView
library(multcompView)
cld(lsm,Letters="abcdefghij")
detach(resolvable)
11
B.4: Latin Square Design (steps are similar for any row-column design)
Datafile: latin.txt
row col trt yield
1 1 3 3.1
1 2 6 5.95
1 3 1 1.75
1 4 5 6.4
1 5 2 3.85
1 6 4 5.3
2 1 2 4.8
2 2 1 2.7
2 3 3 3.3
2 4 6 5.95
2 5 4 3.7
2 6 5 5.4
3 1 1 3
3 2 2 2.95
3 3 5 6.7
3 4 4 5.95
3 5 6 7.75
3 6 3 7.1
4 1 5 6.4
4 2 4 5.8
4 3 2 3.8
4 4 3 6.55
4 5 1 4.8
4 6 6 9.4
5 1 6 5.2
5 2 3 4.85
5 3 4 6.6
5 4 2 4.6
5 5 5 7
5 6 1 5
6 1 4 4.25
6 2 5 6.65
6 3 6 9.3
6 4 1 4.95
6 5 3 9.3
6 6 2 8.4
# R-Script for Latin Square Design (steps are similar for any row-column design)
attach(latin)
names(latin)
row=factor(row)
col=factor(col)
trt=factor(trt)
lm1=lm(yield~trt+row+col)
anova(lm1)
12
library(lsmeans)
lsm=lsmeans(lm1,"trt")
lsm
pairs(lsm)
#pairs statement is an optional statement
#to provide letters for groups, need to install multcompView
library(multcompView)
cld(lsm, Letters="abcdefghij")
detach(latin)
B.5 Treatment Contrast Analysis in a Block Design (similarly one can write contrasts
for any design
datafile: tree1.txt
rep trt height
1 1 144.44
1 2 113.5
1 3 60.88
1 4 163.44
1 5 110.11
1 6 260.05
1 7 114
1 8 91.94
1 9 156.11
1 10 80.2
2 1 145.11
2 2 118.61
2 3 90.94
2 4 158.55
2 5 116
2 6 102.27
2 7 115.16
2 8 58.16
2 9 177.97
2 10 108.05
3 1 104
3 2 118.61
3 3 80.33
3 4 158.88
3 5 119.66
3 6 256.22
3 7 114.88
3 8 76.83
3 9 148.22
3 10 45.18
4 1 105.44
4 2 123
13
4 3 92
4 4 153.11
4 5 103.22
4 6 217.8
4 7 106.33
4 8 79.5
4 9 183.17
4 10 79.55
# R-Script for Treatment Contrast Analysis (steps are similar for any design)
attach(tree1)
names(tree1)
tree=factor(trt)
rep=factor(rep)
lm1=lm(height~rep+tree)
anova(lm1)
#contrast analysis
library(lsmeans)
lsm = lsmeans(lm1, "tree")
lsm
pairs(lsm)
#pairs statement is an optional statement
#For grouping of treatments with letters, you need to install multcompView package and run
the following code
cld(lsm,Letters="ABCDEFGHI", sort="false")
contrast(lsm, list(con1 = c(1,1,1,1,-1,-1,-1,-1,-1,1),con2 = c(9,-1,-1,-1,-1,-1,-1,-1,-1,-1),con3
= c(1,1,1,1,0,0,0,0,-4,0),con4 = c(1,1,1,1,0,0,0,0,0,-4),con5 = c(0,0,0,0,1,1,1,1,-4,0),con6 =
c(0,0,0,0,1,1,1,1,0,-4)))
detach(tree1)
15 1 5 4
1 2 6 3
2 2 5 3
3 2 5 4
4 2 5 3
5 2 7 6
6 2 5 3
7 2 5 3
8 2 7 7
9 2 5 3
10 2 7 7
11 2 5 4
12 2 5 3
13 2 5 4
14 2 5 4
15 2 5 5
1 3 6 4
2 3 5 3
3 3 5 3
4 3 5 3
5 3 6 6
6 3 5 3
7 3 6 3
8 3 6 6
9 3 5 4
10 3 5 6
11 3 5 5
12 3 5 3
13 3 6 5
14 3 5 3
15 3 6 6
# R-Script for ANCOVA in RCB Design (steps are similar for any design)
attach(ANCOVA)
trt=factor(trt)
#ancova with class variable treatments and contiuous initial body weight variable
lm3=lm(y~trt+rep+x)
anova(lm3)
library(lsmeans)
lsm=lsmeans(lm3,"trt")
lsm
pairs(lsm)
#pairs statement is an optional statement
Library(multcompView)
cld(lsm,Letters="abcdefgh")
detach(ANCOVA)
15
B.7 Randomized Complete Block Design with Factorial Treatment Structure (Factorial
RCB Design)
Datafile: fact.txt
REP FYM P PSB TRT Yield
1 1 1 1 1 0.7
1 1 1 2 2 1.13
1 1 2 1 3 1.23
1 1 2 2 4 1.25
1 1 3 1 5 1.25
1 1 3 2 6 1.25
1 2 1 1 7 0.83
1 2 1 2 8 1.23
1 2 2 1 9 1.18
1 2 2 2 10 0.88
1 2 3 1 11 1.63
1 2 3 2 12 1.48
2 1 1 1 1 0.98
2 1 1 2 2 1.13
2 1 2 1 3 1.18
2 1 2 2 4 1.13
2 1 3 1 5 1.26
2 1 3 2 6 1.25
2 2 1 1 7 0.93
2 2 1 2 8 0.88
2 2 2 1 9 1.5
2 2 2 2 10 1.3
2 2 3 1 11 1.38
2 2 3 2 12 1.43
3 1 1 1 1 0.9
3 1 1 2 2 1.1
3 1 2 1 3 1.1
3 1 2 2 4 0.88
3 1 3 1 5 1.35
3 1 3 2 6 1.35
3 2 1 1 7 1.1
3 2 1 2 8 1.03
3 2 2 1 9 1.3
3 2 2 2 10 0.88
3 2 3 1 11 1.38
3 2 3 2 12 1.43
4 1 1 1 1 0.73
4 1 1 2 2 1.25
4 1 2 1 3 1.43
4 1 2 2 4 1.25
4 1 3 1 5 1.1
4 1 3 2 6 1.75
16
4 2 1 1 7 0.98
4 2 1 2 8 1.38
4 2 2 1 9 1.35
4 2 2 2 10 1.43
4 2 3 1 11 1.3
4 2 3 2 12 1.5
# R-Script for Factorial RCB Design (steps are similar for partially confounded
factorial experiments)
attach(fact)
names(fact)
rep=factor(REP)
fym=factor(FYM)
p=factor(P)
psb=factor(PSB)
lm1=lm(Yield~rep+fym+p+psb+fym:p+fym:psb+p:psb+fym:p:psb)
lm1
anova(lm1)
library(lsmeans)
lsm1=lsmeans(lm1,"fym")
lsm1
#All pairs statement are optional
pairs(lsm1)
lsm2=lsmeans(lm1,"p")
lsm2
pairs(lsm2)
lsm3=lsmeans(lm1,"psb")
lsm3
pairs(lsm3)
lsm4=lsmeans(lm1,~fym:p)
lsm4
pairs(lsm4)
lsm5=lsmeans(lm1,~fym:psb)
lsm5
pairs(lsm5)
lsm6=lsmeans(lm1,~p:psb)
lsm6
pairs(lsm6)
lsm7=lsmeans(lm1,~fym:p:psb)
lsm7
pairs(lsm7)
#to provide letters for groups, need to install multcompView
library(multcompView)
cld(lsm1, Letters="ABCDEF")
cld(lsm2, Letters="ABCDEF")
cld(lsm3,Letters="ABCDEF")
cld(lsm4,Letters="ABCDEFGHI")
cld(lsm5,Letters="ABCDEFGHI")
17
cld(lsm6,Letters="ABCDEFGHI")
cld(lsm7,Letters="ABCDEFGHIJKLM")
detach(fact)
# R-Script for Fractional Factorial Experiments for Estimating Main Effects and Two-
factor Interactions
attach(fractional)
names(fractional)
a=factor(A)
b=factor(B)
c=factor(C)
d=factor(D)
e=factor(E)
18
f=factor(F)
lm1=lm(X~a+b+c+d+e+f+a:b+a:c+a:d+a:e+a:f+b:c+b:d+b:e+b:f
+c:d+c:e+c:f+d:e+d:f+e:f)
anova(lm1)
library(lsmeans)
lsm1=lsmeans(lm1,"a")
lsm1
#All pairs statement are optional
pairs(lsm1)
lsm2=lsmeans(lm1,"b")
lsm2
pairs(lsm2)
lsm3=lsmeans(lm1,"c")
lsm3
pairs(lsm3)
lsm4=lsmeans(lm1,"d")
lsm4
pairs(lsm4)
lsm5=lsmeans(lm1,"e")
lsm5
pairs(lsm5)
lsm6=lsmeans(lm1,"f")
lsm6
pairs(lsm6)
lsm7=lsmeans(lm1,~a:b)
lsm7
pairs(lsm7)
lsm8=lsmeans(lm1,~a:c)
lsm8
pairs(lsm8)
lsm9=lsmeans(lm1,~a:d)
lsm9
pairs(lsm9)
lsm10=lsmeans(lm1,~a:e)
lsm10
pairs(lsm10)
lsm11=lsmeans(lm1,~a:f)
lsm11
pairs(lsm11)
lsm12=lsmeans(lm1,~b:c)
lsm12
pairs(lsm12)
lsm13=lsmeans(lm1,~b:d)
lsm13
pairs(lsm13)
lsm14=lsmeans(lm1,~b:e)
lsm14
pairs(lsm14)
19
lsm15=lsmeans(lm1,~b:f)
lsm15
pairs(lsm15)
lsm16=lsmeans(lm1,~c:d)
lsm16
pairs(lsm16)
lsm17=lsmeans(lm1,~c:e)
lsm17
pairs(lsm17)
lsm18=lsmeans(lm1,~c:f)
lsm18
pairs(lsm18)
lsm19=lsmeans(lm1,~d:e)
lsm19
pairs(lsm19)
lsm20=lsmeans(lm1,~d:f)
lsm20
pairs(lsm20)
lsm21=lsmeans(lm1,~e:f)
lsm21
pairs(lsm21)
library(multcompView)
cld(lsm1,Letters="ab")
cld(lsm2,Letters="ab")
cld(lsm3,Letters="ab")
cld(lsm4,Letters="ab")
cld(lsm5,Letters="ab")
cld(lsm6,Letters="ab")
cld(lsm7,Letters="abcd")
cld(lsm8,Letters="abcd")
cld(lsm9,Letters="abcd")
cld(lsm10,Letters="abcd")
cld(lsm11,Letters="abcd")
cld(lsm12,Letters="abcd")
cld(lsm13,Letters="abcd")
cld(lsm14,Letters="abcd")
cld(lsm15,Letters="abcd")
cld(lsm16,Letters="abcd")
cld(lsm17,Letters="abcd")
cld(lsm18,Letters="abcd")
cld(lsm19,Letters="abcd")
cld(lsm20,Letters="abcd")
cld(lsm21,Letters="abcd")
20
B.9: Split Plot Design
Datafile: plots in the package library
library(agricolae)
data(plots)
str(plots)
plots[,1] <-as.factor(plots[,1])
# split-plot analysis
model <- aov(yield ~ block + A + Error(plot)+ B + A:B, data=plots)
summary(model)
attach(plots)
b<-nlevels(B)
a<-nlevels(A)
r<-nlevels(block)
dfa <- df.residual(model$plot)
Ea <-deviance(model$plot)/dfa
dfb <- df.residual(model$Within)
Eb <-deviance(model$Within)/dfb
Eab <- (Ea +(b-1)*Eb)/(b*r)
#dfab<-(Ea +(b-1)*Eb)^2/(Ea^2/dfa +((b-1)*Eb)^2/dfb)
# Comparison A, A(b1), A(b2), A(b3)
title1= "CD at 5% for main plot means"
comparison1 <-LSD.test(yield,A,dfa,Ea)
title1
Comparison1
title2="CD at 5% for sub plot means"
comparison2 <-LSD.test(yield,B,dfb,Eb)
title2
comparison2
title3="CD at 5% for sub plot means at same level main plot"
sd3=sqrt(2*Eb/r)
cd3=qt(0.975,dfb)*sd3
title3
cd3
#comparison6 <-LSD.test(yield[A=="a1"],B[A=="a1"],dfb,Eb)
#comparison7 <-LSD.test(yield[A=="a2"],B[A=="a2"],dfb,Eb)
#comparison8 <-LSD.test(yield[B=="b1"],A[B=="b2"],dfab,Eab)
title4= "calculation Main Plot Means at same or different levels of subplot treatment"
ab <- sqrt(2*((b-1)*Eb+Ea)/(b*r))
tval <- ((b-1)*Eb*qt(0.975,dfb)+Ea*qt(0.975,dfa))/((b-1)*Eb + Ea)
title4=
CD4 <- ab*tval
title4
CD4
plots
detach(plots)
21
B.10: Strip Plot Design
Datafile: STRIP.txt
rep A B yield
1 1 1 103.6
1 1 2 126.25
1 1 3 115.39
1 2 1 103.8
1 2 2 119.32
1 2 3 106.4
1 3 1 138.3
1 3 2 132.81
1 3 3 128.9
2 1 1 91.65
2 1 2 103.3
2 1 3 101.56
2 2 1 116.65
2 2 2 125.4
2 2 3 144.65
2 3 1 106.6
2 3 2 129.35
2 3 3 138.3
3 1 1 126.91
3 1 2 119.9
3 1 3 134.19
3 2 1 131.19
3 2 2 119.73
3 2 3 127.11
3 3 1 125.8
3 3 2 113.8
3 3 3 125.35
4 1 1 129.61
4 1 2 118.39
4 1 3 123
4 2 1 120.81
4 2 2 120.26
4 2 3 125.6
4 3 1 104.71
4 3 2 135.6
4 3 3 114.31
5 1 1 128.29
5 1 2 129.4
5 1 3 123.71
5 2 1 131.29
5 2 2 122.85
5 2 3 138.2
5 3 1 123.31
5 3 2 142.71
5 3 3 152.21
6 1 1 121.06
22
6 1 2 112.95
6 1 3 115.91
6 2 1 119.6
6 2 2 122.45
6 2 3 126.61
6 3 1 126.96
6 3 2 130.94
6 3 3 131.7
#R Script for Strip Plot Design
attach(STRIP)
names(STRIP)
block=factor(rep)
A=factor(A)
B=factor(B)
library(agricolae)
model<-strip.plot(block, A, B, yield)
Ea = model$Ea
Eb = model$Eb
Ec = model$Ec
b<-nlevels(A)
a<-nlevels(B)
r<-nlevels(block)
dfa = model$gl.a
dfb = model$gl.b
dfc = model$gl.c
#Two vertical plot means at same or different levels of horizontal plot means
sd1 = sqrt(2*((b-1)*Ec+Ea)/(r*b))
twb = ((b-1)*Ec*qt(0.975,dfc)+Ea*qt(0.975,dfa))/((b-1)*Ec+Ea)
cd3 = sd1*twb
# Two horizontal plot means at same or different levels of vertical plot means
sd2 = sqrt(2*((a-1)*Ec+Eb)/(r*a))
twa = ((a-1)*Ec+qt(0.975,dfc)+Eb*qt(0.975,dfb))/((a-1)*Ec+Eb)
cd4 =sd2*twa
title1 = "CD for vertical plot means"
title1
cd1
title2 = "CD for horizontal plot means"
title2
23
cd2
title3 = "CD two vertical plot means at the same or different levels of horizontal plot means"
title3
cd3
title4 = "CD for horizontal plot means at the same or different levels of vertical plot means"
title4
cd4
detach(STRIP)
24
2 1 2 3289
2 1 3 2756
2 1 4 2600
2 1 5 2689
2 1 6 2578
2 1 7 3178
2 1 8 3244
2 1 9 2444
2 1 10 3156
2 1 11 2667
2 1 12 2689
2 2 1 2444
2 2 2 2667
2 2 3 2511
2 2 4 2444
2 2 5 2422
2 2 6 2400
2 2 7 3044
2 2 8 2911
2 2 9 2222
2 2 10 2978
2 2 11 2267
2 2 12 2444
2 3 1 2711
2 3 2 2889
2 3 3 2400
2 3 4 2222
2 3 5 2444
2 3 6 2222
2 3 7 2889
2 3 8 3111
2 3 9 2667
2 3 10 2756
2 3 11 2111
2 3 12 2289
3 1 1 3286
3 1 2 2518
3 1 3 757
3 1 4 2553
3 1 5 2908
3 1 6 1797
3 1 7 1749
3 1 8 1501
3 1 9 1513
3 1 10 2447
3 1 11 2600
3 1 12 1631
3 2 1 2459
3 2 2 2364
25
3 2 3 993
3 2 4 2388
3 2 5 2482
3 2 6 1560
3 2 7 1537
3 2 8 2317
3 2 9 1608
3 2 10 2459
3 2 11 2884
3 2 12 1466
3 3 1 3286
3 3 2 2364
3 3 3 875
3 3 4 2884
3 3 5 2884
3 3 6 2033
3 3 7 1537
3 3 8 2577
3 3 9 2104
3 3 10 2813
3 3 11 2648
3 3 12 1844
4 1 1 1370
4 1 2 904
4 1 3 858
4 1 4 904
4 1 5 1438
4 1 6 873
4 1 7 848
4 1 8 1668
4 1 9 910
4 1 10 1558
4 1 11 1508
4 1 12 1280
4 2 1 1209
4 2 2 729
4 2 3 942
4 2 4 959
4 2 5 1456
4 2 6 959
4 2 7 639
4 2 8 1770
4 2 9 907
4 2 10 1606
4 2 11 1389
4 2 12 1207
4 3 1 1320
4 3 2 1007
4 3 3 839
26
4 3 4 1155
4 3 5 1695
4 3 6 946
4 3 7 643
4 3 8 1607
4 3 9 1081
4 3 10 1705
4 3 11 1447
4 3 12 1256
5 1 1 2233
5 1 2 2222
5 1 3 2000
5 1 4 2667
5 1 5 2444
5 1 6 1778
5 1 7 1778
5 1 8 3000
5 1 9 1778
5 1 10 3778
5 1 11 3111
5 1 12 2222
5 2 1 2222
5 2 2 2444
5 2 3 1778
5 2 4 3289
5 2 5 2000
5 2 6 1889
5 2 7 1722
5 2 8 2889
5 2 9 1611
5 2 10 3667
5 2 11 3111
5 2 12 2000
5 3 1 2222
5 3 2 2722
5 3 3 1778
5 3 4 3333
5 3 5 2000
5 3 6 1556
5 3 7 1722
5 3 8 3222
5 3 9 1333
5 3 10 3556
5 3 11 3222
5 3 12 2222
6 1 1 1666
6 1 2 1611
6 1 3 1389
6 1 4 1511
27
6 1 5 1644
6 1 6 1833
6 1 7 1788
6 1 8 1644
6 1 9 1889
6 1 10 2000
6 1 11 944
6 1 12 1488
6 2 1 1333
6 2 2 1389
6 2 3 1244
6 2 4 1778
6 2 5 1622
6 2 6 1822
6 2 7 2333
6 2 8 2220
6 2 9 1822
6 2 10 1556
6 2 11 388
6 2 12 1400
6 3 1 2222
6 3 2 1944
6 3 3 2056
6 3 4 1889
6 3 5 1711
6 3 6 2111
6 3 7 1711
6 3 8 2220
6 3 9 2444
6 3 10 1356
6 3 11 722
6 3 12 1356
attach(COMBINED2)
names(COMBINED2)
loc=factor(loc)
levels(loc)
varn=factor(varn)
rep=factor(rep)
#Individual Analysis
out=by(COMBINED2,COMBINED2[,"loc"],function(x)
aov(syield~factor(rep)+factor(varn),data=x))
out=as.list(out)
sapply(out,summary)
lapply(out,TukeyHSD,"factor(varn)")
MSE=sapply(1:6,function(i,out) sum(out[[i]]$residual^2)/out[[i]]$df.residual,out)
28
residfs=sapply(1:6,function(i,out) out[[i]]$df.residual,out)
29
attach(rsd)
anal= rsm(yield~ SO(N,S), data=rsd)
summary(anal)
detach(rsd)
Note: In analysis of data generated from designed experiments, the R Scripts given above,
makes use of lm and library(lsmeans) and library(multcompView). In these scripts, the
adjusted means for treatment effects are obtained. In case of balanced and orthogonal
designs, the adjusted means are same as original means. For multiple comparison procedure,
the default option used is Tukey's Honest Significant Difference Test at 5% level of
significance. If one is analysing data from balanced and orthogonal designs, then one may use
different options for multiple comparisons in agricolae R Package.
30
C. Non-parametric Tests (For More Details on Examples, please refer to
lecture notes)
C.1. Binomial test
Suppose for example x= 8 and n=38, the test is as follows:
R Script:
binom.test(8, 38, p = 0.5)
(a) R Script (This is a goodness of fit test with equal expected frequencies):
chisq.test(c(25,32,18,20))
(b) R Script (This is a goodness of fit test with unequal expected frequencies):
ofs <- c(25,32,18,20)
null.probs <- c(1/3,1/3,1/6,1/6)
chisq.test(ofs, p=null.probs)
chisq.test(tbl)
R Script:
y<-c(5.2, 5.5,3.8,2.5,8.3,2.1,1.7,10,10,6.9,7.5,10.6)
runs.test(y)
f12 <- sum(x2>m)
f21 <- sum(x1<=m) # Pop.1 samples below or at median
f22 <- sum(x2<=m)
table <- matrix(c(f11,f12,f21,f22), nrow=2,ncol=2) # 2x2 contingency table
chisq.test(table)
R Script:
b<-c(80,80,92,79,92,82,88,89,92,83)
a<-c(86,84,78,90,92,77,89,90,90,86)
wilcox.exact(a,b, paired = TRUE, alternative = "two.sided")
R Script:
a<-c(40,30,40,45,55,30 )
b<-c(50,50,45,55,60,40 )
ks.test(a,b)
32
3 56
3 60
3 56
3 62
R Script:
attach(mydata)
fix(mydata)
kruskal.test(response ~ group, data = mydata)
D. Multivariate Techniques
D.1: Principal Component Analysis
Datafile: pca.txt
sn pp ph ngl yld
1 142 0.525 8.2 2.47
2 143 0.64 9.5 4.76
3 107 0.66 9.3 3.31
4 78 0.66 7.5 1.97
5 100 0.46 5.9 1.34
6 86.5 0.345 6.4 1.14
7 103.5 0.86 6.4 1.5
8 155.99 0.33 7.5 2.03
9 80.88 0.285 8.4 2.54
10 109.77 0.59 10.6 4.9
11 61.77 0.265 8.3 2.91
12 79.11 0.66 11.6 2.76
13 155.99 0.42 8.1 0.59
14 61.81 0.34 9.4 0.84
15 74.5 0.63 8.4 3.87
16 97 0.705 7.2 4.47
17 93.14 0.68 6.4 3.31
18 37.43 0.665 8.4 1.57
19 36.44 0.275 7.4 0.53
20 51 0.28 7.4 1.15
21 104 0.28 9.8 1.08
22 49 0.49 4.8 1.83
23 54.66 0.385 5.5 0.76
24 55.55 0.265 5 0.43
25 88.44 0.98 5 4.08
26 99.55 0.645 9.6 2.83
27 63.99 0.635 5.6 2.57
28 101.77 0.29 8.2 7.42
29 138.66 0.72 9.9 2.62
30 90.22 0.63 8.4 2
31 76.92 1.25 7.3 1.99
32 126.22 0.58 6.9 1.36
33 80.36 0.605 6.8 0.68
34 150.23 1.19 8.8 5.36
35 56.5 0.355 9.7 2.12
33
36 136 0.59 10.2 4.16
37 144.5 0.61 9.8 3.12
38 157.33 0.605 8.8 2.07
39 91.99 0.38 7.7 1.17
40 121.5 0.55 7.7 3.62
41 64.5 0.32 5.7 0.67
42 116 0.455 6.8 3.05
43 77.5 0.72 11.8 1.7
44 70.43 0.625 10 1.55
45 133.77 0.535 9.3 3.28
46 89.99 0.49 9.8 2.69
#Summary results
summary(output)
#scree plot
plot(output)
#Loadings
output$loadings
#PC scores
output$scores
loadings(output, cuttoff=0.0001)
print(output, digits=4, cuttoff=0.0001)
biplot(output)
detach(pca)
1 8 1190 1380
1 9 1032 1228
1 10 1250 1490
2 1 532 600
2 2 884 1025
2 3 800 945
2 4 765 900
2 5 835 1005
2 6 1070 1294
2 7 1140 1400
2 8 1040 1215
2 9 1145 1362
2 10 1180 1402
3 1 644 725
3 2 664 770
3 3 943 1120
3 4 893 1050
3 5 1071 1285
3 6 988 1195
3 7 880 1070
3 8 940 1090
3 9 1005 1195
3 10 860 1025
4 1 477 535
4 2 754 874
4 3 838 980
4 4 1052 1242
4 5 1037 1244
4 6 1170 1415
4 7 1075 1310
4 8 1150 1220
4 9 1035 1190
4 10 915 1025
35
E. Miscellaneous
E.1. Variance Components Estimation
Data:
Table 1: Insect Damage Data for Example
#R-Script
library(varComp)
data<-read.csv(“insect_damage.csv”)
vcf = varComp(Y~., data, ~Variety)
summary(vcf)
E.2. GE interaction and Stability Analysis
Data: Yield data of various genotypes selected from various location available in the package
agrocolae and name of the dataset is “plrv”. Partial data is given below-
#R-Script:
library(agricolae)
data(plrv)
attach(plrv)
model<- AMMI(Locality, Genotype, Rep, Yield)
detach(plrv)
# biplot PC2 vs PC1
plot(model)
detach(plrv)
library(plantbreeding)
data(fulldial)
out <-diallele1(dataframe = fulldial, male = "MALE", female = "FEMALE", progeny =
"TRT", replication = "REP", yvar = "YIELD" )
print(out)
out$anvout # analysis of variance
out$anova.mod1 # analysis of variance for GCA and SCA effects out$components.model1 #
model1 GCA, SCA and reciprocal components
out$gca.effmat # GCA effects
out$sca.effmat # SCA effect matrix
heatmap(out$sca.effmat, labRow = rownames(out$sca.effmat), labCol =
colnames(out$sca.effmat)) # heatmap plot of SCA matrix out$reciprocal.effmat # reciprocal
effect matrix
37
38