[Robast-commits] r378 - in branches/robast-0.7/pkg/RobAStBase: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 5 22:24:55 CEST 2009


Author: ruckdeschel
Date: 2009-10-05 22:24:54 +0200 (Mon, 05 Oct 2009)
New Revision: 378

Added:
   branches/robast-0.7/pkg/RobAStBase/R/qqplot.R
   branches/robast-0.7/pkg/RobAStBase/man/internals-qqplot.Rd
   branches/robast-0.7/pkg/RobAStBase/man/qqplot.Rd
Modified:
   branches/robast-0.7/pkg/RobAStBase/NAMESPACE
Log:
methods for qqplot filed into RobAstBase (and into distr, distrEx, distrMod)

Modified: branches/robast-0.7/pkg/RobAStBase/NAMESPACE
===================================================================
--- branches/robast-0.7/pkg/RobAStBase/NAMESPACE	2009-09-23 14:33:03 UTC (rev 377)
+++ branches/robast-0.7/pkg/RobAStBase/NAMESPACE	2009-10-05 20:24:54 UTC (rev 378)
@@ -56,7 +56,7 @@
               "Mroot","kStepEstimator.start")
 exportMethods("pICList","ICList", "ksteps", "uksteps", 
               "start", "startval", "ustartval")
-exportMethods("ddPlot")
+exportMethods("ddPlot", "qqplot")
 exportMethods("cutoff.quantile", "cutoff.quantile<-")
 export("oneStepEstimator", "kStepEstimator")
 export("ContNeighborhood", "TotalVarNeighborhood") 

