Brian Z Ring
2013-Jan-05 05:13 UTC
[R] package metafor: error when setting 'col' and 'at' for a forest plot
I am using metafor to create forest plots. This code gives me the expected plot (setting x axis tick marks): forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp) As does this (setting colors): forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), slab=forest$SNP, atransf=exp) But if I try to set both 'at' and 'col': forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp) I receive this error: Error in polygon(x = c(alim[2], alim[2] - (1.4/100) * cex * (xlim[2] - : formal argument "col" matched by multiple actual arguments Any help greatly appreciated. Brian Z Ring PhD Professor, Director Institute of Personalized and Genomic Medicine College of Life Science Huazhong University of Science and Technology Wuhan, ?China
David Winsemius
2013-Jan-05 18:30 UTC
[R] package metafor: error when setting 'col' and 'at' for a forest plot
On Jan 4, 2013, at 9:13 PM, Brian Z Ring wrote:> I am using metafor to create forest plots. This code gives me the > expected > plot (setting x axis tick marks): > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, at=log(c(. > 05, .25, > 1, 10)), slab=forest$SNP, atransf=exp) > > As does this (setting colors): > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), > slab=forest$SNP, atransf=exp) > > But if I try to set both 'at' and 'col': > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), > at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp) > > I receive this error: > Error in polygon(x = c(alim[2], alim[2] - (1.4/100) * cex * (xlim[2] > - : > formal argument "col" matched by multiple actual arguments > > Any help greatly appreciated.Can you reproduce this using the examples in the package help pages? -- David Winsemius, MD Alameda, CA, USA
Viechtbauer Wolfgang (STAT)
2013-Jan-07 10:15 UTC
[R] package metafor: error when setting 'col' and 'at' for a forest plot
Dear Brian, At the moment, the various forest() functions are not meant to accept 'col' as an argument. While it is indeed possible to specify a 'col' argument, it will be passed on via the ... argument to further functions within forest() and this is where things can go awry. To give a more technical explanation, let's look at your example. First, note that the highest 'at' value you specified is log(10), which is approximately 2.30. However, the highest upper CI bound in your dataset is 2.9. Therefore, the forest() function wants to draw a right-pointed arrow for that study using the polygon() function. The code within forest() looks something like this: polygon(<lots of other stuff>, col="black", ...) When you specify a 'col' argument, it is passed on to polygon() via ... -- but col="black" is already hard-coded in forest() and so you get the "formal argument "col" matched by multiple actual arguments" error. The issue of changing colors in the forest() functions has come up before: https://stat.ethz.ch/pipermail/r-help/2011-August/287788.html In fact, the problems associated with allowing the user to specify colors in high-level plotting functions, such as forest(), was nicely discussed in a recent article by Paul Murrell in the R Journal: http://journal.r-project.org/archive/2012-2/RJournal_2012-2_Murrell.pdf I may add functionality to the forest() functions to handle a 'col' argument for specifying row colors, but I will have to evaulate carefully how well that will work. Also, I would then need to change the current 'col' argument in the forest.rma() function -- breaking backwards compatability :/ Back to your example. You can actually get it to work if you use: forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, at=log(c(.05, .25, 1, 20)), slab=forest$SNP, atransf=exp) in which case the values of 'at' encompass the CI bounds of all studies. Then the forest() function does not use polygon(), but segments() and here 'col' is not hard-coded. One (probably) unintended consequence of using 'col' this way is that the x axis label is also given a different color. A few other notes: 1) Calling your data frame 'forest' is probably not a good idea -- since that is the name of a function. 2) Your data appear to be (raw -- not log transformed) odds ratios and the corresponding CI bounds. So, you should not be using the atransf arguments -- or you would be transforming your odds ratios to exp(ORs). Probably closer to what you want is: dat <- read.table(header=TRUE, text=" SNP Group High Low OR rs1137101 A 1.21 0.87 1.03 rs1137101 B 2.11 1.21 1.6 rs1137101 C 2.9 1.42 2.03 rs1042522 A 1.12 0.84 0.97 rs1042522 B 1.15 0.79 0.95 rs1042522 C 0.92 0.5 0.7 rs1625895 A 1.14 0.76 0.93 rs1625895 B 1.15 0.75 0.93 rs1625895 C NA NA NA ACEI/D A 1.55 0.79 1.11 ACEI/D B 1.25 0.76 0.98 ACEI/D C 0.85 0.41 0.59 ") forest(dat$OR, ci.lb=dat$Low, ci.ub=dat$High, col=c(1,2,3), at=c(.25, 1, 2, 3), slab=dat$SNP, refline=1, xlab=" ", xlim=c(-1.5,5.5)) mtext("Odds Ratio", side=1, line=2.5, adj=0.45) where I manually add the x axis label, so that it is in black. Again, though, using 'col' this way is technically not intended (even though it does work here). I hope this helps! Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 (VIJV1) 6200 MD Maastricht, The Netherlands +31 (43) 388-4170 | http://www.wvbauer.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] > On Behalf Of Brian Z Ring > Sent: Sunday, January 06, 2013 05:48 > To: 'David Winsemius'; r-help at r-project.org > Subject: Re: [R] package metafor: error when setting 'col' and 'at' for a > forest plot > > Good suggestion, and yes, the given examples work. Using a modification of > one of the supplied examples, where in the final line I only added the > parameter col=c(1,2,3): > > data(dat.bcg) > dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, > data=dat.bcg, append=TRUE) > forest(dat$yi, dat$vi, slab=paste(dat$author, dat$year, sep=", "), > atransf=exp, at=log(c(.05,.25,1,4,20)), col=c(1,2,3)) > > I get a plot similar to what I want to achieve. My code: > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), > at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp) > > differs in the data and using confidence intervals instead of vi (sample > variance). The parameters being changed in my line of code are fairly > simple, just color of each row and the x axis tick marks. Setting each of > these independently with my data works fine, it's only when I try to do > both > that it fails. I'm still stuck. > > Here is some example data that should reproduce the error: > SNP Group High Low OR > rs1137101 A 1.21 0.87 1.03 > rs1137101 B 2.11 1.21 1.6 > rs1137101 C 2.9 1.42 2.03 > rs1042522 A 1.12 0.84 0.97 > rs1042522 B 1.15 0.79 0.95 > rs1042522 C 0.92 0.5 0.7 > rs1625895 A 1.14 0.76 0.93 > rs1625895 B 1.15 0.75 0.93 > rs1625895 C NA NA NA > ACEI/D A 1.55 0.79 1.11 > ACEI/D B 1.25 0.76 0.98 > ACEI/D C 0.85 0.41 0.59 > > -----Original Message----- > From: David Winsemius [mailto:dwinsemius at comcast.net] > Sent: Sunday, January 06, 2013 2:31 AM > To: Brian Z Ring > Cc: r-help at r-project.org > Subject: Re: [R] package metafor: error when setting 'col' and 'at' for a > forest plot > > > On Jan 4, 2013, at 9:13 PM, Brian Z Ring wrote: > > > I am using metafor to create forest plots. This code gives me the > > expected plot (setting x axis tick marks): > > > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, at=log(c(. > > 05, .25, > > 1, 10)), slab=forest$SNP, atransf=exp) > > > > As does this (setting colors): > > > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), > > slab=forest$SNP, atransf=exp) > > > > But if I try to set both 'at' and 'col': > > > > forest(forest$OR, ci.lb=forest$Low, ci.ub=forest$High, col=c(1,2,3), > > at=log(c(.05, .25, 1, 10)), slab=forest$SNP, atransf=exp) > > > > I receive this error: > > Error in polygon(x = c(alim[2], alim[2] - (1.4/100) * cex * (xlim[2] > > - : > > formal argument "col" matched by multiple actual arguments > > > > Any help greatly appreciated. > > Can you reproduce this using the examples in the package help pages? > > -- > > David Winsemius, MD > Alameda, CA, USA > > ______________________________________________ > R-help at 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.
Bert Gunter
2013-Jan-07 15:37 UTC
[R] Function to tabulate t-test (1) How can I get dependent variable name (2) How can I make data frame know to function
John: R2.12 ??? Time to update. 1. ?t.test and note the last entry in the Value section. 2. ?with -- Bert On Mon, Jan 7, 2013 at 6:44 AM, John Sorkin <JSorkin at grecc.umaryland.edu> wrote:> Windows 7 > R 2.12.1 > I am trying to write a function (see sample code below) that will take the output of a t-test and produce results suitable for a table. > I have two questions > (1) You will note that the name of the outcome variable, which is "value" in the input is replaced by the string "outcome by class" in the data frame produced by my function. How can I make my function put the name of the variable being analyzed,, i.e "value" in the output data frame > (2) How can I pass the entire input data to the function so my call to the function will not have to be in its current ugly form, i.e. > Table1(data$value,data$sex) > and instead could just be > Table1(value,sex,data=data) > > > x <- data.frame(value=rnorm(20) ,sex=rep("Male", 20)) > y <- data.frame(value=rnorm(20,4),sex=rep("Female",20)) > data <- rbind(x,y) > temp <- t.test(value~sex,data=data) > temp > v<-data.frame(dep=temp$data.name, > female=temp$estimate[1],male=temp$estimate[2], > p=temp$p.value, > CILow=temp$conf.int[1],CIHigh=temp$conf.int[2]) > row.names(v) <- NULL > > > > Table1 <- function(outcome,class) { > temp <- t.test(outcome~ class) > mydf <- data.frame(dep=temp$data.name, > female=temp$estimate[1],male=temp$estimate[2], > p=temp$p.value, > CILow=temp$conf.int[1],CIHigh=temp$conf.int[2]) > row.names(mydf) <- NULL > mydf} > Table1(data$value,data$sex) > > > > Thank you, > John > > > > John David Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > Confidentiality Statement: > This email message, including any attachments, is for ...{{dropped:27}}
Seemingly Similar Threads
- Using Metafor package: how to backtransform model coefficients when Freeman Tukey double arcine transformation is used
- back transforming arcsine transformations in metafor
- Annotate forest plot 'forest.rma()' for meta-analysis with metafor package
- tweaking forest plot (metafor package)
- z to r transformation within print.rma.uni and forest from the package metafor