From 5ec8d295e46cfec36a7da7fc57aad4d55fda3742 Mon Sep 17 00:00:00 2001
From: Walmes Zeviani <walmes@ufpr.br>
Date: Thu, 8 Oct 2015 14:41:33 -0300
Subject: [PATCH] Add dataset of the chapter 11.

---
 R/legTools.R          |  66 ++++++++++++++++++++++++++++
 data-raw/cornYield3.R |  98 ++++++++++++++++++++++++++++++++++++++++++
 data/cornYield3.RData | Bin 0 -> 445 bytes
 3 files changed, 164 insertions(+)
 create mode 100644 data-raw/cornYield3.R
 create mode 100644 data/cornYield3.RData

diff --git a/R/legTools.R b/R/legTools.R
index 502dfd7..e063ffe 100644
--- a/R/legTools.R
+++ b/R/legTools.R
@@ -1439,3 +1439,69 @@ NULL
 #' }
 #'
 NULL
+
+#' @name cornYield3
+#'
+#' @title An triple lattice design in corn yield
+#'
+#' @description This is a experiment evaluating the yield (kg/plot) for
+#'     16 corn hybrids in a triple lattice design.
+#'
+#' \itemize{
+#'
+#' \item \code{rept} a categorical unordered factor with 3 levels.
+#'
+#' \item \code{block} a categorical unordered factor with 4 levels in
+#'     each \code{rept}, so 12 at all. Each block has size 4.
+#'
+#' \item \code{hybrid} a unordered factor with 16 levels, the corn
+#'     hybrids studied.
+#'
+#' \item \code{yield} the (continuous) response variable of the
+#'     experiment in kg/plot.
+#'
+#' }
+#'
+#' @docType data
+#'
+#' @keywords datasets
+#'
+#' @usage data(cornYield3)
+#'
+#' @format a \code{data.frame} with 48 records and 4 variables.
+#'
+#' @source Pimentel Gomes, F. (2009). Curso de Estatística Experimental
+#'     (15th ed.). Piracicaba, São Paulo: FEALQ. (page 215)
+#'
+#' @examples
+#'
+#' require(lattice)
+#'
+#' data(cornYield3)
+#' str(cornYield3)
+#'
+#' xyplot(yield~hybrid|rept, groups=block,
+#'        data=cornYield3, type="b",
+#'        ylab=expression(Yield~(kg~plot^{-1})),
+#'        xlab="Hybrid")
+#'
+#' xyplot(yield~hybrid, data=cornYield3,
+#'        jitter.x=TRUE, type=c("p", "a"),
+#'        ylab=expression(Yield~(kg~plot^{-1})),
+#'        xlab="Hybrid")
+#'
+#' g <- nlevels(cornYield3$hybrid)
+#' a <- seq(0, by=(2*pi)/(g), length.out=g)
+#' y <- sin(a)
+#' x <- cos(a)
+#' plot(y~x, asp=1, xlim=c(-1,1), ylim=c(-1,1))
+#'
+#' for (b in levels(cornYield3$block)){
+#'     cbn <- combn(x=as.integer(cornYield3$hybrid[cornYield3$block==b]),
+#'                  m=2)
+#'     segments(
+#'         x0=x[cbn[1,]], y0=y[cbn[1,]],
+#'         x1=x[cbn[2,]], y1=y[cbn[2,]], col=b)
+#' }
+#'
+NULL
diff --git a/data-raw/cornYield3.R b/data-raw/cornYield3.R
new file mode 100644
index 0000000..6053d7c
--- /dev/null
+++ b/data-raw/cornYield3.R
@@ -0,0 +1,98 @@
+##----------------------------------------------------------------------
+## Data generation. Pimentel page 215.
+
+cornYield3 <- read.table("clipboard", header=FALSE, sep="\t")
+cornYield3[, 4] <- as.numeric(sub(x=cornYield3[, 4], ",", "."))
+names(cornYield3) <- c("rept", "block", "hybrid", "yield")
+cornYield3 <- transform(cornYield3, rept=factor(rept),
+                        block=factor(block), hybrid=factor(hybrid))
+cornYield3 <- cornYield3[
+    with(cornYield3, order(rept, block, hybrid)), ]
+dput(cornYield3)
+
+cornYield3 <- structure(list(
+    rept = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
+                       1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
+                       2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
+                       3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L),
+                     .Label = c("1", "2", "3"),
+                     class = "factor"),
+    block = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
+                        4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
+                        3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L,
+                        2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L),
+                      .Label = c("1", "2", "3", "4"),
+                      class = "factor"),
+    hybrid = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
+                         12L, 13L, 14L, 15L, 16L, 1L, 5L, 9L, 13L, 2L,
+                         6L, 10L, 14L, 3L, 7L, 11L, 15L, 4L, 8L, 12L,
+                         16L, 1L, 6L, 11L, 16L, 2L, 5L, 12L, 15L, 3L,
+                         8L, 9L, 14L, 4L, 7L, 10L, 13L),
+                       .Label = c("1", "2", "3", "4", "5", "6", "7",
+                                  "8", "9", "10", "11", "12", "13",
+                                  "14", "15", "16"),
+                       class = "factor"),
+    yield = c(2, 2.9, 2.2, 3.9, 2.3, 2.5, 1.4, 1.7, 1.6, 3, 1.5, 2.1,
+              2.3, 3.4, 2, 2.8, 2.2, 2.3, 2.7, 1.4, 3.1, 2.8, 2.6, 2.8,
+              3.1, 2.9, 2.5, 2.4, 4, 2.8, 2.7, 1.5, 3, 2.9, 2.6, 3.1,
+              1.8, 1.9, 2.9, 2.5, 1.7, 2, 1.4, 2.3, 4.4, 3.7, 3.3,
+              2.2)),
+              row.names=1:48,
+              class = "data.frame")
+
+str(cornYield3)
+
+save(cornYield3, file="../data/cornYield3.RData")
+
+##----------------------------------------------------------------------
+
+aggregate(yield~block+rept, data=cornYield3, FUN=sum)
+aggregate(yield~hybrid, data=cornYield3, FUN=sum)
+
+m0 <- aov(terms(yield~rept/block+hybrid, keep.order=TRUE),
+          data=cornYield3)
+anova(m0)
+
+library(doBy)
+L <- LSmeans(m0, effect="hybrid")
+
+str(L)
+L$K
+
+##----------------------------------------------------------------------
+## Examples.
+
+require(lattice)
+
+data(cornYield3)
+str(cornYield3)
+
+xyplot(yield~hybrid|rept, groups=block,
+       data=cornYield3, type="b",
+       ylab=expression(Yield~(kg~plot^{-1})),
+       xlab="Hybrid")
+
+xyplot(yield~hybrid, data=cornYield3,
+       jitter.x=TRUE, type=c("p", "a"),
+       ylab=expression(Yield~(kg~plot^{-1})),
+       xlab="Hybrid")
+
+g <- nlevels(cornYield3$hybrid)
+a <- seq(0, by=(2*pi)/(g), length.out=g)
+y <- sin(a)
+x <- cos(a)
+plot(y~x, asp=1, xlim=c(-1,1), ylim=c(-1,1))
+
+for (b in levels(cornYield3$block)){
+    cbn <- combn(x=as.integer(cornYield3$hybrid[cornYield3$block==b]),
+                 m=2)
+    segments(
+        x0=x[cbn[1,]], y0=y[cbn[1,]],
+        x1=x[cbn[2,]], y1=y[cbn[2,]], col=b)
+}
+
+
+rm(list=ls())
+load("../data/cornYield3.RData")
+ls()
+str(cornYield3)
diff --git a/data/cornYield3.RData b/data/cornYield3.RData
new file mode 100644
index 0000000000000000000000000000000000000000..521496e22cc5b63519d06ff5eb2fef5a14d7fc66
GIT binary patch
literal 445
zcmV;u0Yd&CiwFP!000001I1L$PQpMCUbY2F`K$3gNTGmwY7ahvCp?x?BC%3ah=!Z5
zq0gkRV>B9c+x=z(n+PNv++@1ncINwLX1m?1%TdoB*^DvH49*!h1T?vLl$gnCVz#3+
zn_ti3Wa2SqoaSyZH^uB0QO6lS(v0J5tJ6vnKg7vGAgA!kx1}zD9sy4ymZKzG5KpO1
z!)Tdi0<CxK*S>yC&HkC6x6Oahskv*10Q!<+5NH4H@QuvnJW^Oym?f+@kHYH08p3j3
zOITZ}OHK_w4!(^z16p-(Oz1W?_!ama@XPSG!KXS};8&sF)ON=?Xm<bx1cn682%HnR
z0N`C$p{_zbg*=7&3Jnw*9`Zqo=G=hE5mdcm1f}PEyaa8m`Lq~;DdYTix%R)L-~U9s
z1^);1*lRxC6u%BV%2&aA%13c!xu!gU1s#evwKe&ve$*KlSUXxi(x*Btt$)&ouK$gB
z4ZfC#_JR6RbyGhl=&y;{-tJq!W#-{sOt%dEduA5jFDYQ0q|q&X&zsdan@z~I$}ezD
nu$HBd9TF{mmnT`M`^OovC*d;eOfx~jIa&V#5o%E6Kn4H+EPdC*

literal 0
HcmV?d00001

-- 
GitLab