Skip to content
Snippets Groups Projects
Commit 130b993f authored by Walmes Zeviani's avatar Walmes Zeviani
Browse files

Add dataset of a 3^3 RBD experiment, Pimentel pg 126.

parent 605a12bb
No related branches found
No related tags found
No related merge requests found
...@@ -695,3 +695,101 @@ NULL ...@@ -695,3 +695,101 @@ NULL
#' #'
#' #'
NULL NULL
#' @name sugarcaneYield4
#'
#' @title Triple factorial NPK fertilization on sugar cane yield
#'
#' @description These data are from an \eqn{3^3} factorial experiment
#' studing the effect of NPK on the yield of sugar cane.
#'
#' \itemize{
#' \item \code{block} a local control factor with 3 levels.
#' \item \code{rept} factor with 2 levels.
#' \item \code{N} integer coded nitrogen levels (0, 1, 2).
#' \item \code{P} integer coded phosphorus levels (0, 1, 2).
#' \item \code{K} integer coded potassium levels (0, 1, 2).
#' \item \code{yield} sugar cane yield (ton/ha).
#' }
#'
#' @details There is a missprint in the book for the 9th entry, which
#' has yield 59.0, that is coded as 202 istead of 220.
#'
#' @docType data
#'
#' @keywords datasets
#'
#' @usage data(sugarcaneYield4)
#'
#' @format a \code{data.frame} with 54 records and 6 variables.
#'
#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
#' ed.). Piracicaba, São Paulo: FEALQ. (page 126)
#'
#' @examples
#'
#' library(lattice)
#' library(latticeExtra)
#' library(multcomp)
#'
#' data(sugarcaneYield4)
#' str(sugarcaneYield4)
#'
#' xyplot(yield~N|P, groups=K,
#' auto.key=list(title="Potassim level", columns=3),
#' strip=strip.custom(var.name="Phosphorus", strip.names=TRUE,
#' strip.levels=TRUE, sep=": "),
#' data=sugarcaneYield4, type=c("p", "a"),
#' ylab=expression(Yield~(ton~ha^{-1})),
#' xlab="Nitrogen level level")
#'
#' ## Sums in each cell combination.
#' addmargins(with(sugarcaneYield4, tapply(yield, list(P, N), FUN=sum)))
#' addmargins(with(sugarcaneYield4, tapply(yield, list(K, N), FUN=sum)))
#' addmargins(with(sugarcaneYield4, tapply(yield, list(K, P), FUN=sum)))
#'
#' sugarcaneYield4 <- transform(sugarcaneYield4,
#' blockr=interaction(block, rept),
#' nitro=factor(N),
#' phosp=factor(P),
#' potas=factor(K))
#' str(sugarcaneYield4)
#'
#' m0 <- lm(yield~blockr+(nitro+phosp+potas)^3, data=sugarcaneYield4)
#' par(mfrow=c(2,2)); plot(m0); layout(1)
#' anova(m0)
#'
#' m1 <- update(m0, .~blockr+(nitro+phosp)^2)
#' par(mfrow=c(2,2)); plot(m1); layout(1)
#'
#' anova(m0, m1)
#' anova(m1)
#'
#' m2 <- aov(yield~blockr+nitro/phosp, data=sugarcaneYield4)
#' anova(m2)
#'
#' PinN <- sapply(paste0("nitro", levels(sugarcaneYield4$nitro)),
#' FUN=grep, x=names(coef(m2))[m2$assign==3L],
#' simplify=FALSE)
#'
#' summary(m2, split=list("nitro:phosp"=PinN))
#'
#' X <- model.matrix(m1)
#' X
#'
#' aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
#'
#' ## It is better use multcomp::LSmatrix().
#' L <- aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
#' rownames(L) <- with(L, paste0("N", nitro, ":P", phosp))
#' L <- as.matrix(L[, colnames(X)])
#' str(L)
#'
#' ## Least squares means for N:P combinations.
#' L%*%coef(m1)
#'
#' g1 <- glht(m1, linfct=L)
#'
#' confint(g1, calpha=univariate_calpha())
#'
NULL
##----------------------------------------------------------------------
## Data generation.
sugarcaneYield4 <- read.table("http://www.leg.ufpr.br/~walmes/data/pimentel_npk2.txt",
header=TRUE, sep="\t")
names(sugarcaneYield4)[c(1,6)] <- c("block", "yield")
sugarcaneYield4 <- transform(sugarcaneYield4, rept=factor(rept))
str(sugarcaneYield4)
sugarcaneYield4 <- sugarcaneYield4[
with(sugarcaneYield4, order(block, rept, N, P, K)),]
save(sugarcaneYield4, file="../data/sugarcaneYield4.RData")
##----------------------------------------------------------------------
## Examples.
library(lattice)
library(latticeExtra)
library(multcomp)
data(sugarcaneYield4)
str(sugarcaneYield4)
xyplot(yield~N|P, groups=K,
auto.key=list(title="Potassim level", columns=3),
strip=strip.custom(var.name="Phosphorus", strip.names=TRUE,
strip.levels=TRUE, sep=": "),
data=sugarcaneYield4, type=c("p", "a"),
ylab=expression(Yield~(ton~ha^{-1})),
xlab="Nitrogen level level")
## Sums in each cell combination.
addmargins(with(sugarcaneYield4, tapply(yield, list(P, N), FUN=sum)))
addmargins(with(sugarcaneYield4, tapply(yield, list(K, N), FUN=sum)))
addmargins(with(sugarcaneYield4, tapply(yield, list(K, P), FUN=sum)))
sugarcaneYield4 <- transform(sugarcaneYield4,
blockr=interaction(block, rept),
nitro=factor(N),
phosp=factor(P),
potas=factor(K))
str(sugarcaneYield4)
m0 <- lm(yield~blockr+(nitro+phosp+potas)^3, data=sugarcaneYield4)
par(mfrow=c(2,2)); plot(m0); layout(1)
anova(m0)
m1 <- update(m0, .~blockr+(nitro+phosp)^2)
par(mfrow=c(2,2)); plot(m1); layout(1)
anova(m0, m1)
anova(m1)
m2 <- aov(yield~blockr+nitro/phosp, data=sugarcaneYield4)
anova(m2)
PinN <- sapply(paste0("nitro", levels(sugarcaneYield4$nitro)),
FUN=grep, x=names(coef(m2))[m2$assign==3L],
simplify=FALSE)
summary(m2, split=list("nitro:phosp"=PinN))
X <- model.matrix(m1)
X
aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
## It is better use multcomp::LSmatrix().
L <- aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
rownames(L) <- with(L, paste0("N", nitro, ":P", phosp))
L <- as.matrix(L[, colnames(X)])
str(L)
## Least squares means for N:P combinations.
L%*%coef(m1)
g1 <- glht(m1, linfct=L)
confint(g1, calpha=univariate_calpha())
rm(list=ls())
load("../data/sugarcaneYield4.RData")
ls()
str(sugarcaneYield4)
File added
...@@ -2,7 +2,43 @@ ...@@ -2,7 +2,43 @@
;;; This format is meant to be slightly human-readable; ;;; This format is meant to be slightly human-readable;
;;; nevertheless, you probably don't want to edit it. ;;; nevertheless, you probably don't want to edit it.
;;; -*- End Of Bookmark File Format Version Stamp -*- ;;; -*- End Of Bookmark File Format Version Stamp -*-
(#1=(#("kornYield" 0 9 (#1=(#("sugarcaneYield4" 0 15
(bmkp-full-record #1#))
(filename . "~/GitLab/legTools/R/legTools.R")
(buffer-name . "legTools.R")
(front-context-string . "@name sugarcaneY")
(rear-context-string . "\n#'\n#'\nNULL\n\n#' ")
(front-context-region-string)
(rear-context-region-string)
(visits . 0)
(time . #2=(22014 55562 242485 989000))
(created . #2#)
(position . 21758))
#1=(#("filterCake" 0 10
(bmkp-full-record #1#))
(filename . "~/GitLab/legTools/R/legTools.R")
(buffer-name . "legTools.R")
(front-context-string . "@name filterCake")
(rear-context-string . "m1)\n#'\nNULL\n\n#' ")
(front-context-region-string)
(rear-context-region-string)
(visits . 0)
(time . #2=(22014 51467 333208 857000))
(created . #2#)
(position . 20038))
#1=(#("vinasseFert" 0 11
(bmkp-full-record #1#))
(filename . "~/GitLab/legTools/R/legTools.R")
(buffer-name . "legTools.R")
(front-context-string . "@name vinasseFer")
(rear-context-string . ")))\n#'\nNULL\n\n#' ")
(front-context-region-string)
(rear-context-region-string)
(visits . 0)
(time . #2=(22014 51452 901653 865000))
(created . #2#)
(position . 18556))
#1=(#("kornYield" 0 9
(bmkp-full-record #1#)) (bmkp-full-record #1#))
(filename . "~/GitLab/legTools/R/legTools.R") (filename . "~/GitLab/legTools/R/legTools.R")
(buffer-name . "legTools.R") (buffer-name . "legTools.R")
......
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/legTools.R
\docType{data}
\name{sugarcaneYield4}
\alias{sugarcaneYield4}
\title{Triple factorial NPK fertilization on sugar cane yield}
\format{a \code{data.frame} with 54 records and 6 variables.}
\source{
Frederico, P. (2009). Curso de Estatística Experimental (15th
ed.). Piracicaba, São Paulo: FEALQ. (page 126)
}
\usage{
data(sugarcaneYield4)
}
\description{
These data are from an \eqn{3^3} factorial experiment
studing the effect of NPK on the yield of sugar cane.
\itemize{
\item \code{block} a local control factor with 3 levels.
\item \code{rept} factor with 2 levels.
\item \code{N} integer coded nitrogen levels (0, 1, 2).
\item \code{P} integer coded phosphorus levels (0, 1, 2).
\item \code{K} integer coded potassium levels (0, 1, 2).
\item \code{yield} sugar cane yield (ton/ha).
}
}
\details{
There is a missprint in the book for the 9th entry, which
has yield 59.0, that is coded as 202 istead of 220.
}
\examples{
library(lattice)
library(latticeExtra)
library(multcomp)
data(sugarcaneYield4)
str(sugarcaneYield4)
xyplot(yield~N|P, groups=K,
auto.key=list(title="Potassim level", columns=3),
strip=strip.custom(var.name="Phosphorus", strip.names=TRUE,
strip.levels=TRUE, sep=": "),
data=sugarcaneYield4, type=c("p", "a"),
ylab=expression(Yield~(ton~ha^{-1})),
xlab="Nitrogen level level")
## Sums in each cell combination.
addmargins(with(sugarcaneYield4, tapply(yield, list(P, N), FUN=sum)))
addmargins(with(sugarcaneYield4, tapply(yield, list(K, N), FUN=sum)))
addmargins(with(sugarcaneYield4, tapply(yield, list(K, P), FUN=sum)))
sugarcaneYield4 <- transform(sugarcaneYield4,
blockr=interaction(block, rept),
nitro=factor(N),
phosp=factor(P),
potas=factor(K))
str(sugarcaneYield4)
m0 <- lm(yield~blockr+(nitro+phosp+potas)^3, data=sugarcaneYield4)
par(mfrow=c(2,2)); plot(m0); layout(1)
anova(m0)
m1 <- update(m0, .~blockr+(nitro+phosp)^2)
par(mfrow=c(2,2)); plot(m1); layout(1)
anova(m0, m1)
anova(m1)
m2 <- aov(yield~blockr+nitro/phosp, data=sugarcaneYield4)
anova(m2)
PinN <- sapply(paste0("nitro", levels(sugarcaneYield4$nitro)),
FUN=grep, x=names(coef(m2))[m2$assign==3L],
simplify=FALSE)
summary(m2, split=list("nitro:phosp"=PinN))
X <- model.matrix(m1)
X
aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
## It is better use multcomp::LSmatrix().
L <- aggregate(X~nitro+phosp, data=sugarcaneYield4, FUN=mean)
rownames(L) <- with(L, paste0("N", nitro, ":P", phosp))
L <- as.matrix(L[, colnames(X)])
str(L)
## Least squares means for N:P combinations.
L\%*\%coef(m1)
g1 <- glht(m1, linfct=L)
confint(g1, calpha=univariate_calpha())
}
\keyword{datasets}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment