Skip to content
Snippets Groups Projects
Commit 038e3116 authored by Fernando Mayer's avatar Fernando Mayer
Browse files

Merge branch 'feature/4' into 'devel'

Feature/4

Adds functions used by @wbonat in a recent paper.

See merge request !8
parents 4e76bb02 6f0f6392
No related branches found
No related tags found
No related merge requests found
Package: legTools Package: legTools
Title: Convenience Functions, Small GUI to Teach Statistics and Some Datasets Title: Convenience Functions, Small GUI to Teach Statistics and Some Datasets
Version: 0.1.1 Version: 0.1.2
Authors@R: person("LEG", "Core Team", email = "leg@ufpr.br", role = Authors@R: person("LEG", "Core Team", email = "leg@ufpr.br", role =
c("aut", "cre")) c("aut", "cre"))
Description: legTools is a collection of R functions and datasets used for Description: legTools is a collection of R functions and datasets used for
...@@ -11,11 +11,14 @@ Description: legTools is a collection of R functions and datasets used for ...@@ -11,11 +11,14 @@ Description: legTools is a collection of R functions and datasets used for
Depends: Depends:
R (>= 3.2.1) R (>= 3.2.1)
Imports: Imports:
lattice lattice,
latticeExtra
Depends: Depends:
gWidgets, gWidgets,
gWidgetstcltk, gWidgetstcltk,
knitr knitr,
markdown,
RWordPress
License: GPL-3 | file LICENSE License: GPL-3 | file LICENSE
URL: http://git.leg.ufpr.br/leg/legTools URL: http://git.leg.ufpr.br/leg/legTools
BugReports: http://git.leg.ufpr.br/leg/legTools/issues BugReports: http://git.leg.ufpr.br/leg/legTools/issues
......
# Generated by roxygen2 (4.1.1): do not edit by hand # Generated by roxygen2 (4.1.1): do not edit by hand
export(biasBox) export(biasBox)
export(knit2wpCrayon)
export(loessGui) export(loessGui)
export(panel.segplot.by)
export(polyGui) export(polyGui)
export(runAllChunks) export(runAllChunks)
export(subsetDropAll) export(subsetDropAll)
export(twoStripCombined) export(twoStripCombined)
export(yscale.component.right)
import(RWordPress)
import(gWidgets) import(gWidgets)
import(gWidgetstcltk) import(gWidgetstcltk)
import(knitr) import(knitr)
import(lattice) import(lattice)
import(latticeExtra)
import(markdown)
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
#' #'
#' @name knit2wpCrayon #' @name knit2wpCrayon
#' #'
#' @description This function improves the \code{RWordPress::knit2wp} to #' @description This function improves \code{RWordPress::knit2wp} to
#' allow properly render code when using Crayon Sintax Highlighter. #' allow properly render code when using Crayon Sintax Highlighter
#' in Wordpress.
#' #'
#' @param input a markdown or Rmarkdown file. #' @param input a markdown or Rmarkdown file.
#' @param title title for the post. #' @param title title for the post.
...@@ -16,15 +17,15 @@ ...@@ -16,15 +17,15 @@
#' @param upload logical, if the file is to be updated to the blog. #' @param upload logical, if the file is to be updated to the blog.
#' @param publish logical, if the post is to be published or stay in #' @param publish logical, if the post is to be published or stay in
#' draft mode. #' draft mode.
#' @param write logical, is the result of knit be written to a html #' @param write logical, if the result of knit should be written to a
#' file. This is useful to copy from this file and paste inside the #' html file. This is useful to copy from this file and paste inside
#' wordpress post editor (on text mode, not visual mode). #' the Wordpress editor (on text mode, not visual mode).
#' #'
#' @return None is returned by the function. #' @return Nothing is returned by the function.
#' #'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br} #' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#' #'
#' @import knitr RWordPress #' @import knitr markdown RWordPress
#' @export #' @export
#' @examples #' @examples
#' \donttest{ #' \donttest{
...@@ -53,19 +54,35 @@ knit2wpCrayon <- function(input, title="A post from knitr", ..., ...@@ -53,19 +54,35 @@ knit2wpCrayon <- function(input, title="A post from knitr", ...,
action=c("newPost", "editPost", "newPage"), action=c("newPost", "editPost", "newPage"),
postid, encoding=getOption("encoding"), postid, encoding=getOption("encoding"),
upload=FALSE, publish=FALSE, write=TRUE){ upload=FALSE, publish=FALSE, write=TRUE){
##
##-------------------------------------------
## Loading required packages.
##
if (!requireNamespace("knitr", quietly=TRUE)){
stop("`knitr` needed for this function to work. Please install it.",
call.=FALSE)
}
if (!requireNamespace("markdown", quietly=TRUE)){
stop("`markdown` needed for this function to work. Please install it.",
call.=FALSE)
}
if (!requireNamespace("RWordPress", quietly=TRUE)){
stop("`RWordPress` needed for this function to work. Please install it.",
call.=FALSE)
}
out <- knit(input, encoding=encoding) out <- knit(input, encoding=encoding)
on.exit(unlink(out)) on.exit(unlink(out))
con <- file(out, encoding=encoding) con <- file(out, encoding=encoding)
on.exit(close(con), add=TRUE) on.exit(close(con), add=TRUE)
content <- knitr:::native_encode(readLines(con, warn=FALSE)) content <- native_encode(readLines(con, warn=FALSE))
content <- paste(content, collapse="\n") content <- paste(content, collapse="\n")
content <- markdown::markdownToHTML(text=content, fragment.only=TRUE) content <- markdownToHTML(text=content, fragment.only=TRUE)
content <- gsub( content <- gsub(
pattern="<pre><code class=\"([[:alpha:]]+)\">(.+?)</code></pre>", pattern="<pre><code class=\"([[:alpha:]]+)\">(.+?)</code></pre>",
replacement="<pre class=\"lang:\\1 decode:true\">\\2</pre>", replacement="<pre class=\"lang:\\1 decode:true\">\\2</pre>",
x=content) x=content)
content=knitr:::native_encode(content, "UTF-8") content=native_encode(content, "UTF-8")
title=knitr:::native_encode(title, "UTF-8") title=native_encode(title, "UTF-8")
if (write){ if (write){
writeLines(text=content, writeLines(text=content,
con=gsub(x=out, pattern="\\.md$", replacement=".html")) con=gsub(x=out, pattern="\\.md$", replacement=".html"))
......
...@@ -13,10 +13,11 @@ NULL ...@@ -13,10 +13,11 @@ NULL
#' #'
#' @description This is an artifial dataset corresponding a experiment #' @description This is an artifial dataset corresponding a experiment
#' to study the effect of feeding type (factor with 4 categorical #' to study the effect of feeding type (factor with 4 categorical
#' nominal levels) in pig weight gain. The experiment was a randomized #' nominal levels) in pig weight gain. The experiment was a
#' complete design with five experimental units per treatment level. The #' randomized complete design with five experimental units per
#' experimental unit was a pig. The response measured was weight gain #' treatment level. The experimental unit was a pig. The response
#' from the beggining to the end of the experiment. #' measured was weight gain from the beggining to the end of the
#' experiment.
#' #'
#' \itemize{ #' \itemize{
#' \item \code{ft} feeding type, a categorical factor with 4 #' \item \code{ft} feeding type, a categorical factor with 4
...@@ -32,8 +33,8 @@ NULL ...@@ -32,8 +33,8 @@ NULL
#' #'
#' @format a \code{data.frame} with 20 records and 2 variables. #' @format a \code{data.frame} with 20 records and 2 variables.
#' #'
#' @source Frederico, P. (2009). Curso de Estatística Experimental #' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 62) #' ed.). Piracicaba, São Paulo: FEALQ. (page 62)
#' #'
#' @examples #' @examples
#' #'
...@@ -51,9 +52,9 @@ NULL ...@@ -51,9 +52,9 @@ NULL
#' @title Potato variety competition experiment #' @title Potato variety competition experiment
#' #'
#' @description These data are from an experiment done by the engineer #' @description These data are from an experiment done by the engineer
#' Oscar A. Garay at Balcare, Argentina. The experiment was done in a #' Oscar A. Garay at Balcare, Argentina. The experiment was done in
#' randomized complete block design with 4 blocks. Potato yield (t/ha) #' a randomized complete block design with 4 blocks. Potato yield
#' was recorded in each experimental unit. #' (t/ha) was recorded in each experimental unit.
#' #'
#' \itemize{ #' \itemize{
#' \item \code{block} a categorical unordered factor with 4 levels. #' \item \code{block} a categorical unordered factor with 4 levels.
...@@ -70,8 +71,8 @@ NULL ...@@ -70,8 +71,8 @@ NULL
#' #'
#' @format a \code{data.frame} with 32 records and 3 variables. #' @format a \code{data.frame} with 32 records and 3 variables.
#' #'
#' @source Frederico, P. (2009). Curso de Estatística Experimental #' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 76) #' ed.). Piracicaba, São Paulo: FEALQ. (page 76)
#' #'
#' @examples #' @examples
#' require(lattice) #' require(lattice)
...@@ -89,12 +90,12 @@ NULL ...@@ -89,12 +90,12 @@ NULL
#' @title Plowing level on corn yield #' @title Plowing level on corn yield
#' #'
#' @description These data are from an experiment done by the engineer #' @description These data are from an experiment done by the engineer
#' Duvilio Ometto to study the effect of plowing level on corn yield. It #' Duvilio Ometto to study the effect of plowing level on corn
#' was used 2 levels of plowing: normal (or superficial) and deep. The #' yield. It was used 2 levels of plowing: normal (or superficial)
#' experiment was done in a randomized complete block design with 6 #' and deep. The experiment was done in a randomized complete block
#' blocks. Corn yield (t/ha) was recorded in each experimental unit #' design with 6 blocks. Corn yield (t/ha) was recorded in each
#' but in this experiment there was 2 experimental units for each factor #' experimental unit but in this experiment there was 2 experimental
#' level in each block. #' units for each factor level in each block.
#' #'
#' \itemize{ #' \itemize{
#' \item \code{block} a categorical unordered factor with 6 levels. #' \item \code{block} a categorical unordered factor with 6 levels.
...@@ -110,8 +111,8 @@ NULL ...@@ -110,8 +111,8 @@ NULL
#' #'
#' @format a \code{data.frame} with 24 records and 3 variables. #' @format a \code{data.frame} with 24 records and 3 variables.
#' #'
#' @source Frederico, P. (2009). Curso de Estatística Experimental #' @source Frederico, P. (2009). Curso de Estatística Experimental (15th
#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 91) #' ed.). Piracicaba, São Paulo: FEALQ. (page 91)
#' #'
#' @examples #' @examples
#' require(lattice) #' require(lattice)
...@@ -122,3 +123,86 @@ NULL ...@@ -122,3 +123,86 @@ NULL
#' xlab="Plowing level") #' xlab="Plowing level")
#' #'
NULL NULL
#' @name defoliation
#'
#' @title Bolls in cotton as function of artifitial defoliation
#'
#' @description This dataset contais the result of a real experiment to
#' evaluate the effect of artifitial defoliation in combination with
#' phenological stage of occurence on the production of cotton
#' represented by the number of bolls produced at the end of the
#' crop cycle. The experiment is a \eqn{5\times 5} factorial with 5
#' replications casualized at random to the experimental units (a
#' randomized complete design). The experimental unit was a pot with
#' 2 plants. An interesting fact about this data is that the
#' response is a count variable that shows underdispersion (sample
#' variance less than the sample mean).
#'
#' \itemize{
#' \item \code{phenol} a categorical ordered factor with 5 levels
#' that represent the phenological stages of the cotton plant in
#' which defoliation was applied.
#' \item \code{defol} a numeric factor with 5 levels that represents the
#' artifical level of defoliation (percent in leaf area removed with
#' scissors) applied for all leaves in the plant.
#' \item \code{rept} index for each experimenal unit in each treatment cell.
#' \item \code{bolls} the number of bolls produced (count variable)
#' evaluated at harvest.
#' }
#'
#' @details The experiment was done in a greenhouse at Universidade
#' Federal da Grande Dourados. Visit
#' \itemize{
#' \item 1) \code{http://www.cabdirect.org/abstracts/20123299470.html}
#' \item 2) \code{http://leg.ufpr.br/doku.php/publications:papercompanions:zeviani-jas2014}
#' }
#' 1 for an article discussing the effect of defoliation on cotton yield and
#' visit 2 for an article that evaluate a count regression model able to
#' deal with the underdispersion. See the references section also.
#'
#' @docType data
#'
#' @keywords datasets
#'
#' @usage data(defoliation)
#'
#' @format a \code{data.frame} with 125 records and 4 variables.
#'
#' @references Silva, A. M., Degrande, P. E., Suekane, R., Fernandes,
#' M. G., & Zeviani, W. M. (2012). Impacto de diferentes níveis de
#' desfolha artificial nos estádios fenológicos do
#' algodoeiro. Revista de Ciências Agrárias, 35(1), 163–172.
#'
#' Zeviani, W. M., Ribeiro, P. J., Bonat, W. H., Shimakura, S. E., &
#' Muniz, J. A. (2014). The Gamma-count distribution in the analysis
#' of experimental underdispersed data. Journal of Applied
#' Statistics, 41(12),
#' 1–11. http://doi.org/10.1080/02664763.2014.922168
#'
#' @examples
#'
#' library(lattice)
#' library(latticeExtra)
#'
#' ## x11(width=7, height=2.8)
#' xyplot(bolls~defol|phenol, data=defoliation,
#' layout=c(NA, 1), type=c("p", "smooth"),
#' xlab="Artificial defoliation level",
#' ylab="Number of bolls produced",
#' xlim=extendrange(c(0:1), f=0.15), jitter.x=TRUE)
#'
#' ## Sample mean and variance in each treatment cell.
#' mv <- aggregate(bolls~phenol+defol, data=defoliation,
#' FUN=function(x) c(mean=mean(x), var=var(x)))
#' str(mv)
#'
#' xlim <- ylim <- extendrange(c(mv$bolls), f=0.05)
#'
#' ## Evidence in favor of the underdispersion.
#' xyplot(bolls[,"var"]~bolls[,"mean"], data=mv,
#' aspect="iso", xlim=xlim, ylim=ylim,
#' ylab="Sample variance", xlab="Sample mean")+
#' layer(panel.abline(a=0, b=1, lty=2))
#'
NULL
#' @title Lattice panel to non overlapping segments in \code{segplot()}
#'
#' @name panel.segplot.by
#'
#' @description This panel allows no overlapping of segments in
#' \code{latticeExtra::segplot()} when using the argument groups.
#'
#' @param x,y,z,data,centers,subscripts,... see
#' \code{\link[latticeExtra]{segplot}}.
#' @param groups the grouping variable. Must be a factor.
#' @param f numeric, factor that is the vertical distance among
#' arrows. In general a value less than 1. Default is 0.05.
#' @param rev logical, use the reverse order of the factor levels to
#' place the segments. Default is \code{FALSE}.
#'
#' @return None is returned.
#'
#' @seealso \code{\link[latticeExtra]{segplot}}
#'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#'
#' @export
#'
#' @examples
#'
#' library(latticeExtra)
#'
#' m0 <- lm(log(breaks)~wool*tension, data=warpbreaks)
#' anova(m0)
#' par(mfrow=c(2,2)); plot(m0); layout(1)
#'
#' pred <- data.frame(wool=c("A", "B", "A", "B", "A", "B"),
#' tension=c("L", "L", "M", "M", "H", "H"))
#'
#' X <- matrix(c(1, 1, 1, 1, 1, 1,
#' 0, 1, 0, 1, 0, 1,
#' 0, 0, 1, 1, 0, 0,
#' 0, 0, 0, 0, 1, 1,
#' 0, 0, 0, 1, 0, 0,
#' 0, 0, 0, 0, 0, 1), nrow=6, ncol=6)
#'
#' ## Estimate and standart error.
#' ## X%*%coef(m0)
#' ## sqrt(diag(X%*%vcov(m0)%*%t(X)))
#'
#' U <- chol(vcov(m0))
#' pred$est <- X%*%coef(m0)
#' pred$se <- sqrt(apply(X%*%t(U), MARGIN=1, FUN=function(x) sum(x^2)))
#'
#' tval <- qt(p=c(lwr=0.025, upr=0.975), df=df.residual(m0))
#' pred <- cbind(pred, sweep(x=outer(pred$se, tval, "*"),
#' MARGIN=1, STATS=pred$est, FUN="+"))
#'
#' ## Overlapping segments.
#' segplot(wool~lwr+upr, centers=est, data=pred, draw=FALSE)
#'
#' ## Prefer ordering always before using "pch=".
#' pred <- pred[with(pred, order(tension, wool)), ]
#'
#' segplot(tension~lwr+upr, data=pred,
#' centers=est, draw=FALSE,
#' ylab="Tension level",
#' xlab=expression("Estimate"%+-%"error margin for a 0.95 CI"),
#' groups=wool, f=0.05, rev=TRUE,
#' pch=as.integer(pred$wool),
#' panel=panel.segplot.by,
#' key=list(title="Type of wool", cex.title=1.1,
#' text=list(levels(pred$wool)),
#' lines=list(pch=1:2, lty=1),
#' divide=1, type="o"))
#'
panel.segplot.by <- function(x, y, z, data, centers, subscripts,
groups, f=0.05, rev=FALSE, ...){
if(!missing(data)){
da <- eval(data, envir=parent.frame())
groups <- da[, deparse(substitute(groups))]
}
d <- 2*((as.numeric(groups)-1)/(nlevels(groups)-1))-1
if (rev){
d <- rev(d)
}
z <- as.numeric(z)+f*d
panel.segplot(x, y, z, centers=centers,
subscripts=subscripts, ...)
}
#' @title y-axis annotations on the right side
#'
#' @name yscale.components.right
#'
#' @description This function if for place y axis annotation on the
#' right side of the plot.
#'
#' @param ... arguments passed by the lattice function called. See
#' \link[lattice]{yscale.components.default}.
#'
#' @import lattice latticeExtra
#'
#' @source When such feature was necessary, a search in the web was done
#' and a post in the r-help mailing list inspired us
#' \code{http://r.789695.n4.nabble.com/Spacing-between-lattice-panels-td855613.html}.
#'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#'
#' @export
#'
#' @examples
#'
#' library(lattice)
#' library(latticeExtra)
#'
#' ## alternating=2 works when relation="same".
#' p1 <- xyplot(yield~K|N+P, data=npk,
#' scales=list(y=list(alternating=2)))
#' useOuterStrips(p1)
#'
#' ## y annotation don't is written on the right side.
#' p2 <- xyplot(yield~K|N+P, data=npk,
#' scales=list(y=list(relation="free", alternating=2)))
#' useOuterStrips(p2)
#'
#' ## The desired result.
#' p3 <- xyplot(yield~K|N+P, data=npk,
#' scales=list(y=list(relation="free", alternating=2)),
#' ylab=NULL, ylab.right="Yield",
#' yscale.component=yscale.component.right,
#' between=list(x=0.5, y=0.2),
#' par.settings=list(
#' layout.widths=list(
#' right.padding=-2,
#' left.padding=-2,
#' ylab.right=5),
#' strip.background=list(col=c("gray50", "gray90"))),
#' )
#' useOuterStrips(p3)
#'
yscale.component.right <- function(...){
ans <- yscale.components.default(...)
ans$right <- ans$left
ans$left <- NULL
ans
}
...@@ -30,7 +30,7 @@ check(cleanup = FALSE, manual = TRUE, vignettes = FALSE, ...@@ -30,7 +30,7 @@ check(cleanup = FALSE, manual = TRUE, vignettes = FALSE,
# Run examples from all functions of the package # Run examples from all functions of the package
# run_examples() # run_examples()
# Run examples from a specific function # Run examples from a specific function
# dev_example("loessGui") # dev_example("yscale.components.right")
## Show all exported objects. ## Show all exported objects.
ls("package:legTools") ls("package:legTools")
......
##----------------------------------------------------------------------
## Data generation.
phenol <- c("vegetative", "flower bud", "blossom", "boll", "boll open")
defoliation <- expand.grid(rept=1:5,
defol=seq(0, 1, length.out=5),
phenol=factor(phenol, levels=phenol),
KEEP.OUT.ATTRS=FALSE)
defoliation$bolls <- c(10, 9, 8, 8, 10, 11, 9, 10, 10, 10, 8, 8, 10, 8,
9, 9, 7, 7, 8, 9, 8, 6, 6, 5, 6, 7, 8, 8, 9, 10,
9, 12, 7, 10, 9, 8, 9, 9, 10, 8, 11, 10, 7, 8, 8,
7, 7, 7, 7, 8, 10, 9, 8, 12, 8, 7, 5, 5, 7, 5, 6,
5, 7, 4, 7, 8, 5, 7, 6, 4, 5, 5, 4, 4, 5, 8, 10,
7, 8, 10, 9, 6, 6, 8, 6, 9, 7, 11, 8, 9,6, 6, 6,
6, 7, 3, 3, 2, 4, 3, 11, 7, 9, 12 , 11, 9, 13, 8,
10, 10, 9, 7, 7, 9, 9, 8, 8, 10, 8, 10, 9, 8, 10,
8, 10)
defoliation <- defoliation[,c(3,2,1,4)]
str(defoliation)
save(defoliation, file="../data/defoliation.RData")
rm(list=ls())
load(file="../data/defoliation.RData")
ls()
##----------------------------------------------------------------------
## Examples.
library(lattice)
library(latticeExtra)
x11(width=7, height=2.8)
xyplot(bolls~defol|phenol, data=defoliation,
layout=c(NA, 1), type=c("p", "smooth"),
xlab="Artificial defoliation level",
ylab="Number of bolls produced",
xlim=extendrange(c(0:1), f=0.15), jitter.x=TRUE)
## Sample mean and variance in each treatment cell.
mv <- aggregate(bolls~phenol+defol, data=defoliation,
FUN=function(x) c(mean=mean(x), var=var(x)))
str(mv)
xlim <- ylim <- extendrange(c(mv$bolls), f=0.05)
## Evidence in favor of the underdispersion.
xyplot(bolls[,"var"]~bolls[,"mean"], data=mv,
aspect="iso", xlim=xlim, ylim=ylim,
ylab="Sample variance", xlab="Sample mean")+
layer(panel.abline(a=0, b=1, lty=2))
File added
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/legTools.R
\docType{data}
\name{defoliation}
\alias{defoliation}
\title{Bolls in cotton as function of artifitial defoliation}
\format{a \code{data.frame} with 125 records and 4 variables.}
\usage{
data(defoliation)
}
\description{
This dataset contais the result of a real experiment to
evaluate the effect of artifitial defoliation in combination with
phenological stage of occurence on the production of cotton
represented by the number of bolls produced at the end of the
crop cycle. The experiment is a \eqn{5\times 5} factorial with 5
replications casualized at random to the experimental units (a
randomized complete design). The experimental unit was a pot with
2 plants. An interesting fact about this data is that the
response is a count variable that shows underdispersion (sample
variance less than the sample mean).
\itemize{
\item \code{phenol} a categorical ordered factor with 5 levels
that represent the phenological stages of the cotton plant in
which defoliation was applied.
\item \code{defol} a numeric factor with 5 levels that represents the
artifical level of defoliation (percent in leaf area removed with
scissors) applied for all leaves in the plant.
\item \code{rept} index for each experimenal unit in each treatment cell.
\item \code{bolls} the number of bolls produced (count variable)
evaluated at harvest.
}
}
\details{
The experiment was done in a greenhouse at Universidade
Federal da Grande Dourados. Visit
\itemize{
\item 1) \code{http://www.cabdirect.org/abstracts/20123299470.html}
\item 2) \code{http://leg.ufpr.br/doku.php/publications:papercompanions:zeviani-jas2014}
}
1 for an article discussing the effect of defoliation on cotton yield and
visit 2 for an article that evaluate a count regression model able to
deal with the underdispersion. See the references section also.
}
\examples{
library(lattice)
library(latticeExtra)
## x11(width=7, height=2.8)
xyplot(bolls~defol|phenol, data=defoliation,
layout=c(NA, 1), type=c("p", "smooth"),
xlab="Artificial defoliation level",
ylab="Number of bolls produced",
xlim=extendrange(c(0:1), f=0.15), jitter.x=TRUE)
## Sample mean and variance in each treatment cell.
mv <- aggregate(bolls~phenol+defol, data=defoliation,
FUN=function(x) c(mean=mean(x), var=var(x)))
str(mv)
xlim <- ylim <- extendrange(c(mv$bolls), f=0.05)
## Evidence in favor of the underdispersion.
xyplot(bolls[,"var"]~bolls[,"mean"], data=mv,
aspect="iso", xlim=xlim, ylim=ylim,
ylab="Sample variance", xlab="Sample mean")+
layer(panel.abline(a=0, b=1, lty=2))
}
\references{
Silva, A. M., Degrande, P. E., Suekane, R., Fernandes,
M. G., & Zeviani, W. M. (2012). Impacto de diferentes níveis de
desfolha artificial nos estádios fenológicos do
algodoeiro. Revista de Ciências Agrárias, 35(1), 163–172.
Zeviani, W. M., Ribeiro, P. J., Bonat, W. H., Shimakura, S. E., &
Muniz, J. A. (2014). The Gamma-count distribution in the analysis
of experimental underdispersed data. Journal of Applied
Statistics, 41(12),
1–11. http://doi.org/10.1080/02664763.2014.922168
}
\keyword{datasets}
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/knit2wpCrayon.R
\name{knit2wpCrayon}
\alias{knit2wpCrayon}
\title{knit to wordpress that uses crayon sintax highlight}
\usage{
knit2wpCrayon(input, title = "A post from knitr", ..., action = c("newPost",
"editPost", "newPage"), postid, encoding = getOption("encoding"),
upload = FALSE, publish = FALSE, write = TRUE)
}
\arguments{
\item{input}{a markdown or Rmarkdown file.}
\item{title}{title for the post.}
\item{...}{other meta information of the post. See}
\item{action}{indicates a new post, a edition of the post or a new
page.}
\item{postid}{number of the post.}
\item{encoding}{ht encoding of the input file.}
\item{upload}{logical, if the file is to be updated to the blog.}
\item{publish}{logical, if the post is to be published or stay in
draft mode.}
\item{write}{logical, if the result of knit should be written to a
html file. This is useful to copy from this file and paste inside
the Wordpress editor (on text mode, not visual mode).}
}
\value{
Nothing is returned by the function.
}
\description{
This function improves \code{RWordPress::knit2wp} to
allow properly render code when using Crayon Sintax Highlighter
in Wordpress.
}
\examples{
\donttest{
library(knitr)
library(RWordPress)
post <- "2015-08-24_polyGui.Rmd"
title <- "Interface para regressão polinomial"
categ <- c("gui", "rbloggers_pt")
keywd <- c("gWdigets", "legTools", "lm", "poly")
pass <- scan(n=1, what=character())
options(WordpressLogin=c(walmes=pass),
WordpressURL="http://blog.leg.ufpr.br/xmlrpc.php")
knit2wpCrayon(post, title=title,
action="editPost", postid=179,
categories=categ, mt_keywords=keywd,
## write=TRUE, upload=FALSE,
write=FALSE, upload=TRUE,
publish=FALSE)
}
}
\author{
Walmes Zeviani, \email{walmes@ufpr.br}
}
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/panel.segplot.by.R
\name{panel.segplot.by}
\alias{panel.segplot.by}
\title{Lattice panel to non overlapping segments in \code{segplot()}}
\usage{
panel.segplot.by(x, y, z, data, centers, subscripts, groups, f = 0.05,
rev = FALSE, ...)
}
\arguments{
\item{x,y,z,data,centers,subscripts,...}{see
\code{\link[latticeExtra]{segplot}}.}
\item{groups}{the grouping variable. Must be a factor.}
\item{f}{numeric, factor that is the vertical distance among
arrows. In general a value less than 1. Default is 0.05.}
\item{rev}{logical, use the reverse order of the factor levels to
place the segments. Default is \code{FALSE}.}
}
\value{
None is returned.
}
\description{
This panel allows no overlapping of segments in
\code{latticeExtra::segplot()} when using the argument groups.
}
\examples{
library(latticeExtra)
m0 <- lm(log(breaks)~wool*tension, data=warpbreaks)
anova(m0)
par(mfrow=c(2,2)); plot(m0); layout(1)
pred <- data.frame(wool=c("A", "B", "A", "B", "A", "B"),
tension=c("L", "L", "M", "M", "H", "H"))
X <- matrix(c(1, 1, 1, 1, 1, 1,
0, 1, 0, 1, 0, 1,
0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 1, 1,
0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 1), nrow=6, ncol=6)
## Estimate and standart error.
## X\%*\%coef(m0)
## sqrt(diag(X\%*\%vcov(m0)\%*\%t(X)))
U <- chol(vcov(m0))
pred$est <- X\%*\%coef(m0)
pred$se <- sqrt(apply(X\%*\%t(U), MARGIN=1, FUN=function(x) sum(x^2)))
tval <- qt(p=c(lwr=0.025, upr=0.975), df=df.residual(m0))
pred <- cbind(pred, sweep(x=outer(pred$se, tval, "*"),
MARGIN=1, STATS=pred$est, FUN="+"))
## Overlapping segments.
segplot(wool~lwr+upr, centers=est, data=pred, draw=FALSE)
## Prefer ordering always before using "pch=".
pred <- pred[with(pred, order(tension, wool)), ]
segplot(tension~lwr+upr, data=pred,
centers=est, draw=FALSE,
ylab="Tension level",
xlab=expression("Estimate"\%+-\%"error margin for a 0.95 CI"),
groups=wool, f=0.05, rev=TRUE,
pch=as.integer(pred$wool),
panel=panel.segplot.by,
key=list(title="Type of wool", cex.title=1.1,
text=list(levels(pred$wool)),
lines=list(pch=1:2, lty=1),
divide=1, type="o"))
}
\author{
Walmes Zeviani, \email{walmes@ufpr.br}
}
\seealso{
\code{\link[latticeExtra]{segplot}}
}
...@@ -6,20 +6,20 @@ ...@@ -6,20 +6,20 @@
\title{Plowing level on corn yield} \title{Plowing level on corn yield}
\format{a \code{data.frame} with 24 records and 3 variables.} \format{a \code{data.frame} with 24 records and 3 variables.}
\source{ \source{
Frederico, P. (2009). Curso de Estatística Experimental Frederico, P. (2009). Curso de Estatística Experimental (15th
(15th ed.). Piracicaba, São Paulo: FEALQ. (page 91) ed.). Piracicaba, São Paulo: FEALQ. (page 91)
} }
\usage{ \usage{
data(plowing) data(plowing)
} }
\description{ \description{
These data are from an experiment done by the engineer These data are from an experiment done by the engineer
Duvilio Ometto to study the effect of plowing level on corn yield. It Duvilio Ometto to study the effect of plowing level on corn
was used 2 levels of plowing: normal (or superficial) and deep. The yield. It was used 2 levels of plowing: normal (or superficial)
experiment was done in a randomized complete block design with 6 and deep. The experiment was done in a randomized complete block
blocks. Corn yield (t/ha) was recorded in each experimental unit design with 6 blocks. Corn yield (t/ha) was recorded in each
but in this experiment there was 2 experimental units for each factor experimental unit but in this experiment there was 2 experimental
level in each block. units for each factor level in each block.
\itemize{ \itemize{
\item \code{block} a categorical unordered factor with 6 levels. \item \code{block} a categorical unordered factor with 6 levels.
......
...@@ -6,17 +6,17 @@ ...@@ -6,17 +6,17 @@
\title{Potato variety competition experiment} \title{Potato variety competition experiment}
\format{a \code{data.frame} with 32 records and 3 variables.} \format{a \code{data.frame} with 32 records and 3 variables.}
\source{ \source{
Frederico, P. (2009). Curso de Estatística Experimental Frederico, P. (2009). Curso de Estatística Experimental (15th
(15th ed.). Piracicaba, São Paulo: FEALQ. (page 76) ed.). Piracicaba, São Paulo: FEALQ. (page 76)
} }
\usage{ \usage{
data(potatoyield) data(potatoyield)
} }
\description{ \description{
These data are from an experiment done by the engineer These data are from an experiment done by the engineer
Oscar A. Garay at Balcare, Argentina. The experiment was done in a Oscar A. Garay at Balcare, Argentina. The experiment was done in
randomized complete block design with 4 blocks. Potato yield (t/ha) a randomized complete block design with 4 blocks. Potato yield
was recorded in each experimental unit. (t/ha) was recorded in each experimental unit.
\itemize{ \itemize{
\item \code{block} a categorical unordered factor with 4 levels. \item \code{block} a categorical unordered factor with 4 levels.
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
\title{Feeding type in pig weight gain} \title{Feeding type in pig weight gain}
\format{a \code{data.frame} with 20 records and 2 variables.} \format{a \code{data.frame} with 20 records and 2 variables.}
\source{ \source{
Frederico, P. (2009). Curso de Estatística Experimental Frederico, P. (2009). Curso de Estatística Experimental (15th
(15th ed.). Piracicaba, São Paulo: FEALQ. (page 62) ed.). Piracicaba, São Paulo: FEALQ. (page 62)
} }
\usage{ \usage{
data(wgpigs) data(wgpigs)
...@@ -15,10 +15,11 @@ data(wgpigs) ...@@ -15,10 +15,11 @@ data(wgpigs)
\description{ \description{
This is an artifial dataset corresponding a experiment This is an artifial dataset corresponding a experiment
to study the effect of feeding type (factor with 4 categorical to study the effect of feeding type (factor with 4 categorical
nominal levels) in pig weight gain. The experiment was a randomized nominal levels) in pig weight gain. The experiment was a
complete design with five experimental units per treatment level. The randomized complete design with five experimental units per
experimental unit was a pig. The response measured was weight gain treatment level. The experimental unit was a pig. The response
from the beggining to the end of the experiment. measured was weight gain from the beggining to the end of the
experiment.
\itemize{ \itemize{
\item \code{ft} feeding type, a categorical factor with 4 \item \code{ft} feeding type, a categorical factor with 4
......
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/yscale.components.right.R
\name{yscale.components.right}
\alias{yscale.component.right}
\alias{yscale.components.right}
\title{y-axis annotations on the right side}
\source{
When such feature was necessary, a search in the web was done
and a post in the r-help mailing list inspired us
\code{http://r.789695.n4.nabble.com/Spacing-between-lattice-panels-td855613.html}.
}
\usage{
yscale.component.right(...)
}
\arguments{
\item{...}{arguments passed by the lattice function called. See
\link[lattice]{yscale.components.default}.}
}
\description{
This function if for place y axis annotation on the
right side of the plot.
}
\examples{
library(lattice)
library(latticeExtra)
## alternating=2 works when relation="same".
p1 <- xyplot(yield~K|N+P, data=npk,
scales=list(y=list(alternating=2)))
useOuterStrips(p1)
## y annotation don't is written on the right side.
p2 <- xyplot(yield~K|N+P, data=npk,
scales=list(y=list(relation="free", alternating=2)))
useOuterStrips(p2)
## The desired result.
p3 <- xyplot(yield~K|N+P, data=npk,
scales=list(y=list(relation="free", alternating=2)),
ylab=NULL, ylab.right="Yield",
yscale.component=yscale.component.right,
between=list(x=0.5, y=0.2),
par.settings=list(
layout.widths=list(
right.padding=-2,
left.padding=-2,
ylab.right=5),
strip.background=list(col=c("gray50", "gray90"))),
)
useOuterStrips(p3)
}
\author{
Walmes Zeviani, \email{walmes@ufpr.br}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment