From 9bb4cea9f89fab78959aa0a113d6b8f8c9654ceb Mon Sep 17 00:00:00 2001
From: Walmes Zeviani <walmeszeviani@gmail.com>
Date: Thu, 17 Sep 2015 23:49:20 -0300
Subject: [PATCH] Add dataset from a LSD with a incomplete factorial, Pimentel
 pg 99.

---
 R/legTools.R               |  76 +++++++++++++++++++++++++++++++++++++
 data-raw/sugarcaneYield3.R |  55 +++++++++++++++++++++++++++
 data/sugarcaneYield3.RData | Bin 0 -> 496 bytes
 man/sugarcaneYield2.Rd     |  56 +++++++++++++++++++++++++++
 man/sugarcaneYield3.Rd     |  76 +++++++++++++++++++++++++++++++++++++
 5 files changed, 263 insertions(+)
 create mode 100644 data-raw/sugarcaneYield3.R
 create mode 100644 data/sugarcaneYield3.RData
 create mode 100644 man/sugarcaneYield2.Rd
 create mode 100644 man/sugarcaneYield3.Rd

diff --git a/R/legTools.R b/R/legTools.R
index 734116e..75be3eb 100644
--- a/R/legTools.R
+++ b/R/legTools.R
@@ -343,3 +343,79 @@ NULL
 #' aggregate(yield~variety, data=sugarcaneYield2, FUN=mean)
 #'
 NULL
