From b5a44ac544b03012ca5e0939effb91110ba149d0 Mon Sep 17 00:00:00 2001 From: Derek Ogle Date: Sat, 12 Feb 2022 13:25:33 -0600 Subject: [PATCH] Closing out v0.9.2 (again, w some pkgdown fixes) --- NAMESPACE | 18 - NEWS.md | 4 + R/FSA-defunct.R | 24 ++ R/FSAUtils.R | 82 ---- R/deprecated-residPlot.R | 467 --------------------- R/deprecated_fitPlot.R | 674 ------------------------------- _pkgdown.yml | 7 + docs/news/index.html | 124 +++--- docs/pkgdown.yml | 2 +- docs/reference/Summarize.html | 88 ++-- docs/reference/alkIndivAge.html | 56 +-- docs/reference/expandCounts.html | 128 +++--- docs/reference/growthModels.html | 76 ++-- docs/reference/index.html | 20 + docs/reference/sumTable.html | 60 +-- man/FSA-defunct.Rd | 12 + man/filterD.Rd | 53 --- man/fitPlot.Rd | 287 ------------- man/fsaNews.Rd | 28 -- man/residPlot.Rd | 263 ------------ 20 files changed, 338 insertions(+), 2135 deletions(-) delete mode 100644 R/deprecated-residPlot.R delete mode 100644 R/deprecated_fitPlot.R delete mode 100644 man/filterD.Rd delete mode 100644 man/fitPlot.Rd delete mode 100644 man/fsaNews.Rd delete mode 100644 man/residPlot.Rd diff --git a/NAMESPACE b/NAMESPACE index 707e3d2d..2f2df002 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,15 +22,6 @@ S3method(confint,nlsBoot) S3method(confint,removal) S3method(dunnTest,default) S3method(dunnTest,formula) -S3method(fitPlot,IVR) -S3method(fitPlot,ONEWAY) -S3method(fitPlot,POLY) -S3method(fitPlot,SLR) -S3method(fitPlot,TWOWAY) -S3method(fitPlot,glm) -S3method(fitPlot,lm) -S3method(fitPlot,logreg) -S3method(fitPlot,nls) S3method(hist,boot) S3method(hist,formula) S3method(histFromSum,default) @@ -59,14 +50,6 @@ S3method(rSquared,catchCurve) S3method(rSquared,default) S3method(rSquared,depletion) S3method(rSquared,lm) -S3method(residPlot,IVR) -S3method(residPlot,ONEWAY) -S3method(residPlot,POLY) -S3method(residPlot,SLR) -S3method(residPlot,TWOWAY) -S3method(residPlot,lm) -S3method(residPlot,nlme) -S3method(residPlot,nls) S3method(sumTable,formula) S3method(summary,ageBias) S3method(summary,agePrec) @@ -79,7 +62,6 @@ S3method(summary,mrOpen) S3method(summary,removal) S3method(wrAdd,default) S3method(wrAdd,formula) -export(FSANews) export(GompertzFuns) export(Mmethods) export(RichardsFuns) diff --git a/NEWS.md b/NEWS.md index 984d7851..2609f12f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,12 @@ # FSA 0.9.2 12-Feb-21 * Last version maintained by Derek Ogle. Transfering to fishR Core Team for next version. +* `filterD()`: **REMOVED** (to `FSAmisc`). +* `fitPlot()`: **REMOVED** (to `FSAmisc`). +* `fsaNews()` and `FSANews()`: **Removed**. * `psdAdd()`: Modified. Changed the way `PSDlit` was loaded into the function environment so that `FSA::psdAdd()` will work. Addresses [#85](https://github.com/droglenc/FSA/issues/85). * `PSDLit`: Modified. Added info for Utah Chub (from [here](https://webpages.uidaho.edu/quistlab/publications/NAJFM_2021_Black_et_al_UTC_Ws_length_categories.pdf); address [#84](https://github.com/droglenc/FSA/issues/84)). * `psdVal()`: Modified. Changed the way `PSDlit` was loaded into the function environment so that `FSA::psdVal()` will work. Addresses [#85](https://github.com/droglenc/FSA/issues/85). +* `residPlot()`: **REMOVED** (to `FSAmisc`). * `wrAdd()`: Modified. Changed the way `WSlit` was loaded into the function environment so that `FSA::wrAdd()` will work. Addresses [#85](https://github.com/droglenc/FSA/issues/85). * `WSLit`: Modified. Added info for Utah Chub (from [here](https://webpages.uidaho.edu/quistlab/publications/NAJFM_2021_Black_et_al_UTC_Ws_length_categories.pdf); address [#84](https://github.com/droglenc/FSA/issues/84)). * `wsVal()`: Modified. Changed the way `WSlit` was loaded into the function environment so that `FSA::wsVal()` will work. Addresses [#85](https://github.com/droglenc/FSA/issues/85). diff --git a/R/FSA-defunct.R b/R/FSA-defunct.R index 150c8025..154a5c53 100644 --- a/R/FSA-defunct.R +++ b/R/FSA-defunct.R @@ -33,6 +33,24 @@ diags <- function(...) { .Defunct(msg="'diags' has been removed (to 'FSAmisc' on GitHub).") } +#' @rdname FSA-defunct +#' @export +filterD <- function(...) { + .Defunct(msg="'filter' has been removed (to 'FSAmisc' on GitHub); please use 'droplevels' after 'subset' or 'dplyr::filter' for the same result (see fishR post from 26-May-2021).") +} + +#' @rdname FSA-defunct +#' @export +fitPlot <- function(...) { + .Defunct(msg="'fitPlot' has been removed (to 'FSAmisc' on GitHub).") +} + +#' @rdname FSA-defunct +#' @export +fsaNews <- FSANews <- function(...) { + .Defunct(msg="'fsaNews' and 'FSANews' have been removed (to 'FSAmisc' on GitHub).") +} + #' @rdname FSA-defunct #' @export hoCoef <- function(...) { @@ -51,6 +69,12 @@ plotBinResp <- function(...) { .Defunct(msg="'plotBinResp' has been removed; use 'ggplot2' as described in the fishR blog post of 25-May-2021.") } +#' @rdname FSA-defunct +#' @export +residPlot <- function(...) { + .Defunct(msg="'residPlot' has been removed (to 'FSAmisc' on GitHub).") +} + #' @rdname FSA-defunct #' @export Subset <- function(...) { diff --git a/R/FSAUtils.R b/R/FSAUtils.R index 01fe82e3..4ebf42f4 100644 --- a/R/FSAUtils.R +++ b/R/FSAUtils.R @@ -194,39 +194,6 @@ fishR <- function(where=c("home","IFAR","general","books", invisible(tmp) } -#' @name fsaNews -#' -#' @title Read news and changes for the 'FSA' package. -#' -#' @description Opens up the \href{https://github.com/droglenc/FSA/blob/master/NEWS.md}{News.md GitHub file} for the \sQuote{FSA} package in an external browser. -#' -#' @aliases fsaNews FSANews -#' -#' @return None. -#' -#' @author Derek H. Ogle, \email{derek@@derekogle.com} -#' -#' @keywords manip -#' -#' @examples -#' \dontrun{ -#' ## Opens an external webpage ... only run interactively -#' FSANews() -#' } -#' -#' @rdname fsaNews -#' @export -fsaNews <- function () { - utils::browseURL("https://github.com/droglenc/FSA/blob/master/NEWS.md") -} - -#' @rdname fsaNews -#' @export -FSANews <- function () { - fsaNews() -} - - #' @title Shows rows from the head and tail of a data frame or matrix. #' #' @description Shows rows from the head and tail of a data frame or matrix. @@ -829,55 +796,6 @@ se <- function (x,na.rm=TRUE) { sqrt(stats::var(x)/length(x)) } -#' @name filterD-deprecated -#' -#' @title DEPRECATED - Subsets/filters a data frame and drops the unused levels. -#' -#' @description Subsets/filters a data frame and drops the unused levels. -#' -#' @details Newbie students using R expect that when a factor variable is filtered with \code{\link[dplyr]{filter}} that any original levels that are no longer used after the filtering will be ignored. This, however, is not the case and often results in tables with empty cells and figures with empty bars. One remedy is to use \code{\link[base]{droplevels}} immediately following \code{\link[dplyr]{filter}}. This generally becomes a repetitive sequence for most newbie students; thus, \code{filterD} incorporate these two functions into one function. -#' -#' \code{filterD} is a wrapper for \code{\link[dplyr]{filter}} from \pkg{dplyr} followed by \code{\link[base]{droplevels}} just before the data.frame is returned. Otherwise, there is no new code here. -#' -#' This function is only used for data frames. -#' -#' @param x A data frame. -#' @param except Indices of columns from which NOT to drop levels. -#' @param \dots further arguments to be passed to \code{\link[dplyr]{filter}}. -#' -#' @return A data frame with the filtered rows. -#' -#' @author Derek H. Ogle, \email{derek@@derekogle.com} -#' -#' @section IFAR Chapter: Basic Data Manipulations. -#' -#' @seealso See \code{subset} and \code{\link[dplyr]{filter}} from \pkg{dplyr} for similar functionality. See \code{drop.levels} in \pkg{gdata} and \code{droplevels} for related functionality. -#' -#' @keywords misc -#' -#' @examples -#' ## The problem -- note use of unused level in the final table. -#' levels(iris$Species) -#' iris.set1 <- subset(iris,Species=="setosa" | Species=="versicolor") -#' levels(iris.set1$Species) -#' xtabs(~Species,data=iris.set1) -#' -#' ## A fix using filterD -#' iris.set3 <- filterD(iris,Species=="setosa" | Species=="versicolor") -#' levels(iris.set3$Species) -#' xtabs(~Species,data=iris.set3) -#' -#' @rdname filterD -#' @export -filterD <- function(x,...,except=NULL) { - .Deprecated(msg="'filter' is deprecated and will soon be removed from 'FSA'; please use 'droplevels' after 'subset' or 'dplyr::filter' for the same result (see fishR post from 26-May-2021).") - res <- dplyr::filter(x,...) - res <- droplevels(res,except) - if (nrow(res)==0) - WARN("The resultant data.frame has 0 rows. Try str() on the result.\n") - res -} - #' @title Finds the number of valid (non-NA) values in a vector. #' diff --git a/R/deprecated-residPlot.R b/R/deprecated-residPlot.R deleted file mode 100644 index 75486a04..00000000 --- a/R/deprecated-residPlot.R +++ /dev/null @@ -1,467 +0,0 @@ -#' @title DEPRECATED -- Construct a residual plot from lm or nls objects. -#' -#' @description Constructs a residual plot for \code{lm} or \code{nls} objects. Different symbols for different groups can be added to the plot if an indicator variable regression is used. -#' -#' @details Three types of residuals are allowed for most model types. Raw residuals are simply the difference between the observed response variable and the predicted/fitted value. Standardized residuals are internally studentized residuals returned by \code{\link{rstandard}} for linear models and are the raw residual divided by the standard deviation of the residuals for nonlinear models (as is done by \code{\link[nlstools]{nlsResiduals}} from \pkg{nlstools}). Studentized residuals are the externally studentized residuals returned by \code{\link{rstudent}} for linear models and are not available for nonlinear models. -#' -#' Externally Studentized residuals are not supported for \code{nls} or \code{nlme} objects. -#' -#' If \code{outlier.test=TRUE} then significant outliers are detected with \code{\link[car]{outlierTest}} from the \pkg{car} package. See the help for this function for more details. -#' -#' The user can include the model call as a title to the residual plot by using \code{main="MODEL"}. This only works for models created with \code{lm()}. -#' -#' If the user chooses to add a legend without identifying coordinates for the upper-left corner of the legend (i.e., \code{legend=TRUE}) then the R console is suspended until the user places the legend by clicking on the produced graphic at the point where the upper-left corner of the legend should appear. A legend will only be placed if the \code{mdl} is an indicator variable regression, even if \code{legend=TRUE}. -#' -#' @note This function is meant to allow newbie students the ability to easily construct residual plots for one-way ANOVA, two-way ANOVA, simple linear regression, and indicator variable regressions. The plots can be constructed by submitting a saved linear model to this function which allows students to interact with and visualize moderately complex linear models in a fairly easy and efficient manner. -#' -#' @aliases residPlot residPlot.lm residPlot.SLR residPlot.IVR residPlot.POLY residPlot.ONEWAY residPlot.TWOWAY residPlot.nls -#' -#' @param object An \code{lm} or \code{nls} object (i.e., returned from fitting a model with either \code{lm} or \code{nls}). -#' @param resid.type The type of residual to use. \sQuote{Raw} residuals are used by default. See details. -#' @param outlier.test A logical that indicates if an \code{outlierTest} will \code{TRUE} (default) be performed and if the individual with the largest studentized residual is deemed to be a significant outlier it will be noted on the residual plot by its observation number. -#' @param loess A logical that indicates if a loess smoother line and approximate confidence interval band is fit to and shown on the residual plot (\code{TRUE}). -#' @param bp A logical that indicates if the plot for the one-way and two-way ANOVA will be a boxplot (\code{TRUE}; default) or not. -#' @param alpha A numeric that indicates the alpha level to use for the outlier test (only used if \code{outlier.test=TRUE}). -#' @param xlab A string for labeling the x-axis. -#' @param ylab A string for labeling the y-axis. -#' @param main A string for the main label to the plot. See details. -#' @param pch A numeric that indicates the plotting character to be used or a vector of numerics that indicates what plotting character codes to use for the levels of the second factor. See \code{par}. -#' @param col A vector of color names that indicates what color of points and lines to use for the levels of the first factor. See \code{par}. -#' @param lty.ref A numeric that indicates the line type to use for the reference line at residual=0. See \code{par}. -#' @param lwd.ref A numeric that indicates the line width to use for the reference line at residual=0. See \code{par}. -#' @param col.ref A numeric or character that indicates the line color to use for the reference line at residual=0. See \code{par}. -#' @param lty.loess A numeric that indicates the line type to use for loess fit line. See \code{par}. -#' @param lwd.loess A numeric that indicates the line width to use for loess fit line. See \code{par}. -#' @param col.loess A numeric or character that indicates the line color to use for loess fit line. See \code{par}. -#' @param trans.loess A single numeric that indicates how transparent the loess band should be (larger numbers are more transparent). -#' @param legend If \code{TRUE}, draw a legend and the user must click in the upper-left corner of where the legend should be placed; if \code{FALSE} do not draw a legend. If a vector of length 2 then draw the upper left corner of the legend at the coordinates given in the vector of length 2. -#' @param cex.leg A single numeric values used to represent the character expansion value for the legend. Ignored if \code{legend=FALSE}. -#' @param box.lty.leg A single numeric values used to indicate the type of line to use for the box around the legend. The default is to not plot a box. -#' @param inclHist A logical that indicates if a second pane that includes the histogram of residuals should be constructed. -#' @param \dots Other arguments to the generic \code{plot} function. -#' -#' @return None. However, a residual plot is produced. -#' -#' @author Derek H. Ogle, \email{derek@@derekogle.com} -#' -#' @seealso See \code{\link[car]{residualPlots}} in \pkg{car} and \code{\link[nlstools]{nlsResiduals}} in \pkg{nlstools}) for similar functionality. See \code{\link[car]{outlierTest}} in \pkg{car} for related methods. -#' -#' @keywords hplot models -#' -#' @examples -#' # create year factor variable -#' Mirex$fyear <- factor(Mirex$year) -#' Mirex$cyear <- as.character(Mirex$year) -#' Mirex$cspecies <- as.character(Mirex$species) -#' -#' ## One-way ANOVA -#' aov1 <- lm(mirex~fyear,data=Mirex) -#' residPlot(aov1) -#' -#' ## Two-Way ANOVA -#' aov2 <- lm(mirex~species*fyear,data=Mirex) -#' residPlot(aov2) -#' -#' ## Simple linear regression -#' slr1 <- lm(mirex~weight,data=Mirex) -#' residPlot(slr1) -#' residPlot(slr1,loess=TRUE,main="MODEL") -#' -#' ## Indicator variable regression with only one factor -#' ivr1 <- lm(mirex~weight*fyear,data=Mirex) -#' residPlot(ivr1) -#' residPlot(ivr1,inclHist=FALSE,pch=19) -#' residPlot(ivr1,inclHist=FALSE,pch=19,col="black") -#' residPlot(ivr1,legend=FALSE,loess=TRUE) -#' -#' ## Indicator variable regression (assuming same slope) -#' ivr2 <- lm(mirex~weight+fyear,data=Mirex) -#' residPlot(ivr2,legend=FALSE,loess=TRUE) -#' -#' ## Indicator variable regression with two factors -#' ## Reduce number of years for visual simplicity -#' Mirex2 <- droplevels(subset(Mirex,fyear %in% c(1977,1992))) -#' -#' ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2) -#' residPlot(ivr3) -#' residPlot(ivr3,loess=TRUE,legend=FALSE) -#' -#' ## IVR w/ factors in different order (notice use of colors and symbols) -#' ivr4 <- lm(mirex~weight*species*fyear,data=Mirex2) -#' residPlot(ivr4) -#' -#' -#' ## Nonlinear regression ... from first example in nls() -#' DNase1 <- subset(DNase,Run==1) -#' fm1DNase1 <- nls(density~SSlogis(log(conc),Asym,xmid,scal),DNase1) -#' residPlot(fm1DNase1) -#' residPlot(fm1DNase1,resid.type="standardized") -#' -#' -#' ## Examples showing outlier detection -#' x <- c(runif(100)) -#' y <- c(7,runif(98),-5) -#' lma <- lm(y~x) -#' residPlot(lma) -#' residPlot(lma,resid.type="studentized") -#' -#' @rdname residPlot -#' @export -residPlot <- function (object,...) { - if ("lm" %in% class(object)) ## This is a hack so no double deprecation warning - .Deprecated(msg="'residPlot' is deprecated and will soon be removed from 'FSA'; see fishR post from 1-Jun-2021 for alternative methods.") - UseMethod("residPlot") -} - -#' @rdname residPlot -#' @export -residPlot.lm <- function(object,...) { # nocov start - object <- iTypeoflm(object) - if (object$type=="MLR") - STOP("Multiple linear regression objects are not supported by residPlot.") - residPlot(object,...) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.SLR <- function(object,xlab="Fitted Values",ylab="Residuals",main="", - pch=16,col="black",lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - outlier.test=TRUE,alpha=0.05, - loess=FALSE,lty.loess=2,lwd.loess=1,col.loess="black", - trans.loess=8,inclHist=TRUE,...) { # nocov start - main <- iGetMainTitle(object,main) - fv <- object$mdl$fitted.values - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch,col=col) - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - if (inclHist) iHistResids(r,ylab) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.POLY <- function(object,...) { # nocov start - residPlot.SLR(object,...) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.IVR <- function(object,legend="topright",cex.leg=1,box.lty.leg=0,...) { - ## Do some checks - if (object$ENumNum>1) STOP("'residPlot()' cannot handle >1 covariate in an IVR.") - if (object$EFactNum>2) STOP("'resodPlot()' cannot handle >2 factors in an IVR.") - ## Decide if a one-way or two-way IVR - if (object$EFactNum==1) iResidPlotIVR1(object,legend,cex.leg,box.lty.leg,...) - else iResidPlotIVR2(object,legend,cex.leg,box.lty.leg,...) -} - - -iResidPlotIVR1 <- function(object,legend,cex.leg,box.lty.leg, - xlab="Fitted Values",ylab="Residuals",main="", - pch=c(16,21,15,22,17,24,c(3:14)),col="Dark 2", - lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - outlier.test=TRUE,alpha=0.05, - loess=FALSE,lty.loess=2,lwd.loess=1,col.loess="black", - trans.loess=8,inclHist=TRUE,...) { # nocov start - main <- iGetMainTitle(object,main) - fv <- object$mdl$fitted.values - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - leg <- iLegendHelp(legend) # will there be a legend - if (!leg$do.legend) { - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch[1],col=ifelse(col=="Dark 2","black",col)) - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - } else { - # extract the factor variable from the 2nd position - f1 <- object$mf[,object$EFactPos[1]] - # Handle colors, pchs, ltys -- one for each level of f1 factor unless only - # one color is given - col <- iFitPlotClrs2(f1,col) - pch <- iFitPlotPchs2(f1,pch) - ### Plot the points - # Makes room for legend - ifelse(leg$do.legend,xlim <- c(min(fv),max(fv)+0.3*(max(fv)-min(fv))), - xlim <- range(fv)) - # Creates plot schematic -- no points or lines - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - # Plots points w/ different colors & points - levs.f1 <- unique(f1) - for (i in seq_along(levs.f1)) { - fv.obs <- fv[f1==levs.f1[i]] - r.obs <- r[f1==levs.f1[i]] - graphics::points(fv.obs,r.obs,col=col[i],pch=pch[i]) - } # end for i - ## add outlier test if asked for - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - ### Prepare and place the legend - if (leg$do.legend) { - graphics::legend(x=leg$x,y=leg$y,legend=levs.f1,col=col,pch=pch, - cex=cex.leg,box.lty=box.lty.leg) - graphics::box() - } - } - if (inclHist) iHistResids(r,ylab) -} # nocov end - - -iResidPlotIVR2 <- function(object,legend,cex.leg,box.lty.leg, - xlab="Fitted Values",ylab="Residuals",main="", - pch=c(16,21,15,22,17,24,c(3:14)),col="Dark 2", - lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - outlier.test=TRUE,alpha=0.05, - loess=FALSE,lty.loess=2,lwd.loess=1,col.loess="black", - trans.loess=8,inclHist=TRUE,...) { # nocov start - main <- iGetMainTitle(object,main) - fv <- object$mdl$fitted.values - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - leg <- iLegendHelp(legend) # will there be a legend - if (!leg$do.legend) { - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch[1],col="black") - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - } else { - f1 <- object$mf[,object$EFactPos[1]] - f2 <- object$mf[,object$EFactPos[2]] - # find number of levels of each factor - levs.f1 <- unique(f1) - num.f1 <- length(levs.f1) - levs.f2 <- unique(f2) - num.f2 <- length(levs.f2) - # Handle colors, pchs, ltys -- one for each level of f1 factor unless - # only one color is given - col <- iFitPlotClrs2(f1,col) - pch <- iFitPlotPchs2(f2,pch) - ### Plot the points - # Makes room for legend - ifelse(leg$do.legend, - xlim <- c(min(fv),max(fv)+0.3*(max(fv)-min(fv))), - xlim <- range(fv)) - # Creates plot schematic -- no points or lines - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - for (i in seq_along(levs.f1)) { - for (j in seq_along(levs.f2)) { - # Plots points w/ different colors & points - fv.obs <- fv[f1==levs.f1[i] & f2==levs.f2[j]] - r.obs <- r[f1==levs.f1[i] & f2==levs.f2[j]] - graphics::points(fv.obs,r.obs,col=col[i],pch=pch[j]) - } # end for j - } # end for i - ## add outlier test if asked for - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - ### Prepare and place the legend - if (leg$do.legend) { - lcol <- rep(col,each=num.f2) - lpch <- rep(pch,times=num.f1) - levs <- expand.grid(levs.f1,levs.f2,stringsAsFactors=FALSE, - KEEP.OUT.ATTRS=FALSE) - levs <- paste(levs[,1],levs[,2],sep =":") - graphics::legend(x=leg$x,y=leg$y,legend=levs,col=lcol,pch=lpch, - cex=cex.leg,box.lty=box.lty.leg) - graphics::box() - } - } - if (inclHist) iHistResids(r,ylab) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.ONEWAY <- function(object,xlab="Fitted Values",ylab="Residuals",main="", - pch=16,col="black",lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - bp=TRUE,outlier.test=TRUE,alpha=0.05, - loess=FALSE,lty.loess=2,lwd.loess=1,col.loess="black",trans.loess=8, - inclHist=TRUE,...) { # nocov start - main <- iGetMainTitle(object,main) - if (bp & xlab=="Fitted Values") xlab <- "Treatment Group" - fv <- object$mdl$fitted.values - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - gf <- object$mf[,2] - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - if (bp) { - graphics::boxplot(r~gf,xlab=xlab,ylab=ylab,main=main) - graphics::abline(h=0,lty=lty.ref,lwd=lwd.ref,col=col.ref) - } else { - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch,col=col) - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - } - if (inclHist) iHistResids(r,ylab) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.TWOWAY <- function(object,xlab="Fitted Values",ylab="Residuals",main="", - pch=16,col="black",lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - bp=TRUE,outlier.test=TRUE,alpha=0.05, - loess=FALSE,lty.loess=2,lwd.loess=1,col.loess="black",trans.loess=8, - inclHist=TRUE,...) { # nocov start - main <- iGetMainTitle(object,main) - if (bp & xlab=="Fitted Values") xlab <- "Treatment Group" - fv <- object$mdl$fitted.values - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - gf1 <- object$mf[,2] - gf2 <- object$mf[,3] - gf <- interaction(gf1,gf2) - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - if (bp) { - graphics::boxplot(r~gf,xlab=xlab,ylab=ylab,main=main) - graphics::abline(h=0,lty=lty.ref,lwd=lwd.ref,col=col.ref) - } else { - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch,col=col) - if (outlier.test) iAddOutlierTestResults(object,fv,r,alpha) - } - if (inclHist) iHistResids(r,ylab) -} # nocov end - -#' @rdname residPlot -#' @export -residPlot.nls<-function(object,xlab="Fitted Values",ylab="Residuals",main="", - pch=16,col="black",lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - loess=FALSE,lty.loess=2,lwd.loess=1, - col.loess="black",trans.loess=8,inclHist=TRUE,...) { # nocov start - fv <- stats::fitted(object) - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch,col=col) - if (inclHist) iHistResids(r,ylab) -} # nocov end - - - -#' @rdname residPlot -#' @export -residPlot.nlme<-function(object,xlab="Fitted Values",ylab="Residuals",main="", - pch=16,col="black",lty.ref=3,lwd.ref=1,col.ref="black", - resid.type=c("raw","standardized","studentized"), - loess=FALSE,lty.loess=2,lwd.loess=1, - col.loess="black",trans.loess=8,inclHist=TRUE,...) { # nocov start - fv <- stats::fitted(object) - tmp <- iHndlResidType(object,match.arg(resid.type),ylab) - r <- tmp$r - ylab <- tmp$ylab - if (inclHist) withr::local_par(list(mfrow=c(1,2))) - iMakeBaseResidPlot(r,fv,xlab,ylab,main,lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess,...) - graphics::points(r~fv,pch=pch,col=col) - if (inclHist) iHistResids(r,ylab) -} # nocov end - - - -################################################################## -### internal functions used in residPlot -################################################################## -iMakeBaseResidPlot <- function(r,fv,xlab,ylab,main, - lty.ref,lwd.ref,col.ref, - loess,lty.loess,lwd.loess,col.loess,trans.loess, - ...) { - ## makes a base plot that has the axes with appropriate range - ## and labels, the horizontal reference line at 0, and, if - ## asked for, a loess smoother for the points. The functions - ## that call this then just need to add the points. - xrng <- range(fv) - yrng <- range(r) - graphics::plot(r~fv,col="white",xlab=xlab,ylab=ylab,main=main,...) - if (loess) iAddLoessLine(r,fv,lty.loess,lwd.loess,col.loess,trans.loess) - graphics::abline(h=0,lty=lty.ref,lwd=lwd.ref,col=col.ref) -} - -iAddOutlierTestResults <- function(object,fv,r,alpha) { - # get results - out <- car::outlierTest(object$mdl,cutoff=alpha) - # number of points returned by outlierTest - num <- length(out$bonf.p) - # If only one point returned then ... - if (num==1) { - if (is.na(out$bonf.p)) num <- 0 # if it is NA then p>1 ... so not a significant point - else if (out$bonf.p>alpha) num <- 0 # if p>alpha then ... not a significant point - } - # If there are significant points to be highlighted then ... - if (num>0) { # nocov start - # Determine which observation(s) is/are "significant" outlier(s) - obs <- which(names(fv) %in% names(out$bonf.p)) - # Set text position based on sign of r if only one "outlier" is detected - if (num==1) ifelse(r[obs]<0,pos <- 3,pos <- 1) - # Use thigmophobe to find better text positions if more "outliers" are detected - else pos <- plotrix::thigmophobe(fv,r)[obs] - # place labels - graphics::text(fv[obs],r[obs],names(fv)[obs], - cex=1.1,col="red",pos=pos,xpd=TRUE) - } # nocov end -} # end iAddOutlierTestResults internal function - -iGetMainTitle <- function(object,main) { - if (main=="MODEL") { - ## user asked to use model - # get formula parts (extra spaces are removed) - frm.chr <- gsub("\\s+","",as.character(stats::formula(object$mdl))) - # put together as a main title - main <- paste0(frm.chr[2],frm.chr[1],frm.chr[3]) - } - # return the title (will be original if not main="MODEL") - main -} # end iGetMainTitle internal function - -iHistResids <- function(r,xlab) { - hist.formula(~r,xlab=xlab) -} - -iHndlResidType <- function(object,resid.type,ylab) { - suppressWarnings(if(!inherits(object,c("nls","nlme"))) { - switch(resid.type, - raw= { r <- object$mdl$residuals }, - standardized= { r <- stats::rstandard(object$mdl) }, - studentized= { r <- stats::rstudent(object$mdl) } - ) - } else if (inherits(object,"nls")) { - r <- stats::residuals(object) - if (resid.type=="studentized") STOP("resid.type= cannot be 'studentized' for NLS objects. Try resid.type='standardized'.") - else if (resid.type=="standardized") { - # this follows nlsResiduals() from nlstools - r <- (r-mean(r))/summary(object)$sigma - } - } else { - if (resid.type=="studentized") STOP("resid.type= cannot be 'studentized' for NLME objects. Try resid.type='standardized'.") - else if (resid.type=="standardized") { - r <- stats::residuals(object,type="pearson") - } else { - r <- stats::residuals(object,type="response") - } - } - ) - if (resid.type!="raw" & ylab=="Residuals") { - if (resid.type=="standardized") ylab <- "Standardized Residuals" - else ylab <- "Studentized Residuals" - } - return(list(r=r,ylab=ylab)) -} \ No newline at end of file diff --git a/R/deprecated_fitPlot.R b/R/deprecated_fitPlot.R deleted file mode 100644 index 2e6b23b6..00000000 --- a/R/deprecated_fitPlot.R +++ /dev/null @@ -1,674 +0,0 @@ -#' @title DEPRECATED -- Fitted model plot for an lm, glm, or nls object. -#' -#' @description A generic function for constructing a fitted model plot for an \code{lm}, \code{glm}, or \code{nls} object. Supported objects are linear models from simple linear regression (SLR), indicator variable regression (IVR), one-way ANOVA, or two-way ANOVA models; general linear models that are logistic regressions with a binary response; and non-linear regression with a single numerical response variable, at least one continuous explanatory variable and up to two group-factor explanatory variables. -#' -#' @details This function does not work with a multiple linear regression, indicator variable regressions with more than two factors, ANOVAs other than one-way and two-way, or models with a categorical response variable. In addition, if the linear model contains a factor then the model must be fit with the quantitative explanatory variable first, followed by the factor(s). This function only works for non-linear models with two or fewer groups. -#' -#' This function is basically a wrapper to a variety of other functions. For one-way or two-way ANOVAs the primary functions called are \code{interaction.plot} and \code{lineplot.CI}. For simple linear regression the function performs similarly to \code{abline} except that the line is constrained to the domain. For indicator variable regression the function behaves as if several \code{abline} functions had been called. -#' -#' A legend can be added to the plot in three different ways. First, if \code{legend = TRUE} then the R console is suspended until the user places the legend on the graphic by clicking on the graphic at the point where the upper-left corner of the legend should appear. Second, the \code{legend=} argument can be set to one of \code{"bottomright"}, \code{"bottom"}, \code{"bottomleft"}, \code{"left"}, \code{"topleft"}, \code{"top"}, \code{"topright"}, \code{"right"} and \code{"center"}. In this case, the legend will be placed inside the plot frame at the given location. Finally, the \code{legend=} argument can be set to a vector of length two which identifies the plot coordinates for the upper-left corner of where the legend should be placed. A legend will not be drawn if \code{legend = FALSE} or \code{legend = NULL}. A legend also will not be drawn if there are not multiple groups in the model. -#' -#' @note This function is meant to allow newbie students the ability to visualize the most common linear models found in an introductory or intermediate level undergraduate statistics course without getting \dQuote{bogged-down} in the gritty details of a wide variety of functions. This generic function and it's S3 functions allow the student to visualize the means plot of a one-way anova, the main effects and interaction plots of a two-way ANOVA, the fit of a simple linear regression, the fits of many lines in an indicator variable regression, and the fit of a non-linear model with a simple and mostly common set of arguments -- generally, all that is required is a fitted linear model of the type mentioned here as the first argument. This function thus allows newbie students to interact with and visualize moderately complex linear models in a fairly easy and efficient manner. THIS IS NOT A RESEARCH GRADE FUNCTION and the user should learn how to use the functions that this function is based on, build plots from \dQuote{scratch}, or use more sophisticated plotting packages (e.g., \pkg{ggplot2} or \pkg{lattice}). -#' -#' @aliases fitPlot fitPlot.lm fitPlot.SLR fitPlot.IVR fitPlot.POLY fitPlot.ONEWAY fitPlot.TWOWAY fitPlot.nls fitPlot.glm fitPlot.logreg -#' -#' @param object An \code{lm} or \code{nls} object (i.e., returned from fitting a model with either \code{lm} or \code{nls}). -#' @param interval In SLR or IVR, a string that indicates whether to plot confidence (\code{="confidence"}) or prediction (\code{="prediction"}) intervals. For a SLR object both can be plotted by using \code{="both"}. In one-way or two-way ANOVA, a logical that indicates whether the confidence intervals should be plotted or not. -#' @param conf.level A decimal numeric that indicates the level of confidence to use for confidence and prediction intervals. -#' @param plot.pts A logical that indicates (\code{TRUE} (default)) whether the points are plotted along with the fitted lines. Set to \code{FALSE} to plot just the fitted lines. -#' @param pch A numeric or vector of numerics that indicates what plotting character codes should be used. In SLR this is the single value to be used for all points. In IVR a vector is used to identify the characters for the levels of the second factor. -#' @param col A vector of color names or the name of a palette (from \code{\link[grDevices]{hcl.pals}}) that indicates what color of points and lines to use for the levels of the first factor in an IVR or the second factor in a two-way ANOVA. -#' @param col.pt A string used to indicate the color of the plotted points. Used only for SLR and logistic regression objects. -#' @param col.mdl A string used to indicate the color of the fitted line. Used only for SLR and logistic regression objects. -#' @param lwd A numeric used to indicate the line width of the fitted line. -#' @param lty A numeric or vector of numerics used to indicate the type of line used for the fitted line. In SLR this is a single value to be used for the fitted line. In IVR a vector is used to identify the line types for the levels of the second factor. See \code{par}. -#' @param lty.ci a numeric used to indicate the type of line used for the confidence band lines for SLR objects or interval lines for one-way and two-way ANOVA. For IVR, the confidence band types are controlled by \code{lty}. -#' @param lty.pi a numeric used to indicate the type of line used for the prediction band lines for SLR objects. For IVR, the prediction band types are controlled by \code{lty}. See \code{par}. -#' @param xlab a string for labeling the x-axis. -#' @param ylab a string for labeling the y-axis. -#' @param main a string for the main label to the plot. Defaults to the model call. -#' @param legend Controls use and placement of the legend. See details. -#' @param type The type of graphic to construct in a one-way and two-way ANOVA. If \code{"b"} then points are plotted and lines are used to connect points (DEFAULT). If \code{"p"} then only points are used and if \code{"l"} then only lines are drawn. -#' @param ci.fun A function used to put error bars on the one-way or two-way ANOVA graphs. The default is to use the internal \code{iCIfp} function which will place t-distribution based confidence intervals on the graph. The user can provide alternative functions that may plot other types of \sQuote{error bars}. See examples in \code{\link[sciplot]{lineplot.CI}} function of \pkg{sciplot} package. -#' @param col.ci A vector of color names or numbers or the name of a palette (see details) that indicates what colors to use for the confidence interval bars in one-way and two-way ANOVAs. -#' @param which A character string listing the factor in the two-way ANOVA for which the means should be calculated and plotted. This argument is used to indicate for which factor a main effects plot should be constructed. If left missing then an interaction plot is constructed. -#' @param change.order A logical that is used to change the order of the factors in the \code{lm} object. This is used to change which factor is plotted on the x-axis and which is used to connect the means when constructing an interaction plot (ignored if \code{which} is used). -#' @param cex.leg A single numeric values used to represent the character expansion value for the legend. Ignored if \code{legend=FALSE}. -#' @param box.lty.leg A single numeric values used to indicate the type of line to use for the box around the legend. The default is to not plot a box. -#' @param d A data frame that contains the variables used in construction of the \code{nls} object. -#' @param jittered A logical that indicates whether the points should be jittered horizontally. -#' @param legend.lbls A vector of strings that will be the labels for the legend in an nls fitPlot graphic. -#' @param transparency A numeric that indicates how many points would be plotted on top of each other in a logistic regression before the \sQuote{point} would have the full \code{pt.col} color. The reciprocal of this value is the alpha transparency value. -#' @param plot.p A logical that indicates if the proportion for categorized values of X are plotted (\code{TRUE}; default). -#' @param breaks A number that indicates how many intervals over which to compute proportions or a numeric vector that contains the endpoints of the intervals over which to compute proportions if \code{plot.p=TRUE}. -#' @param p.col A color to plot the proportions. -#' @param p.pch A plotting character for plotting the proportions. -#' @param p.cex A character expansion factor for plotting the proportions. -#' @param mdl.vals A numeric that represents the number of values to use for plotting the logistic regression. A larger number means a smoother line. -#' @param xlim A vector of length two to control the x-axis in the logistic regression plot. If this is changed from the default then the domain over which the logistic regression model is plotted will change. -#' @param ylim A vector of length two to control the y-axis in the nonlinear regression plot. -#' @param yaxis1.ticks A numeric vector that indicates where tick marks should be placed on the left y-axis (for the proportion of \sQuote{successes}) for the logistic regression plot. -#' @param yaxis1.lbls A numeric vector that indicates labels for the tick marks on the left y-axis (for the proportion of \sQuote{successes}) for the logistic regression plot. -#' @param yaxis2.show A logical that indicates whether the right y-axis should be created (\code{=TRUE}; default) or not for the logistic regression plot. -#' @param \dots Other arguments to be passed to the plot functions. -#' -#' @return None. However, a fitted-line plot is produced. -#' -#' @author Derek H. Ogle, \email{derek@@derekogle.com} -#' -#' @seealso See \code{\link{abline}}, \code{\link[car]{regLine}} in \pkg{car}, \code{\link[psych]{error.bars}} in \pkg{psych}, \code{interaction.plot}, and \code{\link[sciplot]{lineplot.CI}} in \pkg{sciplot} for similar functionality. -#' -#' @keywords hplot models -#' -#' @examples -#' # create year as a factor variable -#' Mirex$fyear <- factor(Mirex$year) -#' # reduce number of years for visual simplicity for iVRs -#' Mirex2 <- droplevels(subset(Mirex,fyear %in% c(1977,1992))) -#' -#' ## One-way ANOVA -#' aov1 <- lm(mirex~fyear,data=Mirex) -#' fitPlot(aov1) -#' -#' ## Two-way ANOVA -#' aov2 <- lm(mirex~fyear*species,data=Mirex) -#' # interaction plots and a color change -#' fitPlot(aov2,legend="bottomleft") -#' fitPlot(aov2,change.order=TRUE) -#' # main effects plots -#' fitPlot(aov2,which="species") -#' fitPlot(aov2,which="fyear") -#' -#' ## Simple linear regression (show color change and confidence/prediction bands) -#' slr1 <- lm(mirex~weight,data=Mirex) -#' fitPlot(slr1) -#' fitPlot(slr1,interval="both") -#' -#' ## Indicator variable regression with one factor (also showing confidence bands) -#' ivr1 <- lm(mirex~weight*fyear,data=Mirex2) -#' fitPlot(ivr1,legend="topleft") -#' fitPlot(ivr1,legend="topleft",interval="confidence") -#' fitPlot(ivr1,legend="topleft",interval="confidence",col="Dark 2") -#' -#' ## Indicator variable regression with one factor (assuming parallel lines) -#' ivr2 <- lm(mirex~weight+species,data=Mirex2) -#' fitPlot(ivr2,legend="topleft") -#' -#' ## Indicator variable regression with two factors -#' ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2) -#' fitPlot(ivr3,ylim=c(0,0.8),legend="topleft") -#' fitPlot(ivr3,ylim=c(0,0.8),legend="topleft",col="Spectral") -#' -#' ## Polynomial regression -#' poly1 <- lm(mirex~weight+I(weight^2),data=Mirex) -#' fitPlot(poly1,interval="both") -#' -#' ## Non-linear model example -#' lr.sv <- list(B1=6,B2=7.2,B3=-1.5) -#' nl1 <- nls(cells~B1/(1+exp(B2+B3*days)),start=lr.sv,data=Ecoli) -#' fitPlot(nl1,Ecoli,cex.main=0.7,lwd=2) -#' -#' ## Logistic regression example -#' ## NASA space shuttle o-ring failures -- from graphics package -#' d <- data.frame(fail=factor(c(2,2,2,2,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,1,1,1,1), -#' levels = 1:2, labels = c("no","yes")), -#' temperature <- c(53,57,58,63,66,67,67,67,68,69,70,70,70,70, -#' 72,73,75,75,76,76,78,79,81)) -#' glm1 <- glm(fail~temperature,data=d,family="binomial") -#' fitPlot(glm1) -#' fitPlot(glm1,yaxis1.ticks=c(0,1),yaxis1.lbls=c(0,1)) -#' -#' @rdname fitPlot -#' @export -fitPlot <- function (object, ...) { - if ("lm" %in% class(object)) ## This is a hack so no double deprecation warning - .Deprecated(msg="'fitPlot' is deprecated and will soon be removed from 'FSA'; see fishR post from 25-May-2021 for alternative methods.") - UseMethod("fitPlot") -} - -#' @rdname fitPlot -#' @export -fitPlot.lm <- function(object, ...) { - object <- iTypeoflm(object) - if (object$Rnum>1) - STOP("'fitPlot()' does not work with more than 1 LHS variable.") - if (object$type=="MLR") - STOP("Multiple linear regression objects are not supported by fitPlot.") - fitPlot(object,...) -} - -#' @rdname fitPlot -#' @export -fitPlot.SLR <- function(object,plot.pts=TRUE,pch=16,col.pt="black", - col.mdl="red",lwd=3,lty=1, - interval=c("none","confidence","prediction","both"), - conf.level=0.95,lty.ci=2,lty.pi=3, - xlab=object$Enames[1],ylab=object$Rname,main="", - ylim=NULL,...) { - ## Some tests - - ## Check on conf.level - iCheckConfLevel(conf.level) - - interval <- match.arg(interval) - if (length(col.pt)>1) { - WARN("Only first color used for points in this SLR.") - col.pt <- col.pt[1] - } - if (length(col.mdl)>1) { - WARN("Only first color used for the model in this SLR.") - col.mdl <- col.mdl[1] - } - ## Get data ready - # extract x and y variables - y <- object$mf[,object$Rname] - x <- object$mf[,object$Enames[1]] - # create predictions to draw the line - xvals <- seq(min(x),max(x),length.out=200) - newdf <- data.frame(xvals) - # sets name of variables so that predict() will work - names(newdf) <- object$Enames[1] - # computes predicted values (and CI for use later) - predC <- stats::predict(object$mdl,newdf,interval="confidence") - predP <- stats::predict(object$mdl,newdf,interval="prediction") - ## Put plot together # nocov start - # Find y-axis range - if (is.null(ylim)) { - if (interval %in% c("prediction","both")) ylim <- range(predP) - else ylim <- range(predC) - } - # plot points in white to "disappear" if asked for - if (!plot.pts) col.pt <- "white" - graphics::plot(y~x,pch=pch,col=col.pt,ylim=ylim, - xlab=xlab,ylab=ylab,main=main,...) - # plot fitted line over range of data - graphics::lines(xvals,predC[,"fit"],col=col.mdl,lwd=lwd,lty=lty) - # puts CI on graph if asked for - if (interval %in% c("confidence","both")) { - graphics::lines(xvals,predC[,"upr"],col=col.mdl,lwd=1,lty=lty.ci) - graphics::lines(xvals,predC[,"lwr"],col=col.mdl,lwd=1,lty=lty.ci) - } - # puts PI on graph if asked for - if (interval %in% c("prediction","both")) { - graphics::lines(xvals,predP[,"upr"],col=col.mdl,lwd=1,lty=lty.pi) - graphics::lines(xvals,predP[,"lwr"],col=col.mdl,lwd=1,lty=lty.pi) - } # nocov end -} - - -#' @rdname fitPlot -#' @export -fitPlot.IVR <- function(object,...) { - ## Do some checks - if (object$ENumNum>1) - STOP("'fitPlot()' cannot handle >1 covariate in an IVR.") - if (object$EFactNum>2) - STOP("'fitPlot()' cannot handle >2 factors in an IVR.") - ## Decide if a one-way or two-way IVR - if (object$EFactNum==1) iFitPlotIVR1(object,...) - else iFitPlotIVR2(object,...) -} - -iFitPlotIVR1 <- function(object,plot.pts=TRUE,pch=c(16,21,15,22,17,24,c(3:14)), - col="black",lty=rep(1:6,6),lwd=3, - interval=c("none","confidence","prediction","both"), - conf.level=0.95, - xlab=names(object$mf[object$ENumPos]), - ylab=object$Rname,main="", - legend="topright",cex.leg=1,box.lty.leg=0,...) { - ## Some checks - - ## Check on conf.level - iCheckConfLevel(conf.level) - - interval <- match.arg(interval) - # extract y and x quantitative variables - y <- object$mf[,object$Rname] - x <- object$mf[,object$ENumPos[1]] - # extract the factor variable(s) from the 2nd position - f1 <- object$mf[,object$EFactPos[1]] - # find number of levels of each factor - levs.f1 <- unique(f1) - num.f1 <- length(levs.f1) - # Handle colors, pchs, ltys -- one for each level of f1 factor unless - # only one color is given - col <- iFitPlotClrs2(f1,col) - pch <- iFitPlotPchs2(f1,pch) - lty <- iFitPlotLtys2(f1,lty) - ## Check if groups will be able to be seen - if (sum(c(length(unique(pch))==1, - length(unique(lty))==1, - length(unique(col))==1))>1) - WARN("Your choices for 'col', 'pch', and 'lty' will make it difficult to see groups.") - ### Plot the points - # Creates plot schematic -- no points or lines # nocov start - graphics::plot(y~x,col="white",xlab=xlab,ylab=ylab,main=main,...) - if (plot.pts) { - # Plots points w/ different colors & points - for (i in 1:num.f1) graphics::points(x[f1==levs.f1[i]], - y[f1==levs.f1[i]], - col=col[i],pch=pch[i]) - } - for (i in 1:num.f1) { - # Make the predictions at a bunch of values of x - x.obs <- x[f1==levs.f1[i]] - y.obs <- y[f1==levs.f1[i]] - xvals <- seq(min(x.obs),max(x.obs),length.out=200) - newdf <- data.frame(xvals,as.factor(rep(levs.f1[i],length(xvals)))) - names(newdf) <- names(object$mf)[c(object$ENumPos,object$EFactPos)] - predC <- stats::predict(object$mdl,newdf,interval="confidence") - # Plot just the line if no intervals called for - graphics::lines(xvals,predC[,"fit"],col=col[i],lwd=lwd,lty=lty[i]) - # add CI if asked for - if (interval %in% c("confidence","both")) { - graphics::lines(xvals,predC[,"upr"],col=col[i],lwd=1,lty=lty[i]) - graphics::lines(xvals,predC[,"lwr"],col=col[i],lwd=1,lty=lty[i]) - } - # add PI if asked for - if (interval %in% c("prediction","both")) { - predP <- stats::predict(object$mdl,newdf,interval="prediction") - graphics::lines(xvals,predP[,"upr"],col=col[i],lwd=1,lty=lty[i]) - graphics::lines(xvals,predP[,"lwr"],col=col[i],lwd=1,lty=lty[i]) - } - } # end for i - # Prepare list of col,pch,lty for legend - leg <- iLegendHelp(legend) - if (leg$do.legend) { - if (plot.pts) graphics::legend(x=leg$x,y=leg$y,legend=levs.f1,col=col, - pch=pch,lty=lty,cex=cex.leg,box.lty=box.lty.leg) - else graphics::legend(x=leg$x,y=leg$y,legend=levs.f1,col=col,lty=lty, - cex=cex.leg,box.lty=box.lty.leg) - graphics::box() - } # nocov end -} - -iFitPlotIVR2 <- function(object,plot.pts=TRUE,pch=c(16,21,15,22,17,24,c(3:14)), - col="Dark 2",lty=rep(1:6,6),lwd=3, - interval=c("none","confidence","prediction","both"), - conf.level=0.95, - xlab=names(object$mf[object$ENumPos]), - ylab=object$Rname,main="", - legend="topright",cex.leg=1,box.lty.leg=0,...) { - - ## Check on conf.level - iCheckConfLevel(conf.level) - - interval <- match.arg(interval) - # extract y and x quantitative variables - y <- object$mf[,object$Rname] - x <- object$mf[,object$ENumPos[1]] - # extract the factor variable(s) - f1 <- object$mf[,object$EFactPos[1]] - f2 <- object$mf[,object$EFactPos[2]] - # find number of levels of each factor - levs.f1 <- unique(f1) - levs.f2 <- unique(f2) - num.f1 <- length(levs.f1) - num.f2 <- length(levs.f2) - # Handle cols, pchs, lty1 -- one for each level of f1 factor unless - # only one color is given - col <- iFitPlotClrs2(f1,col) - pch <- iFitPlotPchs2(f2,pch) - lty <- iFitPlotLtys2(f2,lty) - ### Plot the points - # Creates plot schematic -- no points or lines - # nocov start - graphics::plot(y~x,col="white",xlab=xlab,ylab=ylab,main=main,...) - if (plot.pts) { - for (i in 1:num.f1) { - for (j in 1:num.f2) { - # Plots points w/ different colors & points - x.obs <- x[f1==levs.f1[i] & f2==levs.f2[j]] - y.obs <- y[f1==levs.f1[i] & f2==levs.f2[j]] - graphics::points(x.obs,y.obs,col=col[i],pch=pch[j]) - } - } - } - for (i in 1:num.f1) { - for (j in 1:num.f2) { - # Plots points w/ different colors & points - x.obs <- x[f1==levs.f1[i] & f2==levs.f2[j]] - y.obs <- y[f1==levs.f1[i] & f2==levs.f2[j]] - # Make the predictions at a bunch of values of x - xvals <- seq(min(x.obs),max(x.obs),length.out=200) - newdf <- data.frame(xvals, - as.factor(rep(levs.f1[i],length(xvals))), - as.factor(rep(levs.f2[j],length(xvals)))) - names(newdf) <- names(object$mf)[c(object$ENumPos,object$EFactPos)] - pred <- stats::predict(object$mdl,newdf,interval="confidence") - # Plot just the line if no intervals called for - graphics::lines(xvals,pred[,"fit"],col=col[i],lwd=lwd,lty=lty[j]) - # add CI if asked for - if (interval %in% c("confidence","both")) { - graphics::lines(xvals,pred[,"upr"],col=col[i],lwd=1,lty=lty[j]) - graphics::lines(xvals,pred[,"lwr"],col=col[i],lwd=1,lty=lty[j]) - } - # add PI if asked for - if (interval %in% c("prediction","both")) { - pred <- stats::predict(object$mdl,newdf,interval="prediction") - graphics::lines(xvals,pred[,"upr"],col=col[i],lwd=1,lty=lty[j]) - graphics::lines(xvals,pred[,"lwr"],col=col[i],lwd=1,lty=lty[j]) - } - } # end for j - } # end for i - # Prepare list of col,pch,lty for legend - leg <- iLegendHelp(legend) - if (leg$do.legend) { - lcol <- rep(col,each=num.f2) - lpch <- rep(pch,times=num.f1) - llty <- rep(lty,times=num.f1) - levs <- expand.grid(levs.f1,levs.f2,stringsAsFactors=FALSE, - KEEP.OUT.ATTRS=FALSE) - levs <- paste(levs[,1],levs[,2],sep =":") - if (plot.pts) graphics::legend(x=leg$x,y=leg$y,legend=levs, - col=lcol,pch=lpch,lty=llty, - cex=cex.leg,box.lty=box.lty.leg) - else graphics::legend(x=leg$x,y=leg$y,legend=levs,col=lcol, - lty=llty,cex=cex.leg,box.lty=box.lty.leg) - graphics::box() - } # nocov end -} - -#' @rdname fitPlot -#' @export -fitPlot.POLY <- function(object,...) { - fitPlot.SLR(object,...) -} - - -#' @rdname fitPlot -#' @export -fitPlot.ONEWAY <- function (object, - xlab=object$Enames[1],ylab=object$Rname,main="", - type="b",pch=16,lty=1,col="black", - interval=TRUE,conf.level=0.95,ci.fun=iCIfp(conf.level), - col.ci=col,lty.ci=1, - ...) { - - ## Check on conf.level - iCheckConfLevel(conf.level) - - if (length(col)>1) { - WARN("Only first color used.") - col <- col[1] - } - if (length(col.ci)>1) { - WARN("Only first color used for the CIs.") - col.ci <- col.ci[1] - } - # extract x and y variables - y <- object$mf[,object$Rname] - f1 <- object$mf[,object$Ename[1]] - # nocov start - if (interval) { - sciplot::lineplot.CI(f1,y,main=main,xlab=xlab,ylab=ylab, - type=type,pch=pch,lty=lty,col=col,legend=FALSE, - ci.fun=ci.fun,err.col=col.ci,err.lty=lty.ci,...) - } else stats::interaction.plot(f1,rep(1,length(y)),y, - main=main,xlab=xlab,ylab=ylab,type=type, - pch=pch,lty=lty,col=col,legend=FALSE,...) -} # nocov end - - -#' @rdname fitPlot -#' @export -fitPlot.TWOWAY <- function(object,which,change.order=FALSE, - xlab=object$Enames[ord[1]],ylab=object$Rname, - main="",type="b", - pch=c(16,21,15,22,17,24,c(3:14)),lty=c(1:6,1:6,1:6), - col="Dark 2", - interval=TRUE,conf.level=0.95, - ci.fun=iCIfp(conf.level),lty.ci=1, - legend="topright",cex.leg=1,box.lty.leg=0, - ...) { - - ## Check on conf.level - iCheckConfLevel(conf.level) - - # extract y variables - y <- object$mf[,object$Rname] - # find the factor variables - if (missing(which)) { - # need both factors, check to see if order was changed from model fit - ifelse(change.order,ord <- c(2,1),ord <- c(1,2)) - x.factor <- object$mf[,object$Enames[ord[1]]] - group <- object$mf[,object$Enames[ord[2]]] - ngrps <- length(levels(group)) - } else { # nocov start - # one of the factors was chosen, pick just that variable - ord <- match(which,object$Enames) - x.factor <- object$mf[,object$Enames[ord[1]]] - # handle "other" factor differently depending on if interval is constructed - if(interval) group <- NULL - else group <- rep(1,length(y)) - ngrps <- 1 - if (col=="Dark 2") col <- "black" - } - col <- iFitPlotClrs2(group,col) - pch <- iFitPlotPchs2(group,pch) - lty <- iFitPlotLtys2(group,lty) - if (interval) { - sciplot::lineplot.CI(x.factor,y,group, - main=main,xlab=xlab,ylab=ylab,type=type, - pch=pch[1:ngrps],lty=lty[1:ngrps],col=col[1:ngrps], - legend=FALSE,ci.fun=ci.fun,err.lty=lty.ci,...) - } else stats::interaction.plot(x.factor,group,y, - main=main,xlab=xlab,ylab=ylab,type=type, - pch=pch[1:ngrps],lty=lty[1:ngrps], - col=col[1:ngrps],legend=FALSE,...) - if(ngrps>1) { - leg <- iLegendHelp(legend) - graphics::legend(leg$x,leg$y,legend=levels(group),pch=pch[1:ngrps], - lty=1:ngrps,col=col,cex=cex.leg,box.lty=box.lty.leg) - } - graphics::box() # nocov end -} - - -#' @rdname fitPlot -#' @export -fitPlot.nls <- function(object,d, - pch=c(19,1),col.pt=c("black","red"),col.mdl=col.pt, - lwd=2,lty=1,plot.pts=TRUE,jittered=FALSE,ylim=NULL, - legend=FALSE,legend.lbls=c("Group 1","Group 2"), - ylab=names(mdl$model)[1],xlab=names(mdl$model)[xpos], - main="", ...) { # nocov start - ## add the model option to the NLS object so that data can be extracted - mdl <- stats::update(object,model=TRUE) - ## finds number of variables in the model (this is needed because for some - ## models (e.g., Francis VBGF) the mdel might contain "other" data) - numvars <- length(attr(stats::terms(mdl$model),"term.labels")) - if (missing(d)) { d <- mdl$data } - else if (!is.data.frame(d)) d <- as.data.frame(d) # make sure is data.frame - ## find y variable from model - y <- mdl$model[[1]] - if (numvars==2) { - # find position of x-variable and groups - xpos <- 2 - gpos <- NULL - } else { - for (i in 2:numvars) { - if (!all(mdl$model[[i]]==0 | mdl$model[[i]]==1)) xpos <- i - } - gpos <- seq(1,4)[-c(1,xpos)] - g1 <- mdl$model[[gpos[1]]] - g2 <- mdl$model[[gpos[2]]] - if (length(pch)==1) pch <- rep(pch,2) - if (length(col.pt)==1) col.pt <- rep(col.pt,2) - if (length(col.mdl)==1) col.mdl <- rep(col.mdl,2) - if (length(lwd)==1) lwd <- rep(lwd,2) - if (length(lty)==1) lty <- rep(lty,2) - } - # find x variable from model - x <- mdl$model[[xpos]] - # create a vector of x values for making predictions -- many to make smooth - fitx <- data.frame(seq(min(x),max(x),length.out=max(100,length(x)))) - - if (numvars==2) { - # change name of x to name of x in model so that predict will work - names(fitx) <- names(mdl$model)[xpos] - # data.frame of x values and predicted y values from model - fits <- data.frame(x=fitx,y=stats::predict(mdl,fitx)) - names(fits) <- c("x","y") - # find limit for y-axis - if (is.null(ylim)) ylim <- range(c(y,fits$y)) - if (jittered) x <- jitter(x) - if (plot.pts) graphics::plot(x,y,pch=pch[1],col=col.pt[1],ylim=ylim, - xlab=xlab,ylab=ylab,main=main,...) - else graphics::plot(x,y,type="n",ylim=ylim,xlab=xlab,ylab=ylab,main=main,...) - graphics::lines(fits$x,fits$y,lwd=lwd[1],lty=lty[1],col=col.mdl[1]) - } else { - explg1 <- data.frame(x=fitx,g1=rep(1,length(fitx)),g2=rep(0,length(fitx))) - explg2 <- data.frame(x=fitx,g1=rep(0,length(fitx)),g2=rep(1,length(fitx))) - names(explg1) <- names(explg2) <- names(mdl$model)[c(xpos,gpos[1],gpos[2])] - fitsg1 <- data.frame(x=fitx,y=stats::predict(mdl,explg1)) - fitsg2 <- data.frame(x=fitx,y=stats::predict(mdl,explg2)) - names(fitsg1) <- names(fitsg2) <- c("x","y") - # find limit for y-axis - if (is.null(ylim)) ylim <- range(c(y,fitsg1$y,fitsg2$y)) - if (jittered) x <- jitter(x) - graphics::plot(x,y,type="n",ylim=ylim,xlab=xlab,ylab=ylab,main=main,...) - if (plot.pts) { - graphics::points(x[g1==1],y[g1==1],pch=pch[1],col=col.pt[1]) - graphics::points(x[g2==1],y[g2==1],pch=pch[2],col=col.pt[2]) - } - graphics::lines(fitsg1$x,fitsg1$y,lwd=lwd[1],lty=lty[1],col=col.mdl[1]) - graphics::lines(fitsg2$x,fitsg2$y,lwd=lwd[2],lty=lty[2],col=col.mdl[2]) - leg <- iLegendHelp(legend) - if (leg$do.legend) { - if (plot.pts) graphics::legend(x=leg$x,y=leg$y,legend=legend.lbls, - col=col.pt,pch=pch,lty=lty) - else graphics::legend(x=leg$x,y=leg$y,legend=legend.lbls, - col=col.mdl,lty=lty) - } - } -} # nocov end - -#' @rdname fitPlot -#' @export -fitPlot.glm <- function(object, ...) { - if (object$family$family=="binomial" & object$family$link=="logit") - fitPlot.logreg(object,...) - else - STOP("Currently only logistic regression GLM models are supported by fitPlot.") -} - -#' @rdname fitPlot -#' @export -fitPlot.logreg <- function(object, - xlab=names(object$model)[2],ylab=names(object$model)[1], - main="",plot.pts=TRUE,col.pt="black",transparency=NULL, - plot.p=TRUE,breaks=25,p.col="blue",p.pch=3,p.cex=1, - yaxis1.ticks=seq(0,1,0.1),yaxis1.lbls=c(0,0.5,1), - yaxis2.show=TRUE, - col.mdl="red",lwd=2,lty=1,mdl.vals=50,xlim=range(x), - ...) { # nocov start - ## Get data to plot - yc <- object$model[,1] - x <- object$model[,2] - ## Prepare values to plot the fitted line - nd <- data.frame(seq(min(xlim),max(xlim),length.out=mdl.vals)) - names(nd) <- names(object$model)[2] - ## Make the plot - iPlotBinResp(x,yc,xlab,ylab,plot.pts,col.pt,transparency, - plot.p,breaks,p.col,p.pch,p.cex, - yaxis1.ticks=yaxis1.ticks,yaxis1.lbls=yaxis1.lbls, - yaxis2.show=yaxis2.show, - main=main,xlim=xlim,...) - graphics::lines(nd[,1],stats::predict(object,nd,type="response"), - col=col.mdl,lwd=lwd,lty=lty) -} # nocov end - - -################################################################################ -### internal functions used in fitPlot -################################################################################ -iCIfp1 <- function(x,conf.level) { - t <- stats::qt((1-conf.level)/2,validn(x)-1) - c(mean(x)-t*se(x),mean(x)+t*se(x)) -} - -iCIfp <- function(conf.level) function(x) iCIfp1(x,conf.level) - -iFitPlotClrs2 <- function(var,col,defpal) { - num.grps <- length(unique(var)) - if (num.grps==0) num.grps <- 1 # a hack for which= in two-way ANOVA - if (length(col)==1) { - if (col %in% grDevices::hcl.pals()) - col <- grDevices::hcl.colors(num.grps,palette=col) - else col <- rep(col,num.grps) - } else if (length(col)1 & num.grps <= length(pch)) pch <- pch[1:num.grps] - else if (length(pch)==1 & num.grps>1) pch <- rep(pch,num.grps) - else if (length(pch)1 & num.grps <= length(lty)) lty <- lty[1:num.grps] - else if (length(lty)==1& num.grps>1) lty <- rep(lty,num.grps) - else if (length(lty)50) transparency <- 50 - # plot raw data points - graphics::plot(yn~x,pch=16,col=col2rgbt(col.pt,1/transparency), - yaxt="n",xlab=xlab,ylab=ylab,...) - # puts on ticks - graphics::axis(2,yaxis1.ticks,FALSE,cex.axis=graphics::par()$cex.axis) - # only label a few - graphics::axis(2,yaxis1.lbls,cex.axis=graphics::par()$cex.axis) - if (yaxis2.show) graphics::axis(4,c(0,1),levels(y)) - # plot proportions points - if (plot.p) { - if (is.null(breaks)) { - # if no p intervals defined on call then find ps for each value of x - p.i <- tapply(yn,x,mean) - xs <- as.numeric(names(p.i)) - } else { - if (length(breaks)==1) { - # handle if just a number of breaks is given - x.i <- lencat(x,startcat=min(x),w=(max(x)-min(x))/breaks) - } else { - # handle if actual breaks are given - x.i <- lencat(x,breaks=breaks) - } - p.i <- tapply(yn,x.i,mean) - xs <- as.numeric(names(p.i)) - xs <- xs + min(diff(xs))/2 - } - graphics::points(p.i~xs,pch=p.pch,col=p.col,cex=p.cex) - } -} # nocov end diff --git a/_pkgdown.yml b/_pkgdown.yml index 44f4ed73..612157f9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -110,11 +110,14 @@ reference: - title: Utilities (Other) desc: Miscellaneous utilities. contents: + - FSA - capFirst - col2rgbt - fact2num + - fishR - headtail - is.even + - kCounts - lagratio - perc - peek @@ -139,6 +142,10 @@ reference: - WhitefishLC - WR79 - WSlit + - title: Defunct + desc: Defunct functions. + contents: + - FSA-defunct navbar: type: inverse diff --git a/docs/news/index.html b/docs/news/index.html index e0e353e3..13688d4c 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -57,12 +57,20 @@