Added: branches/robast-0.7/pkg/RobAStBase/R/qqplot.R
===================================================================
--- branches/robast-0.7/pkg/RobAStBase/R/qqplot.R	                        (rev 0)
+++ branches/robast-0.7/pkg/RobAStBase/R/qqplot.R	2009-10-05 20:24:54 UTC (rev 378)
@@ -0,0 +1,116 @@
+################################################################
+# QQ - Plot functions in package RobAStBase
+################################################################
+
+
+.makeLenAndOrder <- distr:::.makeLenAndOrder
+
+.fadeColor <- function(col,x, bg = "white"){
+ ind <- seq(along=x)
+ col <- .makeLenAndOrder(col,ind)
+ colx <- t(sapply(ind,function(i) colorRamp(c(bg,col[i]))(x[i])))
+ colv2col <- function(colvec)
+   rgb(red = colvec[1], green = colvec[2], blue = colvec[3], maxColorValue = 255)
+ apply(colx,1,function(x) colv2col(x))
+}
+
+## into RobAStBase
+setMethod("qqplot", signature(x = "ANY",
+                              y = "RobModel"), function(x, y,
+                              n = length(x), withIdLine = TRUE, withConf = TRUE,
+    withConf.pw  = withConf,  withConf.sim = withConf,
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ..., distance = NormType()){
+
+    mc <- match.call(call = sys.call(sys.parent(1)))
+    if(missing(xlab)) mc$xlab <- as.character(deparse(mc$x))
+    if(missing(ylab)) mc$ylab <- as.character(deparse(mc$y))
+    mcl <- as.list(mc)[-1]
+
+    mcl$y <- y at center
+
+    xD <- fct(distance)(x)
+    x.cex <- 3/(1+log(1+xD))
+    mcl$cex.pch <- x.cex
+
+    return(do.call(getMethod("qqplot", signature(x="ANY", y="ProbFamily")),
+            args=mcl))
+    })
+
+
+## into RobAStBase
+setMethod("qqplot", signature(x = "ANY",
+                              y = "InfRobModel"), function(x, y,
+                              n = length(x), withIdLine = TRUE, withConf = TRUE,
+             withConf.pw  = withConf,   ### shall pointwise confidence lines be plotted
+             withConf.sim = withConf,   ### shall simultaneous confidence lines be plotted
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ...){
+
+    mc <- match.call(call = sys.call(sys.parent(1)))
+    if(missing(xlab)) mc$xlab <- as.character(deparse(mc$x))
+    if(missing(ylab)) mc$ylab <- as.character(deparse(mc$y))
+    mcl <- as.list(mc)[-1]
+    if(is.null(mcl$distance)) distance <- NormType()
+
+    mcl$y <- y at center
+
+    L2D <- L2deriv(y at center)
+    FI <- PosSemDefSymmMatrix(FisherInfo(y at center))
+    L2Dx <- sapply(x, function(z) evalRandVar(L2D,z)[[1]])
+    scx <-  solve(sqrt(FI),matrix(L2Dx,ncol=length(x)))
+    xD <- fct(distance)(scx)
+    x.cex <- 3/(1+log(1+xD))
+    mcl$cex.pch <- x.cex
+
+    return(do.call(getMethod("qqplot", signature(x="ANY", y="ProbFamily")),
+            args=mcl))
+    })
+
+## into RobAStBase
+setMethod("qqplot", signature(x = "ANY",
+                              y = "kStepEstimate"), function(x, y,
+                              n = length(x), withIdLine = TRUE, withConf = TRUE,
+    withConf.pw  = withConf,  withConf.sim = withConf,
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ...,
+    exp.cex2.lbl = -.15,
+    exp.cex2.pch = -.35,
+    exp.fadcol.lbl = 1.85,
+    exp.fadcol.pch = 1.85,
+    bg = "white"
+    ){
+
+    mc <- match.call(call = sys.call(sys.parent(1)))
+    if(missing(xlab)) mc$xlab <- as.character(deparse(mc$x))
+    if(missing(ylab)) mc$ylab <- as.character(deparse(mc$y))
+    mcl <- as.list(mc)[-1]
+
+    IC <- pIC(y)
+    if(!is(IC,"IC"))
+       stop("IC of the kStepEstimator needs to be of class 'IC'")
+
+    L2Fam <- eval(IC at CallL2Fam)
+
+    mcl$y <- L2Fam
+
+    if(is(IC,"HampIC")){
+      w.fct <- weight(weight(IC))
+      wx <- sapply(x,w.fct)
+      mcl$order.traf <- function(x) 1/w.fct(x)
+
+      cex.lbl <- if(is.null(mcl$cex.lbl))  par("cex")  else eval(mcl$cex.lbl)
+      cex.pch <- if(is.null(mcl$cex.pch))  par("cex")  else eval(mcl$cex.pch)
+      mcl$cex.lbl <- cex.lbl*wx^exp.cex2.lbl
+      mcl$cex.pch <- cex.pch*wx^exp.cex2.pch
+
+      col.lbl <- if(is.null(mcl$col.lbl))  par("col")  else eval(mcl$col.lbl)
+      col.pch <- if(is.null(mcl$col.pch))  par("col")  else eval(mcl$col.pch)
+      mcl$col.lbl <- .fadeColor(col.lbl,wx^exp.fadcol.lbl, bg = bg)
+      mcl$col.pch <- .fadeColor(col.pch,wx^exp.fadcol.pch, bg = bg)
+    }
+
+    print(mcl)
+    return(do.call(getMethod("qqplot", signature(x="ANY", y="ProbFamily")),
+            args=mcl))
+    })

