RobAStBase (version 1.2.1)

comparePlot-methods: Compare - Plots

Description

Plots 2-4 influence curves to the same model.

Usage

comparePlot(obj1, obj2, ... )
# S4 method for IC,IC
comparePlot(obj1, obj2, obj3 = NULL, obj4 = NULL, data = NULL,
                 ..., withSweave = getdistrOption("withSweave"),
                 forceSameModel = FALSE, main = FALSE, inner = TRUE,
                 sub = FALSE, col = par("col"), lwd = par("lwd"), lty,
                 col.inner = par("col.main"), cex.inner = 0.8,
                 bmar = par("mar")[1], tmar = par("mar")[3],
                 with.automatic.grid = TRUE, with.legend = FALSE,
                 legend = NULL, legend.bg = "white",
                 legend.location = "bottomright", legend.cex = 0.8,
                 withMBR = FALSE, MBRB = NA, MBR.fac = 2, col.MBR = par("col"),
                 lty.MBR = "dashed", lwd.MBR = 0.8, x.vec = NULL,
                 scaleX = FALSE, scaleX.fct, scaleX.inv, scaleY = FALSE,
                 scaleY.fct = pnorm, scaleY.inv = qnorm, scaleN = 9,
                 x.ticks = NULL, y.ticks = NULL, mfColRow = TRUE,
                 to.draw.arg = NULL,
                 cex.pts = 1, cex.pts.fun = NULL, col.pts = par("col"),
                 pch.pts = 19, cex.npts = 1, cex.npts.fun = NULL,
                 col.npts = par("col"), pch.npts = 20, jitter.fac = 1,
                 with.lab = FALSE, cex.lbs = 1, adj.lbs = c(0, 0),
                 col.lbs = col.pts, lab.pts = NULL, lab.font = NULL,
                 alpha.trsp = NA, which.lbs = NULL, which.Order = NULL,
                 which.nonlbs = NULL, attr.pre = FALSE, return.Order = FALSE,
                 withSubst = TRUE)

Value

An S3 object of class c("plotInfo","DiagnInfo"), i.e., a list containing the information needed to produce the respective plot, which at a later stage could be used by different graphic engines (like, e.g. ggplot) to produce the plot in a different framework. A more detailed description will follow in a subsequent version.

Arguments

obj1

object of class "InfluenceCurve"

obj2

object of class "InfluenceCurve" to be compared with obj1

obj3

optional: object of class "InfluenceCurve" to be compared with obj1

obj4

optional: object of class "InfluenceCurve" to be compared with obj1

data

optional data argument --- for plotting observations into the plot;

withSweave

logical: if TRUE (for working with Sweave) no extra device is opened

forceSameModel

logical; shall we check / enforce that the model of the ICs obj1, obj2, obj3, and obj4 be the same?

main

logical: is a main title to be used? or
just as argument main in plot.default.

col

color[s] of ICs in arguments obj1 [,...,obj4].

lwd

linewidth[s] of ICs in arguments obj1 [,...,obj4].

lty

line-type[s] of ICs in arguments obj1 [,...,obj4].

inner

logical: do panels have their own titles? or
character vector of / cast to length 'number of plotted dimensions'; if argument to.draw.arg is used, this refers to a vector of length length(to.draw.arg), the actually plotted dimensions. For further information, see also description of argument main in plot.default.

sub

logical: is a sub-title to be used? or
just as argument sub in plot.default.

tmar

top margin -- useful for non-standard main title sizes

bmar

bottom margin -- useful for non-standard sub title sizes

cex.inner

magnification to be used for inner titles relative to the current setting of cex; as in par

col.inner

character or integer code; color for the inner title

with.automatic.grid

logical; should a grid be plotted alongside with the ticks of the axes, automatically? If TRUE a respective call to grid in argument panel.first is ignored.

with.legend

logical; shall a legend be plotted?

legend

either NULL or a list of length (number of plotted panels) of items which can be used as argument legend in command legend.

legend.location

a valid argument x for legend --- the place where to put the legend on the last issued plot

legend.bg

background color for the legend

legend.cex

magnification factor for the legend

withMBR

logical; shall horizontal lines with min and max of MBRE be plotted for comparison?

MBRB

matrix (or NA); coerced by usual recycling rules to a matrix with as many rows as plotted panels and with first column the lower bounds and the second column the upper bounds for the respective coordinates (ideally given by the MBR-IC).