Changelog

  • Last version maintained by Derek Ogle. Transfering to fishR Core Team for next version.
  • +filterD(): REMOVED (to FSAmisc).
  • +
  • +fitPlot(): REMOVED (to FSAmisc).
  • +
  • +fsaNews() and FSANews(): Removed.
  • +
  • psdAdd(): Modified. Changed the way PSDlit was loaded into the function environment so that FSA::psdAdd() will work. Addresses #85.
  • PSDLit: Modified. Added info for Utah Chub (from here; address #84).
  • psdVal(): Modified. Changed the way PSDlit was loaded into the function environment so that FSA::psdVal() will work. Addresses #85.
  • +residPlot(): REMOVED (to FSAmisc).
  • +
  • wrAdd(): Modified. Changed the way WSlit was loaded into the function environment so that FSA::wrAdd() will work. Addresses #85.
  • WSLit: Modified. Added info for Utah Chub (from here; address #84).
  • @@ -100,9 +108,9 @@
@@ -204,7 +212,7 @@
  • lots of roxygen2 Rd cleaning.
  • -addLoessLine(): Deleted. Moved functionality to iAddLoessLine() and moved code to residPlot() file..
  • +addLoessLine(): Deleted. Moved functionality to iAddLoessLine() and moved code to residPlot() file..
  • -addOutlierTestResults(): Deleted. Moved functionality to iAddOutlierTestResults() and moved code to residPlot() file.
  • +addOutlierTestResults(): Deleted. Moved functionality to iAddOutlierTestResults() and moved code to residPlot() file.
  • capHistConvert(): Added an interactive() to the Rcapture example in the help file.
  • checkStartcatW(): Deleted. Moved functionality to iCheckStartcatW().
  • -ci.fp(): Deleted. Moved functionality to iCIfp() and moved code to fitPlot() file.
  • +ci.fp(): Deleted. Moved functionality to iCIfp() and moved code to fitPlot() file.
  • -ci.fp.1(): Deleted. Moved functionality to iCIfp1() and moved code to fitPlot() file.
  • +ci.fp.1(): Deleted. Moved functionality to iCIfp1() and moved code to fitPlot() file.
  • ciLabel(): Deleted. Moved functionality to iCILabel().
  • @@ -1837,7 +1845,7 @@
  • getVarFromFormula(): Deleted. Moved functionality to iGetVarFromFormula().
  • @@ -1968,7 +1976,7 @@
  • -fitPlot.IVR(): Modified. Changed to use new typeoflm(), changed interval= argument, removed automatic main title, removed a bunch of unneeded code.
  • +fitPlot.IVR(): Modified. Changed to use new typeoflm(), changed interval= argument, removed automatic main title, removed a bunch of unneeded code.
  • -fitPlot.logreg(): Modified. Removed automatic main title.
  • +fitPlot.logreg(): Modified. Removed automatic main title.
  • -fitPlot.nls(): Modified. Removed automatic main title.
  • +fitPlot.nls(): Modified. Removed automatic main title.
  • -fitPlot.ONEWAY(): Modified. Changed to use new typeoflm(), removed automatic main title, removed one line of unneeded code.
  • +fitPlot.ONEWAY(): Modified. Changed to use new typeoflm(), removed automatic main title, removed one line of unneeded code.
  • -fitPlot.SLR(): Modified. Changed to use new typeoflm(), changed interval= argument, removed automatic main title.
  • +fitPlot.SLR(): Modified. Changed to use new typeoflm(), changed interval= argument, removed automatic main title.
  • -fitPlot.TWOWAY(): Modified. Changed to use new typeoflm() and removed automatic main title
  • +fitPlot.TWOWAY(): Modified. Changed to use new typeoflm() and removed automatic main title
  • gReshape(): Modified. Added a drop= argument so that the user can drop some variables before reshaping. Also, added new.row.names=1:100000 to the reshape() call to work-around issues with duplicate row names (which were particularly problematic if any of the id.vars= had missing values.)
  • @@ -2307,7 +2315,7 @@

    Examples

    # typical output of summary() for a numeric variable summary(d$y) #> Min. 1st Qu. Median Mean 3rd Qu. Max. NA's -#> 0.0000 0.2595 0.5380 0.5120 0.7574 0.9902 3 +#> 0.0000 0.2667 0.5156 0.5131 0.7794 0.9975 3 # this function Summarize(d$y,digits=3) #> n nvalid mean sd min Q1 median Q3 -#> 102.000 99.000 0.512 0.288 0.000 0.260 0.538 0.757 +#> 102.000 99.000 0.513 0.314 0.000 0.267 0.516 0.779 #> max percZero -#> 0.990 2.020 +#> 0.998 2.020 Summarize(~y,data=d,digits=3) #> n nvalid mean sd min Q1 median Q3 -#> 102.000 99.000 0.512 0.288 0.000 0.260 0.538 0.757 +#> 102.000 99.000 0.513 0.314 0.000 0.267 0.516 0.779 #> max percZero -#> 0.990 2.020 +#> 0.998 2.020 Summarize(y~1,data=d,digits=3) #> n nvalid mean sd min Q1 median Q3 -#> 102.000 99.000 0.512 0.288 0.000 0.260 0.538 0.757 +#> 102.000 99.000 0.513 0.314 0.000 0.267 0.516 0.779 #> max percZero -#> 0.990 2.020 +#> 0.998 2.020 # note that nvalid is not shown if there are no NAs and # percZero is not shown if there are no zeros Summarize(~w,data=d,digits=3) #> n mean sd min Q1 median Q3 max -#> 102.000 7.961 0.832 7.000 7.000 8.000 9.000 9.000 +#> 102.000 7.804 0.809 7.000 7.000 8.000 8.000 9.000 Summarize(~v,data=d,digits=3) #> n mean sd min Q1 median Q3 max -#> 102.000 1.059 0.781 0.000 0.000 1.000 2.000 2.000 +#> 102.000 0.980 0.856 0.000 0.000 1.000 2.000 2.000 #> percZero -#> 27.451 +#> 37.255 # note that the nvalid and percZero results can be forced to be shown Summarize(~w,data=d,digits=3,nvalid="always",percZero="always") #> n nvalid mean sd min Q1 median Q3 -#> 102.000 102.000 7.961 0.832 7.000 7.000 8.000 9.000 +#> 102.000 102.000 7.804 0.809 7.000 7.000 8.000 8.000 #> max percZero #> 9.000 0.000 ## Numeric vector by levels of a factor variable Summarize(y~g1,data=d,digits=3) #> g1 n nvalid mean sd min Q1 median Q3 max percZero -#> 1 A 29 28 0.471 0.339 0.000 0.164 0.466 0.767 0.977 7.143 -#> 2 B 16 14 0.433 0.303 0.071 0.229 0.336 0.601 0.990 0.000 -#> 3 C 29 29 0.557 0.263 0.069 0.347 0.588 0.795 0.961 0.000 +#> 1 A 21 21 0.513 0.337 0.000 0.254 0.535 0.854 0.974 4.762 +#> 2 B 27 25 0.530 0.323 0.000 0.259 0.528 0.808 0.963 4.000 +#> 3 C 27 26 0.516 0.286 0.023 0.302 0.441 0.754 0.998 0.000 Summarize(y~g2,data=d,digits=3) #> g2 n nvalid mean sd min Q1 median Q3 max percZero -#> 1 UNKNOWN 34 32 0.482 0.254 0.021 0.273 0.526 0.639 0.972 0.000 -#> 2 female 37 37 0.545 0.310 0.000 0.238 0.574 0.810 0.990 2.703 -#> 3 male 31 30 0.504 0.300 0.000 0.262 0.454 0.782 0.985 3.333 +#> 1 UNKNOWN 35 35 0.538 0.284 0.000 0.376 0.516 0.766 0.988 2.857 +#> 2 female 37 34 0.519 0.336 0.000 0.240 0.521 0.838 0.998 2.941 +#> 3 male 30 30 0.478 0.329 0.003 0.189 0.515 0.755 0.963 0.000 Summarize(y~g2,data=d,digits=3,exclude="UNKNOWN") -#> g2 n nvalid mean sd min Q1 median Q3 max percZero -#> 1 female 37 37 0.545 0.31 0 0.238 0.574 0.810 0.990 2.703 -#> 2 male 31 30 0.504 0.30 0 0.262 0.454 0.782 0.985 3.333 +#> g2 n nvalid mean sd min Q1 median Q3 max percZero +#> 1 female 37 34 0.519 0.336 0.000 0.240 0.521 0.838 0.998 2.941 +#> 2 male 30 30 0.478 0.329 0.003 0.189 0.515 0.755 0.963 0.000 ## Numeric vector by levels of two factor variables Summarize(y~g1+g2,data=d,digits=3) #> g1 g2 n nvalid mean sd min Q1 median Q3 max percZero -#> 1 A UNKNOWN 10 9 0.365 0.336 0.021 0.072 0.277 0.631 0.972 0.000 -#> 2 B UNKNOWN 5 4 0.365 0.200 0.184 0.243 0.317 0.438 0.641 0.000 -#> 3 C UNKNOWN 7 7 0.628 0.200 0.347 0.525 0.613 0.713 0.961 0.000 -#> 4 A female 9 9 0.465 0.344 0.000 0.196 0.458 0.759 0.964 11.111 -#> 5 B female 8 8 0.496 0.376 0.071 0.192 0.403 0.848 0.990 0.000 -#> 6 C female 13 13 0.597 0.310 0.069 0.389 0.756 0.824 0.894 0.000 -#> 7 A male 10 10 0.571 0.342 0.000 0.259 0.709 0.832 0.977 10.000 -#> 8 B male 3 2 0.316 0.042 0.286 0.301 0.316 0.331 0.345 0.000 -#> 9 C male 9 9 0.442 0.216 0.167 0.280 0.452 0.588 0.795 0.000 +#> 1 A UNKNOWN 6 6 0.542 0.342 0.124 0.323 0.467 0.843 0.953 0.000 +#> 2 B UNKNOWN 10 10 0.616 0.298 0.000 0.475 0.582 0.894 0.947 10.000 +#> 3 C UNKNOWN 11 11 0.481 0.273 0.027 0.359 0.416 0.651 0.988 0.000 +#> 4 A female 9 9 0.540 0.364 0.000 0.274 0.666 0.854 0.974 11.111 +#> 5 B female 8 6 0.537 0.330 0.099 0.295 0.572 0.756 0.958 0.000 +#> 6 C female 8 7 0.500 0.370 0.023 0.238 0.421 0.791 0.998 0.000 +#> 7 A male 6 6 0.444 0.344 0.017 0.213 0.394 0.708 0.894 0.000 +#> 8 B male 9 9 0.429 0.354 0.003 0.147 0.280 0.709 0.963 0.000 +#> 9 C male 8 8 0.578 0.248 0.186 0.360 0.720 0.746 0.819 0.000 Summarize(y~g1+g2,data=d,digits=3,exclude="UNKNOWN") -#> g1 g2 n nvalid mean sd min Q1 median Q3 max percZero -#> 1 A female 9 9 0.465 0.344 0.000 0.196 0.458 0.759 0.964 11.111 -#> 2 B female 8 8 0.496 0.376 0.071 0.192 0.403 0.848 0.990 0.000 -#> 3 C female 13 13 0.597 0.310 0.069 0.389 0.756 0.824 0.894 0.000 -#> 4 A male 10 10 0.571 0.342 0.000 0.259 0.709 0.832 0.977 10.000 -#> 5 B male 3 2 0.316 0.042 0.286 0.301 0.316 0.331 0.345 0.000 -#> 6 C male 9 9 0.442 0.216 0.167 0.280 0.452 0.588 0.795 0.000 +#> g1 g2 n nvalid mean sd min Q1 median Q3 max percZero +#> 1 A female 9 9 0.540 0.364 0.000 0.274 0.666 0.854 0.974 11.111 +#> 2 B female 8 6 0.537 0.330 0.099 0.295 0.572 0.756 0.958 0.000 +#> 3 C female 8 7 0.500 0.370 0.023 0.238 0.421 0.791 0.998 0.000 +#> 4 A male 6 6 0.444 0.344 0.017 0.213 0.394 0.708 0.894 0.000 +#> 5 B male 9 9 0.429 0.354 0.003 0.147 0.280 0.709 0.963 0.000 +#> 6 C male 8 8 0.578 0.248 0.186 0.360 0.720 0.746 0.819 0.000 ## What happens if RHS of formula is not a factor Summarize(y~w,data=d,digits=3) #> w n nvalid mean sd min Q1 median Q3 max percZero -#> 1 7 37 37 0.519 0.265 0.071 0.277 0.536 0.754 0.977 0.000 -#> 2 8 32 29 0.531 0.304 0.000 0.263 0.631 0.795 0.990 3.448 -#> 3 9 33 33 0.487 0.306 0.000 0.256 0.554 0.689 0.985 3.030 +#> 1 7 45 44 0.585 0.323 0.000 0.320 0.707 0.879 0.974 2.273 +#> 2 8 32 32 0.461 0.319 0.000 0.196 0.403 0.677 0.998 3.125 +#> 3 9 25 23 0.448 0.271 0.003 0.295 0.421 0.635 0.953 0.000 ## Summarizing multiple variables in a data.frame (must reduce to numerics) lapply(as.list(d[,1:3]),Summarize,digits=4) #> $y #> n nvalid mean sd min Q1 median Q3 -#> 102.0000 99.0000 0.5120 0.2882 0.0000 0.2595 0.5380 0.7574 +#> 102.0000 99.0000 0.5131 0.3142 0.0000 0.2667 0.5156 0.7794 #> max percZero -#> 0.9902 2.0202 +#> 0.9975 2.0202 #> #> $w #> n mean sd min Q1 median Q3 max -#> 102.0000 7.9608 0.8316 7.0000 7.0000 8.0000 9.0000 9.0000 +#> 102.0000 7.8039 0.8089 7.0000 7.0000 8.0000 8.0000 9.0000 #> #> $v #> n mean sd min Q1 median Q3 max -#> 102.0000 1.0588 0.7813 0.0000 0.0000 1.0000 2.0000 2.0000 +#> 102.0000 0.9804 0.8557 0.0000 0.0000 1.0000 2.0000 2.0000 #> percZero -#> 27.4510 +#> 37.2549 #>
diff --git a/docs/reference/alkIndivAge.html b/docs/reference/alkIndivAge.html index 7248eda3..8527e579 100644 --- a/docs/reference/alkIndivAge.html +++ b/docs/reference/alkIndivAge.html @@ -192,24 +192,24 @@

Examples

# mean length-at-age Summarize(len~age,data=WR1.comb,digits=2) #> age n mean sd min Q1 median Q3 max -#> 1 4 987 51.87 5.15 35 48.00 52.0 56.00 64 -#> 2 5 395 71.76 5.33 60 68.00 72.0 76.00 84 -#> 3 6 271 86.75 4.73 75 83.00 87.0 89.00 99 -#> 4 7 449 97.58 5.19 86 93.00 97.0 102.00 114 -#> 5 8 146 101.14 5.80 90 97.00 101.0 107.00 113 -#> 6 9 77 103.79 3.11 100 102.00 103.0 105.00 113 -#> 7 10 38 105.16 7.22 95 97.25 107.0 109.75 119 -#> 8 11 6 112.17 0.98 111 111.25 112.5 113.00 113 +#> 1 4 987 51.86 5.14 35 48.00 52.0 56.00 64 +#> 2 5 395 71.80 5.33 60 68.00 72.0 76.00 84 +#> 3 6 270 86.76 4.83 75 83.00 87.0 89.00 99 +#> 4 7 449 97.45 5.17 85 93.00 97.0 101.00 112 +#> 5 8 146 101.29 5.86 90 97.00 101.5 106.75 113 +#> 6 9 78 103.85 3.08 100 102.00 103.0 105.75 112 +#> 7 10 38 105.42 7.08 95 98.25 107.0 109.75 119 +#> 8 11 6 111.67 1.51 110 110.25 112.0 113.00 113 # age frequency distribution ( af <- xtabs(~age,data=WR1.comb) ) #> age #> 4 5 6 7 8 9 10 11 -#> 987 395 271 449 146 77 38 6 +#> 987 395 270 449 146 78 38 6 # proportional age distribution ( ap <- prop.table(af) ) #> age #> 4 5 6 7 8 9 -#> 0.416631490 0.166737020 0.114394259 0.189531448 0.061629379 0.032503166 +#> 0.416631490 0.166737020 0.113972140 0.189531448 0.061629379 0.032925285 #> 10 11 #> 0.016040523 0.002532714 @@ -278,15 +278,15 @@

Examples

# combine orig age & new ages WR2.comb <- rbind(WR2.age, WR2.len) Summarize(len~age,data=WR2.comb,digits=2) -#> age n mean sd min Q1 median Q3 max -#> 1 4 986 51.85 5.14 35 48.00 52.0 56.00 64 -#> 2 5 396 71.73 5.29 60 68.00 72.0 76.00 84 -#> 3 6 270 86.71 4.65 75 83.00 87.0 89.00 99 -#> 4 7 449 97.55 5.15 85 93.00 97.0 101.00 114 -#> 5 8 147 101.22 5.77 90 97.00 101.0 107.00 113 -#> 6 9 77 103.92 2.99 100 102.00 103.0 105.00 113 -#> 7 10 38 105.08 7.35 95 97.00 106.5 109.75 119 -#> 8 11 6 112.00 1.26 110 111.25 112.5 113.00 113 +#> age n mean sd min Q1 median Q3 max +#> 1 4 987 51.85 5.12 35 48.00 52.0 56.0 64 +#> 2 5 395 71.76 5.22 60 68.00 72.0 76.0 84 +#> 3 6 271 86.76 4.59 75 83.00 87.0 89.0 99 +#> 4 7 448 97.60 5.21 85 93.00 97.0 102.0 114 +#> 5 8 145 101.14 5.76 90 96.00 101.0 107.0 113 +#> 6 9 79 103.75 3.10 100 102.00 103.0 105.0 112 +#> 7 10 38 105.13 7.30 95 97.00 106.5 110.5 119 +#> 8 11 6 111.83 0.75 111 111.25 112.0 112.0 113 ## Third Example -- Uneven breaks for length categories WR3 <- WR79 @@ -353,15 +353,15 @@

Examples

#> 8 8 42 4 40 WR3.comb <- rbind(WR3.age, WR3.len) Summarize(len~age,data=WR3.comb,digits=2) -#> age n mean sd min Q1 median Q3 max -#> 1 4 986 51.84 5.12 35 48.00 52.0 56.00 64 -#> 2 5 396 71.77 5.30 60 68.00 72.0 76.00 84 -#> 3 6 271 86.73 4.70 75 83.00 87.0 89.00 99 -#> 4 7 452 97.77 5.44 85 93.00 97.0 102.00 112 -#> 5 8 140 100.36 5.20 90 97.00 101.0 103.00 113 -#> 6 9 78 104.50 3.04 100 102.00 103.0 107.00 113 -#> 7 10 42 104.69 7.28 95 98.00 103.0 112.00 119 -#> 8 11 4 113.50 2.89 110 112.25 113.5 114.75 117 +#> age n mean sd min Q1 median Q3 max +#> 1 4 987 51.87 5.15 35 48 52.0 56 64 +#> 2 5 395 71.72 5.25 60 68 72.0 76 84 +#> 3 6 271 86.85 4.71 75 83 87.0 89 99 +#> 4 7 451 97.65 5.34 85 93 97.0 102 113 +#> 5 8 142 100.68 5.44 90 97 101.0 104 113 +#> 6 9 78 104.40 3.20 100 102 103.0 107 113 +#> 7 10 40 104.80 7.14 95 98 103.5 112 119 +#> 8 11 5 112.60 2.70 110 111 112.0 113 117 diff --git a/docs/reference/expandCounts.html b/docs/reference/expandCounts.html index 4d5701c2..553c31dd 100644 --- a/docs/reference/expandCounts.html +++ b/docs/reference/expandCounts.html @@ -153,23 +153,23 @@

Examples

#> 2 rows had an individual measurement. #> 4 rows with multiple measurements were expanded to 15 rows of individual measurements. #> name lwr.bin upr.bin newlen lennote -#> 1 Frank 17.0 17.5 17.3 Expanded length +#> 1 Frank 17.0 17.5 17.0 Expanded length #> 2 Max 17.0 17.5 17.5 Expanded length -#> 3 Johnson 15.0 15.5 15.5 Expanded length -#> 4 Johnson 15.0 15.5 15.0 Expanded length -#> 5 Johnson 15.0 15.5 15.5 Expanded length -#> 6 Johnson 15.0 15.5 15.4 Expanded length -#> 7 Johnson 15.0 15.5 15.1 Expanded length -#> 8 Johnson 15.0 15.5 15.2 Expanded length +#> 3 Johnson 15.0 15.5 15.3 Expanded length +#> 4 Johnson 15.0 15.5 15.3 Expanded length +#> 5 Johnson 15.0 15.5 15.0 Expanded length +#> 6 Johnson 15.0 15.5 15.3 Expanded length +#> 7 Johnson 15.0 15.5 15.0 Expanded length +#> 8 Johnson 15.0 15.5 15.5 Expanded length #> 9 Johnson 15.5 16.0 16.0 Expanded length -#> 10 Johnson 15.5 16.0 16.0 Expanded length -#> 11 Johnson 15.5 16.0 15.6 Expanded length -#> 12 Johnson 15.5 16.0 15.6 Expanded length -#> 13 Jones 16.0 16.5 16.0 Expanded length -#> 14 Jones 16.0 16.5 16.5 Expanded length -#> 15 Frank 16.0 16.5 16.5 Expanded length -#> 16 Frank 16.0 16.5 16.4 Expanded length -#> 17 Frank 16.0 16.5 16.5 Expanded length +#> 10 Johnson 15.5 16.0 15.9 Expanded length +#> 11 Johnson 15.5 16.0 15.9 Expanded length +#> 12 Johnson 15.5 16.0 15.5 Expanded length +#> 13 Jones 16.0 16.5 16.3 Expanded length +#> 14 Jones 16.0 16.5 16.0 Expanded length +#> 15 Frank 16.0 16.5 16.3 Expanded length +#> 16 Frank 16.0 16.5 16.3 Expanded length +#> 17 Frank 16.0 16.5 16.3 Expanded length # some need expansion ( d2 <- data.frame(name=c("Johnson","Johnson","Jones","Frank","Frank","Max"), @@ -213,20 +213,20 @@

Examples

#> 1 Frank 17.1 17.1 17.1 Observed length #> 2 Max 17.3 17.3 17.3 Observed length #> 3 Johnson 15.0 15.5 15.4 Expanded length -#> 4 Johnson 15.0 15.5 15.5 Expanded length -#> 5 Johnson 15.0 15.5 15.3 Expanded length -#> 6 Johnson 15.0 15.5 15.2 Expanded length -#> 7 Johnson 15.0 15.5 15.0 Expanded length -#> 8 Johnson 15.0 15.5 15.2 Expanded length -#> 9 Johnson 15.5 16.0 15.6 Expanded length -#> 10 Johnson 15.5 16.0 15.6 Expanded length -#> 11 Johnson 15.5 16.0 15.7 Expanded length -#> 12 Johnson 15.5 16.0 16.0 Expanded length +#> 4 Johnson 15.0 15.5 15.2 Expanded length +#> 5 Johnson 15.0 15.5 15.0 Expanded length +#> 6 Johnson 15.0 15.5 15.3 Expanded length +#> 7 Johnson 15.0 15.5 15.1 Expanded length +#> 8 Johnson 15.0 15.5 15.0 Expanded length +#> 9 Johnson 15.5 16.0 15.7 Expanded length +#> 10 Johnson 15.5 16.0 16.0 Expanded length +#> 11 Johnson 15.5 16.0 16.0 Expanded length +#> 12 Johnson 15.5 16.0 15.7 Expanded length #> 13 Jones 16.0 16.5 16.0 Expanded length -#> 14 Jones 16.0 16.5 16.0 Expanded length -#> 15 Frank 16.0 16.5 16.1 Expanded length -#> 16 Frank 16.0 16.5 16.0 Expanded length -#> 17 Frank 16.0 16.5 16.5 Expanded length +#> 14 Jones 16.0 16.5 16.3 Expanded length +#> 15 Frank 16.0 16.5 16.3 Expanded length +#> 16 Frank 16.0 16.5 16.5 Expanded length +#> 17 Frank 16.0 16.5 16.1 Expanded length # none need expansion ( d3 <- data.frame(name=c("Johnson","Johnson","Jones","Frank","Frank","Max"), @@ -326,21 +326,21 @@

Examples

#> name lwr.bin upr.bin newlen lennote #> 1 Frank 17.1 17.1 17.1 Observed length #> 2 Max 17.3 17.3 17.3 Observed length -#> 3 Johnson 15.0 15.5 15.4 Expanded length -#> 4 Johnson 15.0 15.5 15.0 Expanded length -#> 5 Johnson 15.0 15.5 15.0 Expanded length -#> 6 Johnson 15.0 15.5 15.5 Expanded length -#> 7 Johnson 15.0 15.5 15.3 Expanded length -#> 8 Johnson 15.0 15.5 15.1 Expanded length +#> 3 Johnson 15.0 15.5 15.3 Expanded length +#> 4 Johnson 15.0 15.5 15.5 Expanded length +#> 5 Johnson 15.0 15.5 15.1 Expanded length +#> 6 Johnson 15.0 15.5 15.4 Expanded length +#> 7 Johnson 15.0 15.5 15.0 Expanded length +#> 8 Johnson 15.0 15.5 15.2 Expanded length #> 9 Johnson 15.0 15.9 15.9 Expanded length #> 10 Johnson 15.0 15.9 15.4 Expanded length -#> 11 Johnson 15.0 15.9 15.5 Expanded length -#> 12 Johnson 15.0 15.9 15.0 Expanded length -#> 13 Jones 16.0 16.5 16.1 Expanded length -#> 14 Jones 16.0 16.5 16.2 Expanded length -#> 15 Frank 16.0 16.9 16.6 Expanded length -#> 16 Frank 16.0 16.9 16.4 Expanded length -#> 17 Frank 16.0 16.9 16.1 Expanded length +#> 11 Johnson 15.0 15.9 15.1 Expanded length +#> 12 Johnson 15.0 15.9 15.3 Expanded length +#> 13 Jones 16.0 16.5 16.5 Expanded length +#> 14 Jones 16.0 16.5 16.4 Expanded length +#> 15 Frank 16.0 16.9 16.8 Expanded length +#> 16 Frank 16.0 16.9 16.8 Expanded length +#> 17 Frank 16.0 16.9 16.5 Expanded length # some need expansion but include zeros and NAs for counts ( d2a <- data.frame(name=c("Johnson","Johnson","Jones","Frank","Frank","Max","Max","Max","Max"), @@ -368,21 +368,21 @@

Examples

#> 3 Max NA NA NA Observed length #> 4 Frank 17.1 17.1 17.1 Observed length #> 5 Max 17.3 17.3 17.3 Observed length -#> 6 Johnson 15.0 15.5 15.5 Expanded length -#> 7 Johnson 15.0 15.5 15.0 Expanded length -#> 8 Johnson 15.0 15.5 15.5 Expanded length -#> 9 Johnson 15.0 15.5 15.1 Expanded length -#> 10 Johnson 15.0 15.5 15.4 Expanded length -#> 11 Johnson 15.0 15.5 15.1 Expanded length -#> 12 Johnson 15.5 16.0 15.9 Expanded length -#> 13 Johnson 15.5 16.0 15.6 Expanded length -#> 14 Johnson 15.5 16.0 15.7 Expanded length +#> 6 Johnson 15.0 15.5 15.1 Expanded length +#> 7 Johnson 15.0 15.5 15.2 Expanded length +#> 8 Johnson 15.0 15.5 15.4 Expanded length +#> 9 Johnson 15.0 15.5 15.4 Expanded length +#> 10 Johnson 15.0 15.5 15.2 Expanded length +#> 11 Johnson 15.0 15.5 15.2 Expanded length +#> 12 Johnson 15.5 16.0 16.0 Expanded length +#> 13 Johnson 15.5 16.0 15.5 Expanded length +#> 14 Johnson 15.5 16.0 15.8 Expanded length #> 15 Johnson 15.5 16.0 16.0 Expanded length -#> 16 Jones 16.0 16.5 16.2 Expanded length -#> 17 Jones 16.0 16.5 16.4 Expanded length -#> 18 Frank 16.0 16.5 16.2 Expanded length -#> 19 Frank 16.0 16.5 16.2 Expanded length -#> 20 Frank 16.0 16.5 16.5 Expanded length +#> 16 Jones 16.0 16.5 16.3 Expanded length +#> 17 Jones 16.0 16.5 16.3 Expanded length +#> 18 Frank 16.0 16.5 16.3 Expanded length +#> 19 Frank 16.0 16.5 16.3 Expanded length +#> 20 Frank 16.0 16.5 16.0 Expanded length # some need expansion but include NAs for upper values ( d2b <- data.frame(name=c("Johnson","Johnson","Jones","Frank","Frank","Max"), @@ -413,11 +413,11 @@

Examples

#> 10 Johnson 15.5 15.5 15.5 Observed length #> 11 Johnson 15.5 15.5 15.5 Observed length #> 12 Johnson 15.5 15.5 15.5 Observed length -#> 13 Jones 16.0 16.5 16.0 Expanded length +#> 13 Jones 16.0 16.5 16.4 Expanded length #> 14 Jones 16.0 16.5 16.0 Expanded length -#> 15 Frank 16.0 16.5 16.2 Expanded length -#> 16 Frank 16.0 16.5 16.0 Expanded length -#> 17 Frank 16.0 16.5 16.3 Expanded length +#> 15 Frank 16.0 16.5 16.3 Expanded length +#> 16 Frank 16.0 16.5 16.2 Expanded length +#> 17 Frank 16.0 16.5 16.2 Expanded length # some need expansion but include NAs for upper values ( d2c <- data.frame(name=c("Johnson","Johnson","Jones","Frank","Frank","Max"), @@ -448,11 +448,11 @@

Examples

#> 10 Johnson 15.5 15.5 15.5 Observed length #> 11 Johnson 15.5 15.5 15.5 Observed length #> 12 Johnson 15.5 15.5 15.5 Observed length -#> 13 Jones 16.0 16.5 16.1 Expanded length -#> 14 Jones 16.0 16.5 16.1 Expanded length -#> 15 Frank 16.0 16.5 16.4 Expanded length -#> 16 Frank 16.0 16.5 16.3 Expanded length -#> 17 Frank 16.0 16.5 16.5 Expanded length +#> 13 Jones 16.0 16.5 16.4 Expanded length +#> 14 Jones 16.0 16.5 16.0 Expanded length +#> 15 Frank 16.0 16.5 16.2 Expanded length +#> 16 Frank 16.0 16.5 16.2 Expanded length +#> 17 Frank 16.0 16.5 16.1 Expanded length if (FALSE) { ##!!##!!## Change path to where example file is and then run to demo diff --git a/docs/reference/growthModels.html b/docs/reference/growthModels.html index f552339b..bd36eeb3 100644 --- a/docs/reference/growthModels.html +++ b/docs/reference/growthModels.html @@ -187,8 +187,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*(1-exp(-K*(t-t0))) #> } -#> <bytecode: 0x000000001f6a1168> -#> <environment: 0x000000001f4d08a8> +#> <bytecode: 0x000000000972e5e8> +#> <environment: 0x00000000091f6a88> ages <- 0:20 plot(vb1(ages,Linf=20,K=0.3,t0=-0.2)~ages,type="b",pch=19) @@ -199,8 +199,8 @@

Examples

#> r <- (L3-L2)/(L2-L1) #> L1+(L3-L1)*((1-r^(2*((t-t1)/(t3-t1))))/(1-r^2)) #> } -#> <bytecode: 0x000000001f655938> -#> <environment: 0x000000000a5da208> +#> <bytecode: 0x00000000079a3778> +#> <environment: 0x0000000006a39718> plot(vb2(ages,L1=10,L2=19,L3=20,t1=2,t3=18)~ages,type="b",pch=19) ( vb2c <- vbFuns("Francis",simple=TRUE) ) # compare to vb2 @@ -208,8 +208,8 @@

Examples

#> r <- (L3-L2)/(L2-L1) #> L1+(L3-L1)*((1-r^(2*((t-t1)/(t3-t1))))/(1-r^2)) #> } -#> <bytecode: 0x000000001f6361c0> -#> <environment: 0x0000000008655c98> +#> <bytecode: 0x00000000078092d0> +#> <environment: 0x00000000226f0b50> ## Simple Examples -- Gompertz ( gomp1 <- GompertzFuns() ) @@ -219,8 +219,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*exp(-exp(-gi*(t-ti))) #> } -#> <bytecode: 0x0000000006570610> -#> <environment: 0x000000001f8a5f48> +#> <bytecode: 0x000000001f7a23b0> +#> <environment: 0x0000000006f13f10> plot(gomp1(ages,Linf=800,gi=0.5,ti=5)~ages,type="b",pch=19) ( gomp2 <- GompertzFuns("Ricker2") ) @@ -230,24 +230,24 @@

Examples

#> L0 <- L0[[1]] } #> L0*exp(a*(1-exp(-gi*t))) #> } -#> <bytecode: 0x00000000068b7a18> -#> <environment: 0x0000000006ead368> +#> <bytecode: 0x0000000006f926a0> +#> <environment: 0x00000000227ce5e8> plot(gomp2(ages,L0=2,a=6,gi=0.5)~ages,type="b",pch=19) ( gomp2c <- GompertzFuns("Ricker2",simple=TRUE) ) # compare to gomp2 #> function(t,L0,a,gi) { #> L0*exp(a*(1-exp(-gi*t))) #> } -#> <bytecode: 0x000000000709b110> -#> <environment: 0x0000000006ec7230> +#> <bytecode: 0x0000000022a02240> +#> <environment: 0x0000000021ac5b38> ( gompT <- GompertzFuns("Troynikov1")) #> function(Lm,dt,Linf,gi=NULL) { #> if (length(Linf)==2) { gi <- Linf[2] #> Linf <- Linf[1] } #> Linf*((Lm/Linf)^exp(-gi*dt))-Lm #> } -#> <bytecode: 0x00000000061252f0> -#> <environment: 0x00000000063ab450> +#> <bytecode: 0x0000000022120938> +#> <environment: 0x0000000022101058> ## Simple Examples -- Richards ( rich1 <- RichardsFuns() ) @@ -258,8 +258,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*(1-a*exp(-k*t))^b #> } -#> <bytecode: 0x0000000006e12798> -#> <environment: 0x0000000006755da0> +#> <bytecode: 0x00000000226a9490> +#> <environment: 0x0000000021ef8d68> plot(rich1(ages,Linf=800,k=0.5,a=1,b=6)~ages,type="b",pch=19) ( rich2 <- RichardsFuns(2) ) @@ -270,8 +270,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*(1-(1/b)*exp(-k*(t-ti)))^b #> } -#> <bytecode: 0x0000000006e1c3a8> -#> <environment: 0x000000000662a5f8> +#> <bytecode: 0x00000000226b31b8> +#> <environment: 0x000000002242f3b0> plot(rich2(ages,Linf=800,k=0.5,ti=3,b=6)~ages,type="b",pch=19) ( rich3 <- RichardsFuns(3) ) @@ -282,8 +282,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf/((1+b*exp(-k*(t-ti)))^(1/b)) #> } -#> <bytecode: 0x00000000061d1428> -#> <environment: 0x0000000006edc920> +#> <bytecode: 0x00000000226bcb60> +#> <environment: 0x0000000021c9c788> plot(rich3(ages,Linf=800,k=0.5,ti=3,b=0.15)~ages,type="b",pch=19) ( rich4 <- RichardsFuns(4) ) @@ -294,8 +294,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*(1+(b-1)*exp(-k*(t-ti)))^(1/(1-b)) #> } -#> <bytecode: 0x00000000061dabd8> -#> <environment: 0x0000000006faeb80> +#> <bytecode: 0x00000000220b0448> +#> <environment: 0x0000000022535f08> plot(rich4(ages,Linf=800,k=0.5,ti=3,b=0.95)~ages,type="b",pch=19) lines(rich4(ages,Linf=800,k=0.5,ti=3,b=1.5)~ages,type="b",pch=19,col="blue") @@ -307,8 +307,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf*(1+(((L0/Linf)^(1-b))-1)*exp(-k*t))^(1/(1-b)) #> } -#> <bytecode: 0x00000000061e3c88> -#> <environment: 0x0000000006a72ac0> +#> <bytecode: 0x00000000220b98e8> +#> <environment: 0x00000000221df530> plot(rich5(ages,Linf=800,k=0.5,L0=50,b=1.5)~ages,type="b",pch=19) ( rich6 <- RichardsFuns(6) ) @@ -320,16 +320,16 @@

Examples

#> Linf <- Linf[[1]] } #> Lninf+(Linf-Lninf)*(1+(b-1)*exp(-k*(t-ti)))^(1/(1-b)) #> } -#> <bytecode: 0x00000000061f0238> -#> <environment: 0x0000000006b77b38> +#> <bytecode: 0x00000000220c66b0> +#> <environment: 0x00000000222d6448> plot(rich6(ages,Linf=800,k=0.5,ti=3,Lninf=50,b=1.5)~ages,type="b",pch=19) ( rich2c <- RichardsFuns(2,simple=TRUE) ) # compare to rich2 #> function(t,Linf,k,ti,b) { #> Linf*(1-(1/b)*exp(-k*(t-ti)))^b #> } -#> <bytecode: 0x00000000061d0148> -#> <environment: 0x0000000006c7a228> +#> <bytecode: 0x00000000226bb810> +#> <environment: 0x0000000022a7a248> ## Simple Examples -- Logistic ( log1 <- logisticFuns() ) @@ -339,8 +339,8 @@

Examples

#> Linf <- Linf[[1]] } #> Linf/(1+exp(-gninf*(t-ti))) #> } -#> <bytecode: 0x0000000006d17780> -#> <environment: 0x0000000006d442b8> +#> <bytecode: 0x0000000023ace4a8> +#> <environment: 0x0000000023af7f40> plot(log1(ages,Linf=800,gninf=0.5,ti=5)~ages,type="b",pch=19) ( log2 <- logisticFuns("CJ2") ) @@ -350,16 +350,16 @@

Examples

#> Linf <- Linf[[1]] } #> Linf/(1+a*exp(-gninf*t)) #> } -#> <bytecode: 0x0000000006d220b0> -#> <environment: 0x0000000023d4a930> +#> <bytecode: 0x0000000023ad6a68> +#> <environment: 0x0000000023be8b28> plot(log2(ages,Linf=800,gninf=0.5,a=10)~ages,type="b",pch=19) ( log2c <- logisticFuns("CJ2",simple=TRUE) ) # compare to log2 #> function(t,Linf,gninf,a) { #> Linf/(1+a*exp(-gninf*t)) #> } -#> <bytecode: 0x0000000006d276a0> -#> <environment: 0x0000000023e76058> +#> <bytecode: 0x0000000023adf7f8> +#> <environment: 0x0000000023d535e8> ( log3 <- logisticFuns("Karkach") ) #> function(t,Linf,L0=NULL,gninf=NULL) { #> if (length(Linf)==3) { L0 <- Linf[[2]] @@ -367,8 +367,8 @@

Examples

#> Linf <- Linf[[1]] } #> L0*Linf/(L0+(Linf-L0)*exp(-gninf*t)) #> } -#> <bytecode: 0x0000000006d287c0> -#> <environment: 0x0000000023eda150> +#> <bytecode: 0x0000000023ae0e58> +#> <environment: 0x0000000023da54f0> plot(log3(ages,L0=10,Linf=800,gninf=0.5)~ages,type="b",pch=19) ( log4 <- logisticFuns("Haddon") ) @@ -378,8 +378,8 @@

Examples

#> dLmax <- dLmax[1] } #> dLmax/(1+exp(log(19)*((Lm-L50)/(L95-L50)))) #> } -#> <bytecode: 0x0000000006d35e48> -#> <environment: 0x0000000024033928> +#> <bytecode: 0x0000000023aeb5c8> +#> <environment: 0x0000000023eb4390> ########################################################### diff --git a/docs/reference/index.html b/docs/reference/index.html index 81f17a41..637580d8 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -321,6 +321,10 @@

Utilities (Other)

Miscellaneous utilities.

+

FSA

+ +

Fisheries stock assessment methods and data.

+

capFirst()

Capitalizes the first letter of first or all words in a string.

@@ -332,6 +336,10 @@

Utilities (Other) fact2num()

Converts "numeric" factor levels to numeric values.

+ +

fishR()

+ +

Opens web pages associated with the fishR website.

headtail()

@@ -340,6 +348,10 @@

Utilities (Other) is.odd() is.even()

Determine if a number is odd or even.

+ +

kCounts() kPvalue() purl2() reproInfo()

+ +

Specific utilities for use in a knitr document.

lagratio()

@@ -428,6 +440,14 @@

Data

WSlit

All known standard weight equations.

+ +

Defunct

+

Defunction functions.

+ + +

bootCase() chooseColors() compIntercepts() compSlopes() diags() filterD() fitPlot() fsaNews() hoCoef() mapvalues() plotBinResp() residPlot() Subset()

+ +

DEFUNCT functions.

diff --git a/man/FSA-defunct.Rd b/man/FSA-defunct.Rd index c38f4ee2..8b0e9610 100644 --- a/man/FSA-defunct.Rd +++ b/man/FSA-defunct.Rd @@ -7,9 +7,13 @@ \alias{compIntercepts} \alias{compSlopes} \alias{diags} +\alias{filterD} +\alias{fitPlot} +\alias{fsaNews} \alias{hoCoef} \alias{mapvalues} \alias{plotBinResp} +\alias{residPlot} \alias{Subset} \title{DEFUNCT functions.} \usage{ @@ -23,12 +27,20 @@ compSlopes(...) diags(...) +filterD(...) + +fitPlot(...) + +fsaNews(...) + hoCoef(...) mapvalues(...) plotBinResp(...) +residPlot(...) + Subset(...) } \arguments{ diff --git a/man/filterD.Rd b/man/filterD.Rd deleted file mode 100644 index 4df10a7b..00000000 --- a/man/filterD.Rd +++ /dev/null @@ -1,53 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSAUtils.R -\name{filterD-deprecated} -\alias{filterD-deprecated} -\alias{filterD} -\title{DEPRECATED - Subsets/filters a data frame and drops the unused levels.} -\usage{ -filterD(x, ..., except = NULL) -} -\arguments{ -\item{x}{A data frame.} - -\item{\dots}{further arguments to be passed to \code{\link[dplyr]{filter}}.} - -\item{except}{Indices of columns from which NOT to drop levels.} -} -\value{ -A data frame with the filtered rows. -} -\description{ -Subsets/filters a data frame and drops the unused levels. -} -\details{ -Newbie students using R expect that when a factor variable is filtered with \code{\link[dplyr]{filter}} that any original levels that are no longer used after the filtering will be ignored. This, however, is not the case and often results in tables with empty cells and figures with empty bars. One remedy is to use \code{\link[base]{droplevels}} immediately following \code{\link[dplyr]{filter}}. This generally becomes a repetitive sequence for most newbie students; thus, \code{filterD} incorporate these two functions into one function. - -\code{filterD} is a wrapper for \code{\link[dplyr]{filter}} from \pkg{dplyr} followed by \code{\link[base]{droplevels}} just before the data.frame is returned. Otherwise, there is no new code here. - -This function is only used for data frames. -} -\section{IFAR Chapter}{ - Basic Data Manipulations. -} - -\examples{ -## The problem -- note use of unused level in the final table. -levels(iris$Species) -iris.set1 <- subset(iris,Species=="setosa" | Species=="versicolor") -levels(iris.set1$Species) -xtabs(~Species,data=iris.set1) - -## A fix using filterD -iris.set3 <- filterD(iris,Species=="setosa" | Species=="versicolor") -levels(iris.set3$Species) -xtabs(~Species,data=iris.set3) - -} -\seealso{ -See \code{subset} and \code{\link[dplyr]{filter}} from \pkg{dplyr} for similar functionality. See \code{drop.levels} in \pkg{gdata} and \code{droplevels} for related functionality. -} -\author{ -Derek H. Ogle, \email{derek@derekogle.com} -} -\keyword{misc} diff --git a/man/fitPlot.Rd b/man/fitPlot.Rd deleted file mode 100644 index 14259cc3..00000000 --- a/man/fitPlot.Rd +++ /dev/null @@ -1,287 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/deprecated_fitPlot.R -\name{fitPlot} -\alias{fitPlot} -\alias{fitPlot.lm} -\alias{fitPlot.SLR} -\alias{fitPlot.IVR} -\alias{fitPlot.POLY} -\alias{fitPlot.ONEWAY} -\alias{fitPlot.TWOWAY} -\alias{fitPlot.nls} -\alias{fitPlot.glm} -\alias{fitPlot.logreg} -\title{DEPRECATED -- Fitted model plot for an lm, glm, or nls object.} -\usage{ -fitPlot(object, ...) - -\method{fitPlot}{lm}(object, ...) - -\method{fitPlot}{SLR}( - object, - plot.pts = TRUE, - pch = 16, - col.pt = "black", - col.mdl = "red", - lwd = 3, - lty = 1, - interval = c("none", "confidence", "prediction", "both"), - conf.level = 0.95, - lty.ci = 2, - lty.pi = 3, - xlab = object$Enames[1], - ylab = object$Rname, - main = "", - ylim = NULL, - ... -) - -\method{fitPlot}{IVR}(object, ...) - -\method{fitPlot}{POLY}(object, ...) - -\method{fitPlot}{ONEWAY}( - object, - xlab = object$Enames[1], - ylab = object$Rname, - main = "", - type = "b", - pch = 16, - lty = 1, - col = "black", - interval = TRUE, - conf.level = 0.95, - ci.fun = iCIfp(conf.level), - col.ci = col, - lty.ci = 1, - ... -) - -\method{fitPlot}{TWOWAY}( - object, - which, - change.order = FALSE, - xlab = object$Enames[ord[1]], - ylab = object$Rname, - main = "", - type = "b", - pch = c(16, 21, 15, 22, 17, 24, c(3:14)), - lty = c(1:6, 1:6, 1:6), - col = "Dark 2", - interval = TRUE, - conf.level = 0.95, - ci.fun = iCIfp(conf.level), - lty.ci = 1, - legend = "topright", - cex.leg = 1, - box.lty.leg = 0, - ... -) - -\method{fitPlot}{nls}( - object, - d, - pch = c(19, 1), - col.pt = c("black", "red"), - col.mdl = col.pt, - lwd = 2, - lty = 1, - plot.pts = TRUE, - jittered = FALSE, - ylim = NULL, - legend = FALSE, - legend.lbls = c("Group 1", "Group 2"), - ylab = names(mdl$model)[1], - xlab = names(mdl$model)[xpos], - main = "", - ... -) - -\method{fitPlot}{glm}(object, ...) - -\method{fitPlot}{logreg}( - object, - xlab = names(object$model)[2], - ylab = names(object$model)[1], - main = "", - plot.pts = TRUE, - col.pt = "black", - transparency = NULL, - plot.p = TRUE, - breaks = 25, - p.col = "blue", - p.pch = 3, - p.cex = 1, - yaxis1.ticks = seq(0, 1, 0.1), - yaxis1.lbls = c(0, 0.5, 1), - yaxis2.show = TRUE, - col.mdl = "red", - lwd = 2, - lty = 1, - mdl.vals = 50, - xlim = range(x), - ... -) -} -\arguments{ -\item{object}{An \code{lm} or \code{nls} object (i.e., returned from fitting a model with either \code{lm} or \code{nls}).} - -\item{\dots}{Other arguments to be passed to the plot functions.} - -\item{plot.pts}{A logical that indicates (\code{TRUE} (default)) whether the points are plotted along with the fitted lines. Set to \code{FALSE} to plot just the fitted lines.} - -\item{pch}{A numeric or vector of numerics that indicates what plotting character codes should be used. In SLR this is the single value to be used for all points. In IVR a vector is used to identify the characters for the levels of the second factor.} - -\item{col.pt}{A string used to indicate the color of the plotted points. Used only for SLR and logistic regression objects.} - -\item{col.mdl}{A string used to indicate the color of the fitted line. Used only for SLR and logistic regression objects.} - -\item{lwd}{A numeric used to indicate the line width of the fitted line.} - -\item{lty}{A numeric or vector of numerics used to indicate the type of line used for the fitted line. In SLR this is a single value to be used for the fitted line. In IVR a vector is used to identify the line types for the levels of the second factor. See \code{par}.} - -\item{interval}{In SLR or IVR, a string that indicates whether to plot confidence (\code{="confidence"}) or prediction (\code{="prediction"}) intervals. For a SLR object both can be plotted by using \code{="both"}. In one-way or two-way ANOVA, a logical that indicates whether the confidence intervals should be plotted or not.} - -\item{conf.level}{A decimal numeric that indicates the level of confidence to use for confidence and prediction intervals.} - -\item{lty.ci}{a numeric used to indicate the type of line used for the confidence band lines for SLR objects or interval lines for one-way and two-way ANOVA. For IVR, the confidence band types are controlled by \code{lty}.} - -\item{lty.pi}{a numeric used to indicate the type of line used for the prediction band lines for SLR objects. For IVR, the prediction band types are controlled by \code{lty}. See \code{par}.} - -\item{xlab}{a string for labeling the x-axis.} - -\item{ylab}{a string for labeling the y-axis.} - -\item{main}{a string for the main label to the plot. Defaults to the model call.} - -\item{ylim}{A vector of length two to control the y-axis in the nonlinear regression plot.} - -\item{type}{The type of graphic to construct in a one-way and two-way ANOVA. If \code{"b"} then points are plotted and lines are used to connect points (DEFAULT). If \code{"p"} then only points are used and if \code{"l"} then only lines are drawn.} - -\item{col}{A vector of color names or the name of a palette (from \code{\link[grDevices]{hcl.pals}}) that indicates what color of points and lines to use for the levels of the first factor in an IVR or the second factor in a two-way ANOVA.} - -\item{ci.fun}{A function used to put error bars on the one-way or two-way ANOVA graphs. The default is to use the internal \code{iCIfp} function which will place t-distribution based confidence intervals on the graph. The user can provide alternative functions that may plot other types of \sQuote{error bars}. See examples in \code{\link[sciplot]{lineplot.CI}} function of \pkg{sciplot} package.} - -\item{col.ci}{A vector of color names or numbers or the name of a palette (see details) that indicates what colors to use for the confidence interval bars in one-way and two-way ANOVAs.} - -\item{which}{A character string listing the factor in the two-way ANOVA for which the means should be calculated and plotted. This argument is used to indicate for which factor a main effects plot should be constructed. If left missing then an interaction plot is constructed.} - -\item{change.order}{A logical that is used to change the order of the factors in the \code{lm} object. This is used to change which factor is plotted on the x-axis and which is used to connect the means when constructing an interaction plot (ignored if \code{which} is used).} - -\item{legend}{Controls use and placement of the legend. See details.} - -\item{cex.leg}{A single numeric values used to represent the character expansion value for the legend. Ignored if \code{legend=FALSE}.} - -\item{box.lty.leg}{A single numeric values used to indicate the type of line to use for the box around the legend. The default is to not plot a box.} - -\item{d}{A data frame that contains the variables used in construction of the \code{nls} object.} - -\item{jittered}{A logical that indicates whether the points should be jittered horizontally.} - -\item{legend.lbls}{A vector of strings that will be the labels for the legend in an nls fitPlot graphic.} - -\item{transparency}{A numeric that indicates how many points would be plotted on top of each other in a logistic regression before the \sQuote{point} would have the full \code{pt.col} color. The reciprocal of this value is the alpha transparency value.} - -\item{plot.p}{A logical that indicates if the proportion for categorized values of X are plotted (\code{TRUE}; default).} - -\item{breaks}{A number that indicates how many intervals over which to compute proportions or a numeric vector that contains the endpoints of the intervals over which to compute proportions if \code{plot.p=TRUE}.} - -\item{p.col}{A color to plot the proportions.} - -\item{p.pch}{A plotting character for plotting the proportions.} - -\item{p.cex}{A character expansion factor for plotting the proportions.} - -\item{yaxis1.ticks}{A numeric vector that indicates where tick marks should be placed on the left y-axis (for the proportion of \sQuote{successes}) for the logistic regression plot.} - -\item{yaxis1.lbls}{A numeric vector that indicates labels for the tick marks on the left y-axis (for the proportion of \sQuote{successes}) for the logistic regression plot.} - -\item{yaxis2.show}{A logical that indicates whether the right y-axis should be created (\code{=TRUE}; default) or not for the logistic regression plot.} - -\item{mdl.vals}{A numeric that represents the number of values to use for plotting the logistic regression. A larger number means a smoother line.} - -\item{xlim}{A vector of length two to control the x-axis in the logistic regression plot. If this is changed from the default then the domain over which the logistic regression model is plotted will change.} -} -\value{ -None. However, a fitted-line plot is produced. -} -\description{ -A generic function for constructing a fitted model plot for an \code{lm}, \code{glm}, or \code{nls} object. Supported objects are linear models from simple linear regression (SLR), indicator variable regression (IVR), one-way ANOVA, or two-way ANOVA models; general linear models that are logistic regressions with a binary response; and non-linear regression with a single numerical response variable, at least one continuous explanatory variable and up to two group-factor explanatory variables. -} -\details{ -This function does not work with a multiple linear regression, indicator variable regressions with more than two factors, ANOVAs other than one-way and two-way, or models with a categorical response variable. In addition, if the linear model contains a factor then the model must be fit with the quantitative explanatory variable first, followed by the factor(s). This function only works for non-linear models with two or fewer groups. - -This function is basically a wrapper to a variety of other functions. For one-way or two-way ANOVAs the primary functions called are \code{interaction.plot} and \code{lineplot.CI}. For simple linear regression the function performs similarly to \code{abline} except that the line is constrained to the domain. For indicator variable regression the function behaves as if several \code{abline} functions had been called. - -A legend can be added to the plot in three different ways. First, if \code{legend = TRUE} then the R console is suspended until the user places the legend on the graphic by clicking on the graphic at the point where the upper-left corner of the legend should appear. Second, the \code{legend=} argument can be set to one of \code{"bottomright"}, \code{"bottom"}, \code{"bottomleft"}, \code{"left"}, \code{"topleft"}, \code{"top"}, \code{"topright"}, \code{"right"} and \code{"center"}. In this case, the legend will be placed inside the plot frame at the given location. Finally, the \code{legend=} argument can be set to a vector of length two which identifies the plot coordinates for the upper-left corner of where the legend should be placed. A legend will not be drawn if \code{legend = FALSE} or \code{legend = NULL}. A legend also will not be drawn if there are not multiple groups in the model. -} -\note{ -This function is meant to allow newbie students the ability to visualize the most common linear models found in an introductory or intermediate level undergraduate statistics course without getting \dQuote{bogged-down} in the gritty details of a wide variety of functions. This generic function and it's S3 functions allow the student to visualize the means plot of a one-way anova, the main effects and interaction plots of a two-way ANOVA, the fit of a simple linear regression, the fits of many lines in an indicator variable regression, and the fit of a non-linear model with a simple and mostly common set of arguments -- generally, all that is required is a fitted linear model of the type mentioned here as the first argument. This function thus allows newbie students to interact with and visualize moderately complex linear models in a fairly easy and efficient manner. THIS IS NOT A RESEARCH GRADE FUNCTION and the user should learn how to use the functions that this function is based on, build plots from \dQuote{scratch}, or use more sophisticated plotting packages (e.g., \pkg{ggplot2} or \pkg{lattice}). -} -\examples{ -# create year as a factor variable -Mirex$fyear <- factor(Mirex$year) -# reduce number of years for visual simplicity for iVRs -Mirex2 <- droplevels(subset(Mirex,fyear \%in\% c(1977,1992))) - -## One-way ANOVA -aov1 <- lm(mirex~fyear,data=Mirex) -fitPlot(aov1) - -## Two-way ANOVA -aov2 <- lm(mirex~fyear*species,data=Mirex) -# interaction plots and a color change -fitPlot(aov2,legend="bottomleft") -fitPlot(aov2,change.order=TRUE) -# main effects plots -fitPlot(aov2,which="species") -fitPlot(aov2,which="fyear") - -## Simple linear regression (show color change and confidence/prediction bands) -slr1 <- lm(mirex~weight,data=Mirex) -fitPlot(slr1) -fitPlot(slr1,interval="both") - -## Indicator variable regression with one factor (also showing confidence bands) -ivr1 <- lm(mirex~weight*fyear,data=Mirex2) -fitPlot(ivr1,legend="topleft") -fitPlot(ivr1,legend="topleft",interval="confidence") -fitPlot(ivr1,legend="topleft",interval="confidence",col="Dark 2") - -## Indicator variable regression with one factor (assuming parallel lines) -ivr2 <- lm(mirex~weight+species,data=Mirex2) -fitPlot(ivr2,legend="topleft") - -## Indicator variable regression with two factors -ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2) -fitPlot(ivr3,ylim=c(0,0.8),legend="topleft") -fitPlot(ivr3,ylim=c(0,0.8),legend="topleft",col="Spectral") - -## Polynomial regression -poly1 <- lm(mirex~weight+I(weight^2),data=Mirex) -fitPlot(poly1,interval="both") - -## Non-linear model example -lr.sv <- list(B1=6,B2=7.2,B3=-1.5) -nl1 <- nls(cells~B1/(1+exp(B2+B3*days)),start=lr.sv,data=Ecoli) -fitPlot(nl1,Ecoli,cex.main=0.7,lwd=2) - -## Logistic regression example -## NASA space shuttle o-ring failures -- from graphics package -d <- data.frame(fail=factor(c(2,2,2,2,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,1,1,1,1), - levels = 1:2, labels = c("no","yes")), - temperature <- c(53,57,58,63,66,67,67,67,68,69,70,70,70,70, - 72,73,75,75,76,76,78,79,81)) -glm1 <- glm(fail~temperature,data=d,family="binomial") -fitPlot(glm1) -fitPlot(glm1,yaxis1.ticks=c(0,1),yaxis1.lbls=c(0,1)) - -} -\seealso{ -See \code{\link{abline}}, \code{\link[car]{regLine}} in \pkg{car}, \code{\link[psych]{error.bars}} in \pkg{psych}, \code{interaction.plot}, and \code{\link[sciplot]{lineplot.CI}} in \pkg{sciplot} for similar functionality. -} -\author{ -Derek H. Ogle, \email{derek@derekogle.com} -} -\keyword{hplot} -\keyword{models} diff --git a/man/fsaNews.Rd b/man/fsaNews.Rd deleted file mode 100644 index 7056abcd..00000000 --- a/man/fsaNews.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/FSAUtils.R -\name{fsaNews} -\alias{fsaNews} -\alias{FSANews} -\title{Read news and changes for the 'FSA' package.} -\usage{ -fsaNews() - -FSANews() -} -\value{ -None. -} -\description{ -Opens up the \href{https://github.com/droglenc/FSA/blob/master/NEWS.md}{News.md GitHub file} for the \sQuote{FSA} package in an external browser. -} -\examples{ -\dontrun{ -## Opens an external webpage ... only run interactively -FSANews() -} - -} -\author{ -Derek H. Ogle, \email{derek@derekogle.com} -} -\keyword{manip} diff --git a/man/residPlot.Rd b/man/residPlot.Rd deleted file mode 100644 index c15d08f2..00000000 --- a/man/residPlot.Rd +++ /dev/null @@ -1,263 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/deprecated-residPlot.R -\name{residPlot} -\alias{residPlot} -\alias{residPlot.lm} -\alias{residPlot.SLR} -\alias{residPlot.IVR} -\alias{residPlot.POLY} -\alias{residPlot.ONEWAY} -\alias{residPlot.TWOWAY} -\alias{residPlot.nls} -\alias{residPlot.nlme} -\title{DEPRECATED -- Construct a residual plot from lm or nls objects.} -\usage{ -residPlot(object, ...) - -\method{residPlot}{lm}(object, ...) - -\method{residPlot}{SLR}( - object, - xlab = "Fitted Values", - ylab = "Residuals", - main = "", - pch = 16, - col = "black", - lty.ref = 3, - lwd.ref = 1, - col.ref = "black", - resid.type = c("raw", "standardized", "studentized"), - outlier.test = TRUE, - alpha = 0.05, - loess = FALSE, - lty.loess = 2, - lwd.loess = 1, - col.loess = "black", - trans.loess = 8, - inclHist = TRUE, - ... -) - -\method{residPlot}{POLY}(object, ...) - -\method{residPlot}{IVR}(object, legend = "topright", cex.leg = 1, box.lty.leg = 0, ...) - -\method{residPlot}{ONEWAY}( - object, - xlab = "Fitted Values", - ylab = "Residuals", - main = "", - pch = 16, - col = "black", - lty.ref = 3, - lwd.ref = 1, - col.ref = "black", - resid.type = c("raw", "standardized", "studentized"), - bp = TRUE, - outlier.test = TRUE, - alpha = 0.05, - loess = FALSE, - lty.loess = 2, - lwd.loess = 1, - col.loess = "black", - trans.loess = 8, - inclHist = TRUE, - ... -) - -\method{residPlot}{TWOWAY}( - object, - xlab = "Fitted Values", - ylab = "Residuals", - main = "", - pch = 16, - col = "black", - lty.ref = 3, - lwd.ref = 1, - col.ref = "black", - resid.type = c("raw", "standardized", "studentized"), - bp = TRUE, - outlier.test = TRUE, - alpha = 0.05, - loess = FALSE, - lty.loess = 2, - lwd.loess = 1, - col.loess = "black", - trans.loess = 8, - inclHist = TRUE, - ... -) - -\method{residPlot}{nls}( - object, - xlab = "Fitted Values", - ylab = "Residuals", - main = "", - pch = 16, - col = "black", - lty.ref = 3, - lwd.ref = 1, - col.ref = "black", - resid.type = c("raw", "standardized", "studentized"), - loess = FALSE, - lty.loess = 2, - lwd.loess = 1, - col.loess = "black", - trans.loess = 8, - inclHist = TRUE, - ... -) - -\method{residPlot}{nlme}( - object, - xlab = "Fitted Values", - ylab = "Residuals", - main = "", - pch = 16, - col = "black", - lty.ref = 3, - lwd.ref = 1, - col.ref = "black", - resid.type = c("raw", "standardized", "studentized"), - loess = FALSE, - lty.loess = 2, - lwd.loess = 1, - col.loess = "black", - trans.loess = 8, - inclHist = TRUE, - ... -) -} -\arguments{ -\item{object}{An \code{lm} or \code{nls} object (i.e., returned from fitting a model with either \code{lm} or \code{nls}).} - -\item{\dots}{Other arguments to the generic \code{plot} function.} - -\item{xlab}{A string for labeling the x-axis.} - -\item{ylab}{A string for labeling the y-axis.} - -\item{main}{A string for the main label to the plot. See details.} - -\item{pch}{A numeric that indicates the plotting character to be used or a vector of numerics that indicates what plotting character codes to use for the levels of the second factor. See \code{par}.} - -\item{col}{A vector of color names that indicates what color of points and lines to use for the levels of the first factor. See \code{par}.} - -\item{lty.ref}{A numeric that indicates the line type to use for the reference line at residual=0. See \code{par}.} - -\item{lwd.ref}{A numeric that indicates the line width to use for the reference line at residual=0. See \code{par}.} - -\item{col.ref}{A numeric or character that indicates the line color to use for the reference line at residual=0. See \code{par}.} - -\item{resid.type}{The type of residual to use. \sQuote{Raw} residuals are used by default. See details.} - -\item{outlier.test}{A logical that indicates if an \code{outlierTest} will \code{TRUE} (default) be performed and if the individual with the largest studentized residual is deemed to be a significant outlier it will be noted on the residual plot by its observation number.} - -\item{alpha}{A numeric that indicates the alpha level to use for the outlier test (only used if \code{outlier.test=TRUE}).} - -\item{loess}{A logical that indicates if a loess smoother line and approximate confidence interval band is fit to and shown on the residual plot (\code{TRUE}).} - -\item{lty.loess}{A numeric that indicates the line type to use for loess fit line. See \code{par}.} - -\item{lwd.loess}{A numeric that indicates the line width to use for loess fit line. See \code{par}.} - -\item{col.loess}{A numeric or character that indicates the line color to use for loess fit line. See \code{par}.} - -\item{trans.loess}{A single numeric that indicates how transparent the loess band should be (larger numbers are more transparent).} - -\item{inclHist}{A logical that indicates if a second pane that includes the histogram of residuals should be constructed.} - -\item{legend}{If \code{TRUE}, draw a legend and the user must click in the upper-left corner of where the legend should be placed; if \code{FALSE} do not draw a legend. If a vector of length 2 then draw the upper left corner of the legend at the coordinates given in the vector of length 2.} - -\item{cex.leg}{A single numeric values used to represent the character expansion value for the legend. Ignored if \code{legend=FALSE}.} - -\item{box.lty.leg}{A single numeric values used to indicate the type of line to use for the box around the legend. The default is to not plot a box.} - -\item{bp}{A logical that indicates if the plot for the one-way and two-way ANOVA will be a boxplot (\code{TRUE}; default) or not.} -} -\value{ -None. However, a residual plot is produced. -} -\description{ -Constructs a residual plot for \code{lm} or \code{nls} objects. Different symbols for different groups can be added to the plot if an indicator variable regression is used. -} -\details{ -Three types of residuals are allowed for most model types. Raw residuals are simply the difference between the observed response variable and the predicted/fitted value. Standardized residuals are internally studentized residuals returned by \code{\link{rstandard}} for linear models and are the raw residual divided by the standard deviation of the residuals for nonlinear models (as is done by \code{\link[nlstools]{nlsResiduals}} from \pkg{nlstools}). Studentized residuals are the externally studentized residuals returned by \code{\link{rstudent}} for linear models and are not available for nonlinear models. - -Externally Studentized residuals are not supported for \code{nls} or \code{nlme} objects. - -If \code{outlier.test=TRUE} then significant outliers are detected with \code{\link[car]{outlierTest}} from the \pkg{car} package. See the help for this function for more details. - -The user can include the model call as a title to the residual plot by using \code{main="MODEL"}. This only works for models created with \code{lm()}. - -If the user chooses to add a legend without identifying coordinates for the upper-left corner of the legend (i.e., \code{legend=TRUE}) then the R console is suspended until the user places the legend by clicking on the produced graphic at the point where the upper-left corner of the legend should appear. A legend will only be placed if the \code{mdl} is an indicator variable regression, even if \code{legend=TRUE}. -} -\note{ -This function is meant to allow newbie students the ability to easily construct residual plots for one-way ANOVA, two-way ANOVA, simple linear regression, and indicator variable regressions. The plots can be constructed by submitting a saved linear model to this function which allows students to interact with and visualize moderately complex linear models in a fairly easy and efficient manner. -} -\examples{ -# create year factor variable -Mirex$fyear <- factor(Mirex$year) -Mirex$cyear <- as.character(Mirex$year) -Mirex$cspecies <- as.character(Mirex$species) - -## One-way ANOVA -aov1 <- lm(mirex~fyear,data=Mirex) -residPlot(aov1) - -## Two-Way ANOVA -aov2 <- lm(mirex~species*fyear,data=Mirex) -residPlot(aov2) - -## Simple linear regression -slr1 <- lm(mirex~weight,data=Mirex) -residPlot(slr1) -residPlot(slr1,loess=TRUE,main="MODEL") - -## Indicator variable regression with only one factor -ivr1 <- lm(mirex~weight*fyear,data=Mirex) -residPlot(ivr1) -residPlot(ivr1,inclHist=FALSE,pch=19) -residPlot(ivr1,inclHist=FALSE,pch=19,col="black") -residPlot(ivr1,legend=FALSE,loess=TRUE) - -## Indicator variable regression (assuming same slope) -ivr2 <- lm(mirex~weight+fyear,data=Mirex) -residPlot(ivr2,legend=FALSE,loess=TRUE) - -## Indicator variable regression with two factors -## Reduce number of years for visual simplicity -Mirex2 <- droplevels(subset(Mirex,fyear \%in\% c(1977,1992))) - -ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2) -residPlot(ivr3) -residPlot(ivr3,loess=TRUE,legend=FALSE) - -## IVR w/ factors in different order (notice use of colors and symbols) -ivr4 <- lm(mirex~weight*species*fyear,data=Mirex2) -residPlot(ivr4) - - -## Nonlinear regression ... from first example in nls() -DNase1 <- subset(DNase,Run==1) -fm1DNase1 <- nls(density~SSlogis(log(conc),Asym,xmid,scal),DNase1) -residPlot(fm1DNase1) -residPlot(fm1DNase1,resid.type="standardized") - - -## Examples showing outlier detection -x <- c(runif(100)) -y <- c(7,runif(98),-5) -lma <- lm(y~x) -residPlot(lma) -residPlot(lma,resid.type="studentized") - -} -\seealso{ -See \code{\link[car]{residualPlots}} in \pkg{car} and \code{\link[nlstools]{nlsResiduals}} in \pkg{nlstools}) for similar functionality. See \code{\link[car]{outlierTest}} in \pkg{car} for related methods. -} -\author{ -Derek H. Ogle, \email{derek@derekogle.com} -} -\keyword{hplot} -\keyword{models}