Re: [R] Split plot analysis problems
I don't think you are clear enough about the layout within each block. If the four treatments are randomized, I would choose the first model. KW On Tue, Jul 21, 2009 at 9:38 AM, Jean-Paul Maalouf jean-paul.maal...@u-bordeaux1.fr wrote: Hello, I would be very grateful if someone could give me a hand with my split plot design problems. So here is my design : I am studying the crossed-effects of water (wet/dry) and mowing (mowed/not-mowed = nm) on plant height (PH) within 2 types of plant communities (Xerobromion and Mesobromion) : - Within each type of communities, I have localised 4 blocks - In each block, I have defined 4 plots in order to have the 4 possible treatments of both the water and mowing factors : nm/dry ; mowed/dry ; mowed/wet ; nm/wet. Here is my data table : Community Block Mowing WaterPH 1 Mesob1 Mowed Wet 7.40 2 Mesob1 nm Wet 13.10 3 Mesob1 Mowed Dry 5.55 4 Mesob1 nm Dry 10.35 5 Mesob2 nm Dry 10.70 6 Mesob2 Mowed Dry 6.38 7 Mesob2 nm Wet 9.75 8 Mesob2 Mowed Wet 6.35 9 Mesob3 nm Wet 9.60 10 Mesob3 Mowed Dry 5.10 11 Mesob3 nm Dry 10.05 12 Mesob3 Mowed Wet 6.25 13 Mesob4 nm Wet 9.00 14 Mesob4 Mowed Wet 6.50 15 Mesob4 nm Dry 7.75 16 Mesob4 Mowed Dry 5.90 17 Xerob5 nm Wet 7.69 18 Xerob5 Mowed Wet 8.11 19 Xerob5 nm Dry 3.98 20 Xerob5 Mowed Dry 3.69 21 Xerob6 nm Wet 5.24 22 Xerob6 Mowed Wet 4.22 23 Xerob6 nm Dry 6.55 24 Xerob6 Mowed Dry 4.40 25 Xerob7 Mowed Dry 3.79 26 Xerob7 nm Dry 3.91 27 Xerob7 nm Wet 9.00 28 Xerob7 Mowed Wet 8.50 29 Xerob8 Mowed Dry 3.33 30 Xerob8 nm Wet 6.25 31 Xerob8 Mowed Wet 8.00 32 Xerob8 nm Dry 6.33 I actually have 2 questions : I wrote my model in two different ways, and there were differences in P-Values according to the model written : First model : summary(aov(PH~Community*Mowing*Water + Error(Block))) Error: Block Df Sum Sq Mean Sq F value Pr(F) Community 1 42.182 42.182 24.407 0.002603 ** Residuals 6 10.370 1.728 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Error: Within Df Sum Sq Mean Sq F valuePr(F) Mowing 1 40.007 40.007 21.1747 0.0002215 *** Water 1 23.120 23.120 12.2370 0.0025673 ** Community:Mowing1 21.060 21.060 11.1467 0.0036554 ** Community:Water 1 6.901 6.901 3.6524 0.0720478 . Mowing:Water1 1.611 1.611 0.8527 0.3680090 Community:Mowing:Water 1 0.858 0.858 0.4542 0.5089331 Residuals 18 34.008 1.889 --- - Second model (assuming that Mowing*Water are nested inside the Block factor) : summary(aov(PH~Community*Mowing*Water + Error(Block/(Mowing*Water Error: Block Df Sum Sq Mean Sq F value Pr(F) Community 1 42.182 42.182 24.407 0.002603 ** Residuals 6 10.370 1.728 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Error: Block:Mowing Df Sum Sq Mean Sq F valuePr(F) Mowing1 40.007 40.007 37.791 0.0008489 *** Community:Mowing 1 21.060 21.060 19.893 0.0042820 ** Residuals 6 6.352 1.059 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Error: Block:Water Df Sum Sq Mean Sq F value Pr(F) Water1 23.1200 23.1200 6.0725 0.04884 * Community:Water 1 6.9006 6.9006 1.8125 0.22685 Residuals6 22.8439 3.8073 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Error: Block:Mowing:Water Df Sum Sq Mean Sq F value Pr(F) Mowing:Water1 1.6110 1.6110 2.0085 0.2062 Community:Mowing:Water 1 0.8581 0.8581 1.0697 0.3409 Residuals 6 4.8126 0.8021 Both models give me interesting (but different!) results. Which one would be the most appropriate? Second question : How can I verify preliminary assumptions (normality of residuals and variance homogeneity) in this kind of models? When I ask R to extract residuals, the answer is NULL: residuals(aov(PH~Community*Mowing*Water + Error(Block/(Mowing*Water NULL residuals(aov(PH~Community*Mowing*Water + Error(Block))) NULL A huge thanks to the one who will rescue (or at least try to rescue) my PhD! Sincerely, -- Jean-Paul Maalouf UMR 1202 BIOGECO Inra - Université Bordeaux 1 Bâtiment B8, Avenue des Facultés 33405 Talence, France Tel : 05 40008772 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help
Re: [R] productivity tools in R?
On Wed, Jul 1, 2009 at 12:35 PM, miguel bernal mber...@marine.rutgers.eduwrote: and debugging. I think there is a package to visualize the links between functions in a package, but I don't know its name (if anybody knows it, I will love to know it). See the 'foodweb' function in the mvbutils package. Kevin [[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.
Re: [R] Sweave template
Frank, Your template is very interesting. The pretty-ifing of the left arrow and tilde in the input chunk has the unfortunate side-effect of making the code non-paste-able into R. I seem to recall that your reports used to include the latex source code as an appendix. Maybe one option could be to include an appendix with the results of Stangle applied to the .Rnw file, formatted as plain text. This would create a concise collection of all the necessary code to reproduce the results. Just brainstorming here Kevin Wright On Sun, Jun 14, 2009 at 11:29 PM, Frank E Harrell Jr f.harr...@vanderbilt.edu wrote: Dear Group, I have made significant improvements to our Sweave template, have made the template self-contained (i.e., you can run it yourself and it will find the datasets it needs), and have included the output pdf file. This is at http://biostat.mc.vanderbilt.edu/SweaveTemplate . You will see in the pdf file the enhancements in how R code is pretty-printed, and I have added an example where some R function output is suppressed from the listing that Sweave typesets. The new template also suggests how to auto-document the computing environment at the end of the report, and how to properly reference R and add-on packages. Figures are centered (but not as nicely as Marc Schwartz' approach) and better defaults are used for axis label and tick mark label positioning. Thanks to Romain Francois for providing the trick of suppressing parts of R output (replacing it with ...) and Peter Ruckdeschel for his excellent SweaveListingUtils package. Suggestions for further improvements are welcomed. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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. [[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.
Re: [R] Excel Export in a beauty way
Also see this post at https://stat.ethz.ch/pipermail/r-help/2008-July/169149.html The same idea is discussed in a SAS proceedings paper (but it is NOT specific to SAS) www.lexjansen.com/wuss/2005/data_presentation/dp_using_*sas*_with_xml.pdfhttp://www.lexjansen.com/wuss/2005/data_presentation/dp_using_sas_with_xml.pdf As Marc indicated, the autofit column widths is a bit confusing. It would be better called set the column width to a number large enough to show all current contents. Kevin On Thu, Jun 4, 2009 at 12:37 AM, Patrick Connolly p_conno...@slingshot.co.nz wrote: On Wed, 03-Jun-2009 at 08:54AM -0500, Marc Schwartz wrote: [...] For example, using the Perl package that I do for the WriteXLS package, it is not possible to use the AutoFit capability to easily set all column widths wide enough to visually allow for the data contained within each. From the available Perl package documentation, this appears to be a run time only feature, which means that it would require Excel to be available and running and the user either going through the column formatting menu, or creating a macro to automate the process. I've used that Perl script for some time and find it very useful (thanks Marc). I can't see a lot of point in trying to get the column widths done by it. In Excel, it's very easy to highlight every column and then double click on the line separating any two column names and that will set ALL the widths to their optimum in one go. (Just in case anyone didn't know.) If that's not sufficient, one of those other methods might suit. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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. [[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.
Re: [R] Changing point color/character in qqmath
Apologies once more, there was a slight error in our example. Here is a correct version of how to color the points in qqmath according to another variable. qqmath(~ yield | variety, data = barley, groups=year, auto.key=TRUE, prepanel = function(x, ...) { list(xlim = range(qnorm(ppoints(length(x) }, panel = function(x, ...) { qx - qnorm(ppoints(length(x)))[rank(x)] panel.xyplot(qx, x, ...) }) Kevin On Wed, May 27, 2009 at 4:39 PM, Kevin W kw.st...@gmail.com wrote: Thanks to Deepayan, I have a corrected version of how to color points in a qqmath plot according to another variable. Using the barley data for a more concise example:: qqmath(~ yield | variety, data = barley, groups=year, auto.key=TRUE, prepanel = function(x, ...) { list(xlim = range(qnorm(ppoints(length(x) }, panel = function(x, ...) { xx - qnorm(ppoints(length(x)))[order(x)] panel.xyplot(x = xx, y = x, ...) }) The example I posted previously (and shown below) is not correct. My apologies. Kevin On Wed, May 27, 2009 at 11:05 AM, Kevin W kw.st...@gmail.com wrote: Having solved this problem, I am posting this so that the next time I search for how to do this I will find an answer... Using qqmath(..., groups=num) creates a separate qq distribution for each group (within a panel). Using the 'col' or 'pch' argument does not (usually) work because panel.qqmath sorts the data (but not 'col' or 'pch') before plotting. Sorting the data before calling qqmath will ensure that the sorting does not change the order of the data. For example, to obtain one distribution per voice part and color the point by part 1 or part 2: library(lattice) singer - singer singer - singer[order(singer$height),] singer$part - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 1), levels = c(Bass, Tenor, Alto, Soprano)) singer$num - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 2)) qqmath(~ height | part, data = singer, col=singer$num, layout=c(4,1)) Kevin [[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.
[R] Changing point color/character in qqmath
Having solved this problem, I am posting this so that the next time I search for how to do this I will find an answer... Using qqmath(..., groups=num) creates a separate qq distribution for each group (within a panel). Using the 'col' or 'pch' argument does not (usually) work because panel.qqmath sorts the data (but not 'col' or 'pch') before plotting. Sorting the data before calling qqmath will ensure that the sorting does not change the order of the data. For example, to obtain one distribution per voice part and color the point by part 1 or part 2: library(lattice) singer - singer singer - singer[order(singer$height),] singer$part - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 1), levels = c(Bass, Tenor, Alto, Soprano)) singer$num - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 2)) qqmath(~ height | part, data = singer, col=singer$num, layout=c(4,1)) Kevin [[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.
Re: [R] Sort matrix by column 1 ascending then by column 2 decending
See also this tip on the R wiki: http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:sort Also available as the orderBy function in the doBy package. Kevin Wright On Wed, May 27, 2009 at 11:19 AM, Linlin Yan yanlinli...@gmail.com wrote: It's a very interesting problem. I just wrote a function for it: order.matrix - function(m, columnsDecreasing = c('1'=FALSE), rows = 1:nrow(m)) { if (length(columnsDecreasing) 0) { col - as.integer(names(columnsDecreasing[1])); values - sort(unique(m[rows, col]), decreasing=columnsDecreasing[1]); unlist(sapply(values, function(x) order.matrix(m, columnsDecreasing[-1], which((1:nrow(m) %in% rows) (m[, col]==x); } else { rows; } } For instance: m - matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4) m [,1] [,2] [1,]2 0.5 [2,]1 0.3 [3,]1 0.5 [4,]3 0.2 m[order.matrix(m),] [,1] [,2] [1,]1 0.3 [2,]1 0.5 [3,]2 0.5 [4,]3 0.2 m[order.matrix(m, c(1=FALSE, 2=TRUE)),] [,1] [,2] [1,]1 0.5 [2,]1 0.3 [3,]2 0.5 [4,]3 0.2 Any comment is welcome! ;) On Wed, May 27, 2009 at 11:04 PM, Linlin Yan yanlinli...@gmail.com wrote: m - matrix( c(2, 1, 1, 3, .5, .3, .5, .2), 4) m [,1] [,2] [1,]2 0.5 [2,]1 0.3 [3,]1 0.5 [4,]3 0.2 m[unlist(sapply(sort(unique(m[,1])), function(x) which(m[,1]==x)[order(m[(m[,1]==x),2], decreasing=TRUE)])),] [,1] [,2] [1,]1 0.5 [2,]1 0.3 [3,]2 0.5 [4,]3 0.2 On Wed, May 27, 2009 at 8:39 PM, Paul Geeleher paulgeele...@gmail.com wrote: I've got a matrix with 2 columns and n rows. I need to sort it first by the values in column 1 ascending. Then for values which are the same in column 1, sort by column 2 decending. For example: 2 .5 1 .3 1 .5 3 .2 Goes to: 1 .5 1 .3 2 .5 3 .2 This is easy to do in spreadsheet programs but I can't seem to work out how to do it in R and haven't been able to find a solution anywhere. Thanks! -Paul. -- Paul Geeleher School of Mathematics, Statistics and Applied Mathematics National University of Ireland Galway Ireland __ 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. __ 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. [[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.
Re: [R] Changing point color/character in qqmath
Thanks to Deepayan, I have a corrected version of how to color points in a qqmath plot according to another variable. Using the barley data for a more concise example:: qqmath(~ yield | variety, data = barley, groups=year, auto.key=TRUE, prepanel = function(x, ...) { list(xlim = range(qnorm(ppoints(length(x) }, panel = function(x, ...) { xx - qnorm(ppoints(length(x)))[order(x)] panel.xyplot(x = xx, y = x, ...) }) The example I posted previously (and shown below) is not correct. My apologies. Kevin On Wed, May 27, 2009 at 11:05 AM, Kevin W kw.st...@gmail.com wrote: Having solved this problem, I am posting this so that the next time I search for how to do this I will find an answer... Using qqmath(..., groups=num) creates a separate qq distribution for each group (within a panel). Using the 'col' or 'pch' argument does not (usually) work because panel.qqmath sorts the data (but not 'col' or 'pch') before plotting. Sorting the data before calling qqmath will ensure that the sorting does not change the order of the data. For example, to obtain one distribution per voice part and color the point by part 1 or part 2: library(lattice) singer - singer singer - singer[order(singer$height),] singer$part - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 1), levels = c(Bass, Tenor, Alto, Soprano)) singer$num - factor(sapply(strsplit(as.character(singer$voice.part), split = ), [, 2)) qqmath(~ height | part, data = singer, col=singer$num, layout=c(4,1)) Kevin [[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.
[R] Any R workshops on BUGS or resampling or other...?
I would like to know about any workshops/meetings on the topics of (1) using some version of BUGS with R (2) resampling methods (3) other advanced courses. Thanks for any ideas. Kevin Wright [[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.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Here's another offering of an attempt to create unique colors. These are light/medium colors...no dark colors. cols - matrix(c(0, 0, .90, # gray .3, 0, .70, .6, 0, .50, 0, .15, 1, # red 0, .30, 1, 0, .45, 1, .08, .3, 1, # orange .08, .5, 1, .08, .7, 1, .17, .3, 1, # yellow # .17, .5, 1, .17, .7, 1, .17, .3, .82, # khaki .17, .7, .80, # .17, .75, .80, .25, .3, 1, # green .25, .5, 1, .25, .75, 1, .40, .35, 1, # cyan .40, .65, 1, #.40, .80, 1, .59, .3, 1, # blue .59, .5, 1, .59, .7, 1, .70, .3, 1, # purple .70, .5, 1, .70, .7, 1, .80, .3, 1, # magenta .80, .5, 1, .80, .7, 1 ), ncol=3, byrow=TRUE) cols - cols[order(cols[,2]+1-1.1*cols[,3]),] # Rough order by 'brightness' cols - hsv(cols[,1], cols[,2], cols[,3]) # Make colors ones - rep(1, length=length(cols)) # Get hsv for labels names(ones) - apply(round(rgb2hsv(col2rgb(c(cols))),2), 2, function(x) {paste(x, collapse=, )}) x - 1:15 y - 1:15 grid - expand.grid(x=x, y=y) grid$z - sample(seq(from=0, to=1, length=length(x)*length(y))) print(levelplot(z~x*y, grid, at=seq(from=0,to=1,length=length(cols)+1), col.regions=cols, colorkey = TRUE, main=Are colors identifiable with the key?)) #pie(ones, col=cols, cex=.75) Kevin Wright On Sat, Mar 14, 2009 at 2:35 PM, Kingsford Jones kingsfordjo...@gmail.comwrote: On Fri, Mar 13, 2009 at 7:58 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks yet again for your help! I have tried this, and once again i have failed! I have put the code that i've used below (i'm sure you'll note some bad practice) It doesn't appear you changed the factor to a character. Here's a reproducible example using 4 colors (but 15 should work the same way) #install.packages(c('TraMineR', 'epitools')) library(TraMineR); library(epitools) data(actcal) mycols - colors.plot(T) #left-click on 4 colors of choosing #then right-click to 'Stop' mycols - as.character(mycols[,3]) seqiplot(seqdef(actcal,13:24), cpal=mycols) If you type choosing colors without the quotes into RSeek you will see many options for choosing colors in R. Be sure to notice the tabs for various types of output in the RSeek results page ('Support Lists', 'Functions', ...). hth, Kingsford Jones if that is any use to help explain where i'm going wrong, it seems to run fine and feeds back just what you noted it would, but i still get the error message as before - if you have any more suggestions i'd be very greatful, i'm sure it is down to me missing something very simple! Thanks again, Ross mycols - colors.plot(T) str(mycols$color.names) Factor w/ 15 levels slategray2,snow3,..: 9 10 11 12 13 14 15 1 2 3 ... ##Factor w/ 4 levels blue,green,..: 3 4 2 1 str(as.character(mycols$color.names)) chr [1:15] tomato1 tomato4 turquoise1 violet violetred4 wheat3 ... ##chr [1:4] tomato1 yellow1 green blue attach(dd) seqiplot(data.seq[1:4,], withlegend=FALSE, ylab=Seal ID, + axes = F, title = 30-09-2008, cpal=mycols) There were 12 warnings (use warnings() to see them) y.lab.pos - c(0.7, 1.9, 3.1, 4.3) axis(2, at=y.lab.pos, labels=paste(ID[1:4], sep=), tick=FALSE) detach(dd) Kingsford Jones wrote: On Fri, Mar 13, 2009 at 7:19 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Many thanks yet again for your reply, thanks for that method, i gave it a go and i checked 'mycols' and sure enough it had selected the chosen colours and listed their names, but when i used it for making the graph warnigs informed me that the supplied colour in not numeric or character. The data frame holds is storing the colors as class factor. You'll need to convert to character. Note mycols - colors.plot(T) str(mycols$color.names) Factor w/ 4 levels blue,green,..: 3 4 2 1 str(as.character(mycols$color.names)) chr [1:4] tomato1 yellow1 green blue hth, Kingsford Ross Kingsford Jones wrote: One option for creating your own palette is #install.packages('epitools') mycols - colors.plot(locator = TRUE) then left-click on 15 colors of your liking and then right-click 'Stop'. mycols will be a data.frame with the third column containing the color names. Kingsford On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the