Added: branches/robast-0.7/pkg/RobAStBase/man/internals-qqplot.Rd
===================================================================
--- branches/robast-0.7/pkg/RobAStBase/man/internals-qqplot.Rd	                        (rev 0)
+++ branches/robast-0.7/pkg/RobAStBase/man/internals-qqplot.Rd	2009-10-05 20:24:54 UTC (rev 378)
@@ -0,0 +1,44 @@
+\name{internals_for_qqplot}
+\alias{internals_for_qqplot}
+\alias{.fadeColor}
+
+
+\title{Internal functions for qqplot of package RobAStBase}
+
+\description{
+These functions are used internally by qqplot of package RobAStBase.}
+
+\usage{
+.fadeColor(col,x, bg = "white")
+}
+
+
+\arguments{
+\item{col}{(a vector of) color(s)}
+\item{x}{a (numeric) vector of fading weights}
+\item{bg}{a color (of length 1): the background color against which to fade}
+}
+
+\details{
+\code{.fadecolor} uses function \code{colorRamp} to interpolate between
+color \code{col} and \code{bg}, at coordinate given by \code{x}.
+}
+
+
+\value{
+\item{.fadecolor}{a vector of (rgb) colors of same length as \code{x} containing
+the corresponding colors \code{col} faded towards \code{white} according
+to \code{colorRamp}.}
+}
+
+\author{
+  Peter Ruckdeschel \email{Peter.Ruckdeschel at itwm.fraunhofer.de},
+}
+
+\seealso{\code{\link[stats]{ks.test}}, \code{\link[distr]{qqplot}}
+,\code{\link[distr:internals-qqplot]{internals_qqplot}}
+,\code{\link[distrMod:internals-qqplot]{internals_qqplot}}
+, \code{\link[distrMod]{qqplot}}, \code{\link[RobAStBase]{qqplot}}
+}
+\keyword{internal}
+\concept{utilities}

