diff --git a/R/legTools.R b/R/legTools.R index c6b3d2b2763be31e82125cdba9d3c8f99c84d331..f062b1ccfbc8bc65fdea38a960de9382b9de6c0e 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 0000000000000000000000000000000000000000..bca2a49ad0772abb18b6acf311a5246b84fd5464 --- /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 Binary files /dev/null and b/data/kornYield.RData differ diff --git a/data/potatoYield.RData b/data/potatoYield.RData index c650a954d79af8e08247412563bcb3aa15f310ef..b640671588ce1ba3ab701862821577e03eda9e25 100644 Binary files a/data/potatoYield.RData and b/data/potatoYield.RData differ diff --git a/legTools.bmk b/legTools.bmk index bb8d9f981bcfe6a595e2fd43bd94b5799ed26b13..93387a08a5d6208de2a7f7c6c371ca8a235746ee 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 0000000000000000000000000000000000000000..be35646c7d45321f0319e8f3ad3301126e51277a --- /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 66fc799e3e867bf1900a1f18a2de5c528d62150e..30c69cacc5761c0d39ad9463b2e461cf81dcf26b 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 441fce52b311a438c6aa1f1e765ccf9a585cdbe2..3a0752606e317a05121ac7558ed23f1a5014e590 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 b7418bf52cefa4b442e48191f3ac4cce9dedaa33..048af7a28000f61f627a4957d2ed5d733898fa35 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: