ellipse/0000755000176200001440000000000013224007655011713 5ustar liggesusersellipse/NAMESPACE0000644000176200001440000000101213223713324013120 0ustar liggesusersexport(ellipse,plotcorr,pairs) importFrom("graphics", "axis", "box", "lines", "mtext", "par", "plot", "plot.new", "polygon", "strwidth", "text") importFrom("stats", "approx", "qchisq", "qf", "spline") S3method(ellipse,arima0) S3method(ellipse,default) S3method(ellipse,glm) S3method(ellipse,lm) S3method(ellipse,nls) S3method(ellipse,profile) S3method(ellipse,profile.glm) S3method(ellipse,profile.nls) S3method(pairs,profile) S3method(pairs,default,.pairs_default) S3method(pairs,formula,.pairs_formula) ellipse/R/0000755000176200001440000000000012112453473012112 5ustar liggesusersellipse/R/pairs.profile.R0000644000176200001440000000743113223703726015022 0ustar liggesuserspairs <- function(x, ...) UseMethod("pairs") .pairs_default <- function(x, ...) graphics::pairs(x, ...) .pairs_formula <- function(formula, data = NULL, ..., subset, na.action = stats::na.pass) { # This code is copied from graphics:::pairs.formula # because the non-standard evaluation wouldn't survive # the indirect call. m <- match.call(expand.dots = FALSE) if (is.matrix(eval(m$data, parent.frame()))) m$data <- as.data.frame(data) m$... <- NULL m$na.action <- na.action m[[1L]] <- quote(stats::model.frame) mf <- eval(m, parent.frame()) graphics::pairs(mf, ...) } "pairs.profile" <- function (x, labels = c(names(x), "Profile tau"), panel = lines, invert = TRUE, plot.tau = TRUE, plot.trace = TRUE, plot.sketch = TRUE, plot.ellipse = FALSE, level = 0.95, ...) { doaxis <- function(which, dolabel = TRUE) axis(which, labels = dolabel) # outer = TRUE, line = -0.5, labels = dolabel) setup <- function(x, y, ...) plot(range(x[!is.na(x)]), range(y[!is.na(y)]), type = "n", axes = FALSE, ...) if (is.character(panel)) panel <- get(panel, mode = "function") n <- length(x) if (plot.tau) n <- n + 1 oldpar <- par("oma", "mar", "cex", "tck", "mgp", "mex", "mfrow") oldcex <- par("cex") CEX <- oldcex * max(7.7/(2 * n + 3), 0.6) par(mfrow = c(n, n), mgp = c(2, 0.8, 0), oma = rep(3, 4), mar = rep(0.5, 4), tck = -0.03/n) on.exit({ par(oldpar) }) par(cex = CEX) if (length(labels) < n) labels <- paste(deparse(substitute(x)), "[,", 1:n, "]", sep = "") if (par("pty") == "s") { dif <- diff(par("fin"))/2 if (dif > 0) par(omi = c(dif * n, 0, dif * n, 0) + par("omi")) else par(omi = c(0, (-dif) * n, 0, (-dif) * n) + par("omi")) } alltau <- unlist(lapply(x, function(x) x[[1]]), use.names = FALSE) order <- if (invert) 1:n else n:1 for (i in order) { for (j in 1:n) { if (i <= length(x)) { icomp <- x[[i]] ipars <- as.matrix(icomp[[2]]) } if (j <= length(x)) { jcomp <- x[[j]] jpars <- as.matrix(jcomp[[2]]) } xx1 <- NA xx2 <- NA yy1 <- NA yy2 <- NA if (i <= length(x)) { yy1 <- ipars[, i] if (j <= length(x)) { xx1 <- ipars[, j] xx2 <- jpars[, j] yy2 <- jpars[, i] } else { xx1 <- icomp[[1]] } } else { yy1 <- jcomp[[1]] if (j <= length(x)) { xx1 <- jpars[, j] } } xx <- c(xx1, NA, xx2) yy <- c(yy1, NA, yy2) if (i <= length(x)) { if (j <= length(x)) setup(xx, yy, ...) else setup(alltau, yy, ...) } else { if (j <= length(x)) setup(xx, alltau, ...) else setup(alltau, alltau) } box() if (i == 1) doaxis(3, j%%2 == 0) if (i == n) doaxis(1, j%%2 == 1) if (j == 1) doaxis(2, i%%2 == 0) if (j == n) doaxis(4, i%%2 == 1) if (i != j) { if ((i <= length(x)) && (j <= length(x))) { if (plot.trace) panel(xx, yy, ...) if (plot.sketch) for (l in level) panel(ellipse(x, which = c(j, i), level = l), ...) if (plot.ellipse && !is.null(fit <- attr(x, "original.fit"))) for (l in level) panel(ellipse(fit, which = c(j, i), level = l), ...) } else if (plot.tau) panel(xx, yy, ...) } else { par(usr = c(0, 1, 0, 1)) text(0.5, 0.5, labels[i], cex = 1.5 * CEX) } } } invisible() } ellipse/R/ellipse.lm.R0000644000176200001440000000046111210103405014263 0ustar liggesusers"ellipse.lm" <- function (x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, x$df.residual)), ...) { s <- summary(x) ellipse.default(s$sigma^2 * s$cov.unscaled[which, which], centre = x$coefficients[which], t = t, ...) } ellipse/R/ellipse.glm.R0000644000176200001440000000102011210103405014422 0ustar liggesusers"ellipse.glm" <- function (x, which = c(1, 2), level = 0.95, t, npoints = 100, dispersion, ...) { s <- summary(x) est.disp <- missing(dispersion) & !(x$family$family %in% c('poisson','binomial')) if (missing(dispersion)) dispersion <- s$dispersion if (missing(t)) t <- ifelse(est.disp,sqrt(2 * qf(level, 2, s$df[2])), sqrt(qchisq(level, 2))) ellipse.default(dispersion * s$cov.unscaled[which, which], centre = x$coefficients[which], t = t, npoints = npoints, ...) } ellipse/R/ellipse.nls.R0000644000176200001440000000045311210103405014450 0ustar liggesusers"ellipse.nls" <- function (x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, s$df[2])), ...) { s <- summary(x) ellipse.default(s$sigma^2 * s$cov.unscaled[which, which], centre = x$m$getPars()[which], t = t, ...) } ellipse/R/ellipse.R0000644000176200001440000000006610443476553013705 0ustar liggesusers"ellipse" <-function (x, ...) UseMethod("ellipse") ellipse/R/ellipse.arima0.R0000644000176200001440000000027211210103405015024 0ustar liggesusersellipse.arima0<- function(x, which = c(1, 2), level = 0.95, t = sqrt(qchisq(level, 2)), ...) { ellipse.default(x$var.coef[which, which], centre = x$coef[which], t = t, ...) } ellipse/R/ellipse.profile.glm.R0000644000176200001440000000104710443476553016122 0ustar liggesusers"ellipse.profile.glm" <- function (x, which = c(1, 2), level = 0.95, t, npoints = 100, dispersion, ...) { if (missing(dispersion)) dispersion <- ifelse(attr(x,"original.fit")$family$family %in% c('poisson','binomial'), 1, NA) if (missing(t)) t <- ifelse(is.na(dispersion),sqrt(2 * qf(level, 2, attr(x,"summary")$df[2])), sqrt(qchisq(level, 2)*dispersion/attr(x,"summary")$dispersion)) ellipse.profile(x, which = which, level = level, t = t, npoints = npoints) } ellipse/R/ellipse.profile.nls.R0000644000176200001440000000040310443476553016132 0ustar liggesusers"ellipse.profile.nls" <- function (x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, attr(x, "summary")$df[2])), npoints = 100, ...) { ellipse.profile(x, which = which, level = level, t = t, npoints = npoints) } ellipse/R/ellipse.profile.R0000644000176200001440000000452610443476553015351 0ustar liggesusers"ellipse.profile" <- function (x, which = c(1, 2), level = 0.95, t = sqrt(qchisq(level, 2)), npoints = 100, ...) { aa <- x[[which[1]]][[2]][, which[1]] ar <- x[[which[1]]][[2]][, which[2]] ra <- x[[which[2]]][[2]][, which[1]] rr <- x[[which[2]]][[2]][, which[2]] atau <- x[[which[1]]][[1]] rtau <- x[[which[2]]][[1]] arange <- range(c(aa, ra)) rrange <- range(c(ar, rr)) atau <- atau/t rtau <- rtau/t getad <- function(tau1, tau2) { if (abs(tau1) > 1) tau1 <- tau1/abs(tau1) if (abs(tau2) > 1) tau2 <- tau2/abs(tau2) acos1 <- acos(tau1) acos2 <- acos(tau2) d <- abs(acos1 - acos2) a <- (acos1 + acos2)/2 if (acos1 < acos2) a <- -a c(a, d) } myapprox <- function(x, y, where) { good <- is.finite(x) & is.finite(y) x <- x[good] y <- y[good] if (length(x) > 1) { result <- approx(x[good], y[good], where)$y bad <- is.na(result) if (any(bad)) { for (i in 1:length(result)) { if (bad[i]) { if (where[i] > x[length(x)]) { x1 <- x[length(x) - 1] y1 <- y[length(x) - 1] x2 <- x[length(x)] y2 <- y[length(x)] } else if (where[i] < x[1]) { x1 <- x[1] y1 <- y[1] x2 <- x[2] y2 <- y[2] } else stop("Unexpected NA") result[i] <- y1 + (where[i] - x1)/(x2 - x1) * (y2 - y1) } } } } else result <- rep(y, length(where)) result } ad <- matrix(NA, nrow = 5, ncol = 2) ad[1, ] <- getad(1, myapprox(rr, rtau, myapprox(aa, ar, myapprox(atau, aa, 1)))) ad[2, ] <- getad(myapprox(aa, atau, myapprox(rr, ra, myapprox(rtau, rr, 1))), 1) ad[3, ] <- getad(-1, myapprox(rr, rtau, myapprox(aa, ar, myapprox(atau, aa, -1)))) ad[4, ] <- getad(myapprox(aa, atau, myapprox(rr, ra, myapprox(rtau, rr, -1))), -1) i <- order(ad[1:4, 1]) ad[1:4, ] <- ad[i, ] ad[5, 1] <- ad[1, 1] + 2 * pi ad[5, 2] <- ad[1, 2] ad <- ad[!duplicated(ad[, 1]), ] adv <- spline(ad, n = npoints, method= "periodic") avals <- adv$x dvals <- adv$y matrix(c(myapprox(atau, aa, cos(avals + dvals/2)), myapprox(rtau, rr, cos(avals - dvals/2))), length(avals), 2, dimnames = list(NULL, names(x[which]))) } ellipse/R/plotcorr.R0000644000176200001440000000563012132233525014101 0ustar liggesusers"plotcorr" <- function (corr, outline = TRUE, col = 'grey', numbers = FALSE, type = c("full","lower","upper"), diag = (type == "full"), bty = "n", axes = FALSE, xlab = "", ylab = "", asp = 1, cex.lab = par("cex.lab"), cex = 0.75*par("cex"), mar = 0.1 + c(2,2,4,2), ...) { savepar <- par(pty = "s", mar = mar) on.exit(par(savepar)) if (is.null(corr)) return(invisible()) if ((!is.matrix(corr)) || (round(min(corr, na.rm = TRUE), 6) < -1) || (round(max(corr, na.rm = TRUE), 6) > 1)) stop("Need a correlation matrix") plot.new() par(new = TRUE) rowdim <- dim(corr)[1] coldim <- dim(corr)[2] rowlabs <- dimnames(corr)[[1]] collabs <- dimnames(corr)[[2]] if (is.null(rowlabs)) rowlabs <- 1:rowdim if (is.null(collabs)) collabs <- 1:coldim rowlabs <- as.character(rowlabs) collabs <- as.character(collabs) col <- rep(col, length = length(corr)) dim(col) <- dim(corr) type <- match.arg(type) cols <- 1:coldim rows <- 1:rowdim xshift <- 0 yshift <- 0 if (!diag) { if (type == "upper") { cols <- 2:coldim rows <- 1:(rowdim - 1) xshift <- 1 } else if (type == "lower") { cols <- 1:(coldim-1) rows <- 2:rowdim yshift <- -1 } } maxdim <- max(length(rows), length(cols)) plt <- par('plt') xlabwidth <- max(strwidth(rowlabs[rows],units='figure',cex=cex.lab))/(plt[2]-plt[1]) xlabwidth <- xlabwidth*maxdim/(1-xlabwidth) ylabwidth <- max(strwidth(collabs[cols],units='figure',cex=cex.lab))/(plt[4]-plt[3]) ylabwidth <- ylabwidth*maxdim/(1-ylabwidth) plot(c(-xlabwidth-0.5, maxdim + 0.5), c(0.5, maxdim + 1 + ylabwidth), type = "n", bty = bty, axes = axes, xlab = "", ylab = "", asp = asp, cex.lab = cex.lab, ...) text(rep(0, length(rows)), length(rows):1, labels = rowlabs[rows], adj = 1, cex = cex.lab) text(cols-xshift, rep(length(rows) + 1, length(cols)), labels = collabs[cols], srt = 90, adj = 0, cex = cex.lab) mtext(xlab,1,0) mtext(ylab,2,0) mat <- diag(c(1, 1)) plotcorrInternal <- function() { if (i == j && !diag) return() if (!numbers) { mat[1, 2] <- corr[i, j] mat[2, 1] <- mat[1, 2] ell <- ellipse(mat, t = 0.43) ell[, 1] <- ell[, 1] + j - xshift ell[, 2] <- ell[, 2] + length(rows) + 1 - i - yshift polygon(ell, col = col[i, j]) if (outline) lines(ell) } else { text(j + 0.3 - xshift, length(rows) + 1 - i - yshift, round(10 * corr[i, j], 0), adj = 1, cex = cex) } } for (i in 1:dim(corr)[1]) { for (j in 1:dim(corr)[2]) { if (type == "full") { plotcorrInternal() } else if (type == "lower" && (i >= j)) { plotcorrInternal() } else if (type == "upper" && (i <= j)) { plotcorrInternal() } } } invisible() } ellipse/R/ellipse.default.R0000644000176200001440000000154410443476553015332 0ustar liggesusers"ellipse.default" <- function (x, scale = c(1, 1), centre = c(0, 0), level = 0.95, t = sqrt(qchisq(level, 2)), which = c(1, 2), npoints = 100, ...) { names <- c("x", "y") if (is.matrix(x)) { xind <- which[1] yind <- which[2] r <- x[xind, yind] if (missing(scale)) { scale <- sqrt(c(x[xind, xind], x[yind, yind])) if (scale[1] > 0) r <- r/scale[1] if (scale[2] > 0) r <- r/scale[2] } if (!is.null(dimnames(x)[[1]])) names <- dimnames(x)[[1]][c(xind, yind)] } else r <- x r <- min(max(r,-1),1) # clamp to -1..1, in case of rounding errors d <- acos(r) a <- seq(0, 2 * pi, len = npoints) matrix(c(t * scale[1] * cos(a + d/2) + centre[1], t * scale[2] * cos(a - d/2) + centre[2]), npoints, 2, dimnames = list(NULL, names)) } ellipse/MD50000644000176200001440000000251113224007655012222 0ustar liggesusersab362731acc035daf0a26a4174c260d6 *DESCRIPTION f1c594cb593f80cd82e09f1e562de22b *NAMESPACE 73fea51373da9bbc4ff85c413745b526 *R/ellipse.R 4be8275a614fcb4065c37b8762941247 *R/ellipse.arima0.R caee0c1cfc23e089ee9ba8f4b4798039 *R/ellipse.default.R 3c552169931b0006165ac5b1ae888eb3 *R/ellipse.glm.R f3a81546119e55c3f45191add9fea049 *R/ellipse.lm.R 84a3d7dd1aa99c82424453da914feaaa *R/ellipse.nls.R 1f6cc6a9602728096e1a5c17db75a3d1 *R/ellipse.profile.R 179ff82c9db9ac24d7c28250d7dbd4ac *R/ellipse.profile.glm.R e9db7c17f6821149220b411bfd6441a6 *R/ellipse.profile.nls.R 51a4f27c99ed5d47d0ce1445435b49b9 *R/pairs.profile.R f410502cb27f5f2cfaee61bcf133abe3 *R/plotcorr.R b58cd88bf88e9e6f2f4570d0db93c8bb *README c72cbb10c7117b72c4661f1e985e20e4 *man/ellipse-package.Rd a20be12fc0bc7bd5f179a90dcacfa291 *man/ellipse.Rd 2a7bc110f3041d43ddd9ae601bf81912 *man/ellipse.arima0.Rd 13796f5667a8b5b3c3eda8778ec508b1 *man/ellipse.glm.Rd 8de4342bb0e4fd05f84cd2f244d3a58a *man/ellipse.lm.Rd a44b6aebadb5c6335f6e711b23152475 *man/ellipse.nls.Rd 0f2ec2da5cb8932fd631826ca008e366 *man/ellipse.profile.Rd 7c26b34627f1934d7b601edc1fa43b79 *man/ellipse.profile.glm.Rd d61933ab53fb8e18ae250244537e6413 *man/ellipse.profile.nls.Rd 41184b50c2f136f5ba50f6884775a19b *man/pairs.Rd 36e788f8569c1c414c7887c07715c4ed *man/pairs.profile.Rd fc500238b94fb8b704aba56a7abacd44 *man/plotcorr.Rd ellipse/README0000644000176200001440000000234113223725144012572 0ustar liggesusersThis package contains ellipse drawing routines designed for pairwise confidence regions, including distorted ellipses for nonlinear regression regions. It also includes a routine "plotcorr" for plotting correlation matrices using ellipses. The examples require the MASS, nls and ts packages. Release History: 0.2.12 (Jan 2004) - Bug fix for missing values in plotcorr, doc error 0.2.14 (Aug 2004) - Allowed separate colors for each ellipse in plotcorr and fixed some .Rd errors. 0.2.15 (May 2005) - Allowed plotcorr to plot just upper or lower triangle of matrix. 0.3.1 (June 2005) - Added NAMESPACE, package overview topic 0.3.2 (Feb 2006) - Remove deprecated install.R 0.3.3 (Nov 2006) - Nicer colors in plotcorr() example (from Gregor Gorjanc) 0.3.4 (Nov 2006) - Update to strict test compliance 0.3.5 (Sep 2007) - License clarification 0.3.6 (Apr 2009) - Bug fix: ... was not being passed from methods to ellipse.default(). 0.3.7 (Mar 2012) - Minor fix (clean up DESCRIPTION file) 0.3.8 (Apr 2013) - Minor fix (no more \synopsis tag in help) 0.4.1 (Jan 2018) - At request of CRAN, added pairs() generic function to avoid clash with MASS::pairs.profile, and other minor cleanups. ellipse/DESCRIPTION0000644000176200001440000000162213224007655013422 0ustar liggesusersPackage: ellipse Version: 0.4.1 Title: Functions for Drawing Ellipses and Ellipse-Like Confidence Regions Author: Duncan Murdoch and E. D. Chow (porting to R by Jesus M. Frias Celayeta ) Maintainer: Duncan Murdoch Description: Contains various routines for drawing ellipses and ellipse-like confidence regions, implementing the plots described in Murdoch and Chow (1996), A graphical display of large correlation matrices, The American Statistician 50, 178-180. There are also routines implementing the profile plots described in Bates and Watts (1988), Nonlinear Regression Analysis and its Applications. Depends: R (>= 2.0.0),graphics,stats Suggests: MASS LazyLoad: yes License: GPL (>= 2) NeedsCompilation: no Packaged: 2018-01-05 17:15:30 UTC; murdoch Repository: CRAN Date/Publication: 2018-01-05 23:52:13 UTC ellipse/man/0000755000176200001440000000000013223670527012471 5ustar liggesusersellipse/man/ellipse.profile.glm.Rd0000644000176200001440000000473010443476553016642 0ustar liggesusers\name{ellipse.profile.glm} \alias{ellipse.profile.glm} \title{ Pairwise profile sketch for GLM profiles } \description{ This routine approximates a pairwise confidence region for a glm model. } \usage{ \method{ellipse}{profile.glm}(x, which = c(1, 2), level = 0.95, t, npoints = 100, dispersion, \dots) } \arguments{ \item{x}{ An object of class \code{\link[MASS]{profile.glm}}. } \item{which}{ Which pair of parameters to use. } \item{level}{ The \code{level} argument specifies the confidence level for an asymptotic confidence region. } \item{t}{ The square root of the value to be contoured. By default, this is \code{qchisq(level, 2)} for models with fixed dispersion (i.e. binomial and Poisson), and \code{2 * qf(level, 2, df)} for other models, where \code{df} is the residual degrees of freedom. } \item{npoints}{ How many points to use in the ellipse. } \item{dispersion}{ If specified, fixed dispersion is assumed, otherwise the dispersion is taken from the model. } \item{\dots}{ Extra parameters which are not used (for compatibility with the generic). } } \value{ An \code{npoints} x \code{2} matrix with columns having the chosen parameter names, which approximates a contour of the function that was profiled. } \details{ This function uses the 4 point approximation to the contour as described in Appendix 6 of Bates and Watts (1988). It produces the exact contour for quadratic surfaces, and good approximations for mild deviations from quadratic. If the surface is multimodal, the algorithm is likely to produce nonsense. } \references{ Bates and Watts (1988) Nonlinear Regression Analysis \& its Applications } \seealso{ \code{\link{profile}}, \code{\link{glm}}, \code{\link{ellipse.glm}} } \examples{ ## MASS has a pairs.profile function that conflicts with ours, so ## do a little trickery here noMASS <- is.na(match('package:MASS', search())) if (noMASS) require(MASS) ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) glm.D93 <- glm(counts ~ outcome + treatment, family=poisson()) ## Plot an approximate 95\% confidence region for the two outcome variables prof.D93 <- profile(glm.D93) plot(ellipse(prof.D93, which = 2:3), type = 'l') lines(ellipse(glm.D93, which = 2:3), lty = 2) params <- glm.D93$coefficients points(params[2],params[3]) ## Clean up our trickery if (noMASS) detach('package:MASS') } \keyword{dplot} \keyword{models} ellipse/man/ellipse.lm.Rd0000644000176200001440000000252310443476553015032 0ustar liggesusers\name{ellipse.lm} \alias{ellipse.lm} \title{ Outline a pairwise confidence region for a linear model fit. } \description{ This function produces the ellipsoidal outline of a pairwise confidence region for a linear model fit. } \usage{ \method{ellipse}{lm}(x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, x$df.residual)), \dots) } \arguments{ \item{x}{ The first argument should be an \code{lm} object, usually resulting from a call to \code{lm()}. } \item{which}{ Which selects the pair of parameters to be plotted. The default is the first two. } \item{level}{ The confidence level of the region. Default 95\%. } \item{t}{ The t statistic on the boundary of the ellipse. } \item{\dots}{ Other \code{ellipse.default} parameters may also be used. }} \value{ A matrix with columns \code{x} and \code{y} to outline the confidence region. } \details{ The summary function is used to obtain the covariance matrix of the fitted parameters. } \seealso{ \code{\link{ellipse.default}} } \examples{ # Plot the estimate and joint 90\% confidence region for the displacement and cylinder # count linear coefficients in the mtcars dataset data(mtcars) fit <- lm(mpg ~ disp + cyl , mtcars) plot(ellipse(fit, which = c('disp', 'cyl'), level = 0.90), type = 'l') points(fit$coefficients['disp'], fit$coefficients['cyl']) } \keyword{dplot} \keyword{regression} ellipse/man/ellipse-package.Rd0000644000176200001440000000320110443476553016006 0ustar liggesusers\name{ellipse-package} \alias{ellipse-package} \docType{package} \title{ Functions for drawing ellipses and ellipse-like confidence regions } \description{ This package contains various routines for drawing ellipses and ellipse-like confidence regions, implementing the plots described in Murdoch and Chow (1996). There are also routines implementing the profile plots described in Bates and Watts (1988). } \details{ There are three groups of routines in the ellipse package. The first consists of those involved with \code{\link{plotcorr}}, which implements the plots described in Murdoch and Chow (1996). These display correlations using ellipses, whose shape is that of the contours of a bivariate normal distribution with matching correlation. The second group implements a version of the profile plots described in Bates and Watts (1988); see \code{\link{ellipse.profile}} and \code{\link{pairs.profile}}. The last group provide the basis for the others, drawing ellipses based on various S objects, including scalar correlations, covariance matrices \code{\link{arima}}, \code{\link{lm}}, and \code{\link{nls}} fits: see \code{\link{ellipse}}. } \author{ Duncan Murdoch and E. D. Chow (porting to R by Jesus M. Frias Celayeta ) Maintainer: Duncan Murdoch } \references{ Bates, D.M. and Watts, D.G. (1988). Nonlinear Regression Analysis and its Applications. Wiley. Murdoch, D.J. and Chow, E.D. (1996). A graphical display of large correlation matrices. The American Statistician 50, 178-180. } \keyword{ package } \keyword{ dplot } ellipse/man/ellipse.Rd0000644000176200001440000000466710543301562014422 0ustar liggesusers\name{ellipse} \alias{ellipse} \alias{ellipse.default} \title{ Make an ellipse } \description{ A generic function returning an ellipse or other outline of a confidence region for two parameters. } \usage{ ellipse(x, \dots) \method{ellipse}{default}(x, scale = c(1, 1), centre = c(0, 0), level = 0.95, t = sqrt(qchisq(level, 2)), which = c(1, 2), npoints = 100, \dots) } \arguments{ \item{x}{ An object. In the default method the parameter \code{x} should be a correlation between -1 and 1 or a square positive definite matrix at least 2x2 in size. It will be treated as the correlation or covariance of a multivariate normal distribution. } \item{\dots}{ Descendant methods may require additional parameters. } \item{scale}{ If \code{x} is a correlation matrix, then the standard deviations of each parameter can be given in the scale parameter. This defaults to \code{c(1, 1)}, so no rescaling will be done. } \item{centre}{ The centre of the ellipse will be at this position. } \item{level}{ The confidence level of a pairwise confidence region. The default is 0.95, for a 95\% region. This is used to control the size of the ellipse being plotted. A vector of levels may be used. } \item{t}{ The size of the ellipse may also be controlled by specifying the value of a t-statistic on its boundary. This defaults to the appropriate value for the confidence region. } \item{which}{ This parameter selects which pair of variables from the matrix will be plotted. The default is the first 2. } \item{npoints}{ The number of points used in the ellipse. Default is 100. } } \value{ An \code{npoints} x \code{2} matrix is returned with columns named according to the row names of the matrix \code{x} (default \code{'x'} and \code{'y'}), suitable for plotting. } \details{ The default method uses the \code{(cos(theta + d/2), cos(theta - d/2))} parametrization of an ellipse, where \code{cos(d)} is the correlation of the parameters. } \seealso{ \code{\link{ellipse.lm}}, \code{\link{ellipse.nls}}, \code{\link{ellipse.profile}}, \code{\link{ellipse.profile.nls}}, \code{\link{ellipse.arima0}}, \code{\link{plotcorr}} } \references{ Murdoch, D.J. and Chow, E.D. (1996). A graphical display of large correlation matrices. The American Statistician 50, 178-180. } \examples{ # Plot an ellipse corresponding to a 95\% probability region for a # bivariate normal distribution with mean 0, unit variances and # correlation 0.8. plot(ellipse(0.8), type = 'l') } \keyword{dplot} ellipse/man/ellipse.arima0.Rd0000644000176200001440000000243710443476553015577 0ustar liggesusers\name{ellipse.arima0} \alias{ellipse.arima0} \title{ Outline an approximate pairwise confidence region } \description{ This function produces the ellipsoidal outline of an approximate pairwise confidence region for an ARIMA model fit. } \usage{ \method{ellipse}{arima0}(x, which = c(1, 2), level = 0.95, t = sqrt(qchisq(level, 2)), \dots) } \arguments{ \item{x}{ The first argument should be an \code{arima0} object, usually resulting from a call to \code{arima0()}. } \item{which}{ Which selects the pair of parameters to be plotted. The default is the first two. } \item{level}{ The confidence level of the region. Default 95\%. } \item{t}{ The t statistic on the boundary of the ellipse. } \item{\dots}{ Other \code{ellipse.default} parameters may also be used. }} \value{ A matrix with columns \code{x} and \code{y} to outline the confidence region. } \details{ The \code{summary} function is used to obtain the approximate covariance matrix of the fitted parameters. } \seealso{ \code{\link{ellipse}} } \examples{ data(USAccDeaths) fit <- arima0(USAccDeaths, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1))) # Plot the approximate 95\% confidence region for the first two parameters # of the model plot(ellipse(fit), type = 'l') points(fit$coef[1], fit$coef[2]) } \keyword{dplot} \keyword{ts} ellipse/man/pairs.Rd0000644000176200001440000000206213223704402014064 0ustar liggesusers\name{pairs} \alias{pairs} \alias{pairs.default} \alias{pairs.formula} \title{ Scatterplot Matrix } \description{ A matrix of scatterplots is produced. } \usage{ pairs(x, ...) \method{pairs}{default}(x, ...) \method{pairs}{formula}(formula, data = NULL, ..., subset, na.action = stats::na.pass) } \arguments{ \item{x}{ An object containing the data to plot. } \item{formula, data, subset, na.action}{See \code{\link[graphics]{pairs}}}. \item{\dots}{ Other arguments to pass to the methods. } } \details{ The \pkg{ellipse} package defines a \code{\link{pairs.profile}} method for profile objects. Unfortunately, so does the \pkg{MASS} package. The \code{ellipse::pairs} generic is supplied to allow users to choose to use the version in this package. See the \code{\link{pairs.profile}} help page for more details. } \value{ Typically no useful value is produced; this generic function is called for the side effect of producing the display. } \seealso{ \code{\link{pairs.profile}} for the method from this package. } \examples{ example(pairs, "graphics") } ellipse/man/pairs.profile.Rd0000644000176200001440000000620713223713324015533 0ustar liggesusers\name{pairs.profile} \alias{pairs.profile} \title{ Profile pairs } \description{ This function produces pairwise plots of profile traces, profile sketches, and ellipse approximations to confidence intervals. } \usage{ \method{pairs}{profile}(x, labels = c(names(x), "Profile tau"), panel = lines, invert = TRUE, plot.tau = TRUE, plot.trace = TRUE, plot.sketch = TRUE, plot.ellipse = FALSE, level = 0.95, \dots) } \arguments{ \item{x}{ An object of class \code{profile}, generally the result of the \code{profile()} function. } \item{labels}{ The labels to use for each variable. These default to the variable names. } \item{panel}{ The function to use to draw the sketch in each panel. } \item{invert}{ Whether to swap the axes so things look better. } \item{plot.tau}{ Whether to do the profile tau (profile t) plots. } \item{plot.trace}{ Whether to do the profile trace plots. } \item{plot.sketch}{ Whether to do the profile sketch plots. } \item{plot.ellipse}{ Whether to do the ellipse approximations. } \item{level}{ The nominal confidence level for the profile sketches and ellipses. } \item{\dots}{ Other plotting parameters. }} \section{Side Effects}{ Produces a plot on the current device for each pair of variables in the profile object. } \details{ This function implements the plots used in Bates and Watts (1988) for nonlinear regression diagnostics. Unfortunately, the \pkg{MASS} package also defines a \code{\link[MASS:plot.profile]{pairs.profile}} method. The \code{ellipse::\link{pairs}} generic is supplied to allow users to choose to use the version in this package. If \code{x} is a profile object, then \code{ellipse::pairs(x)} is guaranteed to call the method from this package. If you'd rather use the \pkg{MASS} method, then two steps are needed: you need to be sure that \pkg{MASS} is loaded, then call \code{graphics::pairs(x)}. (If \pkg{MASS} is not loaded, you'll get the default method from the \pkg{graphics} package, which will trigger an error since it doesn't know about profile objects.) If both \pkg{ellipse} and \pkg{MASS} are loaded, then \code{pairs(x)} is slightly ambiguous: the method that is called depends on the ordering of \pkg{ellipse} and \pkg{graphics} (not \pkg{MASS}!) in the search list. In almost all cases \pkg{ellipse} will precede \pkg{graphics}, so the \pkg{ellipse} method will usually be the default. If \code{x} is any object other than a profile object, \code{ellipse::pairs(x)} will pass the call on to \code{graphics::pairs(x)}, and the standard method will be called. } \references{ Bates and Watts (1988), Nonlinear Regression Analysis \& its Applications. } \seealso{ \code{\link{profile}}, \code{\link{ellipse.profile}}, \code{\link{ellipse.nls}} } \examples{ # Plot everything for the Puromycin data data(Puromycin) Purboth <- nls(formula = rate ~ ((Vm + delV * (state == "treated")) * conc)/(K + conc), data = Puromycin, start = list(Vm = 160, delV = 40, K = 0.05)) Pur.prof <- profile(Purboth) ellipse::pairs(Pur.prof, plot.ellipse = TRUE) # Show the corresponding plot from MASS: if (requireNamespace("MASS")) graphics::pairs(Pur.prof) } \keyword{dplot} \keyword{regression} \keyword{nonlinear} ellipse/man/ellipse.profile.Rd0000644000176200001440000000404510443476553016063 0ustar liggesusers\name{ellipse.profile} \alias{ellipse.profile} \title{ Pairwise profile sketch } \description{ This routine approximates a contour of a function based on the profile of that function. } \usage{ \method{ellipse}{profile}(x, which = c(1, 2), level = 0.95, t = sqrt(qchisq(level, 2)), npoints = 100, \dots) } \arguments{ \item{x}{ An object of class \code{\link{profile}}, e.g. from \link[MASS:confint]{profile.glm} in the MASS package. } \item{which}{ Which pair of parameters to use. } \item{level}{ The \code{ellipse.profile} function defaults assume that the profiled function is -2 times the log likelihood of a regular model. With this assumption the \code{level} argument specifies the confidence level for an asymptotic confidence region. } \item{t}{ The square root of the value to be contoured. } \item{npoints}{ How many points to use in the ellipse. } \item{\dots}{ Extra arguments are not used. } } \value{ An \code{npoints} x \code{2} matrix with columns having the chosen parameter names, which approximates a contour of the function that was profiled. } \details{ This function uses the 4 point approximation to the contour as described in Appendix 6 of Bates and Watts (1988). It produces the exact contour for quadratic surfaces, and good approximations for mild deviations from quadratic. If the surface is multimodal, the algorithm is likely to produce nonsense. } \references{ Bates and Watts (1988) Nonlinear Regression Analysis \& its Applications } \seealso{ \code{\link{profile}}, \code{\link{ellipse.nls}} } \examples{ # Plot an approximate 95\% confidence region for the Puromycin # parameters Vm and K, and overlay the ellipsoidal region data(Puromycin) Purboth <- nls(formula = rate ~ ((Vm + delV * (state == "treated")) * conc)/(K + conc), data = Puromycin, start = list(Vm = 160, delV = 40, K = 0.05)) Pur.prof <- profile(Purboth) plot(ellipse(Pur.prof, which = c('Vm', 'K')), type = 'l') lines(ellipse(Purboth, which = c('Vm', 'K')), lty = 2) params <- Purboth$m$getPars() points(params['Vm'],params['K']) } \keyword{dplot} \keyword{models} ellipse/man/ellipse.profile.nls.Rd0000644000176200001440000000366213223536726016660 0ustar liggesusers\name{ellipse.profile.nls} \alias{ellipse.profile.nls} \title{ Pairwise profile sketch } \description{ This routine approximates a pairwise confidence region for a nonlinear regression model. } \usage{ \method{ellipse}{profile.nls}(x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, attr(x, "summary")$df[2])), npoints = 100, \dots) } \arguments{ \item{x}{ An object of class \code{\link{profile.nls}}. } \item{which}{ Which pair of parameters to use. } \item{level}{ The \code{level} argument specifies the confidence level for an asymptotic confidence region. } \item{t}{ The square root of the value to be contoured. } \item{npoints}{ How many points to use in the ellipse. } \item{\dots}{ Extra parameters which are not used (for compatibility with the generic). } } \value{ An \code{npoints} x \code{2} matrix with columns having the chosen parameter names, which approximates a contour of the function that was profiled. } \details{ This function uses the 4 point approximation to the contour as described in Appendix 6 of Bates and Watts (1988). It produces the exact contour for quadratic surfaces, and good approximations for mild deviations from quadratic. If the surface is multimodal, the algorithm is likely to produce nonsense. } \references{ Bates and Watts (1988) Nonlinear Regression Analysis \& its Applications } \seealso{ \code{\link{profile}}, \code{\link{ellipse.nls}} } \examples{ # Plot an approximate 95\% confidence region for the Puromycin # parameters Vm and K, and overlay the ellipsoidal region data(Puromycin) Purboth <- nls(formula = rate ~ ((Vm + delV * (state == "treated")) * conc)/(K + conc), data = Puromycin, start = list(Vm = 160, delV = 40, K = 0.05)) Pur.prof <- profile(Purboth) plot(ellipse(Pur.prof, which = c('Vm', 'K')), type = 'l') lines(ellipse(Purboth, which = c('Vm', 'K')), lty = 2) params <- Purboth$m$getPars() points(params['Vm'],params['K']) } \keyword{dplot} \keyword{models} ellipse/man/ellipse.nls.Rd0000644000176200001440000000266610443476553015226 0ustar liggesusers\name{ellipse.nls} \alias{ellipse.nls} \title{ Outline an approximate pairwise confidence region } \description{ This function produces the ellipsoidal outline of an approximate pairwise confidence region for a nonlinear model fit. } \usage{ \method{ellipse}{nls}(x, which = c(1, 2), level = 0.95, t = sqrt(2 * qf(level, 2, s$df[2])), \dots) } \arguments{ \item{x}{ The first argument should be an \code{nls} object, usually resulting from a call to \code{nls()}. } \item{which}{ Which selects the pair of parameters to be plotted. The default is the first two. } \item{level}{ The confidence level of the region. Default 95\%. } \item{t}{ The t statistic on the boundary of the ellipse. } \item{\dots}{ Other \code{ellipse.default} parameters may also be used. }} \value{ A matrix with columns \code{x} and \code{y} to outline the confidence region. } \details{ The summary function is used to obtain the approximate covariance matrix of the fitted parameters. } \seealso{ \code{\link{ellipse.default}}, \code{\link{ellipse.profile}} } \examples{ # Plot an approximate 95\% confidence region for the weight and displacement # parameters in the Michaelis Menten model data(Puromycin) fit <- nls(rate ~ Vm*conc/(K + conc), data = Puromycin, subset = state=="treated", start = list(K = 0.05, Vm = 200)) plot(ellipse(fit,which=c('Vm','K')), type = 'l') params <- fit$m$getPars() points(params['Vm'],params['K']) } \keyword{dplot} \keyword{nonlinear} ellipse/man/plotcorr.Rd0000644000176200001440000000547213223537131014625 0ustar liggesusers\name{plotcorr} \alias{plotcorr} \title{ Plot correlation matrix ellipses } \description{ This function plots a correlation matrix using ellipse-shaped glyphs for each entry. The ellipse represents a level curve of the density of a bivariate normal with the matching correlation. } \usage{ plotcorr(corr, outline = TRUE, col = 'grey', numbers = FALSE, type = c("full","lower","upper"), diag = (type == "full"), bty = "n", axes = FALSE, xlab = "", ylab = "", asp = 1, cex.lab = par("cex.lab"), cex = 0.75*par("cex"), mar = 0.1 + c(2,2,4,2), ...) } \arguments{ \item{corr}{ A matrix containing entries between \code{-1} and \code{1} to be plotted as correlations. } \item{outline}{ Whether the ellipses should be outlined in the default colour. } \item{col}{ Which colour(s) to use to fill the ellipses. } \item{numbers}{ Whether to plot numerical correlations in place of ellipses. If numbers is \code{TRUE}, then the correlations will be rounded to a single decimal place and placed on the plot. } \item{type}{Character. Plot \code{"full"} matrix or just \code{"upper"} or \code{"lower"} triangular part of it.} \item{diag}{Logical. Plot diagonal elements or not. } \item{bty, axes, xlab, ylab, asp, mar, cex.lab, ...}{Graphical parameters which will be passed to \code{\link{plot}} when plotting.} \item{cex}{Graphical parameter which will be passed to \code{\link{text}} when plotting.} } \details{ The ellipses being plotted will be tangent to a unit character square, with the shape chosen to match the required correlation. If \code{numbers = FALSE}, the \code{col} vector will be recycled to colour each of the ellipses; if \code{TRUE}, it will be ignored. } \references{ Murdoch, D.J. and Chow, E.D. (1996). A graphical display of large correlation matrices. The American Statistician 50, 178-180. } \seealso{ \code{\link{ellipse}} } \author{Duncan Murdoch; Gregor Gorjanc suggested the \code{type} and \code{diag} options.} \examples{ save.par <- par(ask = interactive()) # Plot the correlation matrix for the mtcars data full model fit data(mtcars) fit <- lm(mpg ~ ., mtcars) plotcorr(summary(fit, correlation = TRUE)$correlation) # Plot a second figure with numbers in place of the # ellipses plotcorr(summary(fit, correlation = TRUE)$correlation, numbers = TRUE) # Colour the ellipses to emphasize the differences. The color range # is based on RColorBrewer's Reds and Blues (suggested by Gregor Gorjanc) corr.mtcars <- cor(mtcars) ord <- order(corr.mtcars[1,]) xc <- corr.mtcars[ord, ord] colors <- c("#A50F15","#DE2D26","#FB6A4A","#FCAE91","#FEE5D9","white", "#EFF3FF","#BDD7E7","#6BAED6","#3182BD","#08519C") plotcorr(xc, col=colors[5*xc + 6]) plotcorr(xc, col=colors[5*xc + 6], type = "upper") plotcorr(xc, col=colors[5*xc + 6], type = "lower", diag = TRUE) par(save.par) } \keyword{hplot} ellipse/man/ellipse.glm.Rd0000644000176200001440000000367010443476553015205 0ustar liggesusers\name{ellipse.glm} \alias{ellipse.glm} \title{ Outline an approximate pairwise confidence region } \description{ This function produces the ellipsoidal outline of an approximate pairwise confidence region for a generalized linear model fit. } \usage{ \method{ellipse}{glm}(x, which = c(1, 2), level = 0.95, t, npoints = 100, dispersion, \dots) } \arguments{ \item{x}{ The first argument should be a \code{glm} object, usually resulting from a call to \code{glm()}. } \item{which}{ Which selects the pair of parameters to be plotted. The default is the first two. } \item{level}{ The confidence level of the region. Default 95\%. } \item{t}{ The t statistic on the boundary of the ellipse. For Binomial or Poisson families, \code{sqrt(qchisq(level, 2))} is used; for other distributions, \code{sqrt(2*qf(level, 2, df))} where \code{df} is the residual degrees of freedom. } \item{npoints}{ How many points to return in the ellipse. } \item{dispersion}{ The value of dispersion to use. If specified, it is treated as fixed, and the chi-square limits for \code{t} are used. If missing, it is taken from \code{summary(x)}. } \item{\dots}{ Other \code{ellipse.default} parameters may also be used. }} \value{ A matrix with columns named according to which to outline the confidence region. } \details{ The summary function is used to obtain the approximate covariance matrix of the fitted parameters, the dispersion estimate, and the degrees of freedom. } \seealso{ \code{\link{ellipse.default}} } \examples{ ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) glm.D93 <- glm(counts ~ outcome + treatment, family=poisson()) # Plot an approximate 95 \% confidence region for the two Outcome parameters plot(ellipse(glm.D93, which = c(2,3)), type = 'l') points(glm.D93$coefficients[2], glm.D93$coefficients[3]) } \keyword{dplot} \keyword{regression}