From 69448cbac456271fe42268819f70560e3824eff6 Mon Sep 17 00:00:00 2001
From: Walmes Zeviani <walmeszeviani@gmail.com>
Date: Sat, 19 Sep 2015 22:31:32 -0300
Subject: [PATCH] Add dataset of a LSD experiment about weight gain in pigs.

---
 DESCRIPTION        |   3 +-
 R/legTools.R       |  87 ++++++++++++++++++++++++++++++++++++++++++---
 data-raw/wgpigs2.R |  63 ++++++++++++++++++++++++++++++++
 data/wgpigs2.RData | Bin 0 -> 328 bytes
 man/wgpigs2.Rd     |  76 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 223 insertions(+), 6 deletions(-)
 create mode 100644 data-raw/wgpigs2.R
 create mode 100644 data/wgpigs2.RData
 create mode 100644 man/wgpigs2.Rd

diff --git a/DESCRIPTION b/DESCRIPTION
index 1180dc1..5b665af 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -18,7 +18,8 @@ Depends:
     gWidgetstcltk,
     knitr,
     markdown,
-    RWordPress
+    RWordPress,
+    multcomp
 License: GPL-3 | file LICENSE
 URL: http://git.leg.ufpr.br/leg/legTools
 BugReports: http://git.leg.ufpr.br/leg/legTools/issues
diff --git a/R/legTools.R b/R/legTools.R
index 75be3eb..c6b3d2b 100644
--- a/R/legTools.R
+++ b/R/legTools.R
@@ -47,7 +47,7 @@ NULL
 #'
 NULL
 
-#' @name potatoyield
+#' @name potatoYield
 #'
 #' @title Potato variety competition experiment
 #'
@@ -67,7 +67,7 @@ NULL
 #'
 #' @keywords datasets
 #'
-#' @usage data(potatoyield)
+#' @usage data(potatoYield)
 #'
 #' @format a \code{data.frame} with 32 records and 3 variables.
 #'
@@ -76,9 +76,9 @@ NULL
 #'
 #' @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")
@@ -116,7 +116,7 @@ NULL
 #'
 #' @examples
 #' library(lattice)
-#' data(potatoyield)
+#' data(plowing)
 #'
 #' xyplot(yield~plow|block, data=plowing, type=c("p", "a"),
 #'        ylab=expression(Yield~(t~ha^{-1})),
@@ -419,3 +419,80 @@ NULL
 #' aggregate(yield~A+B+C, data=sugarcaneYield3, FUN=mean)
 #'
 NULL