Added: branches/robast-0.7/pkg/RobAStBase/man/qqplot.Rd
===================================================================
--- branches/robast-0.7/pkg/RobAStBase/man/qqplot.Rd	                        (rev 0)
+++ branches/robast-0.7/pkg/RobAStBase/man/qqplot.Rd	2009-10-05 20:24:54 UTC (rev 378)
@@ -0,0 +1,115 @@
+\name{qqplot}
+\docType{methods}
+\title{Methods for Function qqplot in Package `RobAStBase'}
+\usage{
+qqplot(x, y, ...)
+\S4method{qqplot}{ANY,RobModel}(x, y,
+   n = length(x), withIdLine = TRUE, withConf = TRUE,
+   withConf.pw  = withConf,  withConf.sim = withConf,
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ..., distance = NormType())
+\S4method{qqplot}{ANY,InfRobModel}(x, y,
+   n = length(x), withIdLine = TRUE, withConf = TRUE,
+   withConf.pw  = withConf,  withConf.sim = withConf,
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ...)
+\S4method{qqplot}{ANY,kStepEstimate}(x, y,
+   n = length(x), withIdLine = TRUE, withConf = TRUE,
+   withConf.pw  = withConf,  withConf.sim = withConf,
+    plot.it = TRUE, xlab = deparse(substitute(x)),
+    ylab = deparse(substitute(y)), ...,
+    exp.cex2.lbl = -.15,
+    exp.cex2.pch = -.35,
+    exp.fadcol.lbl = 1.85,
+    exp.fadcol.pch = 1.85,
+    bg = "white")
+   }
+\alias{qqplot}
+\alias{qqplot-methods}
+\alias{qqplot,ANY,RobModel-method}
+\alias{qqplot,ANY,InfRobModel-method}
+\alias{qqplot,ANY,kStepEstimate-method}
+
+\arguments{
+\item{x}{data to be checked for compatibility with distribution/model \code{y}.}
+\item{y}{object of class \code{"RobModel"}, of class \code{"InfRobModel"} or of
+class \code{"kStepEstimate"}.}
+\item{n}{numeric; number of quantiles at which to do the comparison.}
+\item{withIdLine}{logical; shall line \code{y = x} be plotted in?}
+\item{withConf}{logical; shall confidence lines be plotted?}
+\item{withConf.pw}{logical; shall pointwise confidence lines be plotted?}
+\item{withConf.sim}{logical; shall simultaneous confidence lines be plotted?}
+\item{plot.it}{logical; shall be plotted at all (inherited from \code{\link[stats:qqnorm]{qqplot}})?}
+\item{xlab}{x-label}
+\item{ylab}{y-label}
+\item{\dots}{further parameters for method \code{qqplot} with signature
+\code{ANY,ProbFamily} or with function \code{plot}}
+\item{distance}{a function mapping observations \code{x} to the positive reals;
+used to determine the size of the plotted points (the larger \code{distance(x)},
+the smaller the points are plotted.}
+\item{exp.cex2.lbl}{for objects \code{kStepEstimate} based on a [p]IC of class \code{HampIC}:
+exponent for the weights of this [p]IC used to magnify the labels.}
+\item{exp.cex2.pch}{for objects \code{kStepEstimate} based on a [p]IC of class \code{HampIC}:
+exponent for the weights of this [p]IC used to magnify the symbols.}
+\item{exp.fadcol.lbl}{for objects \code{kStepEstimate} based on a [p]IC of class \code{HampIC}:
+exponent for the weights of this [p]IC used to find out-fading colors.}
+\item{exp.fadcol.pch}{for objects \code{kStepEstimate} based on a [p]IC of class \code{HampIC}:
+exponent for the weights of this [p]IC used to find out-fading colors.}
+\item{bg}{background color to fade against}
+}
+\description{
+  We generalize function \code{\link[stats:qqnorm]{qqplot}} from package \pkg{stats} to
+  be applicable to distribution and probability model objects. In this context,
+  \code{qqplot} produces a QQ plot of data (argument \code{x}) against
+   a (model) distribution. For arguments \code{y} of class \code{RobModel},
+   points at a high \dQuote{distance} to the model
+   are plotted smaller. For arguments \code{y} of class \code{kStepEstimate},
+   points at with low weight in the [p]IC are plotted bigger and their
+   color gets faded out slowly.
+   Graphical parameters may be given as arguments to \code{qqplot}.
+}
+\value{
+    As for function \code{\link[stats:qqnorm]{qqplot}} from package \pkg{stats}: a
+  list with components
+\item{x}{The x coordinates of the points that were/would be plotted}
+  \item{y}{The corresponding quantiles of the second distribution,
+           \emph{including \code{\link{NA}}s}.}
+}
+\references{
+  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
+  \emph{The New S Language}.
+  Wadsworth & Brooks/Cole.
+}
+\author{
+  Peter Ruckdeschel \email{Peter.Ruckdeschel at itwm.fraunhofer.de}
+}
+\seealso{
+  \code{\link[stats:qqnorm]{qqplot}} from package \pkg{stats} -- the standard QQ plot
+  function,  \code{\link[distr]{qqplot}} from package \pkg{distr} for
+  comparisons of distributions, and
+ \code{\link[distrMod]{qqplot}} from package \pkg{distrMod} (which
+  is called intermediately by this method), as well as
+  \code{\link{qqbounds}}, used by \code{qqplot} to produce confidence
+   intervals.
+}
+\details{
+\describe{
+\item{qqplot}{\code{signature(x = "ANY", y = "RobModel")}:
+produces a QQ plot of a dataset \code{x} against the theoretical
+quantiles of distribution of robust model \code{y}.}
+\item{qqplot}{\code{signature(x = "ANY", y = "InfRobModel")}:
+produces a QQ plot of a dataset \code{x} against the theoretical
+quantiles of distribution of infinitesimally robust model \code{y}.}
+\item{qqplot}{\code{signature(x = "ANY", y = "kStepEstimate")}:
+produces a QQ plot of a dataset \code{x} against the theoretical
+quantiles of the model distribution of model at which
+the corresponding \code{kStepEstimate} \code{y} had been calibrated at.}
+}
+}
+
+\examples{
+qqplot(r(Norm(15,sqrt(30)))(40), Chisq(df=15))
+qqplot(r(Norm(15,sqrt(30)))(40), NormLocationFamily())
+}
+\keyword{hplot}
+\keyword{distribution}



More information about the Robast-commits mailing list