David, Thanks for taking the time to look into it. I tried your method and it seems the "type" value wasn't really passed into my.boxplot.stats. If I manually changed type value in my.boxplot.stats, I did see a difference. Attached some data below. Thanks.
==================================================================== structure(list(ID = c(102, 103, 109, 112, 116, 120, 133, 137, 143, 148, 151, 154, 158, 164, 165, 170, 171, 172, 184, 188, 195, 196, 201, 205), CL = c(0.0278, 0.0265, 0.0198, 0.0112, 0.0297, 0.0251, 0.0282, 0.0219, 0.0372, 0.0244, 0.023, 0.0444, 0.0432, 0.0279, 0.0482, 0.051, 0.062, 0.0318, 0.0437, 0.0298, 0.0547, 0.135, 0.0417, 0.0286), V1 = c(2.99, 3.54, 3.06, 2.15, 2.85, 3.27, 2.71, 3.41, 2.87, 3.17, 2.83, 2.68, 2.51, 2.58, 2.15, 2.45, 2.43, 2.96, 2.41, 2.45, 2.12, 1.67, 2.23, 2.13), Q = c(0.185, 0.233, 0.225, 0.528, 0.194, 0.189, 0.0764, 0.109, 0.168, 0.219, 0.149, 0.144, 0.132, 0.107, 0.0389, 0.0954, 0.171, 0.138, 0.0863, 0.0512, 0.104, 0.088, 0.0863, 0.195), V2 = c(5.1, 4.69, 4.75, 3.45, 5.01, 5.06, 7.23, 6.34, 5.41, 4.9, 5.65, 5.72, 5.99, 6.48, 9.43, 6.76, 5.45, 5.9, 7.16, 8.69, 6.69, 7.11, 7.16, 5.29), ETA1 = c(0.192, 0.144, -0.146, -0.718, 0.257, 0.0902, -0.0989, -0.352, 0.179, -0.243, -0.301, 0.355, 0.111, -0.326, 0.221, 0.278, 0.473, -0.195, -0.182, -0.563, 0.0437, 0.947, -0.228, -0.606), ETA2 = c(-0.0444, 0.126, -0.0184, -0.374, -0.0892, 0.0467, -0.0213, 0.208, 0.0333, 0.133, 0.0205, -0.0338, -0.0148, 0.011, -0.168, -0.0406, -0.0475, 0.149, 0.0599, 0.079, -0.0644, -0.303, -0.018, -0.0613), ETA3 = c(-0.103, 0.127, 0.0931, 0.947, -0.0521, -0.0808, -0.701, -0.343, 0.0844, 0.353, -0.036, -0.0667, 0.0493, -0.165, -1.17, -0.277, 0.304, 0.0952, -0.0918, -0.614, 0.0941, -0.0717, -0.0921, 0.725), ETA4 = c(0.0378, -0.0465, -0.0347, -0.353, 0.0188, 0.0302, 0.26, 0.129, -0.0308, -0.13, 0.0135, 0.0248, -0.0184, 0.0606, 0.436, 0.102, -0.113, -0.0343, 0.0338, 0.227, -0.0339, 0.0269, 0.0334, -0.27), DOSE = c(60, 60, 60, 60, 60, 60, 40, 40, 40, 40, 40, 40, 30, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 20), FLAG = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("ID", "CL", "V1", "Q", "V2", "ETA1", "ETA2", "ETA3", "ETA4", "DOSE", "FLAG"), row.names = c(1L, 7L, 12L, 15L, 21L, 27L, 33L, 39L, 45L, 48L, 54L, 60L, 65L, 67L, 71L, 76L, 81L, 86L, 91L, 93L, 98L, 103L, 108L, 112L), class = "data.frame") On Fri, May 7, 2010 at 7:51 PM, David Winsemius <dwinsem...@comcast.net>wrote: > > On May 7, 2010, at 5:05 PM, David Winsemius wrote: > > >> On May 7, 2010, at 4:18 PM, Jun Shen wrote: >> >> David, >>> >>> my.boxplot.stats is modified from boxplot.stats (package grDevices) as >>> follows. x is the original argument, I guess it's the data object for >>> processing. I only added "type". Thanks. >>> >> >> Right, but you should be assigning stats=my.boxplot.stats, not >> stats=myboxplot.stats(type=6). The functions then pick up their arguments >> from their environment. >> >> > Here's a worked example using modifications of a panel.bwplot help page > call: > > (bwplot(voice.part ~ height, data = singer, stats=my.boxplot.stats, > xlab = "Height (inches)", > panel = function(...) { > panel.grid(v = -1, h = 0) > panel.bwplot(..., coef=3, type=1) > }, > par.settings = list(plot.symbol = list(pch = 4)))) > > One of the problems I faced was that I really could not see much difference > between the results of changing the "type" for quantile. You provided no > dataset for which you thought the difference made a .... difference. So I > changed the coef argument to create an effect I could see. > > > > (And learn to send plain text. It is very easy to do so in gmail.) >> >> -- >> David. >> >> >>> Jun >>> >>> ============================================================= >>> > boxplot.stats >>> >>> function (x, coef = 1.5, do.conf = TRUE, do.out = TRUE) >>> { >>> if (coef < 0) >>> stop("'coef' must not be negative") >>> nna <- !is.na(x) >>> n <- sum(nna) >>> stats <- stats::fivenum(x, na.rm = TRUE) >>> iqr <- diff(stats[c(2, 4)]) >>> if (coef == 0) >>> do.out <- FALSE >>> else { >>> out <- if (!is.na(iqr)) { >>> x < (stats[2L] - coef * iqr) | x > (stats[4L] + coef * >>> iqr) >>> } >>> else !is.finite(x) >>> if (any(out[nna], na.rm = TRUE)) >>> stats[c(1, 5)] <- range(x[!out], na.rm = TRUE) >>> } >>> conf <- if (do.conf) >>> stats[3L] + c(-1.58, 1.58) * iqr/sqrt(n) >>> list(stats = stats, n = n, conf = conf, out = if (do.out) x[out & >>> nna] else numeric(0L)) >>> } >>> <environment: namespace:grDevices> >>> >>> >>> On Fri, May 7, 2010 at 3:09 PM, David Winsemius <dwinsem...@comcast.net> >>> wrote: >>> >>> On May 7, 2010, at 3:30 PM, Jun Shen wrote: >>> >>> Dear all, >>> >>> I constructed this function called my.boxplot.stats by replacing fivnum() >>> with quantile() in function boxplot.stats(). So I can try different >>> quantile >>> methods in bwplot(). The problem is I couldn't pass different values to >>> the >>> "type" argument to my.boxplot.stats, which in turn is an argument in >>> bwplot(). Now I just have to manually change the "type" value in >>> my.boxplot.stats. What I would like to do is call bwplot() like >>> >>> bwplot(CL~DOSE,data=patab,stats=my.boxplot.stats(type=7)), >>> >>> >>> You have defined a function with an argument of x that does not have a >>> default value, so it throws an error when you call it with no value for x. >>> (It's not complaining about the type argument.) >>> >>> -- >>> David. >>> >>> >>> But I got an error: >>> Error in my.boxplot.stats(type = 7) : element 1 is empty; >>> the part of the args list of 'is.na' being evaluated was: >>> (x) >>> >>> Thanks a lot. >>> >>> Jun Shen from Millipore Corporation >>> >>> ======================================================== >>> my.boxplot.stats<-function (x, coef = 1.5, *type=6*, do.conf = TRUE, >>> do.out >>> = TRUE) >>> { >>> if (coef < 0) >>> stop("'coef' must not be negative") >>> nna <- !is.na(x) >>> n <- sum(nna) >>> stats <- stats::quantile(x, type=type,na.rm = TRUE) >>> iqr <- diff(stats[c(2, 4)]) >>> if (coef == 0) >>> do.out <- FALSE >>> else { >>> out <- if (!is.na(iqr)) { >>> x < (stats[2L] - coef * iqr) | x > (stats[4L] + coef * >>> iqr) >>> } >>> else !is.finite(x) >>> if (any(out[nna], na.rm = TRUE)) >>> stats[c(1, 5)] <- range(x[!out], na.rm = TRUE) >>> } >>> conf <- if (do.conf) >>> stats[3L] + c(-1.58, 1.58) * iqr/sqrt(n) >>> list(stats = stats, n = n, conf = conf, out = if (do.out) x[out & >>> nna] else numeric(0L)) >>> } >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> David Winsemius, MD >>> West Hartford, CT >>> >>> >>> >> David Winsemius, MD >> West Hartford, CT >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > David Winsemius, MD > West Hartford, CT > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.