+
+#' @name wgpigs2
+#'
+#' @title Age of castration in pig weight gain
+#'
+#' @description This is an artifial dataset corresponding a experiment
+#'     to study the effect of feeding type (factor with 4 categorical
+#'     nominal levels) in pig weight gain. The experiment was a
+#'     randomized complete design with five experimental units per
+#'     treatment level. The experimental unit was a pig. The response
+#'     measured was weight gain from the beggining to the end of the
+#'     experiment.
+#'
+#' \itemize{
+#'   \item \code{litter} a categorical factor with 4 levels that
+#'     represents the rows of the lattin square design and control for
+#'     the differences among litters.
+#'   \item code{size} a categorical ordered variable that represents the
+#'     columns of latin square desing and control for the weight of the
+#'     animals at the beggining of the experiment.
+#'   \item \code{age} age of the animal (days) when castration was
+#'     done. \code{controls} are the animals without castration.
+#'   \item \code{wg} weight gain (kg) after 252 days.
+#' }
+#'
+#' @docType data
+#'
+#' @keywords datasets
+#'
+#' @usage data(wgpigs2)
+#'
+#' @format a \code{data.frame} with 16 records and 4 variables.
+#'
+#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
+#'     ed.). Piracicaba, São Paulo: FEALQ. (page 110)
+#'
+#' @examples
+#'
+#' library(lattice)
+#'
+#' data(wgpigs2)
+#' str(wgpigs2)
+#'
+#' xyplot(wg~age, data=wgpigs2, groups=litter,
+#'        ylab="Weight gain (kg)",
+#'        xlab="Age at castration (days)")
+#'
+#' m0 <- lm(wg~litter+size+age, data=wgpigs2)
+#' par(mfrow=c(2,2)); plot(m0); layout(1)
+#' anova(m0)
+#'
+#' summary(m0)
+#'
+#' library(multcomp)
+#' summary(glht(m0, linfct=mcp(age="Dunnet")),
+#'         test=adjusted(type="single-step"))
+#'
+#' m1 <- glm(wg~litter+size+age, data=wgpigs2, family=Gamma)
+#' m2 <- glm(wg~litter+size+age, data=wgpigs2,
+#'           family=Gamma(link="log"))
+#' m3 <- glm(wg~litter+size+age, data=wgpigs2,
+#'           family=Gamma(link="identity"))
+#'
+#' rbind(logLik(m0),
+#'       logLik(m1),
+#'       logLik(m2),
+#'       logLik(m3))
+#'
+#' par(mfrow=c(2,2)); plot(m1); layout(1)
+#' anova(m1, test="F")
+#' anova(m2, test="F")
+#' anova(m3, test="F")
+#'
+#' summary(glht(m3, linfct=mcp(age="Dunnet")),
+#'         test=adjusted(type="single-step"))
+#'
+NULL
diff --git a/data-raw/wgpigs2.R b/data-raw/wgpigs2.R
new file mode 100644
index 0000000..7c6fced
--- /dev/null
+++ b/data-raw/wgpigs2.R
@@ -0,0 +1,63 @@
+##----------------------------------------------------------------------
+## Data generation.
+
+wgpigs2 <- read.table("http://www.leg.ufpr.br/~walmes/data/pimentel_castracao.txt",
+                      header=TRUE, sep="\t")
+names(wgpigs2) <- c("litter", "size", "age", "wg")
+wgpigs2 <- transform(wgpigs2, litter=factor(litter), size=factor(size))
+
+aggregate(wg~age, data=wgpigs2, FUN=mean)
+
+wgpigs2$age <- factor(wgpigs2$age,
+                      levels=levels(wgpigs2$age)[c(4,3,1,2)],
+                      labels=c("control", "7", "21", "56"))
+str(wgpigs2)
+
+save(wgpigs2, file="../data/wgpigs2.RData")
+
+##----------------------------------------------------------------------
+## Examples.
+
+library(lattice)
+
+data(wgpigs2)
+str(wgpigs2)
+
+xyplot(wg~age, data=wgpigs2, groups=litter,
+       ylab="Weight gain (kg)",
+       xlab="Age at castration (days)")
+
+m0 <- lm(wg~litter+size+age, data=wgpigs2)
+par(mfrow=c(2,2)); plot(m0); layout(1)
+anova(m0)
+
+summary(m0)
+
+library(multcomp)
+summary(glht(m0, linfct=mcp(age="Dunnet")),
+        test=adjusted(type="single-step"))
+
+m1 <- glm(wg~litter+size+age, data=wgpigs2, family=Gamma)
+m2 <- glm(wg~litter+size+age, data=wgpigs2,
+          family=Gamma(link="log"))
+m3 <- glm(wg~litter+size+age, data=wgpigs2,
+          family=Gamma(link="identity"))
+
+rbind(logLik(m0),
+      logLik(m1),
+      logLik(m2),
+      logLik(m3))
+
+par(mfrow=c(2,2)); plot(m1); layout(1)
+anova(m1, test="F")
+anova(m2, test="F")
+anova(m3, test="F")
+
+summary(glht(m3, linfct=mcp(age="Dunnet")),
+        test=adjusted(type="single-step"))
+
+rm(list=ls())
+load("../data/wgpigs2.RData")
+ls()
+str(wgpigs2)
+
diff --git a/data/wgpigs2.RData b/data/wgpigs2.RData
new file mode 100644
index 0000000000000000000000000000000000000000..4c720623e07c42d4ae91cad32526820e37608971
GIT binary patch
literal 328
zcmb2|=3oE=X6~X+gGXHtk`fXUk`mIAk`j{Gj3Q?=uqZQgGpkQX)A!du;iGSsl#n3C
zc9JnOPC=I;jOh}aNJGcuQ|=qvbk(=&m@b#dGU5)Ia#7%zL6c!mB9E|%aKz+dq3-U7
ze$7&|r_G3&6wi|K*SXljD9!2cnT#2%qRnekfBEkUp7~$+snwSSNiIdKXIgbKihKgh
z^saAIfBt-`$kXQsVp8~04I~fFIh&H@)}t-?!(kKOLp~mb2Li>#Y6549I&!?38QX7|
zaLBG@Tc|9e@aj;x)0LwRS6!o>ejJ=CU?p~{Kem{S<D8X?nZp;?PYyo>c?9ZMj?{cv
zao+okudBaxj^#{M)s?ORa^8h$p;}YU&Y8iNY&3QG;+aPyr^K&gH|7^n^-);<=l}oz
f%zY0YdU@)2Uh&pu%4%f0XwT4oLi>6cGXnzvW21ol

literal 0
HcmV?d00001

diff --git a/man/wgpigs2.Rd b/man/wgpigs2.Rd
new file mode 100644
index 0000000..ef1ff36
--- /dev/null
+++ b/man/wgpigs2.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{wgpigs2}
+\alias{wgpigs2}
+\title{Age of castration in pig weight gain}
+\format{a \code{data.frame} with 16 records and 4 variables.}
+\source{
+Frederico, P. (2009). Curso de Estatística Experimental (15th
+    ed.). Piracicaba, São Paulo: FEALQ. (page 110)
+}
+\usage{
+data(wgpigs2)
+}
+\description{
+This is an artifial dataset corresponding a experiment
+    to study the effect of feeding type (factor with 4 categorical
+    nominal levels) in pig weight gain. The experiment was a
+    randomized complete design with five experimental units per
+    treatment level. The experimental unit was a pig. The response
+    measured was weight gain from the beggining to the end of the
+    experiment.
+
+\itemize{
+  \item \code{litter} a categorical factor with 4 levels that
+    represents the rows of the lattin square design and control for
+    the differences among litters.
+  \item code{size} a categorical ordered variable that represents the
+    columns of latin square desing and control for the weight of the
+    animals at the beggining of the experiment.
+  \item \code{age} age of the animal (days) when castration was
+    done. \code{controls} are the animals without castration.
+  \item \code{wg} weight gain (kg) after 252 days.
+}
+}
+\examples{
+library(lattice)
+
+data(wgpigs2)
+str(wgpigs2)
+
+xyplot(wg~age, data=wgpigs2, groups=litter,
+       ylab="Weight gain (kg)",
+       xlab="Age at castration (days)")
+
+m0 <- lm(wg~litter+size+age, data=wgpigs2)
+par(mfrow=c(2,2)); plot(m0); layout(1)
+anova(m0)
+
+summary(m0)
+
+library(multcomp)
+summary(glht(m0, linfct=mcp(age="Dunnet")),
+        test=adjusted(type="single-step"))
+
+m1 <- glm(wg~litter+size+age, data=wgpigs2, family=Gamma)
+m2 <- glm(wg~litter+size+age, data=wgpigs2,
+          family=Gamma(link="log"))
+m3 <- glm(wg~litter+size+age, data=wgpigs2,
+          family=Gamma(link="identity"))
+
+rbind(logLik(m0),
+      logLik(m1),
+      logLik(m2),
+      logLik(m3))
+
+par(mfrow=c(2,2)); plot(m1); layout(1)
+anova(m1, test="F")
+anova(m2, test="F")
+anova(m3, test="F")
+
+summary(glht(m3, linfct=mcp(age="Dunnet")),
+        test=adjusted(type="single-step"))
+}
+\keyword{datasets}
+
-- 
GitLab