From f2c389c29e6d72c12ddd1be8629b0f154e93f1b6 Mon Sep 17 00:00:00 2001 From: Walmes Zeviani <walmeszeviani@gmail.com> Date: Sat, 19 Sep 2015 23:33:18 -0300 Subject: [PATCH] Add dataset of a 2^3 experiment with NPK on korn yield, Pimentel pg 115. --- R/legTools.R | 87 +++++++++++++++++++++++-- data-raw/kornYield.R | 66 +++++++++++++++++++ data/kornYield.RData | Bin 0 -> 386 bytes data/potatoYield.RData | Bin 464 -> 466 bytes legTools.bmk | 77 +++++++++++++--------- man/kornYield.Rd | 76 +++++++++++++++++++++ man/plowing.Rd | 2 +- man/{potatoyield.Rd => potatoYield.Rd} | 10 +-- man/sugarcaneYield3.Rd | 10 +-- 9 files changed, 280 insertions(+), 48 deletions(-) create mode 100644 data-raw/kornYield.R create mode 100644 data/kornYield.RData create mode 100644 man/kornYield.Rd rename man/{potatoyield.Rd => potatoYield.Rd} (89%) diff --git a/R/legTools.R b/R/legTools.R index c6b3d2b..f062b1c 100644 --- a/R/legTools.R +++ b/R/legTools.R @@ -353,19 +353,19 @@ NULL #' experimental unit. #' #' \itemize{ -#' \item \code{row} the rows of the latin square that controls in +#' \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 +#' \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 +#' \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). +#' \item \code{yield} sugarcane yield (kg/plot). #' } #' -#' @details The levels of fetilization are in fact a combination of a +#' @details The levels of fertilization 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: @@ -496,3 +496,80 @@ NULL #' test=adjusted(type="single-step")) #' NULL + +#' @name kornYield +#' +#' @title Korn yield as function of fertilization with NPK +#' +#' @description These data are from an \eqn{2^3} factorial experiment +#' studing the effect of Nitrogen (N), Phosporus (P) and Potassium +#' (K) on korn yield in a randomized block design. +#' +#' \itemize{ +#' \item \code{block} a factor with 4 levels. +#' \item \code{N} low (-1) and high (+1) levels of nitrogen. +#' \item \code{P} low (-1) and high (+1) levels of phosporus. +#' \item \code{K} low (-1) and high (+1) levels of potassium. +#' \item \code{yield} korn yield (ton/ha). +#' } +#' +#' @docType data +#' +#' @keywords datasets +#' +#' @usage data(kornYield) +#' +#' @format a \code{data.frame} with 32 records and 4 variables. +#' +#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th +#' ed.). Piracicaba, São Paulo: FEALQ. (page 115) +#' +#' @examples +#' +#' library(lattice) +#' library(latticeExtra) +#' +#' data(kornYield) +#' str(kornYield) +#' +#' xyplot(yield~N|P, groups=K, +#' data=kornYield, type=c("p", "a"), +#' ylab=expression(Yield~(ton~ha^{-1})), +#' xlab="Nutrient level") +#' +#' xyplot(yield~N, groups=interaction(P, K), +#' data=kornYield, type=c("p", "a"), +#' auto.key=list(columns=2), +#' ylab=expression(Yield~(ton~ha^{-1})), +#' xlab="Nutrient level") +#' +#' m0 <- lm(yield~block+(N+P+K)^3, data=kornYield) +#' par(mfrow=c(2,2)); plot(m0); layout(1) +#' anova(m0) +#' +#' m1 <- update(m0, .~block+N+K) +#' par(mfrow=c(2,2)); plot(m1); layout(1) +#' +#' anova(m0, m1) +#' anova(m1) +#' +#' summary(m1) +#' +#' pred <- expand.grid(block="1", +#' N=seq(-1, 1, by=0.1), +#' K=seq(-1, 1, by=0.1)) +#' pred$mu <- predict(m1, newdata=pred) +#' +#' wireframe(mu~N+K, data=pred, +#' scales=list(arrows=FALSE), +#' zlab=list(expression(Yield~(ton~ha^{-1})), rot=90), +#' drape=TRUE, cuts=20, +#' col.regions=colorRampPalette( +#' color=brewer.pal(n=11, name="Spectral"))(21)) +#' +#' levelplot(mu~N+K, data=pred, aspect=1, +#' main=expression(Yield~(ton~ha^{-1})), +#' col.regions=colorRampPalette( +#' color=brewer.pal(n=11, name="Spectral"))) +#' +NULL diff --git a/data-raw/kornYield.R b/data-raw/kornYield.R new file mode 100644 index 0000000..bca2a49 --- /dev/null +++ b/data-raw/kornYield.R @@ -0,0 +1,66 @@ +##---------------------------------------------------------------------- +## Data generation. + +kornYield <- expand.grid(block=gl(4, 1), N=c(-1,1), P=c(-1,1), + K=c(-1,1), KEEP.OUT.ATTRS=FALSE) +kornYield$yield <- c(1.32, 2.12, 1.75, 2.35, 1.80, 2.20, 2.95, 2.96, + 1.66, 2.66, 1.73, 2.58, 1.72, 3.85, 2.62, 3.00, + 2.58, 3.56, 2.86, 2.75, 2.72, 3.20, 2.25, 2.75, + 2.26, 2.08, 1.95, 2.70, 2.95, 3.28, 2.40, 3.35) +str(kornYield) + +save(kornYield, file="../data/kornYield.RData") + +##---------------------------------------------------------------------- +## Examples. + +library(lattice) +library(latticeExtra) + +data(kornYield) +str(kornYield) + +xyplot(yield~N|P, groups=K, + data=kornYield, type=c("p", "a"), + ylab=expression(Yield~(ton~ha^{-1})), + xlab="Nutrient level") + +xyplot(yield~N, groups=interaction(P, K), + data=kornYield, type=c("p", "a"), + auto.key=list(columns=2), + ylab=expression(Yield~(ton~ha^{-1})), + xlab="Nutrient level") + +m0 <- lm(yield~block+(N+P+K)^3, data=kornYield) +par(mfrow=c(2,2)); plot(m0); layout(1) +anova(m0) + +m1 <- update(m0, .~block+N+K) +par(mfrow=c(2,2)); plot(m1); layout(1) + +anova(m0, m1) +anova(m1) + +summary(m1) + +pred <- expand.grid(block="1", + N=seq(-1, 1, by=0.1), + K=seq(-1, 1, by=0.1)) +pred$mu <- predict(m1, newdata=pred) + +wireframe(mu~N+K, data=pred, + scales=list(arrows=FALSE), + zlab=list(expression(Yield~(ton~ha^{-1})), rot=90), + drape=TRUE, cuts=20, + col.regions=colorRampPalette( + color=brewer.pal(n=11, name="Spectral"))(21)) + +levelplot(mu~N+K, data=pred, aspect=1, + main=expression(Yield~(ton~ha^{-1})), + col.regions=colorRampPalette( + color=brewer.pal(n=11, name="Spectral"))) + +rm(list=ls()) +load("../data/kornYield.RData") +ls() +str(kornYield) diff --git a/data/kornYield.RData b/data/kornYield.RData new file mode 100644 index 0000000000000000000000000000000000000000..3889dc55cb58acfb0e96e0359082ab3385d36533 GIT binary patch literal 386 zcmb2|=3oE=X6~X+gGXHtk`fXUk`mIAk`j{Gj3Q?=uqZQgGpkQ{cIKS^sqQmAXFU@W z62#cJHZWzzDXe7(W4Xj3!tipDz5LOIIhHF^S6Uu*n8pwxrgSQUBU$30#4&?5&RLvm zPFi*zHDG>lY?-Rs^e5tsk^dWJ@IU$ZS6<=(gLtlggWRiMk{vwkUT+s(k>9dyexuhz zgA4x_gjw9EpL$#H$F9(OjSpWh{3p?y|E*qO5}!}H!-F+{<vHFSun=ZRv)pj_MX6FK z|K001|1-T}$|_ALW#_E8@xQIZdV|isbE(lAj{GavzQM$9x583KpjyUa!8eDimLD2Q zIzy~C*s@4JIlwkGomKOH)s05sEPde+8MX5)+x(6+GG^VcPc|q>a4psk5L$AmQBvzX zYaxGC;iTy^W^-x#MI<(PTK+tFbA!+c{$m^shI<lUX(_tuWktqJiC@QVEE>XQY|7C2 p|Nnpc291<|=NqCb3YV%(Q+c&ilyR$p1J{OnhTQaLte;pJ7y$QTqbL9X literal 0 HcmV?d00001 diff --git a/data/potatoYield.RData b/data/potatoYield.RData index c650a954d79af8e08247412563bcb3aa15f310ef..b640671588ce1ba3ab701862821577e03eda9e25 100644 GIT binary patch literal 466 zcmb2|=3oE==B*(&{SG;Z$S!jgJ6anroqR{AV{KTWx7J0MMgB7cYGe{TIJTMwnACOs zYumqY|HJeZ+u!chI`Z_SCtvY)%kLL<=04n!qT=m&Od_4@d5?C&Dw#SZpH$8p)$3#Z zE8eBX-U>Z7MUca>cT!U<_o+Je|IDZ41M1z|ugFE;^VrRLEnx!h;)ym=HvZElov&x> zj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SHd4 X_1h-f+(C=a^|`EUbK>@H76t|Y@)h3* diff --git a/legTools.bmk b/legTools.bmk index bb8d9f9..93387a0 100644 --- a/legTools.bmk +++ b/legTools.bmk @@ -2,18 +2,31 @@ ;;; This format is meant to be slightly human-readable; ;;; nevertheless, you probably don't want to edit it. ;;; -*- End Of Bookmark File Format Version Stamp -*- -(#1=(#("wgpigs2" 0 7 +(#1=(#("kornYield" 0 9 (bmkp-full-record #1#)) (filename . "~/GitLab/legTools/R/legTools.R") (buffer-name . "legTools.R") - (front-context-string . "@name wgpigs2\n#'") - (rear-context-string . "an)\n#'\nNULL\n\n#' ") + (front-context-string . "@name kornYield\n") + (rear-context-string . "\"))\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) (visits . 0) - (time . #2=(22014 2449 877392 862000)) + (time . #2=(22014 6386 355822 993000)) (created . #2#) - (position . 14008)) + (position . 16336)) +#1=(#("wgpigs2" 0 7 + (bmkp-full-record #1#)) + (end-position . 14001) + (filename . "~/GitLab/legTools/R/legTools.R") + (buffer-name . "legTools.R") + (front-context-string . "@name wgpigs2\n#'") + (rear-context-string . "an)\n#'\nNULL\n\n#' ") + (front-context-region-string) + (rear-context-region-string) + (visits . 3) + (time 22014 6373 782337 593000) + (created 22014 2449 877392 862000) + (position . 14001)) #1=(#("sugarcaneYield3" 0 15 (bmkp-full-record #1#)) (filename . "~/GitLab/legTools/R/legTools.R") @@ -22,9 +35,9 @@ (rear-context-string . "an)\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2438 565160 262000)) - (created . #2#) + (visits . 2) + (time 22014 6373 622489 1000) + (created 22014 2438 565160 262000) (position . 11050)) #1=(#("sugarcaneYield2" 0 15 (bmkp-full-record #1#)) @@ -34,9 +47,9 @@ (rear-context-string . "y\")\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2428 365189 950000)) - (created . #2#) + (visits . 1) + (time 22014 6373 470955 812000) + (created 22014 2428 365189 950000) (position . 9217)) #1=(#("sugarcaneYield" 0 14 (bmkp-full-record #1#)) @@ -46,9 +59,9 @@ (rear-context-string . "y\")\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2414 357030 236000)) - (created . #2#) + (visits . 1) + (time 22014 6373 318366 504000) + (created 22014 2414 357030 236000) (position . 8152)) #1=(#("cassavaYield" 0 12 (bmkp-full-record #1#)) @@ -58,9 +71,9 @@ (rear-context-string . "2))\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2401 421345 289000)) - (created . #2#) + (visits . 1) + (time 22014 6373 167010 949000) + (created 22014 2401 421345 289000) (position . 6963)) #1=(#("defoliation" 0 11 (bmkp-full-record #1#)) @@ -70,9 +83,9 @@ (rear-context-string . "l\")\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2388 893464 613000)) - (created . #2#) + (visits . 1) + (time 22014 6373 30840 723000) + (created 22014 2388 893464 613000) (position . 3566)) #1=(#("plowing" 0 7 (bmkp-full-record #1#)) @@ -82,9 +95,9 @@ (rear-context-string . "y\")\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2377 645195 878000)) - (created . #2#) + (visits . 1) + (time 22014 6372 878551 941000) + (created 22014 2377 645195 878000) (position . 2330)) #1=(#("potatoYield" 0 11 (bmkp-full-record #1#)) @@ -94,9 +107,9 @@ (rear-context-string . "e\")\n#'\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2364 877635 749000)) - (created . #2#) + (visits . 1) + (time 22014 6372 742266 92000) + (created 22014 2364 877635 749000) (position . 1285)) #1=(#("wgpigs" 0 6 (bmkp-full-record #1#)) @@ -106,9 +119,9 @@ (rear-context-string . "gTools\nNULL\n\n#' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2268 166496 375000)) - (created . #2#) + (visits . 2) + (time 22014 6374 126563 478000) + (created 22014 2268 166496 375000) (position . 219)) #1=(#("legTools.R" 0 10 (bmkp-full-record #1#)) @@ -120,9 +133,9 @@ (rear-context-string . "ype package\n##' ") (front-context-region-string) (rear-context-region-string) - (visits . 0) - (time . #2=(22014 2255 246295 352000)) - (created . #2#) + (visits . 3) + (time 22014 6373 950617 320000) + (created 22014 2255 246295 352000) (position . 195)) #1=(#("DESCRIPTION" 0 11 (bmkp-full-record #1#)) diff --git a/man/kornYield.Rd b/man/kornYield.Rd new file mode 100644 index 0000000..be35646 --- /dev/null +++ b/man/kornYield.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{kornYield} +\alias{kornYield} +\title{Korn yield as function of fertilization with NPK} +\format{a \code{data.frame} with 32 records and 4 variables.} +\source{ +Frederico, P. (2009). Curso de Estatística Experimental (15th + ed.). Piracicaba, São Paulo: FEALQ. (page 115) +} +\usage{ +data(kornYield) +} +\description{ +These data are from an \eqn{2^3} factorial experiment + studing the effect of Nitrogen (N), Phosporus (P) and Potassium + (K) on korn yield in a randomized block design. + +\itemize{ + \item \code{block} a factor with 4 levels. + \item \code{N} low (-1) and high (+1) levels of nitrogen. + \item \code{P} low (-1) and high (+1) levels of phosporus. + \item \code{K} low (-1) and high (+1) levels of potassium. + \item \code{yield} korn yield (ton/ha). +} +} +\examples{ +library(lattice) +library(latticeExtra) + +data(kornYield) +str(kornYield) + +xyplot(yield~N|P, groups=K, + data=kornYield, type=c("p", "a"), + ylab=expression(Yield~(ton~ha^{-1})), + xlab="Nutrient level") + +xyplot(yield~N, groups=interaction(P, K), + data=kornYield, type=c("p", "a"), + auto.key=list(columns=2), + ylab=expression(Yield~(ton~ha^{-1})), + xlab="Nutrient level") + +m0 <- lm(yield~block+(N+P+K)^3, data=kornYield) +par(mfrow=c(2,2)); plot(m0); layout(1) +anova(m0) + +m1 <- update(m0, .~block+N+K) +par(mfrow=c(2,2)); plot(m1); layout(1) + +anova(m0, m1) +anova(m1) + +summary(m1) + +pred <- expand.grid(block="1", + N=seq(-1, 1, by=0.1), + K=seq(-1, 1, by=0.1)) +pred$mu <- predict(m1, newdata=pred) + +wireframe(mu~N+K, data=pred, + scales=list(arrows=FALSE), + zlab=list(expression(Yield~(ton~ha^{-1})), rot=90), + drape=TRUE, cuts=20, + col.regions=colorRampPalette( + color=brewer.pal(n=11, name="Spectral"))(21)) + +levelplot(mu~N+K, data=pred, aspect=1, + main=expression(Yield~(ton~ha^{-1})), + col.regions=colorRampPalette( + color=brewer.pal(n=11, name="Spectral"))) +} +\keyword{datasets} + diff --git a/man/plowing.Rd b/man/plowing.Rd index 66fc799..30c69ca 100644 --- a/man/plowing.Rd +++ b/man/plowing.Rd @@ -29,7 +29,7 @@ These data are from an experiment done by the engineer } \examples{ library(lattice) -data(potatoyield) +data(plowing) xyplot(yield~plow|block, data=plowing, type=c("p", "a"), ylab=expression(Yield~(t~ha^{-1})), diff --git a/man/potatoyield.Rd b/man/potatoYield.Rd similarity index 89% rename from man/potatoyield.Rd rename to man/potatoYield.Rd index 441fce5..3a07526 100644 --- a/man/potatoyield.Rd +++ b/man/potatoYield.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/legTools.R \docType{data} -\name{potatoyield} -\alias{potatoyield} +\name{potatoYield} +\alias{potatoYield} \title{Potato variety competition experiment} \format{a \code{data.frame} with 32 records and 3 variables.} \source{ @@ -10,7 +10,7 @@ Frederico, P. (2009). Curso de Estatística Experimental (15th ed.). Piracicaba, São Paulo: FEALQ. (page 76) } \usage{ -data(potatoyield) +data(potatoYield) } \description{ These data are from an experiment done by the engineer @@ -27,9 +27,9 @@ These data are from an experiment done by the engineer } \examples{ library(lattice) -data(potatoyield) +data(potatoYield) -plot(yield~variety, data=potatoyield, +plot(yield~variety, data=potatoYield, groups=block, type="o", ylab=expression(Yield~(t~ha^{-1})), xlab="Variety") diff --git a/man/sugarcaneYield3.Rd b/man/sugarcaneYield3.Rd index b7418bf..048af7a 100644 --- a/man/sugarcaneYield3.Rd +++ b/man/sugarcaneYield3.Rd @@ -18,20 +18,20 @@ These data are from an experiment done in a latin square experimental unit. \itemize{ - \item \code{row} the rows of the latin square that controls in + \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 + \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 + \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). + \item \code{yield} sugarcane yield (kg/plot). } } \details{ -The levels of fetilization are in fact a combination of a +The levels of fertilization 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: -- GitLab