diff --git a/DESCRIPTION b/DESCRIPTION index 18774b8df15012dd8cd3d9f5fdcc7ab9645c2299..1180dc1c8ad1be9ae942d3f248302eb89cb6fc49 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: legTools 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 = c("aut", "cre")) 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: R (>= 3.2.1) Imports: - lattice + lattice, + latticeExtra Depends: gWidgets, gWidgetstcltk, - knitr + knitr, + markdown, + RWordPress 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/NAMESPACE b/NAMESPACE index 1734ab73d94005b588420f758cce7e8a42c8ad98..b532e33515696adefe8e39d8db9887535e677382 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,18 @@ # Generated by roxygen2 (4.1.1): do not edit by hand export(biasBox) +export(knit2wpCrayon) export(loessGui) +export(panel.segplot.by) export(polyGui) export(runAllChunks) export(subsetDropAll) export(twoStripCombined) +export(yscale.component.right) +import(RWordPress) import(gWidgets) import(gWidgetstcltk) import(knitr) import(lattice) +import(latticeExtra) +import(markdown) diff --git a/R/knit2wpCrayon.R b/R/knit2wpCrayon.R index 5fe2b347abbdc9575742061feecd4ff57c46ab23..bb4c0b344e4df29b9ce3ad830c7999e9667540b5 100644 --- a/R/knit2wpCrayon.R +++ b/R/knit2wpCrayon.R @@ -2,8 +2,9 @@ #' #' @name knit2wpCrayon #' -#' @description This function improves the \code{RWordPress::knit2wp} to -#' allow properly render code when using Crayon Sintax Highlighter. +#' @description This function improves \code{RWordPress::knit2wp} to +#' allow properly render code when using Crayon Sintax Highlighter +#' in Wordpress. #' #' @param input a markdown or Rmarkdown file. #' @param title title for the post. @@ -16,65 +17,81 @@ #' @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 #' draft mode. -#' @param write logical, is the result of knit be written to a html -#' file. This is useful to copy from this file and paste inside the -#' wordpress post editor (on text mode, not visual mode). +#' @param 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). #' -#' @return None is returned by the function. +#' @return Nothing is returned by the function. #' #' @author Walmes Zeviani, \email{walmes@@ufpr.br} #' -#' @import knitr RWordPress +#' @import knitr markdown RWordPress #' @export #' @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) -#' +#' #' } knit2wpCrayon <- function(input, title="A post from knitr", ..., action=c("newPost", "editPost", "newPage"), postid, encoding=getOption("encoding"), 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) on.exit(unlink(out)) con <- file(out, encoding=encoding) 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 <- markdown::markdownToHTML(text=content, fragment.only=TRUE) + content <- markdownToHTML(text=content, fragment.only=TRUE) content <- gsub( pattern="<pre><code class=\"([[:alpha:]]+)\">(.+?)</code></pre>", replacement="<pre class=\"lang:\\1 decode:true\">\\2</pre>", x=content) - content=knitr:::native_encode(content, "UTF-8") - title=knitr:::native_encode(title, "UTF-8") + content=native_encode(content, "UTF-8") + title=native_encode(title, "UTF-8") if (write){ writeLines(text=content, con=gsub(x=out, pattern="\\.md$", replacement=".html")) } if (upload){ action=match.arg(action) - WPargs=list(content=list(description=content, title=title, + WPargs=list(content=list(description=content, title=title, ...), publish=publish) - if (action=="editPost") + if (action=="editPost") WPargs=c(postid=postid, WPargs) do.call("library", list(package="RWordPress", character.only=TRUE)) print(do.call(action, args=WPargs)) diff --git a/R/legTools.R b/R/legTools.R index bd4334fb523f73e1151fe618286230d1b44592e2..9cbf85efaf28c1ebaf3aeaac5f4e87fc74f85159 100644 --- a/R/legTools.R +++ b/R/legTools.R @@ -12,11 +12,12 @@ NULL #' @title Feeding type 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. +#' 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{ft} feeding type, a categorical factor with 4 @@ -32,8 +33,8 @@ NULL #' #' @format a \code{data.frame} with 20 records and 2 variables. #' -#' @source Frederico, P. (2009). Curso de Estatística Experimental -#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 62) +#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th +#' ed.). Piracicaba, São Paulo: FEALQ. (page 62) #' #' @examples #' @@ -51,9 +52,9 @@ NULL #' @title Potato variety competition experiment #' #' @description These data are from an experiment done by the engineer -#' Oscar A. Garay at Balcare, Argentina. The experiment was done in a -#' randomized complete block design with 4 blocks. Potato yield (t/ha) -#' was recorded in each experimental unit. +#' Oscar A. Garay at Balcare, Argentina. The experiment was done in +#' a randomized complete block design with 4 blocks. Potato yield +#' (t/ha) was recorded in each experimental unit. #' #' \itemize{ #' \item \code{block} a categorical unordered factor with 4 levels. @@ -70,8 +71,8 @@ NULL #' #' @format a \code{data.frame} with 32 records and 3 variables. #' -#' @source Frederico, P. (2009). Curso de Estatística Experimental -#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 76) +#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th +#' ed.). Piracicaba, São Paulo: FEALQ. (page 76) #' #' @examples #' require(lattice) @@ -89,12 +90,12 @@ NULL #' @title Plowing level on corn yield #' #' @description These data are from an experiment done by the engineer -#' Duvilio Ometto to study the effect of plowing level on corn yield. It -#' was used 2 levels of plowing: normal (or superficial) and deep. The -#' experiment was done in a randomized complete block design with 6 -#' blocks. Corn yield (t/ha) was recorded in each experimental unit -#' but in this experiment there was 2 experimental units for each factor -#' level in each block. +#' Duvilio Ometto to study the effect of plowing level on corn +#' yield. It was used 2 levels of plowing: normal (or superficial) +#' and deep. The experiment was done in a randomized complete block +#' design with 6 blocks. Corn yield (t/ha) was recorded in each +#' experimental unit but in this experiment there was 2 experimental +#' units for each factor level in each block. #' #' \itemize{ #' \item \code{block} a categorical unordered factor with 6 levels. @@ -110,8 +111,8 @@ NULL #' #' @format a \code{data.frame} with 24 records and 3 variables. #' -#' @source Frederico, P. (2009). Curso de Estatística Experimental -#' (15th ed.). Piracicaba, São Paulo: FEALQ. (page 91) +#' @source Frederico, P. (2009). Curso de Estatística Experimental (15th +#' ed.). Piracicaba, São Paulo: FEALQ. (page 91) #' #' @examples #' require(lattice) @@ -122,3 +123,86 @@ NULL #' xlab="Plowing level") #' 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 diff --git a/R/panel.segplot.by.R b/R/panel.segplot.by.R new file mode 100644 index 0000000000000000000000000000000000000000..0ae4046171b40eb7119e1320943f8011432b0f98 --- /dev/null +++ b/R/panel.segplot.by.R @@ -0,0 +1,85 @@ +#' @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, ...) +} diff --git a/R/yscale.components.right.R b/R/yscale.components.right.R new file mode 100644 index 0000000000000000000000000000000000000000..afbce1c98e725548dcc99440d8deb818de8aedcb --- /dev/null +++ b/R/yscale.components.right.R @@ -0,0 +1,56 @@ +#' @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 +} diff --git a/buildPkg.R b/buildPkg.R index 0ec73c8c77fd4edb47d79d00372c3ab8e7c3f09f..8f1fe872da710dd750791d288955a1cfb8c0673a 100644 --- a/buildPkg.R +++ b/buildPkg.R @@ -30,7 +30,7 @@ check(cleanup = FALSE, manual = TRUE, vignettes = FALSE, # Run examples from all functions of the package # run_examples() # Run examples from a specific function -# dev_example("loessGui") +# dev_example("yscale.components.right") ## Show all exported objects. ls("package:legTools") diff --git a/data-raw/defoliation.R b/data-raw/defoliation.R new file mode 100644 index 0000000000000000000000000000000000000000..b79f1984360487c52400cfd5c01f300743e3d767 --- /dev/null +++ b/data-raw/defoliation.R @@ -0,0 +1,51 @@ +##---------------------------------------------------------------------- +## 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)) diff --git a/data/defoliation.RData b/data/defoliation.RData new file mode 100644 index 0000000000000000000000000000000000000000..7591edb21dc916b9c442700ecfd896ea234fd3fa Binary files /dev/null and b/data/defoliation.RData differ diff --git a/man/defoliation.Rd b/man/defoliation.Rd new file mode 100644 index 0000000000000000000000000000000000000000..d6ea686b6656a2322a38fadc52b0bcfb9bd5170c --- /dev/null +++ b/man/defoliation.Rd @@ -0,0 +1,83 @@ +% 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} + diff --git a/man/knit2wpCrayon.Rd b/man/knit2wpCrayon.Rd new file mode 100644 index 0000000000000000000000000000000000000000..d23869a7b427b882cd92f49c42549c3fc795a32a --- /dev/null +++ b/man/knit2wpCrayon.Rd @@ -0,0 +1,69 @@ +% 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} +} + diff --git a/man/panel.segplot.by.Rd b/man/panel.segplot.by.Rd new file mode 100644 index 0000000000000000000000000000000000000000..bebaf57434034e5bba20de521fd51bd6020ebedc --- /dev/null +++ b/man/panel.segplot.by.Rd @@ -0,0 +1,82 @@ +% 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}} +} + diff --git a/man/plowing.Rd b/man/plowing.Rd index 22c538f000d245fd2f1f2f66ccd181754ad500eb..08bd7fde8c86c7ccafeb29b60ecf1c3c9a7dfa55 100644 --- a/man/plowing.Rd +++ b/man/plowing.Rd @@ -6,20 +6,20 @@ \title{Plowing level on corn yield} \format{a \code{data.frame} with 24 records and 3 variables.} \source{ -Frederico, P. (2009). Curso de Estatística Experimental -(15th ed.). Piracicaba, São Paulo: FEALQ. (page 91) +Frederico, P. (2009). Curso de Estatística Experimental (15th + ed.). Piracicaba, São Paulo: FEALQ. (page 91) } \usage{ data(plowing) } \description{ These data are from an experiment done by the engineer -Duvilio Ometto to study the effect of plowing level on corn yield. It -was used 2 levels of plowing: normal (or superficial) and deep. The -experiment was done in a randomized complete block design with 6 -blocks. Corn yield (t/ha) was recorded in each experimental unit -but in this experiment there was 2 experimental units for each factor -level in each block. + Duvilio Ometto to study the effect of plowing level on corn + yield. It was used 2 levels of plowing: normal (or superficial) + and deep. The experiment was done in a randomized complete block + design with 6 blocks. Corn yield (t/ha) was recorded in each + experimental unit but in this experiment there was 2 experimental + units for each factor level in each block. \itemize{ \item \code{block} a categorical unordered factor with 6 levels. diff --git a/man/potatoyield.Rd b/man/potatoyield.Rd index aa78816a35cf785dcff08dda991b24da3e8a1d91..c4579659b31aed480803e3b82e5d239d4191d544 100644 --- a/man/potatoyield.Rd +++ b/man/potatoyield.Rd @@ -6,17 +6,17 @@ \title{Potato variety competition experiment} \format{a \code{data.frame} with 32 records and 3 variables.} \source{ -Frederico, P. (2009). Curso de Estatística Experimental -(15th ed.). Piracicaba, São Paulo: FEALQ. (page 76) +Frederico, P. (2009). Curso de Estatística Experimental (15th + ed.). Piracicaba, São Paulo: FEALQ. (page 76) } \usage{ data(potatoyield) } \description{ These data are from an experiment done by the engineer -Oscar A. Garay at Balcare, Argentina. The experiment was done in a -randomized complete block design with 4 blocks. Potato yield (t/ha) -was recorded in each experimental unit. + Oscar A. Garay at Balcare, Argentina. The experiment was done in + a randomized complete block design with 4 blocks. Potato yield + (t/ha) was recorded in each experimental unit. \itemize{ \item \code{block} a categorical unordered factor with 4 levels. diff --git a/man/wgpigs.Rd b/man/wgpigs.Rd index 67eebec51c8437acda3321ec8541163b2985092d..0ffa7f43348166d621a14d2ed3f3d3bf854db82f 100644 --- a/man/wgpigs.Rd +++ b/man/wgpigs.Rd @@ -6,19 +6,20 @@ \title{Feeding type in pig weight gain} \format{a \code{data.frame} with 20 records and 2 variables.} \source{ -Frederico, P. (2009). Curso de Estatística Experimental -(15th ed.). Piracicaba, São Paulo: FEALQ. (page 62) +Frederico, P. (2009). Curso de Estatística Experimental (15th + ed.). Piracicaba, São Paulo: FEALQ. (page 62) } \usage{ data(wgpigs) } \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. + 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{ft} feeding type, a categorical factor with 4 diff --git a/man/yscale.components.right.Rd b/man/yscale.components.right.Rd new file mode 100644 index 0000000000000000000000000000000000000000..cfe1220fbe2e36861731f8125f1c16cdedb9552e --- /dev/null +++ b/man/yscale.components.right.Rd @@ -0,0 +1,55 @@ +% 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} +} +