+
+#' @name sugarcaneYield3
+#'
+#' @title Sugarcane yield as function of fertilization strategy
+#'
+#' @description These data are from an experiment done in a latin square
+#'     design of size 5. Sugarcane yield (kg/plot) was recorded in each
+#'     experimental unit.
+#'
+#' \itemize{
+#'     \item \code{row} the rows of the latin square that controls in
+#'     one dimention. A categorical unordered factor with 6 levels.
+#'     \item \code{col} the columns of the latin square that controls in
+#'     one dimention perpendicular to the previus. A categorical
+#'     unordered factor with 6 levels.
+#'     \item \code{fertil} a categorical unordered factor with 6
+#'     levels that is the fertilization strategy applied. These levels
+#'     are a result of treatment cells in a three incomplete factorial
+#'     arrangrment. See detais for more information.
+#'     \item \code{yield} sugarcane yield (kg/plot).
+#' }
+#'
+#' @details The levels of fetilization are in fact a combination of a
+#'     \eqn{3^2} factorial experiment but not all cells are present, so
+#'     this is a (intentional) incomplete three factorial
+#'     experiment. The factors used were limestone (A: present, a:
+#'     absent), \emph{Crotalaria juncae} (B: present, b: absent) and
+#'     fertilizer (C: present, c: absent). Therefore, the level ABC
+#'     means that all three factors are present. To access the effect of
+#'     each factor and interactions can be applied contrasts.
+#'
+#' @docType data
+#'
+#' @keywords datasets
+#'
+#' @usage data(sugarcaneYield3)
+#'
+#' @format a \code{data.frame} with 28 records and 3 variables.
+#'
+#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
+#'     ed.). Piracicaba, São Paulo: FEALQ. (page 99)
+#'
+#' @examples
+#'
+#' library(lattice)
+#' library(latticeExtra)
+#'
+#' xyplot(yield~fertil|col,  groups=row, data=sugarcaneYield3,
+#'        ylab=expression(Yield~(kg~plot^{-1})),
+#'        xlab="Fertilization", scales=list(x=list(rot=90)))
+#'
+#' ## display.brewer.all()
+#'
+#' levelplot(yield~row+col,
+#'           data=sugarcaneYield3, aspect="iso",
+#'           xlab="Row", ylab="Column",
+#'           main=expression(Yield~(kg~plot^{-1})),
+#'           col.regions=colorRampPalette(
+#'               colors=brewer.pal(n=11, name="Spectral")))+
+#'     layer(with(sugarcaneYield3,
+#'                panel.text(x=row, y=col,
+#'                           label=sprintf("%s\n%0.2f", fertil, yield))))
+#'
+#' aggregate(yield~row, data=sugarcaneYield3, FUN=mean)
+#' aggregate(yield~col, data=sugarcaneYield3, FUN=mean)
+#' aggregate(yield~fertil, data=sugarcaneYield3, FUN=mean)
+#'
+#' ## The incomplete factorial structure.
+#' X <- mapply(FUN=grepl, c("A", "B", "C"),
+#'             MoreArgs=list(x=sugarcaneYield3$fertil))*1
+#' sugarcaneYield3 <- cbind(sugarcaneYield3, as.data.frame(X))
+#'
+#' ftable(with(sugarcaneYield3, tapply(yield, list(B, A, C), FUN=mean)))
+#' aggregate(yield~A+B+C, data=sugarcaneYield3, FUN=mean)
+#'
+NULL
diff --git a/data-raw/sugarcaneYield3.R b/data-raw/sugarcaneYield3.R
new file mode 100644
index 0000000..9369267
--- /dev/null
+++ b/data-raw/sugarcaneYield3.R
@@ -0,0 +1,55 @@
+##----------------------------------------------------------------------
+## Data generation.
+
+sugarcaneYield3 <- read.table("http://www.leg.ufpr.br/~walmes/data/pimentel_crotalaria.txt",
+                              header=TRUE, sep="\t")
+names(sugarcaneYield3) <- c("row", "col", "fertil", "yield")
+sugarcaneYield3 <- transform(sugarcaneYield3, row=factor(row),
+                             col=factor(col))
+
+aggregate(yield~fertil, data=sugarcaneYield3, FUN=mean)
+levels(sugarcaneYield3$fertil) <- c("ABC", "ABc", "Ab", "aBC", "aBc", "ab")
+str(sugarcaneYield3)
+
+sugarcaneYield3 <- sugarcaneYield3[with(sugarcaneYield3, order(row, col)),]
+
+save(sugarcaneYield3, file="../data/sugarcaneYield3.RData")
+
+##----------------------------------------------------------------------
+## Examples.
+
+library(lattice)
+library(latticeExtra)
+
+xyplot(yield~fertil|col,  groups=row, data=sugarcaneYield3,
+       ylab=expression(Yield~(kg~plot^{-1})),
+       xlab="Fertilization", scales=list(x=list(rot=90)))
+
+## display.brewer.all()
+
+levelplot(yield~row+col,
+          data=sugarcaneYield3, aspect="iso",
+          xlab="Row", ylab="Column",
+          main=expression(Yield~(kg~plot^{-1})),
+          col.regions=colorRampPalette(
+              colors=brewer.pal(n=11, name="Spectral")))+
+    layer(with(sugarcaneYield3,
+               panel.text(x=row, y=col,
+                          label=sprintf("%s\n%0.2f", fertil, yield))))
+
+aggregate(yield~row, data=sugarcaneYield3, FUN=mean)
+aggregate(yield~col, data=sugarcaneYield3, FUN=mean)
+aggregate(yield~fertil, data=sugarcaneYield3, FUN=mean)
+
+## The incomplete factorial structure.
+X <- mapply(FUN=grepl, c("A", "B", "C"),
+            MoreArgs=list(x=sugarcaneYield3$fertil))*1
+sugarcaneYield3 <- cbind(sugarcaneYield3, as.data.frame(X))
+
+ftable(with(sugarcaneYield3, tapply(yield, list(B, A, C), FUN=mean)))
+aggregate(yield~A+B+C, data=sugarcaneYield3, FUN=mean)
+
+rm(list=ls())
+load("../data/sugarcaneYield3.RData")
+ls()
+str(sugarcaneYield3)
diff --git a/data/sugarcaneYield3.RData b/data/sugarcaneYield3.RData
new file mode 100644
index 0000000000000000000000000000000000000000..1df4969b569f0c7b5f7f26cbde7a35f77331731f
GIT binary patch
literal 496
zcmb2|=3oE=X6~X+gGXHtk`fXUk`mIAk`j{Gj3Q?=uqZQgGpkQ{rmyGgujA!+#=G~7
z&sk5yw1fmPwv~*R_Bcebt`V_LJJdL{FhNXahA4a5;l98*=ci4Mnl>w#Cxx>iRdG>I
zn?ajkPa;q9i~|zO4B8}T&0KTRvh%2c@<Xwus%q1ph%-k1ztF_?ELBV;oqvMG32C4I
zD+MLa7zBU#J)iTHSenZAjSfFgyldGh=w|HrbmqiK!p4)NX4ptis&iXmv&kyOct*jG
z`8O|~lsxFuW;9b~azaxl$4{4*nj|4Z#e)afxj5S&oIj@UK;ToJ`-9hEmF)`_{gdcj
z-!9v<I{IlD%f3PmuLK6hb_UCdtJ>eamZ{-)e8PPClEZ<6uX#A;lycbei`ZRxFCfGa
zC@)kq_w=@ePUjD&W;z(0R$L*O<S!t8L1bc9dxN_`F;mfkUzZzCiN}|7Y+?$G;X4>m
z>~!-wqwco?4(;{}2elN^J1kgq+h&O8@D`@8(D9hP*7-%<3hM<W1!70+{y!J^yD(DV
zv-2H=cl<p~ADVY8cyvyn`0%O&HD7q9O`kEF>vV$7h7J0s^xF+5e=dH|I5#R}66fQM
zVNItrOfFkAN_|aGYZ6imX1;NG0ZW%D)6O6vZ=tW3x*DPuO#H#mko@xYAq`dr1^}g_
B)ZzdD

literal 0
HcmV?d00001

diff --git a/man/sugarcaneYield2.Rd b/man/sugarcaneYield2.Rd
new file mode 100644
index 0000000..da824a9
--- /dev/null
+++ b/man/sugarcaneYield2.Rd
@@ -0,0 +1,56 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/legTools.R
+\docType{data}
+\name{sugarcaneYield2}
+\alias{sugarcaneYield2}
+\title{Sugarcane variety competition experiment}
+\format{a \code{data.frame} with 28 records and 3 variables.}
+\source{
+Frederico, P. (2009). Curso de Estatística Experimental (15th
+    ed.). Piracicaba, São Paulo: FEALQ. (page 96)
+}
+\usage{
+data(sugarcaneYield2)
+}
+\description{
+These data are from an experiment done in a latin square
+    design of size 5. Sugarcane yield (kg/plot) was recorded in each
+    experimental unit.
+
+\itemize{
+    \item \code{row} the rows of the latin square that controls in
+    one dimention. A categorical unordered factor with 5 levels.
+    \item \code{col} the columns of the latin square that controls in
+    one dimention perpendicular to the previus. A categorical
+    unordered factor with 5 levels.
+    \item \code{variety} a categorical unordered factor with 5
+    levels.
+    \item \code{yield} sugarcane yield (kg/plot).
+}
+}
+\examples{
+library(lattice)
+library(latticeExtra)
+
+xyplot(yield~variety|col,  groups=row, data=sugarcaneYield2,
+       ylab=expression(Yield~(kg~plot^{-1})),
+       xlab="Variety")
+
+## display.brewer.all()
+
+levelplot(yield~row+col,
+          data=sugarcaneYield2, aspect="iso",
+          xlab="Row", ylab="Column",
+          main=expression(Yield~(kg~plot^{-1})),
+          col.regions=colorRampPalette(
+              colors=brewer.pal(n=11, name="Spectral")))+
+    layer(with(sugarcaneYield2,
+               panel.text(x=row, y=col,
+                          label=paste(variety, yield))))
+
+aggregate(yield~row, data=sugarcaneYield2, FUN=mean)
+aggregate(yield~col, data=sugarcaneYield2, FUN=mean)
+aggregate(yield~variety, data=sugarcaneYield2, FUN=mean)
+}
+\keyword{datasets}
+
diff --git a/man/sugarcaneYield3.Rd b/man/sugarcaneYield3.Rd
new file mode 100644
index 0000000..b7418bf
--- /dev/null
+++ b/man/sugarcaneYield3.Rd
@@ -0,0 +1,76 @@
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/legTools.R
+\docType{data}
+\name{sugarcaneYield3}
+\alias{sugarcaneYield3}
+\title{Sugarcane yield as function of fertilization strategy}
+\format{a \code{data.frame} with 28 records and 3 variables.}
+\source{
+Frederico, P. (2009). Curso de Estatística Experimental (15th
+    ed.). Piracicaba, São Paulo: FEALQ. (page 99)
+}
+\usage{
+data(sugarcaneYield3)
+}
+\description{
+These data are from an experiment done in a latin square
+    design of size 5. Sugarcane yield (kg/plot) was recorded in each
+    experimental unit.
+
+\itemize{
+    \item \code{row} the rows of the latin square that controls in
+    one dimention. A categorical unordered factor with 6 levels.
+    \item \code{col} the columns of the latin square that controls in
+    one dimention perpendicular to the previus. A categorical
+    unordered factor with 6 levels.
+    \item \code{fertil} a categorical unordered factor with 6
+    levels that is the fertilization strategy applied. These levels
+    are a result of treatment cells in a three incomplete factorial
+    arrangrment. See detais for more information.
+    \item \code{yield} sugarcane yield (kg/plot).
+}
+}
+\details{
+The levels of fetilization are in fact a combination of a
+    \eqn{3^2} factorial experiment but not all cells are present, so
+    this is a (intentional) incomplete three factorial
+    experiment. The factors used were limestone (A: present, a:
+    absent), \emph{Crotalaria juncae} (B: present, b: absent) and
+    fertilizer (C: present, c: absent). Therefore, the level ABC
+    means that all three factors are present. To access the effect of
+    each factor and interactions can be applied contrasts.
+}
+\examples{
+library(lattice)
+library(latticeExtra)
+
+xyplot(yield~fertil|col,  groups=row, data=sugarcaneYield3,
+       ylab=expression(Yield~(kg~plot^{-1})),
+       xlab="Fertilization", scales=list(x=list(rot=90)))
+
+## display.brewer.all()
+
+levelplot(yield~row+col,
+          data=sugarcaneYield3, aspect="iso",
+          xlab="Row", ylab="Column",
+          main=expression(Yield~(kg~plot^{-1})),
+          col.regions=colorRampPalette(
+              colors=brewer.pal(n=11, name="Spectral")))+
+    layer(with(sugarcaneYield3,
+               panel.text(x=row, y=col,
+                          label=sprintf("\%s\\n\%0.2f", fertil, yield))))
+
+aggregate(yield~row, data=sugarcaneYield3, FUN=mean)
+aggregate(yield~col, data=sugarcaneYield3, FUN=mean)
+aggregate(yield~fertil, data=sugarcaneYield3, FUN=mean)
+
+## The incomplete factorial structure.
+X <- mapply(FUN=grepl, c("A", "B", "C"),
+            MoreArgs=list(x=sugarcaneYield3$fertil))*1
+sugarcaneYield3 <- cbind(sugarcaneYield3, as.data.frame(X))
+
+ftable(with(sugarcaneYield3, tapply(yield, list(B, A, C), FUN=mean)))
+aggregate(yield~A+B+C, data=sugarcaneYield3, FUN=mean)
+}
+\keyword{datasets}
+
-- 
GitLab