diff --git a/R/legTools.R b/R/legTools.R index 734116e95c4f07e8ecfb91bd99719443d2ddfe1e..75be3eb232c6eb00f09c70e15b3831d0ca9ade74 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 0000000000000000000000000000000000000000..93692675b1ea163390f7e532126960a16855d5b3 --- /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 Binary files /dev/null and b/data/sugarcaneYield3.RData differ diff --git a/man/sugarcaneYield2.Rd b/man/sugarcaneYield2.Rd new file mode 100644 index 0000000000000000000000000000000000000000..da824a950fb64ee73f38aec5702e2e9c0806c72e --- /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 0000000000000000000000000000000000000000..b7418bf52cefa4b442e48191f3ac4cce9dedaa33 --- /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} +