MBR.fac

positive factor; scales the bounds given by argument MBRB

col.MBR

color for the MBR lines; as usual col-argument;

lty.MBR

line type for the MBR lines; as usual lty-argument;

lwd.MBR

line width for the MBR lines; as usual lwd-argument;

x.vec

a numeric vector of grid points to evaluate the influence curve; by default, x.vec is NULL; then the grid is produced automatically according to the distribution of the IC. x.vec can be useful for usage with a rescaling of the x-axis to avoid that the evaluation points be selected too unevenly (i.e. on an equally spaced grid in the original scale, but then, after rescaling non-equally). The grid has to be specified in original scale; i.e.; when used with rescaling, it should be chosen non-equally spaced.

scaleX

logical; shall X-axis be rescaled (by default according to the cdf of the underlying distribution)?

scaleY

logical; shall Y-axis be rescaled (by default according to a probit scale)?

scaleX.fct

an isotone, vectorized function mapping the domain of the IC to [0,1]; if scaleX is TRUE and scaleX.fct is missing, the cdf of the underlying observation distribution.

scaleX.inv

the inverse function to scale.fct, i.e., an isotone, vectorized function mapping [0,1] to the domain of the IC such that for any x in the domain,
scaleX.inv(scaleX.fct(x))==x; if scaleX is TRUE and scaleX.inv is missing, the quantile function of the underlying observation distribution.

scaleY.fct

an isotone, vectorized function mapping for each coordinate the range of the respective coordinate of the IC to [0,1]; defaulting to the cdf of \({\cal N}(0,1)\); can also be a list of functions with one list element for each of the panels to be plot.

scaleY.inv

an isotone, vectorized function mapping for each coordinate the range [0,1] into the range of the respective coordinate of the IC; defaulting to the quantile function of \({\cal N}(0,1)\); can also be a list of functions with one list element for each of the panels to be plot.

scaleN

integer; defaults to 9; on rescaled axes, number of x and y ticks if drawn automatically;

x.ticks

numeric; defaults to NULL; (then ticks are chosen automatically); if non-NULL, user-given x-ticks (on original scale);

y.ticks

numeric; defaults to NULL; (then ticks are chosen automatically); if non-NULL, user-given y-ticks (on original scale); can be a list with one (numeric or NULL) item per panel

mfColRow

shall default partition in panels be used --- defaults to TRUE

to.draw.arg

Either NULL (default; everything is plotted) or a vector of either integers (the indices of the subplots to be drawn) or characters --- the names of the subplots to be drawn: these names are to be chosen either among the row names of the trafo matrix rownames(trafo(eval(obj1@CallL2Fam)@param)) or if the last expression is NULL a vector "dim<dimnr>", dimnr running through the number of rows of the trafo matrix.

withSubst

logical; if TRUE (default) pattern substitution for titles and lables is used; otherwise no substitution is used.

col.pts

color of the points of the data argument plotted; can be a vector or a matrix. More specifically, if argument attr.pre is TRUE, it is recycled to fill a matrix of dimension n by nIC (n the number of observations prior to any selection and nIC the number of ICs plotted) where filling is done in order column first. The columns are used for possibly different colors for the different ICs from arguments obj1, obj2, and, possibly obj3 and obj4. The selection done via which.lbs and which.Order is then done afterwards and on this matrix; in this case, argument col.npts is ignored. If attr.pre is FALSE, col.pts is recycled to fill a matrix of dimension n.s by nIC where n.s is the number of observations selected for labelling and refers to the index ordering after the selection. Then argument col.npts deteremines the colors of the shown but non-labelled observations as given in argument which.nonlbs.

pch.pts

symbol of the points of the data argument plotted (may be a vector of length nIC or a matrix, see col.pts).

cex.pts

size of the points of the data argument plotted (may be a vector of length nIC or a matrix, see col.pts).

cex.pts.fun

rescaling function for the size of the points to be plotted; either NULL (default), then log(1+abs(x)) is used for each of the rescalings, or a function which is then used for each of the rescalings, or a list of functions; if it is a function or a list of functions, if necessary it is recylced to length nIC * dim where dim is the number of dimensions of the pICs to be plotted; in the index of this list, nIC is incremented first; then dim.

col.npts

