Hi I have a problem with passing line and symbol parameters to user defined panel functions I had a look at the archives and created a panel function on what was shown and on panel.loess. I could not to get panel.locfit to work for what I intend it for. There is another layer to work with before success as lp() is called from locfit. xx <- structure(list(Farm = c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C"), Padd = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), x = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L), y = c(-0.0149119113575325, -2.06204168532879, 0.59115620108342, 0.701065909641364, -0.09209267129213, -0.865247821447864, 0.0241230046650827, 1.07765163669472, 0.0861209136257006, -0.0432194108428863, 1.0752878640701, -0.324831311786088, 1.23524270758109, 1.37506065481906, 0.653119800000345, 0.343529478624465, -1.02800469514037, 0.621939148133714, -0.472190923018883, 0.341027069452984, 0.346279582846995, 0.0315430632529719, -0.0485334640758356, -0.49139051657477, 1.28653851743574, 0.397753324159675, -2.75735912593535, -1.25477580809239, 0.0210974048006148, -1.77042148383975, 0.505895481518074, 1.80124546723389, -0.626702949092294, -0.417560134229316, -0.0590225862046547, -0.252886465059564, -1.47678447981784, -1.18297973979234, 0.204487915335494, -0.264105749006465, -2.22751785897293, 1.93698185670379, -0.51664334633059, 0.400028987594472, 1.55840082305276, 0.309921251997392, -0.229844761531488, -0.0571710727247884, -1.63022881763476, 0.447916795447731, -0.583450668171441, -2.09617753882993, -1.78560353982556, -0.872155343528674)), .Names = c("Farm", "Padd", "x", "y"), row.names = c(NA, -54L), class = "data.frame") library(locfit) panel.Locfit <- function(x,y, nn, h, col, col.line, lwd = lwd, lty = lty, ...){ if (missing(nn) ) nn <- 0.7 if (missing(h) ) h <- 0 if (!missing(col)) { if (missing(col.line)) col.line <- col } # locfit regression xy.loc <- locfit(y ~ lp(x, nn = nn, h = h) ) # newdata xvals <- sort(unique(x)) # predictions xy.loc.pre <- predict(xy.loc, newdata = list(x = xvals), se.fit = TRUE) u.vals <- xy.loc.pre$fit + 2*xy.loc.pre$se.fit # upper l.vals <- xy.loc.pre$fit - 2*xy.loc.pre$se.fit # lower # fit llines(xvals, xy.loc.pre$fit, type= "l", lwd = lwd, lty = lty, col = col.line) } ## panel.locfit xyplot(y ~x|Farm,xx, groups = Padd, par.settings = list(strip.background = list(col = "transparent"), superpose.line = list(col = c("black","grey"), lwd = c(1,2), lty = c(2,1)), superpose.symbol = list(cex = c(0.8, 0.7), col = c("red","black"), pch = c(20,4)) ), auto.key=list(lines=T,points = T,rectangles=F), panel = panel.superpose, panel.groups=function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) ## xyplot The above works nicely and also without par.setting giving lattice defaults. The par.setting is handy for a lot of graphs that I do. But when I tried a 1 panel plot I get the error message. xyplot(y ~x,xx, groups = Farm, auto.key=TRUE, panel = function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) # Error using packet 3 # promise already under evaluation: recursive default argument reference or earlier problems? If I want to plot another curve with different smoothing it is OK with the defaults and par.settings e.g. with the line added panel.Locfit(x,y,nn= 0.9, ...) but gives an error message without par.settings if i want to add panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) Error using packet 1 formal argument "Iwd" matched by multiple actual arguments I also need to plot a smoothed line for all groups trying groups, subscripts and panel.groups as arguments without success Any solutions to solve the above will be gratefully received and faithfully applied. Duncan sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C LC_TIME=English_Australia.1252 attached base packages: [1] datasets utils stats graphics grDevices grid methods base other attached packages: [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2 foreign_0.8-49 chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 RColorBrewer_1.0-5 [9] lattice_0.20-6 loaded via a namespace (and not attached): [1] tools_2.15.0 Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mackay at northnet.com.au
Hi I have a problem with passing line and symbol parameters to user defined panel functions I had a look at the archives and created a panel function on what was shown and on panel.loess. I could not to get panel.locfit to work for what I intend it for. There is another layer to work with before success as lp() is called from locfit. xx <- structure(list(Farm = c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C"), Padd = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), x = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L), y = c(-0.0149119113575325, -2.06204168532879, 0.59115620108342, 0.701065909641364, -0.09209267129213, -0.865247821447864, 0.0241230046650827, 1.07765163669472, 0.0861209136257006, -0.0432194108428863, 1.0752878640701, -0.324831311786088, 1.23524270758109, 1.37506065481906, 0.653119800000345, 0.343529478624465, -1.02800469514037, 0.621939148133714, -0.472190923018883, 0.341027069452984, 0.346279582846995, 0.0315430632529719, -0.0485334640758356, -0.49139051657477, 1.28653851743574, 0.397753324159675, -2.75735912593535, -1.25477580809239, 0.0210974048006148, -1.77042148383975, 0.505895481518074, 1.80124546723389, -0.626702949092294, -0.417560134229316, -0.0590225862046547, -0.252886465059564, -1.47678447981784, -1.18297973979234, 0.204487915335494, -0.264105749006465, -2.22751785897293, 1.93698185670379, -0.51664334633059, 0.400028987594472, 1.55840082305276, 0.309921251997392, -0.229844761531488, -0.0571710727247884, -1.63022881763476, 0.447916795447731, -0.583450668171441, -2.09617753882993, -1.78560353982556, -0.872155343528674)), .Names = c("Farm", "Padd", "x", "y"), row.names = c(NA, -54L), class = "data.frame") library(locfit) panel.Locfit <- function(x,y, nn, h, col, col.line, lwd = lwd, lty = lty, ...){ if (missing(nn) ) nn <- 0.7 if (missing(h) ) h <- 0 if (!missing(col)) { if (missing(col.line)) col.line <- col } # locfit regression xy.loc <- locfit(y ~ lp(x, nn = nn, h = h) ) # newdata xvals <- sort(unique(x)) # predictions xy.loc.pre <- predict(xy.loc, newdata = list(x = xvals), se.fit = TRUE) u.vals <- xy.loc.pre$fit + 2*xy.loc.pre$se.fit # upper l.vals <- xy.loc.pre$fit - 2*xy.loc.pre$se.fit # lower # fit llines(xvals, xy.loc.pre$fit, type= "l", lwd = lwd, lty = lty, col = col.line) } ## panel.locfit xyplot(y ~x|Farm,xx, groups = Padd, par.settings = list(strip.background = list(col = "transparent"), superpose.line = list(col = c("black","grey"), lwd = c(1,2), lty = c(2,1)), superpose.symbol = list(cex = c(0.8, 0.7), col = c("red","black"), pch = c(20,4)) ), auto.key=list(lines=T,points = T,rectangles=F), panel = panel.superpose, panel.groups=function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) ## xyplot The above works nicely and also without par.setting giving lattice defaults. The par.setting is handy for a lot of graphs that I do. But when I tried a 1 panel plot I get the error message. xyplot(y ~x,xx, groups = Farm, auto.key=TRUE, panel = function(x,y, ...){ panel.Locfit(x,y,...) panel.xyplot(x,y,...) } ) # Error using packet 3 # promise already under evaluation: recursive default argument reference or earlier problems? If I want to plot another curve with different smoothing it is OK with the defaults and par.settings e.g. with the line added panel.Locfit(x,y,nn= 0.9, ...) but gives an error message without par.settings if i want to add panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) Error using packet 1 formal argument "Iwd" matched by multiple actual arguments I also need to plot a smoothed line for all groups trying groups, subscripts and panel.groups as arguments without success Any solutions to solve the above will be gratefully received and faithfully applied. Duncan sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C LC_TIME=English_Australia.1252 attached base packages: [1] datasets utils stats graphics grDevices grid methods base other attached packages: [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2 foreign_0.8-49 chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 RColorBrewer_1.0-5 [9] lattice_0.20-6 loaded via a namespace (and not attached): [1] tools_2.15.0 Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mackay at northnet.com.au
On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay <mackay at northnet.com.au> wrote:> Hi > > ?xyplot(y ~x|Farm,xx, > ? ? ? ? groups = Padd, > ? ? ? ? panel = panel.superpose, > ? ? ? ? panel.groups=function(x,y, ...){ > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) > ? ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) > ? ? ? ? ? ? ? ? ? ? ?} > ?) ## xyplot > > The above works nicely and also without par.setting giving lattice defaults. > The par.setting is handy for a lot of graphs that I do. > > But when I tried a 1 panel plot I get the error message. > > ?xyplot(y ~x,xx, > ? ? ? ? groups = Farm, > ? ? ? ? auto.key=TRUE, > ? ? ? ? panel = function(x,y, ...){ > > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) > ? ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) > ? ? ? ? ? ? ? ? ? ? ?} > ? ? ? ? ) >These two plots are NOT THE SAME. Did you want the same as the first but with groups being Farm and Padd ignored ? in that case you (again) need a panel.groups: ?xyplot(y ~x,xx, ? ? ? ?groups = Farm, ? ? ? ?auto.key=TRUE, ? ? ? ?panel = panel.superpose,panel.groups=function(x,y,...){ ? ? ? ? ? ? ? ? ? ? ? panel.Locfit(x,y,...) ? ? ? ? ? ? ? ? ? ? ? panel.xyplot(x,y,...) ? ? ? ? ? ? ? ? ? ? } ? ? ? ?)> If I want to plot another curve with different smoothing > but gives an error message without par.settings if i want to add > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) > > Error using packet 1 > formal argument "Iwd" matched by multiple actual argumentsIt is all in the way you initially specified how to pass the arguments for panel.Locfit. This works without error: ?xyplot(y ~x,xx, ? ? ? ?groups = Farm, ? ? ? ?auto.key=TRUE,lwd=1:3, ? ? ? ?panel = panel.superpose,panel.groups=function(x,y,nn,...){ ? ? ? ? ? ? ? ? ? ? ? panel.Locfit(x,y,nn=.9,...) ? ? ? ? ? ? ? ? ? ? ? panel.xyplot(x,y,...) ? ? ? ? ? ? ? ? ? ? } ? ? ? ?) HTH> I also need to plot a smoothed line for all groups trying groups, subscripts > and panel.groups as arguments without success > > Any solutions to solve the above will be gratefully received and faithfully > applied. > > Duncan > > sessionInfo() > R version 2.15.0 (2012-03-30) > Platform: i386-pc-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=English_Australia.1252 ?LC_CTYPE=English_Australia.1252 > LC_MONETARY=English_Australia.1252 LC_NUMERIC=C > LC_TIME=English_Australia.1252 > > attached base packages: > [1] datasets ?utils ? ? stats ? ? graphics ?grDevices grid ? ? ?methods > base > > other attached packages: > [1] locfit_1.5-7 ? ? ? ?R.oo_1.9.3 ? ? ? ? ?R.methodsS3_1.2.2 foreign_0.8-49 > ? ? ?chron_2.3-42 ? ? ? ?MASS_7.3-17 latticeExtra_0.6-19 RColorBrewer_1.0-5 > [9] lattice_0.20-6 > > loaded via a namespace (and not attached): > [1] tools_2.15.0 > > > > Duncan Mackay > Department of Agronomy and Soil Science > University of New England > ARMIDALE NSW 2351 > Email home: mackay at northnet.com.au > > ______________________________________________ > 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.
Duncan, First off, I admit it is not clear to me what you are trying to achieve and more importantly, why? by "why" I mean 1) I don't see the advantage of writing one general panel function for completely different situations (one/multiple smoothers, grouping levels etc.) 2) your intended result as I understand it seems rather cluttered, google <chartjunk>. 3) I am unfamiliar with locfit package, but are we reinventing the wheel here ? i.e. will modifying settings in xyplot(y ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? With your initial reproducible example (thank you) it was easy to eliminate the errors, but clearly the resulting plots are not what you intended (continue inline): On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay <mackay at northnet.com.au> wrote: <snip>> 3. What I want to be able to add in the above is extra lines with different > values of nn. > ? I think I will have to modify panel.Locfit so that it goes through > different values of nn in each of the panels and groups if I want different > colours for extra lines with different nn valuesYes you could. There are several options: add group.number to the arguments of panel.locfit and use it to make nn a vector, along the lines of panel.foo <- function(x,y,group.number,theta,...){ smpar <- theta[group.number] panel.loess(x,y,smpar,...) panel.xyplot(x,y,...) } xyplot(y~x,xx,group=Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) # or xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1), panel=panel.superpose,panel.groups=panel.foo) Here you will need to modify the Farm group to 6 levels - 3*two smoothers. You could make nn a list and loop over it inside the panel function. Looks like you tried something like that with specifying 2 panel.Locfit, one suggestion to your code: panel.Locfit(x,y,...) # default 0.7 panel.Locfit(x,y,nn=0.9) # i.e. remove the ... to avoid clashes Finally, use ?trellis.focus to plot the second smoother "post-hoc". also the latticeExtra package has many useful tools to create layers of the same (or different) plot with different settings.> 4 Produce an extra line for a fit for all the groups in 1/2+ panels. > ? As for 3 but I do not know how to group all the x and y's ?for each of the > panes using panel.groupsWhy does it matter ? seems you have failed to learn the lesson from the first post - the same functionality applies to 1 as to multiple panels. Does each panel have a different grouping structure ? use packet.number() for panels similar to group.number idea.> I need to do this and then scale up for a panel function to include > confidence bandsthan expand the xlim,ylim or scales in ?xyplot> > For the record making Farm and Padd factors. With 1 panel and groups = Farm > works with the extra line the same colour for its group > a similar situation for the three panels when conditioned by Farm and groups > = Pad???? Like I said I am a little lost on this problem but I hope this helps giving some direction. Cheers> > ?xyplot(y ~x, xx, > ? ? ? ? groups = Farm, > > ? ? ? ? par.settings = list(strip.background = list(col = "transparent"), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? superpose.line ? = list(col = c("black","grey"), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lwd = c(1,2,3), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? lty = c(2,1,3)), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? superpose.symbol = list(cex = c(0.8, 0.7,0.7), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? col > c("red","black","blue"), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pch = c(20,4,16)) > ? ? ? ? ? ? ? ? ? ), > ? ? ? ? auto.key=list(lines=T,points = T,rectangles=F), > > ? ? ? ? panel ?= panel.superpose, > ? ? ? ? panel.groups=function(x,y, ...){ > > ? ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) # default 0.7 > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,nn=0.9,...) > > ? ? ? ? ? ? ? ? ? ? ?} > ?) ## xyplot > > > Regards > > Duncan > > > At 02:12 20/04/2012, you wrote: >> >> On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay <mackay at northnet.com.au> >> wrote: >> > Hi >> > >> > ?xyplot(y ~x|Farm,xx, >> > ? ? ? ? groups = Padd, >> > ? ? ? ? panel = panel.superpose, >> > ? ? ? ? panel.groups=function(x,y, ...){ >> > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) >> > ? ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) >> > ? ? ? ? ? ? ? ? ? ? ?} >> > ?) ## xyplot >> > >> > The above works nicely and also without par.setting giving lattice >> > defaults. >> > The par.setting is handy for a lot of graphs that I do. >> > >> > But when I tried a 1 panel plot I get the error message. >> > >> > ?xyplot(y ~x,xx, >> > ? ? ? ? groups = Farm, >> > ? ? ? ? auto.key=TRUE, >> > ? ? ? ? panel = function(x,y, ...){ >> > >> > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) >> > ? ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) >> > ? ? ? ? ? ? ? ? ? ? ?} >> > ? ? ? ? ) >> > >> >> These two plots are NOT THE SAME. Did you want the same as the first >> but with groups being Farm and Padd ignored ? in that case you (again) >> need a panel.groups: >> >> ?xyplot(y ~x,xx, >> ? ? ? groups = Farm, >> ? ? ? auto.key=TRUE, >> ? ? ? panel = panel.superpose,panel.groups=function(x,y,...){ >> ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,...) >> ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) >> ? ? ? ? ? ? ? ? ? ?} >> ? ? ? ) >> >> >> > If I want to plot another curve with different smoothing >> > but gives an error message without par.settings if i want to add >> > ? ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) >> > >> > Error using packet 1 >> > formal argument "Iwd" matched by multiple actual arguments >> >> It is all in the way you initially specified how to pass the arguments >> for panel.Locfit. This works without error: >> >> ?xyplot(y ~x,xx, >> ? ? ? groups = Farm, >> ? ? ? auto.key=TRUE,lwd=1:3, >> ? ? ? panel = panel.superpose,panel.groups=function(x,y,nn,...){ >> ? ? ? ? ? ? ? ? ? ? ?panel.Locfit(x,y,nn=.9,...) >> ? ? ? ? ? ? ? ? ? ? ?panel.xyplot(x,y,...) >> ? ? ? ? ? ? ? ? ? ?} >> ? ? ? ) >> >> >> HTH >> >> >> >> > I also need to plot a smoothed line for all groups trying groups, >> > subscripts >> > and panel.groups as arguments without success >> > >> > Any solutions to solve the above will be gratefully received and >> > faithfully >> > applied. >> > >> > Duncan >> > >> > sessionInfo() >> > R version 2.15.0 (2012-03-30) >> > Platform: i386-pc-mingw32/i386 (32-bit) >> > >> > locale: >> > [1] LC_COLLATE=English_Australia.1252 ?LC_CTYPE=English_Australia.1252 >> > LC_MONETARY=English_Australia.1252 LC_NUMERIC=C >> > LC_TIME=English_Australia.1252 >> > >> > attached base packages: >> > [1] datasets ?utils ? ? stats ? ? graphics ?grDevices grid ? ? ?methods >> > base >> > >> > other attached packages: >> > [1] locfit_1.5-7 ? ? ? ?R.oo_1.9.3 ? ? ? ? ?R.methodsS3_1.2.2 >> > foreign_0.8-49 >> > ? ? ?chron_2.3-42 ? ? ? ?MASS_7.3-17 latticeExtra_0.6-19 >> > RColorBrewer_1.0-5 >> > [9] lattice_0.20-6 >> > >> > loaded via a namespace (and not attached): >> > [1] tools_2.15.0 >> > >> > >> > >> > Duncan Mackay >> > Department of Agronomy and Soil Science >> > University of New England >> > ARMIDALE NSW 2351 >> > Email home: mackay at northnet.com.au >> > >> > ______________________________________________ >> > 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. >> >> ______________________________________________ >> 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. > >
Hi Bert Thank you for your comments. I do use latticeExtra a lot - about 50% of my graphs at the moment have useOuterStrips some involving combineLimits . Many are complicated - one I have just finished involves useOuterStrips in 8,3 (r,c) panels after http://finzi.psych.upenn.edu/R/Rhelp02/archive/43626.html + 2 different panel.heights for some of the rows and that is just the start I have used other functions when needed I think that I will have to abandon a general function partly on arguments and the graphs I have done in the past an the possibilities in the future I somebody would explain the rules 1 plus many others would be grateful Duncan At 00:19 22/04/2012, you wrote:>Oh ... one more thing. > >You might explore the latticeExtra package. It permits use of a >layering paradigm -- like ggplot -- that largely obviates the need for >panel functions. There are also options in it to gracefully handle >(ignore) replicated arguments. > >-- Bert > >On Sat, Apr 21, 2012 at 2:28 AM, Duncan Mackay <mackay at northnet.com.au> wrote: > > Bert > > I have read Deepayan's book and done all the examples but there is no > > mention of panel.number and panel.groups in the books example. > > > > I just cannot get the fully meaning of what has been written regarding > > passing arguments to panel functions. > > > > Regards > > > > Duncan > > > > > > > > At 14:31 21/04/2012, you wrote: > >> > >> A comment... > >> > >> On Fri, Apr 20, 2012 at 8:32 PM, Duncan Mackay <mackay at northnet.com.au> > >> wrote: > >> > Hi David, ilai > >> > > >> > The root cause of the problem is the passing of arguments to panel > >> > functions > >> > to me and my colleagues. > >> > Just going through the archives there seems to be different ways for > >> > very > >> > similar/same outcomes and > >> > trying to get a pattern is hard to discern. > >> > >> Bad strategy! Trying to infer the rules from examples in complex > >> cases -- and as you said, different equivalent ways -- is nuts. You > >> need to read the docs carefully (including Deepayan's book, possibly) > >> and use the examples for understanding what is explained there. > >> > >> Finally, I don't know if this is relevant or helpful but: > >> > >> ## this code works fine > >> xyplot(rnorm(5) ~ 1:5, type="l", > >> panel = function(...)panel.xyplot(...,lwd=2)) > >> > >> ## This code throws an error about repeat lwd arguments. Is it obvious > >> why? > >> xyplot(rnorm(5) ~ 1:5, lwd=1,type="l", > >> panel = function(...) panel.xyplot(...,lwd=2)) > >> > >> -- Bert > >> > >> > I frequently have to use the subscripts or group.number to access other > >> > data. > >> > I thought I had things sorted out in my head with the panel.groups and > >> > group.number but this has shattered it. > >> > > >> > Thanks > >> > > >> > Duncan > >> > > >> > At 12:15 21/04/2012, you wrote: > >> > > >> >> On Apr 20, 2012, at 9:14 PM, ilai wrote: > >> >> > >> >>> Oops - that is "reply all" > >> >>> On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius > >> >>> <dwinsemius at comcast.net > >> >>> > wrote: > >> >>>> > >> >>>> > >> >>>> I'm a bit puzzled by this exchange. I know there is a > >> >>>> 'panel.locfit', but > >> >>>> you two are spelling it differently. Can you explain why you are > >> >>>> doing so? > >> >>> > >> >>> > >> >>> Hi David, > >> >>> Thanks for stepping in. panel.Locfit is the OP's local function (or > >> >>> just a wrapper ?) which I believe is here > >> >>> http://www.mail-archive.com/r-help at r-project.org/msg167164.html > >> >>> > >> >>> Note the two errors OP encountered (solved down the thread) were > >> >>> caused by the way he called the function in xyplot, not by > >> >>> panel.Locfit itself, which I did not modify. I guess now the issue is > >> >>> how to generalize panel.Locfit somehow, but I am not sure how. I > >> >>> suspect the problem is not my understanding but that there really > >> >>> isn't any one specific problem here for the list to solve, though, > >> >>> again, I am known for misinterpreting OP requests... :) > >> >>> > >> >>>>> ?panel.locfit > >> >>> > >> >>> > >> >>> As I said, I am unfamiliar with the package - but this doesn't > >> >>> surprise me. Thank you for pointing it out, wish you've noticed the > >> >>> exchange sooner... > >> >> > >> >> > >> >> Another puzzle. In the original posting there was this segment: > >> >> --- > >> >> but gives an error message without par.settings if i want to add > >> >> panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) > >> >> > >> >> Error using packet 1 > >> >> formal argument "Iwd" matched by multiple actual arguments > >> >> --- > >> >> > >> >> On my mailer that formal argument starts with a capital "I" but the > >> >> code seemed to be attempting a lowercase "l". > >> >> > >> >> I could never see reason offered for defining a new panel.locfit, but > >> >> I'm wondering if the sometimes similar representation of those two > >> >> different letters could be causing an obscure conflict? > >> >> > >> >> -- > >> >> David. > >> >>> > >> >>> > >> >>> Cheers > >> >>> > >> >>> > >> >>>>> ?panel.Locfit > >> >>>> > >> >>>> No documentation for 'panel.Locfit' in specified packages and > >> >>>> libraries: > >> >>>> you could try '??panel.Locfit' > >> >>>> > >> >>>>> ?panel.locfit > >> >>>> > >> >>>> > >> >>>> {locfit} R Documentation > >> >>>> Locfit panel function > >> >>>> > >> >>>> Description > >> >>>> > >> >>>> This panel function can be used to add locfit fits to plots > >> >>>> generated by > >> >>>> trellis. > >> >>>> > >> >>>> > >> >>>> > >> >>>>> I am trying to construct a function/s to cover as many of the normal > >> >>>>> situations as possible. > >> >>>>> Usually I have to amend colours lines etc to distinguish the data. > >> >>>>> > >> >>>>> I want to cover a number of situations > >> >>>>> 1 Conditioned by panel no groups > >> >>>>> 2 Conditioned by panel and groups. > >> >>>>> 3 Multiple values for above - to show colleagues (EDA) > >> >>>>> 4 Conditioned by panel and groups + an overall fit for all the > >> >>>>> data within > >> >>>>> a panel > >> >>>>> 5 Several y values in a panel eg Y1+Y2 and outer = FALSE with a > >> >>>>> fit for > >> >>>>> each of Y1 and Y2 > >> >>>>> > >> >>>>> I am trying to cover as many of the above situations in 1 function > >> >>>>> before > >> >>>>> resulting to trellis.focus or > >> >>>>> overlaying. The graphs that I normally create are not simple, > >> >>>>> generally > >> >>>>> involving useOuterStrips > >> >>>>> which may have different y scales for panel rows (combindeLimits/ > >> >>>>> manual) > >> >>>>> and different panel row heights. > >> >>>>> > >> >>>>> locfit is like loess but 2 arguments for smoothing; the degree of > >> >>>>> smoothing produced by the defaults > >> >>>>> is approximately that of loess but I normally need less smoothing > >> >>>>> (the > >> >>>>> same would be apply for loess). > >> >>>>> > >> >>>>> Most of the questions to Rhelp are for 1 with just a small number > >> >>>>> for 5 > >> >>>>> and they are not applicable here > >> >>>>> and understanding the requirements for passing arguments in these > >> >>>>> different situations I find difficult. > >> >>>>> I would like to reduce the number of panel functions to the > >> >>>>> minimum to > >> >>>>> cover the general situaltions because > >> >>>>> my graphs are usually not normal and then add to them for a > >> >>>>> particular > >> >>>>> situation. > >> >>>>> > >> >>>>> Regards > >> >>>>> > >> >>>>> Duncan > >> >>>>> > >> >>>>> > >> >>>>> At 01:38 21/04/2012, you wrote: > >> >>>>>> > >> >>>>>> > >> >>>>>> Duncan, > >> >>>>>> First off, I admit it is not clear to me what you are trying to > >> >>>>>> achieve and more importantly, why? by "why" I mean 1) I don't see > >> >>>>>> the > >> >>>>>> advantage of writing one general panel function for completely > >> >>>>>> different situations (one/multiple smoothers, grouping levels > >> >>>>>> etc.) 2) > >> >>>>>> your intended result as I understand it seems rather cluttered, > >> >>>>>> google > >> >>>>>> <chartjunk>. 3) I am unfamiliar with locfit package, but are we > >> >>>>>> reinventing the wheel here ? i.e. will modifying settings in > >> >>>>>> xyplot(y > >> >>>>>> ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? > >> >>>>>> > >> >>>>>> With your initial reproducible example (thank you) it was easy to > >> >>>>>> eliminate the errors, but clearly the resulting plots are not > >> >>>>>> what you > >> >>>>>> intended (continue inline): > >> >>>>>> > >> >>>>>> On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay > >> >>>>>> <mackay at northnet.com.au > >> >>>>>> > > >> >>>>>> wrote: > >> >>>>>> <snip> > >> >>>>>>> > >> >>>>>>> 3. What I want to be able to add in the above is extra lines with > >> >>>>>>> different > >> >>>>>>> values of nn. > >> >>>>>>> I think I will have to modify panel.Locfit so that it goes > >> >>>>>>> through > >> >>>>>>> different values of nn in each of the panels and groups if I want > >> >>>>>>> different > >> >>>>>>> colours for extra lines with different nn values > >> >>>>>> > >> >>>>>> > >> >>>>>> Yes you could. There are several options: > >> >>>>>> add group.number to the arguments of panel.locfit and use it to > >> >>>>>> make > >> >>>>>> nn a vector, along the lines of > >> >>>>>> panel.foo <- function(x,y,group.number,theta,...){ > >> >>>>>> smpar <- theta[group.number] > >> >>>>>> panel.loess(x,y,smpar,...) > >> >>>>>> panel.xyplot(x,y,...) > >> >>>>>> } > >> >>>>>> > >> >>>>>> xyplot (y ~ x ,xx ,group > >> >>>>>> =Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) > >> >>>>>> > >> >>>>>> # or > >> >>>>>> xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1), > >> >>>>>> panel=panel.superpose,panel.groups=panel.foo) > >> >>>>>> > >> >>>>>> Here you will need to modify the Farm group to 6 levels - 3*two > >> >>>>>> smoothers. > >> >>>>>> > >> >>>>>> You could make nn a list and loop over it inside the panel > >> >>>>>> function. > >> >>>>>> Looks like you tried something like that with specifying 2 > >> >>>>>> panel.Locfit, one suggestion to your code: > >> >>>>>> > >> >>>>>> panel.Locfit(x,y,...) # default 0.7 > >> >>>>>> panel.Locfit(x,y,nn=0.9) # i.e. remove the > >> >>>>>> ... to avoid clashes > >> >>>>>> > >> >>>>>> Finally, use ?trellis.focus to plot the second smoother "post-hoc". > >> >>>>>> also the latticeExtra package has many useful tools to create > >> >>>>>> layers > >> >>>>>> of the same (or different) plot with different settings. > >> >>>>>> > >> >>>>>>> 4 Produce an extra line for a fit for all the groups in 1/2+ > >> >>>>>>> panels. > >> >>>>>>> As for 3 but I do not know how to group all the x and y's for > >> >>>>>>> each > >> >>>>>>> of the > >> >>>>>>> panes using panel.groups > >> >>>>>> > >> >>>>>> > >> >>>>>> Why does it matter ? seems you have failed to learn the lesson from > >> >>>>>> the first post - the same functionality applies to 1 as to multiple > >> >>>>>> panels. Does each panel have a different grouping structure ? use > >> >>>>>> packet.number() for panels similar to group.number idea. > >> >>>>>> > >> >>>>>>> I need to do this and then scale up for a panel function to > >> >>>>>>> include > >> >>>>>>> confidence bands > >> >>>>>> > >> >>>>>> > >> >>>>>> than expand the xlim,ylim or scales in ?xyplot > >> >>>>>> > >> >>>>>>> > >> >>>>>>> For the record making Farm and Padd factors. With 1 panel and > >> >>>>>>> groups > >> >>>>>>> Farm > >> >>>>>>> works with the extra line the same colour for its group > >> >>>>>>> a similar situation for the three panels when conditioned by > >> >>>>>>> Farm and > >> >>>>>>> groups > >> >>>>>>> = Pad > >> >>>>>> > >> >>>>>> > >> >>>>>> ???? > >> >>>>>> > >> >>>>>> Like I said I am a little lost on this problem but I hope this > >> >>>>>> helps > >> >>>>>> giving some direction. > >> >>>>>> Cheers > >> >>>>>> > >> >>>>>> > >> >>>>>>> > >> >>>>>>> xyplot(y ~x, xx, > >> >>>>>>> groups = Farm, > >> >>>>>>> > >> >>>>>>> par.settings = list(strip.background = list(col > >> >>>>>>> "transparent"), > >> >>>>>>> superpose.line = list(col > >> >>>>>>> c("black","grey"), > >> >>>>>>> lwd > >> >>>>>>> c(1,2,3), > >> >>>>>>> lty > >> >>>>>>> c(2,1,3)), > >> >>>>>>> superpose.symbol = list(cex = c(0.8, > >> >>>>>>> 0.7,0.7), > >> >>>>>>> col > >> >>>>>>> c("red","black","blue"), > >> >>>>>>> pch > >> >>>>>>> c(20,4,16)) > >> >>>>>>> ), > >> >>>>>>> auto.key=list(lines=T,points = T,rectangles=F), > >> >>>>>>> > >> >>>>>>> panel = panel.superpose, > >> >>>>>>> panel.groups=function(x,y, ...){ > >> >>>>>>> > >> >>>>>>> panel.xyplot(x,y,...) > >> >>>>>>> panel.Locfit(x,y,...) # default 0.7 > >> >>>>>>> panel.Locfit(x,y,nn=0.9,...) > >> >>>>>>> > >> >>>>>>> } > >> >>>>>>> ) ## xyplot > >> >>>>>>> > >> >>>>>>> > >> >>>>>>> Regards > >> >>>>>>> > >> >>>>>>> Duncan > >> >>>>>>> > >> >>>>>>> > >> >>>>>>> At 02:12 20/04/2012, you wrote: > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>> On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay > >> >>>>>>>> <mackay at northnet.com.au> > >> >>>>>>>> wrote: > >> >>>>>>>>> > >> >>>>>>>>> Hi > >> >>>>>>>>> > >> >>>>>>>>> xyplot(y ~x|Farm,xx, > >> >>>>>>>>> groups = Padd, > >> >>>>>>>>> panel = panel.superpose, > >> >>>>>>>>> panel.groups=function(x,y, ...){ > >> >>>>>>>>> panel.Locfit(x,y,...) > >> >>>>>>>>> panel.xyplot(x,y,...) > >> >>>>>>>>> } > >> >>>>>>>>> ) ## xyplot > >> >>>>>>>>> > >> >>>>>>>>> The above works nicely and also without par.setting giving > >> >>>>>>>>> lattice > >> >>>>>>>>> defaults. > >> >>>>>>>>> The par.setting is handy for a lot of graphs that I do. > >> >>>>>>>>> > >> >>>>>>>>> But when I tried a 1 panel plot I get the error message. > >> >>>>>>>>> > >> >>>>>>>>> xyplot(y ~x,xx, > >> >>>>>>>>> groups = Farm, > >> >>>>>>>>> auto.key=TRUE, > >> >>>>>>>>> panel = function(x,y, ...){ > >> >>>>>>>>> > >> >>>>>>>>> panel.Locfit(x,y,...) > >> >>>>>>>>> panel.xyplot(x,y,...) > >> >>>>>>>>> } > >> >>>>>>>>> ) > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>> These two plots are NOT THE SAME. Did you want the same as the > >> >>>>>>>> first > >> >>>>>>>> but with groups being Farm and Padd ignored ? in that case you > >> >>>>>>>> (again) > >> >>>>>>>> need a panel.groups: > >> >>>>>>>> > >> >>>>>>>> xyplot(y ~x,xx, > >> >>>>>>>> groups = Farm, > >> >>>>>>>> auto.key=TRUE, > >> >>>>>>>> panel = panel.superpose,panel.groups=function(x,y,...){ > >> >>>>>>>> panel.Locfit(x,y,...) > >> >>>>>>>> panel.xyplot(x,y,...) > >> >>>>>>>> } > >> >>>>>>>> ) > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>>> If I want to plot another curve with different smoothing > >> >>>>>>>>> but gives an error message without par.settings if i want to add > >> >>>>>>>>> panel.Locfit(x,y,nn= 0.9,lwd > >> >>>>>>>>> c(1,2,3), ...) > >> >>>>>>>>> > >> >>>>>>>>> Error using packet 1 > >> >>>>>>>>> formal argument "Iwd" matched by multiple actual arguments > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>> It is all in the way you initially specified how to pass the > >> >>>>>>>> arguments > >> >>>>>>>> for panel.Locfit. This works without error: > >> >>>>>>>> > >> >>>>>>>> xyplot(y ~x,xx, > >> >>>>>>>> groups = Farm, > >> >>>>>>>> auto.key=TRUE,lwd=1:3, > >> >>>>>>>> panel = panel.superpose,panel.groups=function(x,y,nn,...){ > >> >>>>>>>> panel.Locfit(x,y,nn=.9,...) > >> >>>>>>>> panel.xyplot(x,y,...) > >> >>>>>>>> } > >> >>>>>>>> ) > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>> HTH > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>> > >> >>>>>>>>> I also need to plot a smoothed line for all groups trying > >> >>>>>>>>> groups, > >> >>>>>>>>> subscripts > >> >>>>>>>>> and panel.groups as arguments without success > >> >>>>>>>>> > >> >>>>>>>>> Any solutions to solve the above will be gratefully received and > >> >>>>>>>>> faithfully > >> >>>>>>>>> applied. > >> >>>>>>>>> > >> >>>>>>>>> Duncan > >> >>>>>>>>> > >> >>>>>>>>> sessionInfo() > >> >>>>>>>>> R version 2.15.0 (2012-03-30) > >> >>>>>>>>> Platform: i386-pc-mingw32/i386 (32-bit) > >> >>>>>>>>> > >> >>>>>>>>> locale: > >> >>>>>>>>> [1] LC_COLLATE=English_Australia.1252 > >> >>>>>>>>> LC_CTYPE=English_Australia.1252 > >> >>>>>>>>> LC_MONETARY=English_Australia.1252 LC_NUMERIC=C > >> >>>>>>>>> LC_TIME=English_Australia.1252 > >> >>>>>>>>> > >> >>>>>>>>> attached base packages: > >> >>>>>>>>> [1] datasets utils stats graphics grDevices grid > >> >>>>>>>>> methods > >> >>>>>>>>> base > >> >>>>>>>>> > >> >>>>>>>>> other attached packages: > >> >>>>>>>>> [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2 > >> >>>>>>>>> foreign_0.8-49 > >> >>>>>>>>> chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 > >> >>>>>>>>> RColorBrewer_1.0-5 > >> >>>>>>>>> [9] lattice_0.20-6 > >> >>>>>>>>> > >> >>>>>>>>> loaded via a namespace (and not attached): > >> >>>>>>>>> [1] tools_2.15.0 > >> >>>>>>>>> > >> >>>>>>>>> > >> >>>> > >> >>>> > >> >>>> > >> >>>> David Winsemius, MD > >> >>>> West Hartford, CT > >> >>>> > >> >>>> > >> >>>> ______________________________________________ > >> >>>> 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. > >> >> > >> >> > >> >> David Winsemius, MD > >> >> West Hartford, CT > >> >> > >> > > >> > ______________________________________________ > >> > 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 > >> Genentech Nonclinical Biostatistics > >> > >> Internal Contact Info: > >> Phone: 467-7374 > >> Website: > >> > >> > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > > > > > ______________________________________________ > > 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 >Genentech Nonclinical Biostatistics > >Internal Contact Info: >Phone: 467-7374 >Website: >http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Hi Mark Thats why I did all the examples in Sweave to pick up anything I could not understand in practice but it did not help very much It also gave me a quick reference as they are all bookmarked and are annotated Duncan At 00:01 22/04/2012, you wrote:>Hi Duncan: Don't feel bad about it. I've read his book two or three times and >STILL find it all terribly confusing with many things going unexplained. >People say his book is so great but I don't have that opinion. > > Mark > > >On Sat, Apr 21, 2012 at 5:28 AM, Duncan Mackay ><<mailto:mackay@northnet.com.au>mackay@northnet.com.au> wrote: >Bert >I have read Deepayan's book and done all the examples but there is >no mention of panel.number and panel.groups in the books example. > >I just cannot get the fully meaning of what has been written >regarding passing arguments to panel functions. > >Regards > >Duncan > > > >At 14:31 21/04/2012, you wrote: >A comment... > >On Fri, Apr 20, 2012 at 8:32 PM, Duncan Mackay ><<mailto:mackay@northnet.com.au>mackay@northnet.com.au> wrote: > > Hi David, ilai > > > > The root cause of the problem is the passing of arguments to > panel functions > > to me and my colleagues. > > Just going through the archives there seems to be different ways for very > > similar/same outcomes and > > trying to get a pattern is hard to discern. > >Bad strategy! Trying to infer the rules from examples in complex >cases -- and as you said, different equivalent ways -- is nuts. You >need to read the docs carefully (including Deepayan's book, possibly) >and use the examples for understanding what is explained there. > >Finally, I don't know if this is relevant or helpful but: > >## this code works fine > xyplot(rnorm(5) ~ 1:5, type="l", > panel = function(...)panel.xyplot(...,lwd=2)) > >## This code throws an error about repeat lwd arguments. Is it obvious why? > xyplot(rnorm(5) ~ 1:5, lwd=1,type="l", > panel = function(...) panel.xyplot(...,lwd=2)) > >-- Bert > > > I frequently have to use the subscripts or group.number to access other > > data. > > I thought I had things sorted out in my head with the panel.groups and > > group.number but this has shattered it. > > > > Thanks > > > > Duncan > > > > At 12:15 21/04/2012, you wrote: > > > >> On Apr 20, 2012, at 9:14 PM, ilai wrote: > >> > >>> Oops - that is "reply all" > >>> On Fri, Apr 20, 2012 at 5:29 PM, David Winsemius > <<mailto:dwinsemius@comcast.net>dwinsemius@comcast.net > >>> > wrote: > >>>> > >>>> > >>>> I'm a bit puzzled by this exchange. I know there is a > >>>> 'panel.locfit', but > >>>> you two are spelling it differently. Can you explain why you are > >>>> doing so? > >>> > >>> > >>> Hi David, > >>> Thanks for stepping in. panel.Locfit is the OP's local function (or > >>> just a wrapper ?) which I believe is here > >>> > <http://www.mail-archive.com/r-help@r-project.org/msg167164.html>http://www.mail-archive.com/r-help@r-project.org/msg167164.html > >>> > >>> Note the two errors OP encountered (solved down the thread) were > >>> caused by the way he called the function in xyplot, not by > >>> panel.Locfit itself, which I did not modify. I guess now the issue is > >>> how to generalize panel.Locfit somehow, but I am not sure how. I > >>> suspect the problem is not my understanding but that there really > >>> isn't any one specific problem here for the list to solve, though, > >>> again, I am known for misinterpreting OP requests... :) > >>> > >>>>> ?panel.locfit > >>> > >>> > >>> As I said, I am unfamiliar with the package - but this doesn't > >>> surprise me. Thank you for pointing it out, wish you've noticed the > >>> exchange sooner... > >> > >> > >> Another puzzle. In the original posting there was this segment: > >> --- > >> but gives an error message without par.settings if i want to add > >> panel.Locfit(x,y,nn= 0.9,lwd = c(1,2,3), ...) > >> > >> Error using packet 1 > >> formal argument "Iwd" matched by multiple actual arguments > >> --- > >> > >> On my mailer that formal argument starts with a capital "I" but the > >> code seemed to be attempting a lowercase "l". > >> > >> I could never see reason offered for defining a new panel.locfit, but > >> I'm wondering if the sometimes similar representation of those two > >> different letters could be causing an obscure conflict? > >> > >> -- > >> David. > >>> > >>> > >>> Cheers > >>> > >>> > >>>>> ?panel.Locfit > >>>> > >>>> No documentation for 'panel.Locfit' in specified packages and > >>>> libraries: > >>>> you could try '??panel.Locfit' > >>>> > >>>>> ?panel.locfit > >>>> > >>>> > >>>> {locfit} R Documentation > >>>> Locfit panel function > >>>> > >>>> Description > >>>> > >>>> This panel function can be used to add locfit fits to plots > >>>> generated by > >>>> trellis. > >>>> > >>>> > >>>> > >>>>> I am trying to construct a function/s to cover as many of the normal > >>>>> situations as possible. > >>>>> Usually I have to amend colours lines etc to distinguish the data. > >>>>> > >>>>> I want to cover a number of situations > >>>>> 1 Conditioned by panel no groups > >>>>> 2 Conditioned by panel and groups. > >>>>> 3 Multiple values for above - to show colleagues (EDA) > >>>>> 4 Conditioned by panel and groups + an overall fit for all the > >>>>> data within > >>>>> a panel > >>>>> 5 Several y values in a panel eg Y1+Y2 and outer = FALSE with a > >>>>> fit for > >>>>> each of Y1 and Y2 > >>>>> > >>>>> I am trying to cover as many of the above situations in 1 function > >>>>> before > >>>>> resulting to trellis.focus or > >>>>> overlaying. The graphs that I normally create are not simple, > >>>>> generally > >>>>> involving useOuterStrips > >>>>> which may have different y scales for panel rows (combindeLimits/ > >>>>> manual) > >>>>> and different panel row heights. > >>>>> > >>>>> locfit is like loess but 2 arguments for smoothing; the degree of > >>>>> smoothing produced by the defaults > >>>>> is approximately that of loess but I normally need less smoothing > >>>>> (the > >>>>> same would be apply for loess). > >>>>> > >>>>> Most of the questions to Rhelp are for 1 with just a small number > >>>>> for 5 > >>>>> and they are not applicable here > >>>>> and understanding the requirements for passing arguments in these > >>>>> different situations I find difficult. > >>>>> I would like to reduce the number of panel functions to the > >>>>> minimum to > >>>>> cover the general situaltions because > >>>>> my graphs are usually not normal and then add to them for a > >>>>> particular > >>>>> situation. > >>>>> > >>>>> Regards > >>>>> > >>>>> Duncan > >>>>> > >>>>> > >>>>> At 01:38 21/04/2012, you wrote: > >>>>>> > >>>>>> > >>>>>> Duncan, > >>>>>> First off, I admit it is not clear to me what you are trying to > >>>>>> achieve and more importantly, why? by "why" I mean 1) I don't see > >>>>>> the > >>>>>> advantage of writing one general panel function for completely > >>>>>> different situations (one/multiple smoothers, grouping levels > >>>>>> etc.) 2) > >>>>>> your intended result as I understand it seems rather cluttered, > >>>>>> google > >>>>>> <chartjunk>. 3) I am unfamiliar with locfit package, but are we > >>>>>> reinventing the wheel here ? i.e. will modifying settings in > >>>>>> xyplot(y > >>>>>> ~x, xx, groups = Farm, type=c('p','smooth')) achieve the same ? > >>>>>> > >>>>>> With your initial reproducible example (thank you) it was easy to > >>>>>> eliminate the errors, but clearly the resulting plots are not > >>>>>> what you > >>>>>> intended (continue inline): > >>>>>> > >>>>>> On Thu, Apr 19, 2012 at 4:23 PM, Duncan Mackay > <<mailto:mackay@northnet.com.au>mackay@northnet.com.au > >>>>>> > > >>>>>> wrote: > >>>>>> <snip> > >>>>>>> > >>>>>>> 3. What I want to be able to add in the above is extra lines with > >>>>>>> different > >>>>>>> values of nn. > >>>>>>> I think I will have to modify panel.Locfit so that it goes > >>>>>>> through > >>>>>>> different values of nn in each of the panels and groups if I want > >>>>>>> different > >>>>>>> colours for extra lines with different nn values > >>>>>> > >>>>>> > >>>>>> Yes you could. There are several options: > >>>>>> add group.number to the arguments of panel.locfit and use it to > >>>>>> make > >>>>>> nn a vector, along the lines of > >>>>>> panel.foo <- function(x,y,group.number,theta,...){ > >>>>>> smpar <- theta[group.number] > >>>>>> panel.loess(x,y,smpar,...) > >>>>>> panel.xyplot(x,y,...) > >>>>>> } > >>>>>> > >>>>>> xyplot (y ~ x ,xx ,group > >>>>>> =Farm,theta=c(4,1,.4),panel=panel.superpose,panel.groups=panel.foo) > >>>>>> > >>>>>> # or > >>>>>> xyplot(y~x|Farm,xx,group=Padd,theta=c(.6,1), > >>>>>> panel=panel.superpose,panel.groups=panel.foo) > >>>>>> > >>>>>> Here you will need to modify the Farm group to 6 levels - 3*two > >>>>>> smoothers. > >>>>>> > >>>>>> You could make nn a list and loop over it inside the panel > >>>>>> function. > >>>>>> Looks like you tried something like that with specifying 2 > >>>>>> panel.Locfit, one suggestion to your code: > >>>>>> > >>>>>> panel.Locfit(x,y,...) # default 0.7 > >>>>>> panel.Locfit(x,y,nn=0.9) # i.e. remove the > >>>>>> ... to avoid clashes > >>>>>> > >>>>>> Finally, use ?trellis.focus to plot the second smoother "post-hoc". > >>>>>> also the latticeExtra package has many useful tools to create > >>>>>> layers > >>>>>> of the same (or different) plot with different settings. > >>>>>> > >>>>>>> 4 Produce an extra line for a fit for all the groups in 1/2+ > >>>>>>> panels. > >>>>>>> As for 3 but I do not know how to group all the x and y's for > >>>>>>> each > >>>>>>> of the > >>>>>>> panes using panel.groups > >>>>>> > >>>>>> > >>>>>> Why does it matter ? seems you have failed to learn the lesson from > >>>>>> the first post - the same functionality applies to 1 as to multiple > >>>>>> panels. Does each panel have a different grouping structure ? use > >>>>>> packet.number() for panels similar to group.number idea. > >>>>>> > >>>>>>> I need to do this and then scale up for a panel function to > >>>>>>> include > >>>>>>> confidence bands > >>>>>> > >>>>>> > >>>>>> than expand the xlim,ylim or scales in ?xyplot > >>>>>> > >>>>>>> > >>>>>>> For the record making Farm and Padd factors. With 1 panel and > >>>>>>> groups > >>>>>>> Farm > >>>>>>> works with the extra line the same colour for its group > >>>>>>> a similar situation for the three panels when conditioned by > >>>>>>> Farm and > >>>>>>> groups > >>>>>>> = Pad > >>>>>> > >>>>>> > >>>>>> ???? > >>>>>> > >>>>>> Like I said I am a little lost on this problem but I hope this > >>>>>> helps > >>>>>> giving some direction. > >>>>>> Cheers > >>>>>> > >>>>>> > >>>>>>> > >>>>>>> xyplot(y ~x, xx, > >>>>>>> groups = Farm, > >>>>>>> > >>>>>>> par.settings = list(strip.background = list(col > >>>>>>> "transparent"), > >>>>>>> superpose.line = list(col > >>>>>>> c("black","grey"), > >>>>>>> lwd > >>>>>>> c(1,2,3), > >>>>>>> lty > >>>>>>> c(2,1,3)), > >>>>>>> superpose.symbol = list(cex = c(0.8, > >>>>>>> 0.7,0.7), > >>>>>>> col > >>>>>>> c("red","black","blue"), > >>>>>>> pch > >>>>>>> c(20,4,16)) > >>>>>>> ), > >>>>>>> auto.key=list(lines=T,points = T,rectangles=F), > >>>>>>> > >>>>>>> panel = panel.superpose, > >>>>>>> panel.groups=function(x,y, ...){ > >>>>>>> > >>>>>>> panel.xyplot(x,y,...) > >>>>>>> panel.Locfit(x,y,...) # default 0.7 > >>>>>>> panel.Locfit(x,y,nn=0.9,...) > >>>>>>> > >>>>>>> } > >>>>>>> ) ## xyplot > >>>>>>> > >>>>>>> > >>>>>>> Regards > >>>>>>> > >>>>>>> Duncan > >>>>>>> > >>>>>>> > >>>>>>> At 02:12 20/04/2012, you wrote: > >>>>>>>> > >>>>>>>> > >>>>>>>> On Thu, Apr 19, 2012 at 2:30 AM, Duncan Mackay > >>>>>>>> <<mailto:mackay@northnet.com.au>mackay@northnet.com.au> > >>>>>>>> wrote: > >>>>>>>>> > >>>>>>>>> Hi > >>>>>>>>> > >>>>>>>>> xyplot(y ~x|Farm,xx, > >>>>>>>>> groups = Padd, > >>>>>>>>> panel = panel.superpose, > >>>>>>>>> panel.groups=function(x,y, ...){ > >>>>>>>>> panel.Locfit(x,y,...) > >>>>>>>>> panel.xyplot(x,y,...) > >>>>>>>>> } > >>>>>>>>> ) ## xyplot > >>>>>>>>> > >>>>>>>>> The above works nicely and also without par.setting giving > >>>>>>>>> lattice > >>>>>>>>> defaults. > >>>>>>>>> The par.setting is handy for a lot of graphs that I do. > >>>>>>>>> > >>>>>>>>> But when I tried a 1 panel plot I get the error message. > >>>>>>>>> > >>>>>>>>> xyplot(y ~x,xx, > >>>>>>>>> groups = Farm, > >>>>>>>>> auto.key=TRUE, > >>>>>>>>> panel = function(x,y, ...){ > >>>>>>>>> > >>>>>>>>> panel.Locfit(x,y,...) > >>>>>>>>> panel.xyplot(x,y,...) > >>>>>>>>> } > >>>>>>>>> ) > >>>>>>>> > >>>>>>>> > >>>>>>>> These two plots are NOT THE SAME. Did you want the same as the > >>>>>>>> first > >>>>>>>> but with groups being Farm and Padd ignored ? in that case you > >>>>>>>> (again) > >>>>>>>> need a panel.groups: > >>>>>>>> > >>>>>>>> xyplot(y ~x,xx, > >>>>>>>> groups = Farm, > >>>>>>>> auto.key=TRUE, > >>>>>>>> panel = panel.superpose,panel.groups=function(x,y,...){ > >>>>>>>> panel.Locfit(x,y,...) > >>>>>>>> panel.xyplot(x,y,...) > >>>>>>>> } > >>>>>>>> ) > >>>>>>>> > >>>>>>>> > >>>>>>>>> If I want to plot another curve with different smoothing > >>>>>>>>> but gives an error message without par.settings if i want to add > >>>>>>>>> panel.Locfit(x,y,nn= 0.9,lwd > >>>>>>>>> c(1,2,3), ...) > >>>>>>>>> > >>>>>>>>> Error using packet 1 > >>>>>>>>> formal argument "Iwd" matched by multiple actual arguments > >>>>>>>> > >>>>>>>> > >>>>>>>> It is all in the way you initially specified how to pass the > >>>>>>>> arguments > >>>>>>>> for panel.Locfit. This works without error: > >>>>>>>> > >>>>>>>> xyplot(y ~x,xx, > >>>>>>>> groups = Farm, > >>>>>>>> auto.key=TRUE,lwd=1:3, > >>>>>>>> panel = panel.superpose,panel.groups=function(x,y,nn,...){ > >>>>>>>> panel.Locfit(x,y,nn=.9,...) > >>>>>>>> panel.xyplot(x,y,...) > >>>>>>>> } > >>>>>>>> ) > >>>>>>>> > >>>>>>>> > >>>>>>>> HTH > >>>>>>>> > >>>>>>>> > >>>>>>>> > >>>>>>>>> I also need to plot a smoothed line for all groups trying > >>>>>>>>> groups, > >>>>>>>>> subscripts > >>>>>>>>> and panel.groups as arguments without success > >>>>>>>>> > >>>>>>>>> Any solutions to solve the above will be gratefully received and > >>>>>>>>> faithfully > >>>>>>>>> applied. > >>>>>>>>> > >>>>>>>>> Duncan > >>>>>>>>> > >>>>>>>>> sessionInfo() > >>>>>>>>> R version 2.15.0 (2012-03-30) > >>>>>>>>> Platform: i386-pc-mingw32/i386 (32-bit) > >>>>>>>>> > >>>>>>>>> locale: > >>>>>>>>> [1] LC_COLLATE=English_Australia.1252 > >>>>>>>>> LC_CTYPE=English_Australia.1252 > >>>>>>>>> LC_MONETARY=English_Australia.1252 LC_NUMERIC=C > >>>>>>>>> LC_TIME=English_Australia.1252 > >>>>>>>>> > >>>>>>>>> attached base packages: > >>>>>>>>> [1] datasets utils stats graphics grDevices grid > >>>>>>>>> methods > >>>>>>>>> base > >>>>>>>>> > >>>>>>>>> other attached packages: > >>>>>>>>> [1] locfit_1.5-7 R.oo_1.9.3 R.methodsS3_1.2.2 > >>>>>>>>> foreign_0.8-49 > >>>>>>>>> chron_2.3-42 MASS_7.3-17 latticeExtra_0.6-19 > >>>>>>>>> RColorBrewer_1.0-5 > >>>>>>>>> [9] lattice_0.20-6 > >>>>>>>>> > >>>>>>>>> loaded via a namespace (and not attached): > >>>>>>>>> [1] tools_2.15.0 > >>>>>>>>> > >>>>>>>>> > >>>> > >>>> > >>>> > >>>> David Winsemius, MD > >>>> West Hartford, CT > >>>> > >>>> > >>>> ______________________________________________ > >>>> <mailto:R-help@r-project.org>R-help@r-project.org mailing list > >>>> > <https://stat.ethz.ch/mailman/listinfo/r-help>https://stat.ethz.ch/mailman/listinfo/r-help > >>>> PLEASE do read the posting guide > >>>> > <http://www.R-project.org/posting-guide.html>http://www.R-project.org/posting-guide.html > >>>> and provide commented, minimal, self-contained, reproducible code. > >> > >> > >> David Winsemius, MD > >> West Hartford, CT > >> > > > > ______________________________________________ > > <mailto:R-help@r-project.org>R-help@r-project.org mailing list > > > <https://stat.ethz.ch/mailman/listinfo/r-help>https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > <http://www.R-project.org/posting-guide.html>http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > >-- > >Bert Gunter >Genentech Nonclinical Biostatistics > >Internal Contact Info: >Phone: 467-7374 >Website: ><http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm>http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > >______________________________________________ ><mailto:R-help@r-project.org>R-help@r-project.org mailing list ><https://stat.ethz.ch/mailman/listinfo/r-help>https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide ><http://www.R-project.org/posting-guide.html>http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]