[R] Innovations algorithm
Dear list, I am urgently searching an implementation of the classical innovations algorithm (see, e.g. Brockwell and Davis, Time Series: Theory and Methods) for time series prediction to be used with R (which unfortunately doesn't have this algorithm implemented). Mohamed [[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] Predator Prey Models
Craig O'Connell-2 wrote: Dear R-users, I am currently modifying a previously developed predator prey model and was curious if there was a way to add in a disturbance to the model (let's say at time t=100). The disturbance can be the introduction of 40 prey (N=40) and 10 predators (Pred = 10). I would like to see my model go from a state of equilibrium (up to t = 99), show this disturbance (at t = 100) and then slowly work its way back to equilibrium. Does anybody know if this could be done? You can also use package simecol, (imports deSolve), as follows: library(simecol) LVmod0D - new(odeModel, main = function(time, state, pars) { with(as.list(c(state,pars)), { IngestPred - rI * N * Pred GrowthN- rG * N * (1 - N/K) MortPred - rM * Pred dN- GrowthN - IngestPred dPred - IngestPred * AE - MortPred return(list(c(dN, dPred))) }) }, parms = c(rI = 0.1, rG = 0.9, rM = 0.8, AE = 0.9, K = 20), times = seq(0, 200, by = 1), init = c(N = 20, Pred = 20) , solver=lsoda ) # from reply of previous poster Levents - list(data=data.frame(var=c(N,Pred),time=rep(100,2), value=c(40,10),method=rep(add,2))) Levents lv.sim - sim(LVmod0D,events=Levents) lv.out - out(lv.sim) lv.out plot(lv.sim) I'm not quite sure if the specification of the events is what you need. If I understood correctly this would be more what you want: Levents - list(data=data.frame(var=c(N,Pred),time=rep(100,2), value=c(40,10),method=rep(rep,2))) best Berend -- View this message in context: http://r.789695.n4.nabble.com/Predator-Prey-Models-tp3083759p3084165.html Sent from the R help mailing list archive at Nabble.com. __ 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 in defining vectors
I am completely new to R . while defining a vector i get these following messages c-a(1,2) Error: could not find function a or c=a(1,2) Error: could not find function a Kindly advice, how to get rid of this. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Help-in-defining-vectors-tp3084142p3084142.html Sent from the R help mailing list archive at Nabble.com. __ 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] Help in defining vectors
try a-c(1,2) On Sun, Dec 12, 2010 at 10:57 AM, skd warab...@gmail.com wrote: I am completely new to R . while defining a vector i get these following messages c-a(1,2) Error: could not find function a or c=a(1,2) Error: could not find function a Kindly advice, how to get rid of this. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Help-in-defining-vectors-tp3084142p3084142.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Help in defining vectors
On 2010-12-12 01:57, skd wrote: I am completely new to R . while defining a vector i get these following messages c-a(1,2) Error: could not find function a or c=a(1,2) Error: could not find function a Kindly advice, how to get rid of this. Easy. Read 'An Introduction to R', chapter 2. Peter Ehlers Thanks! __ 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] (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?
On 11/12/2010 5:58 PM, Emmanuel Charpentier wrote: Dear list, Inspired by the original Knuth tools, and for paedaogical reasons, I wish to produce a document presenting some source code with interspersed comments in the source (see Knuth's books rendering TeX and metafont sources to see what I mean). I seemed to remember that a code chunk could be defined piecewise, like in Comments... Chunk1, eval=FALSE, echo=TRUE= SomeCode @ Some other comments... Chunk2, eval=FALSE, echo=TRUE= MoreCode @ And finally, Chunk3, eval=TRUE, echo=TRUE= Chunk1 Chunk2 EndOfTheCode @ That works ... as long as SomeCode, MoreCode and EndOfTheCode are self- standing pieces of R code, but *not* code fragments. You can *not* intersperse comments in, say, a function body, or local() environment this way : when Sweaving, *R* complains of an incomplete source (makes noise about an unexpected end of input at the end of Chunk1, IIRC, and never sees Chunk2). I hoped that Sweave's alternative syntax could offer a way out : no such luck. There seems to be no way to delay R evaluation of a R chunk passed by Sweave ; at least, the eval=FALSE option of chunk declaration is not sufficient for that. It's not evaluation, it's parsing, but you're right: there's no way to delay it. Perhaps Sweave needs a parse=FALSE option. Am I missing something in the Sweave nd odfWeve documentations (that I read till I grew green and moldy) ? Or does this require a fundamental change in the relevant Sweave drivers ? I suspect the latter. Can you suggest alternative ways of doing what I mean to do ? The only workaround I found is to paste a second copy of my code in a \verbatim environment (or, in the case of odfWeave, in the text part), and spice it with \end{verbatim} comments.. \begin{verbatim} chunks. This way, I lose any guarantee of consistency between commented text and effective code. Not any very satisfactory suggestions: - write smaller functions, and make up your large function out of calls to them. Then you can define a whole small function in one chunk. - use keep.source=TRUE, and use R comments rather than nicely typeset ones if you need to make comments within a function definition. I don't know any way to get what you were asking for, but perhaps these are close enough. Duncan Murdoch Any other idea ? Emmanuel Charpentier __ 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.
Re: [R] help requested
On Sat, Dec 11, 2010 at 05:11:37AM -0800, profaar wrote: hi thanks for your reply. there are around 2 nodes in my dataset. will it work for conversion from edge list format to node list format? I am using R under Windows XP. Under Linux, with 20'000 nodes and 10 random edges from each of them, this took abuot 108 sec (CPU 2.4 GHz). The advantage of this solution is that there may be further functions in the package graph (see also class?graphNEL), which could be used in your application. If not, then the conversion itself may be done more efficiently, for example edges - read.table(file=stdin()) 1 2 1 3 1 4 1 5 2 3 2 4 3 2 4 1 4 3 4 5 5 2 5 4 out1 - split(edges$V2, edges$V1) out1 $`1` [1] 2 3 4 5 $`2` [1] 3 4 $`3` [1] 2 $`4` [1] 1 3 5 $`5` [1] 2 4 For the example with 20'000 nodes and 10 random edges from each, this took about 0.2 sec. The output out1 is a list of vectors. This may be transformed to a vector of strings, for example out2 - sapply(out1, paste, collapse= ) cbind(out2) # cbind() is only for a column output out2 1 2 3 4 5 2 3 4 3 2 4 1 3 5 5 2 4 and to a text (with a possible file= argument) cat(paste(names(out2), out2), sep=\n) 1 2 3 4 5 2 3 4 3 2 4 1 3 5 5 2 4 Petr Savicky. __ 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] (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?
On Sat, Dec 11, 2010 at 5:58 PM, Emmanuel Charpentier emm.charpent...@free.fr wrote: Dear list, Inspired by the original Knuth tools, and for paedaogical reasons, I wish to produce a document presenting some source code with interspersed comments in the source (see Knuth's books rendering TeX and metafont sources to see what I mean). I seemed to remember that a code chunk could be defined piecewise, like in Comments... Chunk1, eval=FALSE, echo=TRUE= SomeCode @ Some other comments... Chunk2, eval=FALSE, echo=TRUE= MoreCode @ And finally, Chunk3, eval=TRUE, echo=TRUE= Chunk1 Chunk2 EndOfTheCode @ That works ... as long as SomeCode, MoreCode and EndOfTheCode are self- standing pieces of R code, but *not* code fragments. You can *not* intersperse comments in, say, a function body, or local() environment this way : when Sweaving, *R* complains of an incomplete source (makes noise about an unexpected end of input at the end of Chunk1, IIRC, and never sees Chunk2). I hoped that Sweave's alternative syntax could offer a way out : no such luck. There seems to be no way to delay R evaluation of a R chunk passed by Sweave ; at least, the eval=FALSE option of chunk declaration is not sufficient for that. Am I missing something in the Sweave nd odfWeve documentations (that I read till I grew green and moldy) ? Or does this require a fundamental change in the relevant Sweave drivers ? Can you suggest alternative ways of doing what I mean to do ? The only workaround I found is to paste a second copy of my code in a \verbatim environment (or, in the case of odfWeave, in the text part), and spice it with \end{verbatim} comments.. \begin{verbatim} chunks. This way, I lose any guarantee of consistency between commented text and effective code. Any other idea ? Try the brew package. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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] (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?
On Sun, Dec 12, 2010 at 2:24 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try the brew package. There is another package, markup, which is similar to brew and Sweave. See some comments in this thread [1]. To my knowledge it was never officially released, but you could still try it out. Regards Liviu [1] http://www.mail-archive.com/r-help@r-project.org/msg109238.html __ 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] legend not appearing in Word document
I need help with using graphics in Word 2007 that will later be converted into a pdf document. I have tried several formats and found that I get the best quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get a bunch of lines across the figures. I also tried .tiff and .png but they give me much lower quality. The best quality that converts to pdf appears to be .eps. However, I have now come across a problem with my figure legends. For some reason the legend is visible in R but not in Word. Does anyone know why a legend in .eps format won't work in Word, or how I can get it to work? I have made an example of the legend below that you should be able to save as .eps and paste into Word as an example. I would appreciate any help you can offer on getting the legend in .eps format to work, or on other formats that may be better for Word and pdf files. Thanks, Tim library(plotrix) Satelite.Palette - colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red)) mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 100 to give larger range. Max is 3.1415, rounded up to 3.15 plus one. col.labels-round((seq(0,5000,length.out=5)/1000),1) plot(0, 0, type=n, axes=F, xlab=, ylab=) #New plot for legend color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y) #Adds legend Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 __ 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] legend not appearing in Word document
On 12/12/2010 8:59 AM, Tim Clark wrote: I need help with using graphics in Word 2007 that will later be converted into a pdf document. I have tried several formats and found that I get the best quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get a bunch of lines across the figures. I also tried .tiff and .png but they give me much lower quality. The best quality that converts to pdf appears to be .eps. However, I have now come across a problem with my figure legends. For some reason the legend is visible in R but not in Word. Does anyone know why a legend in .eps format won't work in Word, or how I can get it to work? I have made an example of the legend below that you should be able to save as .eps and paste into Word as an example. I would appreciate any help you can offer on getting the legend in .eps format to work, or on other formats that may be better for Word and pdf files. Thanks, Tim library(plotrix) Satelite.Palette- colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red)) mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 100 to give larger range. Max is 3.1415, rounded up to 3.15 plus one. col.labels-round((seq(0,5000,length.out=5)/1000),1) plot(0, 0, type=n, axes=F, xlab=, ylab=) #New plot for legend color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y) #Adds legend I don't have Word 2007, but when I execute that code I get a legend either on screen or in an EPS file. So this looks like a Word bug; you'll need to talk to Microsoft. Duncan Murdoch __ 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] Why do we have to turn factors into characters for various functions?
Well ... because These are language design issues, and you therefore need to understand something about computer languages to understand the context. Here are brief answers that offer my take; others may be able to fill in or correct. 1. The factor type/class is R's version of C's enum declaration. So you might want to read about that. It can save a lot of storage space (perhaps not as relevant now as 30 years ago), provide associative arrays, and so forth. This is quite useful. But, as you have observed, there are some gotcha's due to confusion between the internal representation of factors (as integers) and the external view (as vectors of character strings given by the levels attribute). Some quite wise folks (Terry Therneau is one, I believe) have found factors sufficiently annoying (especially within data frames) that they recommend their avoidance. 2. The business with strsplit() reflects R's object oriented structure and has essentially nothing to do with factors, per se. strsplit() is a function defined only for character data and is not a generic with a method for factors. Period. Whence the error message. You could, of course, easily make it generic with a factor method (via as.character, presumably). HTH, -- Bert On Sat, Dec 11, 2010 at 4:13 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi Tal, I always think of factors as a way of imposing (however arbitrarily) order on some variable. To that extent, the key aspect is first, second, third, etc., represented numerically in factors as 1, 2, 3, etc. . The labels are for convenience and interpretation. Consider: x - factor(c(5, 4, 6)) y - factor(c(6, 5, 7)) as.numeric(x) as.numeric(y) Is there numeric or character value of 5 more important? Or is its relative position? If you have character data that you might want to split and manipulate, store it as a string variable (you can set an option so stringsAsFactors = FALSE by default in read.table()). If your factor labels are numeric, that suggests it might have been better stored as numeric in the first place. Generally, when I find myself converting factors to numeric or character class data, it means I've been using factor() to recode data (which is not its intended purpose). My 2 cents. Cheers, Josh On Sat, Dec 11, 2010 at 2:48 PM, Tal Galili tal.gal...@gmail.com wrote: Hello dear R-help mailing list, My question is *not* about how factors are implemented in R (which is, if I understand correctly, that factors keeps numbers and assign levels to them). My question *is* about why so many functions that work on factors don't treat them as characters by default? Here are two simple examples: Example one turning the characters inside a factor into numeric: x - factor(4:6) as.numeric(x) # output: 1 2 3 as.numeric(as.character(x)) # output: 4 5 6 # isn't this what we wanted? Example two, using strsplit on a factor: x - factor(paste(letters[4:6], 4:6, sep=A)) strsplit(x, A) # will result in an error: # Error in strsplit(x, A) : non-character argument strsplit(as.character(x), A) # will work and split So what is the reason this is the case? Is it that implementing a switch of factors to characters as the default in some of the basic function will cause old code to break? Is it a better design in some other way? I am curious to know the reason for this. Thank you for your reading, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ 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. -- Bert Gunter Genentech Nonclinical Biostatistics 467-7374 http://devo.gene.com/groups/devo/depts/ncb/home.shtml __ 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] Submissions that include an entire previous digest
Colleagues, Today's digest (Volume 94, Issue 12) contained an entire copy of Digest, Vol 94, Issue 11. It appears that an inconsiderate poster (Message 39 in Issue 12) received the digest and clicked reply, thereby including the entire digest in his/her submission ( 6000 additional lines of text). This made it difficult to scroll through the digest efficiently. At minimum, posters should be aware that this is inconsiderable behavior. Is there some means for the mailing list to detect submissions that contain the entirety of a previous digest (e.g., rejecting emails that contain both Subject: R-help Digest, Vol XX, Issue YY and End of R-help Digest, Vol XX, Issue YY) to prevent this problem? Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ 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] R Plots for Recurrent Events - Suggestions are needed
Hi, I am wondering if there is a simple way to plot MCF(mean cumulative function) for recurrent events in R? MCF (http://www.weibull.com/hotwire/issue57/relbasics57.htm) And do you have some other recommendation in visualize recurrent events? I did some research online. Some people use ggplot2 to plot MCF, but it requires some additional coding. http://user2010.org/slides/Shentu.pdf Your help and suggestions are highly appreciated. Warm regards from Haoda __ 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] Submissions that include an entire previous digest
On 12 December 2010 at 08:13, Dennis Fisher wrote: | Colleagues, | | Today's digest (Volume 94, Issue 12) contained an entire copy of Digest, Vol 94, Issue 11. It appears that an inconsiderate poster (Message 39 in Issue 12) received the digest and clicked reply, thereby including the entire digest in his/her submission ( 6000 additional lines of text). This made it difficult to scroll through the digest efficiently. | | At minimum, posters should be aware that this is inconsiderable behavior. | | Is there some means for the mailing list to detect submissions that contain the entirety of a previous digest (e.g., rejecting emails that contain both Subject: R-help Digest, Vol XX, Issue YY and End of R-help Digest, Vol XX, Issue YY) to prevent this problem? By default, mailman (the Python software running this and many other mailing lists) has a default size of 40 kB per post. Default behaviour is to let the moderator handle the post, one could also automatically reject it. We could obviously dial the size down. And speaking just for myself, I would have no problem unsubscribing serial abusers of the list but others, including the kind sould patrolling this as moderators, are more forgiving. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com __ 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] legend not appearing in Word document
On Sun, Dec 12, 2010 at 3:59 PM, Tim Clark mudiver1...@yahoo.com wrote: I need help with using graphics in Word 2007 that will later be converted into a pdf document. I have tried several formats and found that I get the best quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get a bunch of lines across the figures. I also tried .tiff and .png but they give me much lower quality. The best quality that converts to pdf appears to be .eps. However, I have now come across a problem with my figure legends. For some reason the legend is visible in R but not in Word. Does anyone know why a legend in .eps format won't work in Word, or how I can get it to work? I have made an example of the legend below that you should be able to save as .eps and paste into Word as an example. I would appreciate any help you can offer on getting the legend in .eps format to work, or on other formats that may be better for Word and pdf files. Thanks, Tim library(plotrix) Satelite.Palette - colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red)) mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 100 to give larger range. Max is 3.1415, rounded up to 3.15 plus one. col.labels-round((seq(0,5000,length.out=5)/1000),1) plot(0, 0, type=n, axes=F, xlab=, ylab=) #New plot for legend color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y) #Adds legend Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 Tim Works in Word 2002 on Windows XP with PDF-xchange 3.0 to convert to pdf. Saw reponse from Duncan - agree might be problem with Word 2007 PDF converter. HTH [[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] 95% CI of a IQR and more
Hi guys! I have to calculate the 95% CI for the IQR. I have 100samples with continuous numbers using a compute-intensive method. 1)I can calculate the 95%CI and the IQR, but I don't know how to calculate the CI of the IQR, does anybody have any idea, which method will be appropriate? 2)I have a 2x2 table with gender vs blue eyes or not. How do I calculate the expected two-by-two contingency tables? Do I assume that half the people are female and half are males. And assume some random chance of your eyecolor being blue? 3) I have to use a permutation test, to calculate whether there is a difference in the median of two samples. - How do I do that? I thought permutation test only was for categorical data? Please help! -- View this message in context: http://r.789695.n4.nabble.com/95-CI-of-a-IQR-and-more-tp3084348p3084348.html Sent from the R help mailing list archive at Nabble.com. __ 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] legend not appearing in Word document
Tim Works in Word 2002 on Windows XP with PDF-xchange 3.0 to convert to pdf. Saw reponse from Duncan - agree might be problem with Word 2007 PDF converter. HTH Schalk On Sun, Dec 12, 2010 at 3:59 PM, Tim Clark mudiver1...@yahoo.com wrote: I need help with using graphics in Word 2007 that will later be converted into a pdf document. I have tried several formats and found that I get the best quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get a bunch of lines across the figures. I also tried .tiff and .png but they give me much lower quality. The best quality that converts to pdf appears to be .eps. However, I have now come across a problem with my figure legends. For some reason the legend is visible in R but not in Word. Does anyone know why a legend in .eps format won't work in Word, or how I can get it to work? I have made an example of the legend below that you should be able to save as .eps and paste into Word as an example. I would appreciate any help you can offer on getting the legend in .eps format to work, or on other formats that may be better for Word and pdf files. Thanks, Tim library(plotrix) Satelite.Palette - colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red)) mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 100 to give larger range. Max is 3.1415, rounded up to 3.15 plus one. col.labels-round((seq(0,5000,length.out=5)/1000),1) plot(0, 0, type=n, axes=F, xlab=, ylab=) #New plot for legend color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y) #Adds legend Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 __ 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] legend not appearing in Word document
Have you tried opening your stuff in OpenOffice? Often that converts files better than M$oft Word. And you can save an OO.o document in .doc (and I believe .docx) format. __ 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] Why do we have to turn factors into characters for various functions?
On 12/11/2010 04:48 PM, Tal Galili wrote: Hello dear R-help mailing list, My question is *not* about how factors are implemented in R (which is, if I understand correctly, that factors keeps numbers and assign levels to them). My question *is* about why so many functions that work on factors don't treat them as characters by default? Here are two simple examples: Example one turning the characters inside a factor into numeric: x- factor(4:6) as.numeric(x) # output: 1 2 3 as.numeric(as.character(x)) # output: 4 5 6 # isn't this what we wanted? But your example of 'x' is a very special case. Most factors will not have numeric levels as you have constructed. Most levels will be categorical such as Sex, Race, Country of Origin, Treatment, etc. These are stored as numeric codes (R's enumerated type class), and most modeling functions treat variables of class factor differently. So, as.numeric(x) will just return the numeric codes regardless of the levels of the factor, which is fine. It seems you may be silently suggesting that *if* the levels of the factor are themselves able to be coerced to numeric, then as.numeric(x) should return that instead of the underlying numeric codes. Of course, having functions do different things depending on the particular input is dangerous, thus we have the behavior as it is currently implemented. __ 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] 95% CI of a IQR and more
On Dec 12, 2010, at 10:13 AM, Beckie wrote: Hi guys! I have to calculate the 95% CI for the IQR. I have 100samples with continuous numbers using a compute-intensive method. 1)I can calculate the 95%CI and the IQR, but I don't know how to calculate the CI of the IQR, does anybody have any idea, which method will be appropriate? You could bootstrap the distribution of the 25th and 75th order statistics in your sample or you could look up the analytical distribution in David's Order Statistics. I can assure you that the first option will be easier. Come to think of it that would not actually answer the question, but it should point you to a particular class of tools. 2)I have a 2x2 table with gender vs blue eyes or not. Making this sound even very much more like homework. (HW not generally encouraged on R-help. Suggest you read the Posting Guide.) How do I calculate the expected two-by-two contingency tables? Do I assume that half the people are female and half are males. And assume some random chance of your eyecolor being blue? Doesn't sound right to me. You might want to look at the documentation and code for fisher.test(). 3) I have to use a permutation test, to calculate whether there is a difference in the median of two samples. - How do I do that? I thought permutation test only was for categorical data? Check out the coin package. -- 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.
[R] list manipulation
Hi R users! Does anyone know command similar to cbind for adding a column to a object of the list. For example on this list: c1 $`1` x11 x22 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 $`2` x11 x22 6 2 6 7 2 7 8 2 8 9 2 9 10 2 10 11 2 11 i would like to add column, named random created with - runif(5)-, to the first object in order to obtain something like this: c1 $`1` x11 x22 random 1 1 1 0.5624256 2 1 2 0.6752097 3 1 3 0.1005275 4 1 4 0.3325556 5 1 5 0.7650282 $`2` x11 x22 6 2 6 7 2 7 8 2 8 9 2 9 10 2 10 11 2 11 thanks in advance for help. Regards Andrija [[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] list manipulation
On Dec 12, 2010, at 1:18 PM, andrija djurovic wrote: Hi R users! Does anyone know command similar to cbind for adding a column to a object of the list. For example on this list: c1 $`1` x11 x22 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 So item `1` is probably a data.frame. $`2` x11 x22 6 2 6 7 2 7 8 2 8 9 2 9 10 2 10 11 2 11 i would like to add column, named random created with - runif(5)-, to the first object in order to obtain something like this: c1 $`1` x11 x22 random 1 1 1 0.5624256 2 1 2 0.6752097 3 1 3 0.1005275 4 1 4 0.3325556 5 1 5 0.7650282 Try c1[[1]] - cbind(c1[[1]], runif(5)) (Untested. I supposed you could argue that you had provided a reproducible example, but going through the hoops of creating two such dataframes and then creating a list to hold them seems something that you should have provided code for rather than posting just console output.) -- David. $`2` x11 x22 6 2 6 7 2 7 8 2 8 9 2 9 10 2 10 11 2 11 -- 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.
Re: [R] Why do we have to turn factors into characters for various functions?
On Sun, Dec 12, 2010 at 12:48:30AM +0200, Tal Galili wrote: Hello dear R-help mailing list, My question is *not* about how factors are implemented in R (which is, if I understand correctly, that factors keeps numbers and assign levels to them). My question *is* about why so many functions that work on factors don't treat them as characters by default? Personally, i try to use factors only when there is a specific reason for this and character type otherwise. Factors are natural in the data used for construction of a classification model or for categorical attributes, also for preparing input to table() function and related things. Here are two simple examples: Example one turning the characters inside a factor into numeric: x - factor(4:6) as.numeric(x) # output: 1 2 3 as.numeric(as.character(x)) # output: 4 5 6 # isn't this what we wanted? If you are concerned with computing time, then applying as.numeric() only to the levels is probably better x - factor(rep(4:6, times=100)) cpu1 - system.time( out1 - as.numeric(as.character(x)) ) cpu2 - system.time( out2 - as.numeric(levels(x))[as.integer(x)] ) rbind(cpu1, cpu2) user.self sys.self elapsed user.child sys.child cpu1 0.5700.031 0.601 0 0 cpu2 0.0420.027 0.070 0 0 Is it that implementing a switch of factors to characters as the default in some of the basic function will cause old code to break? I think that this is an important part of the reason. Petr Savicky. __ 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] Tukey HSD not working
DrugUS1 US2 Aptecha Celebrex235.54 269.99 121.02 Detrol LA 157.99 190.99 55.3 Flomax 166.00 190.99 93.45 Lipitor 174.99 200.99 137.7 Novaldex108.6 129.99 22.48 Norvasc 186.66 203.99 161.93 Plavix 107.99 106.99 64.53 Prevacid117.39 134.99 59.83 Prilosec115.99 126.99 57.75 Zyrtec 181.1 200.99 58.79 US1=c(235.54,157.99,166,174.99,108.60,186.66,107.99,117.39,115.99,181.10) US2=c(269.99,190.99,190.99,200.99,129.99,203.99,106.99,134.99,126.99,200.99) Aptecha=c(121.02,55.30,93.45,137.70,22.48,161.93,64.53,59.83,57.75,58.79) y=c(US1,US2,Aptecha) n=rep(10,3) group=rep(1:3,n) data = data.frame(y = y, group = factor(group)) fit = lm(y ~ group, data) anova(fit) summary (fit) -- View this message in context: http://r.789695.n4.nabble.com/Tukey-HSD-not-working-tp3084505p3084505.html Sent from the R help mailing list archive at Nabble.com. __ 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] How to print colorful R output??
Hi All, My aim is actually not that complicated as you guys understand. What I want is this, when I print it by clicking File-- Print... It gaves me a black white output. But what I want is 'red', for all the codes i typed in, 'blue', for the R output, just like the console. Thanks! (I am using windows xp) casper -- View this message in context: http://r.789695.n4.nabble.com/How-to-print-colorful-R-output-tp3082750p3084578.html Sent from the R help mailing list archive at Nabble.com. __ 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] Why do we have to turn factors into characters for various functions?
At 12.12.2010 00:48 +0200, Tal Galili wrote: Hello dear R-help mailing list, My question is *not* about how factors are implemented in R (which is, if I understand correctly, that factors keeps numbers and assign levels to them). My question *is* about why so many functions that work on factors don't treat them as characters by default? Here are two simple examples: Example one turning the characters inside a factor into numeric: x - factor(4:6) as.numeric(x) # output: 1 2 3 as.numeric(as.character(x)) # output: 4 5 6 # isn't this what we wanted? Example two, using strsplit on a factor: x - factor(paste(letters[4:6], 4:6, sep=A)) strsplit(x, A) # will result in an error: # Error in strsplit(x, A) : non-character argument strsplit(as.character(x), A) # will work and split So what is the reason this is the case? Is it that implementing a switch of factors to characters as the default in some of the basic function will cause old code to break? Is it a better design in some other way? I am curious to know the reason for this. In my view the answer can be found implicitly in the language definition. Factors are currently implemented using an integer array to specify the actual levels and a second array of names that are mapped to the integers. Rather unfortunately users often make use of the implementation in order to make some calculations easier. It is the unfortunate use of factors that seems generally accepted, even if the language definition continues: This, however, is an implementation issue and is not guaranteed to hold in all implementations of R. Personally, like some others, I avoid factors, except in cases, where they represent a statistical concept. Certainly I would agree with you that, if only reading the R Language Definition and not the documentation of the function factor, one would rather expect functions like as.numeric or strsplit to operate on the levels of a factor and not on the underlying, implementation specific, integer array. Heinz Thank you for your reading, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[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-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] Tukey HSD not working
On 2010-12-12 10:21, PGZC wrote: DrugUS1 US2 Aptecha Celebrex235.54 269.99 121.02 Detrol LA 157.99 190.99 55.3 Flomax 166.00 190.99 93.45 Lipitor 174.99 200.99 137.7 Novaldex108.6 129.99 22.48 Norvasc 186.66 203.99 161.93 Plavix 107.99 106.99 64.53 Prevacid117.39 134.99 59.83 Prilosec115.99 126.99 57.75 Zyrtec 181.1 200.99 58.79 US1=c(235.54,157.99,166,174.99,108.60,186.66,107.99,117.39,115.99,181.10) US2=c(269.99,190.99,190.99,200.99,129.99,203.99,106.99,134.99,126.99,200.99) Aptecha=c(121.02,55.30,93.45,137.70,22.48,161.93,64.53,59.83,57.75,58.79) y=c(US1,US2,Aptecha) n=rep(10,3) group=rep(1:3,n) data = data.frame(y = y, group = factor(group)) fit = lm(y ~ group, data) anova(fit) summary (fit) The following did appear on that infernal Nabble list but for some reason did not make it to my mail reader: my problem is that ive been trying to do TukeyHSD on this and an error comes up it cant find or use fit, data, group, etc It would seem obvious that you should include just what do TukeyHSD on this means in your world, i.e. what *code* did you use? It would also make *really* good sense to quote the exact error message, which I divine to be: Error in UseMethod(TukeyHSD) : no applicable method for 'TukeyHSD' applied to an object of class lm and which further would seem to be pretty self-explanatory especially in light of this from the help page: x A fitted model object, usually an aov fit. So why not try an *aov* fit? Works for me. Peter Ehlers __ 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] legend not appearing in Word document
Thanks, I will take it up with MS. I just downloaded their latest converter and that hasn't fixed the issue. Hopefully they will have additional advice. Aloha, Tim Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 From: Schalk Heunis schalk.heu...@enerweb.co.za Cc: r help r-help r-help@r-project.org; Tim Clark tim_cl...@nps.gov Sent: Sun, December 12, 2010 6:05:23 AM Subject: Re: [R] legend not appearing in Word document Tim Works in Word 2002 on Windows XP with PDF-xchange 3.0 to convert to pdf. Saw reponse from Duncan - agree might be problem with Word 2007 PDF converter. HTH Schalk I need help with using graphics in Word 2007 that will later be converted into a pdf document. I have tried several formats and found that I get the best quality of graphics using .wmf, .eps format, but when I convert it to .pdf I get a bunch of lines across the figures. I also tried .tiff and .png but they give me much lower quality. The best quality that converts to pdf appears to be .eps. However, I have now come across a problem with my figure legends. For some reason the legend is visible in R but not in Word. Does anyone know why a legend in .eps format won't work in Word, or how I can get it to work? I have made an example of the legend below that you should be able to save as .eps and paste into Word as an example. I would appreciate any help you can offer on getting the legend in .eps format to work, or on other formats that may be better for Word and pdf files. Thanks, Tim library(plotrix) Satelite.Palette - colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red)) mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 100 to give larger range. Max is 3.1415, rounded up to 3.15 plus one. col.labels-round((seq(0,5000,length.out=5)/1000),1) plot(0, 0, type=n, axes=F, xlab=, ylab=) #New plot for legend color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y) #Adds legend Tim Clark Marine Ecologist National Park of American Samoa Pago Pago, AS 96799 __ 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] Specifying Prior Weights in a GLM
Hey Dennis, Thank you. This was helpful. It looks like the structure of my code was incorrect. I was using a variable containing proportions as my D.V. instead of using a two column vector. I re-ran the code using the following: Y-(successes/trials) -Enrique -- View this message in context: http://r.789695.n4.nabble.com/Specifying-Prior-Weights-in-a-GLM-tp3083480p3084674.html Sent from the R help mailing list archive at Nabble.com. __ 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] legend not appearing in Word document
On Sun, Dec 12, 2010 at 3:13 PM, Tim Clark mudiver1...@yahoo.com wrote: Thanks, I will take it up with MS. I just downloaded their latest converter and that hasn't fixed the issue. Hopefully they will have additional advice. Try installing the free bullzip printer driver and then try printing it to pdf. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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] Summary (Re: (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?)
Dear list, see comment at end. On Sat, 11 Dec 2010 22:58:10 +, Emmanuel Charpentier wrote : Dear list, Inspired by the original Knuth tools, and for paedaogical reasons, I wish to produce a document presenting some source code with interspersed comments in the source (see Knuth's books rendering TeX and metafont sources to see what I mean). I seemed to remember that a code chunk could be defined piecewise, like in Comments... Chunk1, eval=FALSE, echo=TRUE= SomeCode @ Some other comments... Chunk2, eval=FALSE, echo=TRUE= MoreCode @ And finally, Chunk3, eval=TRUE, echo=TRUE= Chunk1 Chunk2 EndOfTheCode @ That works ... as long as SomeCode, MoreCode and EndOfTheCode are self- standing pieces of R code, but *not* code fragments. You can *not* intersperse comments in, say, a function body, or local() environment this way : when Sweaving, *R* complains of an incomplete source (makes noise about an unexpected end of input at the end of Chunk1, IIRC, and never sees Chunk2). I hoped that Sweave's alternative syntax could offer a way out : no such luck. There seems to be no way to delay R evaluation of a R chunk passed by Sweave ; at least, the eval=FALSE option of chunk declaration is not sufficient for that. Am I missing something in the Sweave nd odfWeve documentations (that I read till I grew green and moldy) ? Or does this require a fundamental change in the relevant Sweave drivers ? Can you suggest alternative ways of doing what I mean to do ? The only workaround I found is to paste a second copy of my code in a \verbatim environment (or, in the case of odfWeave, in the text part), and spice it with \end{verbatim} comments.. \begin{verbatim} chunks. This way, I lose any guarantee of consistency between commented text and effective code. Any other idea ? Emmanuel Charpentier To summarize the answers I got so far, there seems to be no satisfactory solutions to my current problem with either Sweave or odfWeave : - every (Sw|odfW)eave code chunk has to be parseable in itself. One cannot break it in unparseable pieces in home to paste it later ; - the (hypothetical) parse=FALSE option, suggested by Duncan Murdoch, is, well, hypothetical ; - the brew package is not integrated in either Sweave or odfWeave ; - R-style comments will get you only so far (where is math markup when you need it ?) ; - subdivising work in small units is not a practical solution, when your big piece of software is a collection of small parts and local variable assignments, embedded in a (perforce large) local environment to keep things clean... Therefore, I let this problem to sleep. However, I Cc this answer (with the original question below) to Max Kuhn and Friedrich Leisch, in the (faint) hope that this feature, which does not seem to have been missed by anybody in 8 years, might be considered sufficiently useful to grant addition someday... Sincerely yours, Emmanuel Charpentier __ 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] Summary (Re: (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?)
On 12/12/2010 6:30 PM, Emmanuel Charpentier wrote: Dear list, see comment at end. On Sat, 11 Dec 2010 22:58:10 +, Emmanuel Charpentier wrote : Dear list, Inspired by the original Knuth tools, and for paedaogical reasons, I wish to produce a document presenting some source code with interspersed comments in the source (see Knuth's books rendering TeX and metafont sources to see what I mean). I seemed to remember that a code chunk could be defined piecewise, like in Comments... Chunk1, eval=FALSE, echo=TRUE= SomeCode @ Some other comments... Chunk2, eval=FALSE, echo=TRUE= MoreCode @ And finally, Chunk3, eval=TRUE, echo=TRUE= Chunk1 Chunk2 EndOfTheCode @ That works ... as long as SomeCode, MoreCode and EndOfTheCode are self- standing pieces of R code, but *not* code fragments. You can *not* intersperse comments in, say, a function body, or local() environment this way : when Sweaving, *R* complains of an incomplete source (makes noise about an unexpected end of input at the end of Chunk1, IIRC, and never sees Chunk2). I hoped that Sweave's alternative syntax could offer a way out : no such luck. There seems to be no way to delay R evaluation of a R chunk passed by Sweave ; at least, the eval=FALSE option of chunk declaration is not sufficient for that. Am I missing something in the Sweave nd odfWeve documentations (that I read till I grew green and moldy) ? Or does this require a fundamental change in the relevant Sweave drivers ? Can you suggest alternative ways of doing what I mean to do ? The only workaround I found is to paste a second copy of my code in a \verbatim environment (or, in the case of odfWeave, in the text part), and spice it with \end{verbatim} comments.. \begin{verbatim} chunks. This way, I lose any guarantee of consistency between commented text and effective code. Any other idea ? Emmanuel Charpentier To summarize the answers I got so far, there seems to be no satisfactory solutions to my current problem with either Sweave or odfWeave : - every (Sw|odfW)eave code chunk has to be parseable in itself. One cannot break it in unparseable pieces in home to paste it later ; - the (hypothetical) parse=FALSE option, suggested by Duncan Murdoch, is, well, hypothetical ; - the brew package is not integrated in either Sweave or odfWeave ; - R-style comments will get you only so far (where is math markup when you need it ?) ; - subdivising work in small units is not a practical solution, when your big piece of software is a collection of small parts and local variable assignments, embedded in a (perforce large) local environment to keep things clean... Therefore, I let this problem to sleep. However, I Cc this answer (with the original question below) to Max Kuhn and Friedrich Leisch, in the (faint) hope that this feature, which does not seem to have been missed by anybody in 8 years, might be considered sufficiently useful to grant addition someday... I thought about this a little more, and it's not impossible to solve. For example, using this file named test.Rnw: \documentclass{article} \usepackage{Sweave} \SweaveOpts{concordance=TRUE} \begin{document} Here is the start: start,engine=noParse, echo=TRUE= f - function(x) { @ Here is the end: end,engine=noParse, echo=TRUE= x + 1 } @ Here is the whole thing: = start end f(4) @ \end{document} - The following code does approximately what you want: - testRuncode - function(object, chunk, options) { if(options$engine == noParse options$echo) { chunkout - object$output cat(\\begin{Schunk}\n\\begin{Sinput}\n, file=chunkout) cat(chunk[-1], sep=\n, file=chunkout) cat(\n\\end{Sinput}\n\\end{Schunk}\n, file=chunkout) return(object) } else return(utils:::RweaveLatexRuncode(object, chunk, options)) } testRweave - function() { driver - RweaveLatex() driver$runcode - testRuncode driver } Sweave(test.Rnw, driver=testRweave()) -- It could probably use a lot of elaboration, but it's a start. Duncan Murdoch __ 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] ggplot2 errorbarh
Hi, I'm having problems using the 'width' aesthetic attribute for the geom_errorbarh. This is the same problem reported earlier here, but I'll try to write the problem more clearly: http://www.mail-archive.com/r-help@r-project.org/msg62371.html The problem I'm having is that, the 'width' attribute is supposed to set the height of the endpoints of the whiskers, and respectively, the width of the endpoints of the whiskers in geom_errorbar. The width attribute works fine in geom_errorbar (sets width of whiskers fine), but it has no effect in geom_errorbarh (height of whiskers is the same no matter what value). Does anyone else still have this problem? Also, i'm not looking for the 'size' attribute, which seems to scale the line thickness of the entire errorbar. Thanks! Brian. [[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] Summary (Re: (S|odf)weave : how to intersperse (\LaTeX{}|odf) comments in source code ? Delayed R evaluation ?)
On Sun, Dec 12, 2010 at 6:30 PM, Emmanuel Charpentier emm.charpent...@free.fr wrote: Dear list, see comment at end. On Sat, 11 Dec 2010 22:58:10 +, Emmanuel Charpentier wrote : Dear list, Inspired by the original Knuth tools, and for paedaogical reasons, I wish to produce a document presenting some source code with interspersed comments in the source (see Knuth's books rendering TeX and metafont sources to see what I mean). I seemed to remember that a code chunk could be defined piecewise, like in Comments... Chunk1, eval=FALSE, echo=TRUE= SomeCode @ Some other comments... Chunk2, eval=FALSE, echo=TRUE= MoreCode @ And finally, Chunk3, eval=TRUE, echo=TRUE= Chunk1 Chunk2 EndOfTheCode @ That works ... as long as SomeCode, MoreCode and EndOfTheCode are self- standing pieces of R code, but *not* code fragments. You can *not* intersperse comments in, say, a function body, or local() environment this way : when Sweaving, *R* complains of an incomplete source (makes noise about an unexpected end of input at the end of Chunk1, IIRC, and never sees Chunk2). I hoped that Sweave's alternative syntax could offer a way out : no such luck. There seems to be no way to delay R evaluation of a R chunk passed by Sweave ; at least, the eval=FALSE option of chunk declaration is not sufficient for that. Am I missing something in the Sweave nd odfWeve documentations (that I read till I grew green and moldy) ? Or does this require a fundamental change in the relevant Sweave drivers ? Can you suggest alternative ways of doing what I mean to do ? The only workaround I found is to paste a second copy of my code in a \verbatim environment (or, in the case of odfWeave, in the text part), and spice it with \end{verbatim} comments.. \begin{verbatim} chunks. This way, I lose any guarantee of consistency between commented text and effective code. Any other idea ? Emmanuel Charpentier To summarize the answers I got so far, there seems to be no satisfactory solutions to my current problem with either Sweave or odfWeave : - every (Sw|odfW)eave code chunk has to be parseable in itself. One cannot break it in unparseable pieces in home to paste it later ; - the (hypothetical) parse=FALSE option, suggested by Duncan Murdoch, is, well, hypothetical ; - the brew package is not integrated in either Sweave or odfWeave ; brew doesn't need to be. Its an alternative to Sweave, not something intended to be used with Sweave. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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] ggplot2 errorbarh
Brian Tsai btsai00 at gmail.com writes: Hi, I'm having problems using the 'width' aesthetic attribute for the geom_errorbarh. This is the same problem reported earlier here, but I'll try to write the problem more clearly: http://www.mail-archive.com/r-help at r-project.org/msg62371.html The problem I'm having is that, the 'width' attribute is supposed to set the height of the endpoints of the whiskers, and respectively, the width of the endpoints of the whiskers in geom_errorbar. The width attribute works fine in geom_errorbar (sets width of whiskers fine), but it has no effect in geom_errorbarh (height of whiskers is the same no matter what value). Does anyone else still have this problem? Looking at the answers in the previous thread, I think the commenters are trying to answer your question but be missing the point. I assume you have horizontal errorbars that look like this |--*---| and you want them to look like this: | | |--*---| | | In this case, it would be the height aesthetic rather than the width aesthetic that you would want to modify the length of the end-caps on the bar. If this is *not* what you want, it would help if you could somehow draw a picture of your desired graph (e.g. manipulate the graph you have in an image editor, or use ASCII art as above) ... __ 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] ggplot2 errorbarh
Hi Ben, Indeed this is what i wanted, thanks. height does make more sense, I guess I was just reading the ggplot2 documentation directly, which still refers to width. Brian On Sun, Dec 12, 2010 at 5:12 PM, Ben Bolker bbol...@gmail.com wrote: Brian Tsai btsai00 at gmail.com writes: Hi, I'm having problems using the 'width' aesthetic attribute for the geom_errorbarh. This is the same problem reported earlier here, but I'll try to write the problem more clearly: http://www.mail-archive.com/r-help at r-project.org/msg62371.html The problem I'm having is that, the 'width' attribute is supposed to set the height of the endpoints of the whiskers, and respectively, the width of the endpoints of the whiskers in geom_errorbar. The width attribute works fine in geom_errorbar (sets width of whiskers fine), but it has no effect in geom_errorbarh (height of whiskers is the same no matter what value). Does anyone else still have this problem? Looking at the answers in the previous thread, I think the commenters are trying to answer your question but be missing the point. I assume you have horizontal errorbars that look like this |--*---| and you want them to look like this: | | |--*---| | | In this case, it would be the height aesthetic rather than the width aesthetic that you would want to modify the length of the end-caps on the bar. If this is *not* what you want, it would help if you could somehow draw a picture of your desired graph (e.g. manipulate the graph you have in an image editor, or use ASCII art as above) ... __ 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.
[R] Pure curiosity
Pure curiosity but does anyone know why '-' and '=' generate different columning headers? test - data.frame(V1=c(1,2,3), V2=c(4,5,6)) test V1 V2 1 1 4 2 2 5 3 3 6 test - data.frame(V1-c(1,2,3), V2-c(4,5,6)) test V1c.1..2..3. V2c.4..5..6. 114 225 336 names(test) [1] V1c.1..2..3. V2c.4..5..6. [[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] Pure curiosity
On Mon, Dec 13, 2010 at 1:09 PM, robert denham rjaden...@gmail.com wrote: in test - data.frame(V1=c(1,2,3), V2=c(4,5,6)) you are using arguments to the data.frame function in the tag=value format. From the help: ...: these arguments are of either the form value or tag = value. Component names are created based on the tag (if present) or the deparsed argument itself. in test - data.frame(V1-c(1,2,3), V2-c(4,5,6)) you are using the value part, with the values being c(1,2,3) and c(4,5,6). Someone might explain whats really going on, but I don't think the assignment of c(1,2,3) to the variable V1 is done before the data.frame is evaluated. On Mon, Dec 13, 2010 at 12:53 PM, Matt Cooper mattcst...@gmail.comwrote: Pure curiosity but does anyone know why '-' and '=' generate different columning headers? test - data.frame(V1=c(1,2,3), V2=c(4,5,6)) test V1 V2 1 1 4 2 2 5 3 3 6 test - data.frame(V1-c(1,2,3), V2-c(4,5,6)) test V1c.1..2..3. V2c.4..5..6. 114 225 336 names(test) [1] V1c.1..2..3. V2c.4..5..6. [[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. [[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] Pure curiosity
Just to follow up on Robert's comment, If you do an ls() you'll see that you've created objects V1, V2 in your global environment. A very similar question was discussed last week (I think... it's all a blur) in the context of using - instead of = with named function arguments. Michael On 13 December 2010 14:10, robert denham rjaden...@gmail.com wrote: On Mon, Dec 13, 2010 at 1:09 PM, robert denham rjaden...@gmail.com wrote: in test - data.frame(V1=c(1,2,3), V2=c(4,5,6)) you are using arguments to the data.frame function in the tag=value format. From the help: ...: these arguments are of either the form ‘value’ or ‘tag = value’. Component names are created based on the tag (if present) or the deparsed argument itself. in test - data.frame(V1-c(1,2,3), V2-c(4,5,6)) you are using the value part, with the values being c(1,2,3) and c(4,5,6). Someone might explain whats really going on, but I don't think the assignment of c(1,2,3) to the variable V1 is done before the data.frame is evaluated. On Mon, Dec 13, 2010 at 12:53 PM, Matt Cooper mattcst...@gmail.comwrote: Pure curiosity but does anyone know why '-' and '=' generate different columning headers? test - data.frame(V1=c(1,2,3), V2=c(4,5,6)) test V1 V2 1 1 4 2 2 5 3 3 6 test - data.frame(V1-c(1,2,3), V2-c(4,5,6)) test V1c.1..2..3. V2c.4..5..6. 1 1 4 2 2 5 3 3 6 names(test) [1] V1c.1..2..3. V2c.4..5..6. [[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. [[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-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] R Plots for Recurrent Events - Suggestions are needed
Hi Haoda, I couldn't find a package that implements this, although I'm not familiar with the field so there could be something but using different terminology. However, looking at the the Google preview of Nelson (2003) which is cited by the page that you linked to, the calculations seem very simple (see page 46). Here is a function which I think does what is described there (warning: untested !)... mcf - function(events) { # events a data.frame or matrix where: # col 1 is unitID # col 2 is event time (integer) # col 3 is event type coded as: # 0: recurrence # 1: first appearance (left censoring time) # 2: last appearance (right censoring time) # # Order events data by time, unit id, event type events - events[ order(events[,2], events[,1], events[,3]), ] m - matrix(0, nrow=nrow(events), ncol=4) colnames(m) - c(time, Nrisk, incr, mcf) # copy event times m[, 1] - events[, 2] # number of units observed at each time m[, 2] - cumsum(ifelse(events[, 3] == 2, -1, events[, 3])) # incremental risk irecurrence - events[,3] == 0 m[irecurrence, 3] - 1 / m[irecurrence, 2] # cumulative risk (MCF estimate) m[, 4] - cumsum(m[, 3]) # return results (matrix rows with recurrent events) m[events[,3] == 0, ] } Hope this helps. Michael On 13 December 2010 03:47, Haoda Fu fu...@yahoo.com.cn wrote: Hi, I am wondering if there is a simple way to plot MCF(mean cumulative function) for recurrent events in R? MCF (http://www.weibull.com/hotwire/issue57/relbasics57.htm) And do you have some other recommendation in visualize recurrent events? I did some research online. Some people use ggplot2 to plot MCF, but it requires some additional coding. http://user2010.org/slides/Shentu.pdf Your help and suggestions are highly appreciated. Warm regards from Haoda __ 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.
[R] SAS /slice and /diff equivalent? - Automated multiple comparisons in nlme package?
R users, What is the equivalent of SAS '/diff' and '/slice' in R ? I am successful in fitting the same model PROC MIXED fits using lme() : ###R code: model - lme( y ~ g + h + yr + yr:h, random = ~ 1 | b, data = yield) *** SAS code: proc mixed data=yield covtest cl method=reml; class b g h yr; model y = g h yr yr*h; random b; lsmeans g / diff; The codes above give equivalent outputs (analysis of a 5(g) by 2(h) factorial, RCBD(b)), except for the lsmeans g / diff line, which I cannot reproduce in R! The below gives one of the comparisons I am looking for. anova(model, L=c(gPEN=1, gC5=-1)) Is there a command to automate such thing? I understand from https://stat.ethz.ch/pipermail/r-help/2007-March/128151.html and https://stat.ethz.ch/pipermail/r-help/2004-February/046684.html the issues with lsmeans (this is *not* what I am trying to get here! ). I am just trying to get all possible pairwise comparisons from one simple command. Already checked the effects package but it did not work with a lme() object. Thanks in advance, Daniel __ 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] Plot's aspect ratio and pty
Dear All, I've been playing with pty, and it seems it does not produce square plots as it is expected to (or at least as I expect it to). Consider this simple example: par(pty=s); plot(1:10, 1:10) This should produce a square plot, right? Well, if you have a look at the graph, it is not square! So, maybe the limits? par(pty=s); plot(1:10, 1:10, xlim = c(0,11), ylim=c(0,11)) No, again not. So let's try and help to equalize everything, just to be sure: windows(6, 6); par(mar=c(3, 3, 3, 3), pty=s); plot(1:10, 1:10, xlim = c(0, 11), ylim = c(0, 11)) Again not! pty = s is to generate a square plotting region, and it does not seem to do that. Where is my mistake? Thanks in advance, Marcin __ 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] simple plotting question
Dear R People: When I plot using type=b, I have circles and lines, which is as it should be. Is there a way to have filled in circles using the type argument, please? Or do I need to call the points function also, please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ 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] simple plotting question
Hello Erin, Try this... plot(x, y, type=b, pch=16) Michael On 13 December 2010 18:11, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: When I plot using type=b, I have circles and lines, which is as it should be. Is there a way to have filled in circles using the type argument, please? Or do I need to call the points function also, please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ 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.
Re: [R] Why do we have to turn factors into characters for various functions?
Hi r-help-boun...@r-project.org napsal dne 12.12.2010 21:00:37: At 12.12.2010 00:48 +0200, Tal Galili wrote: Hello dear R-help mailing list, My question is *not* about how factors are implemented in R (which is, if I understand correctly, that factors keeps numbers and assign levels to them). My question *is* about why so many functions that work on factors don't treat them as characters by default? Here are two simple examples: Example one turning the characters inside a factor into numeric: x - factor(4:6) as.numeric(x) # output: 1 2 3 as.numeric(as.character(x)) # output: 4 5 6 # isn't this what we wanted? Example two, using strsplit on a factor: x - factor(paste(letters[4:6], 4:6, sep=A)) strsplit(x, A) # will result in an error: # Error in strsplit(x, A) : non-character argument strsplit(as.character(x), A) # will work and split So what is the reason this is the case? Is it that implementing a switch of factors to characters as the default in some of the basic function will cause old code to break? Is it a better design in some other way? I am curious to know the reason for this. In my view the answer can be found implicitly in the language definition. Factors are currently implemented using an integer array to specify the actual levels and a second array of names that are mapped to the integers. Rather unfortunately users often make use of the implementation in order to make some calculations easier. It is the unfortunate use of factors that seems generally accepted, even if the language definition continues: This, however, is an implementation issue and is not guaranteed to hold in all implementations of R. Personally, like some others, I avoid factors, except in cases, where they represent a statistical concept. On contrary I find factors quite useful. Consider possibility to change its levels set.seed(111) x - factor(sample(1:4, 20, replace=T), labels=c(one, two, three, four)) x [1] three three two three two two one three two one three three [13] one one one two one four two three Levels: one two three four levels(x)[3:4] - more x [1] more more two more two two one more two one more more one one one [16] two one more two more Levels: one two more I believe that if x is character, it can be also done but factor way seems to me more convenient. I also use point distinction in plots by pch=as.numeric(some.factor) quite often. Anyway it is maybe more about personal habits than about bad factor features Regards Petr Certainly I would agree with you that, if only reading the R Language Definition and not the documentation of the function factor, one would rather expect functions like as.numeric or strsplit to operate on the levels of a factor and not on the underlying, implementation specific, integer array. Heinz Thank you for your reading, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[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-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.