color of the non-labelled points of the data argument plotted; (may be a vector of length nIC the number of plotted pICs, i.e., one value for each pIC in arguments obj1, obj2, and, if available, obj3 and obj4, or it can be a matrix nnlb <- sum(which.nonlbs) by nIC, nnlb the number of non-labelled observations.

pch.npts

symbol of the non-labelled points of the data argument plotted (may be a vector of length nIC or a matrix, see col.npts).

cex.npts

size of the non-labelled points of the data argument plotted (may be a vector of length nIC or a matrix, see col.npts).

cex.npts.fun

rescaling function for the size of the non-labelled points to be plotted; either NULL (default), then log(1+abs(x)) is used for each of the rescalings, or a function which is then used for each of the rescalings, or a list of functions; if it is a function or a list of functions, if necessary it is recylced to length nIC * dim where dim is the number of dimensions of the pICs to be plotted; in the index of this list, nIC is incremented first; then dim.

lab.pts

character or NULL; labels to be plotted to the observations; can be a vector of length n, n the number of all observations prior to any selection with which.lbs, which.Order; if lab.pts is NULL, observation indices are used.

with.lab

logical; shall labels be plotted to the observations? (May be a vector of length nIC, see col.pts -- but not a matrix).

cex.lbs

size of the labels; can be vectorized to an array of dim nlbs x nIC x npnl where npnl is the number of plotted panels and nlbs the number of plotted labels; if it is a vector, it is recylced in order labels then plotted ICs then panels.

col.lbs

color of the labels; can be vectorized to a matrix of dim nlbs x nIC as col.pts.

adj.lbs

adjustment of the labels; can be vectorized to an array of dim 2 x nIC x npnl, npnl the number of plotted panels; if it is a vector, it is recycled in order (x,y)-coords then ICs then panels.

lab.font

font to be used for labels (may be a vector of length nIC, see with.lab).

alpha.trsp

alpha transparency to be added ex post to colors col.pch and col.lbl; if one-dim and NA all colors are left unchanged. Otherwise, with usual recycling rules alpha.trsp gets shorted/prolongated to length the data-symbols to be plotted. Coordinates of this vector alpha.trsp with NA are left unchanged, while for the remaining ones, the alpha channel in rgb space is set to the respective coordinate value of alpha.trsp. The non-NA entries must be integers in [0,255] (0 invisible, 255 opaque).

jitter.fac

jittering factor used in case of a DiscreteDistribution for plotting points of the data argument in a jittered fashion (may be a vector of length 2, see with.lab).

attr.pre

logical; do graphical attributes for plotted data refer to indices prior (TRUE) or posterior to selection via arguments which.lbs, which.Order, which.nonlbs (FALSE)?

which.lbs

either an integer vector with the indices of the observations to be plotted into graph or NULL --- then no observation is excluded.

which.Order

for each of the given ICs, we order the observations (descending) according to the norm given by the corresponding normtype(object); then which.Order either is an integer vector with the indices of the ordered observations (remaining after a possible reduction by argument which.lbs) to be plotted into graph or NULL --- then no (further) observation is excluded.

which.nonlbs

indices of the observations which should be plotted but not labelled; either an integer vector with the indices of the observations to be plotted into graph or NULL --- then all non-labelled observations are plotted.

return.Order

logical; if TRUE, a list of length maximally four with order vectors is returned --- one for the ordering w.r.t. each of the given ICs; more specifically, the order of the (remaining) observations given by their original index is returned (remaining means: after a possible reduction by argument which.lbs, and ordering is according to the norm given by normtype(object)); othervise we return invisible() as usual.

...

further arguments to be passed to plot

Author

Peter Ruckdeschel peter.ruckdeschel@uni-oldenburg.de

Details

Any parameters of plot.default may be passed on to this particular plot method.

For main-, inner, and subtitles given as arguments main, inner, and sub, top and bottom margins are enlarged to 5 resp. 6 by default but may also be specified by tmar / bmar arguments. If main / inner / sub are logical then if the respective argument is FALSE nothing is done/plotted, but if it is TRUE, we use a default main title taking up the calling arguments in case of main, default inner titles taking up the class and (named) parameter slots of arguments in case of inner, and a "generated on <data>"-tag in case of sub. Of course, if main / inner / sub are character, this is used for the title; in case of inner it is then checked whether it has correct length. If argument withSubst is TRUE, in all title and axis lable arguments, the following patterns are substituted:

"%C1","%C2",["%C3",]["%C4"]

class of argument obj<i>, i=1,..4

"%A1","%A2",["%A3",]["%A4"]

deparsed argument obj<i>, i=1,..4

"%D"

time/date-string when the plot was generated

If argument ... contains argument ylim, this may either be as in plot.default (i.e. a vector of length 2) or a vector of length 2*(number of plotted dimensions); in the case of longer length, these are the values for ylim for the plotted dimensions of the IC, one pair for each dimension.

In addition, argument ... may contain arguments panel.first, panel.last, i.e., hook expressions to be evaluated at the very beginning and at the very end of each panel (within the then valid coordinates). To be able to use these hooks for each panel individually, they may also be lists of expressions (of the same length as the number of panels and run through in the same order as the panels).

References

Kohl, M. (2005) Numerical Contributions to the Asymptotic Theory of Robustness. Bayreuth: Dissertation.

See Also

L2ParamFamily-class, IC-class, plot

Examples

Run this code
if(require(ROptEst)){

N0 <- NormLocationScaleFamily(mean=0, sd=1) 
N0.Rob1 <- InfRobModel(center = N0, neighbor = ContNeighborhood(radius = 0.5))

IC1 <- optIC(model = N0, risk = asCov())
IC2 <- optIC(model = N0.Rob1, risk = asMSE())

comparePlot(IC1,IC2)

set.seed(12); data <- r(N0)(20)
comparePlot(IC1, IC2, data=data, with.lab = TRUE,
            which.lbs = c(1:4,15:20),
            which.Order = 1:6,
            return.Order = TRUE)


## don't test to reduce check time on CRAN
# \donttest{
## selection of subpanels for plotting
par(mfrow=c(1,1))
comparePlot(IC1, IC2 ,mfColRow = FALSE, to.draw.arg=c("mean"),
            panel.first= grid(),ylim=c(-4,4),xlim=c(-6,6))
## matrix-valued ylim
comparePlot(IC1, IC2, panel.first= grid(),ylim=c(-4,4,0,4),xlim=c(-6,6))

x <- c(data,-12,10)
comparePlot(IC1, IC2, data=x, which.Order=10,
            panel.first= grid(), ylim=c(-4,4,0,4), xlim=c(-6,6))

Y <- Chisq(df=1)* DiscreteDistribution(c(-1,1))
comparePlot(IC1, IC2, data=x, which.Order=10,
            scaleX = TRUE, scaleX.fct=pnorm, scaleX.inv=qnorm,
            scaleY = TRUE, scaleY.fct=p(Y), scaleY.inv=q.l(Y),
            panel.first= grid(), ylim=c(-4,4,0,4), xlim=c(-6,6))
comparePlot(IC1, IC2, data=x, which.Order=10,
            scaleX = TRUE, scaleX.fct=pnorm, scaleX.inv=qnorm,
            scaleY = TRUE, scaleY.fct=p(Y), scaleY.inv=q.l(Y),
            x.ticks = c(-Inf, -10, -1,0,1,10,Inf),
            y.ticks = c(-Inf, -5, -1,0,1,5,Inf),
            panel.first= grid(), ylim=c(-4,4,0,4), xlim=c(-6,6))

## with use of trafo-matrix:
G <- GammaFamily(scale = 1, shape = 2)
## explicitely transforming to
## MASS parametrization:
mtrafo <- function(x){
     nms0 <- names(c(main(param(G)),nuisance(param(G))))
     nms <- c("shape","rate")
     fval0 <- c(x[2], 1/x[1])
     names(fval0) <- nms
     mat0 <- matrix( c(0, -1/x[1]^2, 1, 0), nrow = 2, ncol = 2,
                     dimnames = list(nms,nms0))                          
     list(fval = fval0, mat = mat0)}
G2 <- G
trafo(G2) <- mtrafo
G2
G2.Rob1 <- InfRobModel(center = G2, neighbor = ContNeighborhood(radius = 0.5))
system.time(IC1 <- optIC(model = G2, risk = asCov()))
system.time(IC2 <- optIC(model = G2.Rob1, risk = asMSE()))
system.time(IC2.i <- optIC(model = G2.Rob1, risk = asMSE(normtype=InfoNorm())))
system.time(IC2.s <- optIC(model = G2.Rob1, risk = asMSE(normtype=SelfNorm())))

comparePlot(IC1,IC2, IC2.i, IC2.s)
# }

}

Run the code above in your browser using DataLab