if (FALSE) {
library(agridat)
data(lin.unbalanced)
dat <- lin.unbalanced
# location maximum, Lin & Binns table 1
# aggregate(yield ~ loc, data=dat, FUN=max)
# location mean/index, Lin & Binns, table 1
dat2 <- subset(dat, is.element(dat$gen,
c('Bruce','Laurier','Leger','S1','S2',
'S3','S4','S5','S6','S7','T1','T2')))
aggregate(yield ~ loc, data=dat2, FUN=mean)
libs(reshape2)
dat3 <- acast(dat, gen ~ loc, value.var="yield")
libs(lattice)
lattice::levelplot(t(scale(dat3)), main="lin.unbalanced", xlab="loc", ylab="genotype")
# calculate the superiority measure of Lin & Binns 1988.
# lower is better
locmax <- apply(dat3, 2, max, na.rm=TRUE)
P <- apply(dat3, 1, function(x) {
sum((x-locmax)^2, na.rm=TRUE)/(2*length(na.omit(x)))
})/1000
P <- sort(P)
round(P) # match Lin & Binns 1988 table 2, column P
}
Run the code above in your browser using DataLab