Re: [R] solving system of equations involving non-linearities
Many thanks, BBsolve works like a charm. First I thought I should use the squares of the equations because BBsolve would use some minimization objective function anyway but it actually only works if I don't use the squared equations. I'll check the documentation if I find something about the objective. Thanks for the help, Werner Ravi Varadhan wrote: You have two options: 1. The `BBsolve' function in the BB package to solve this system of 3 equations. 2. Try `nleqslv' function in the nleqslv package. These would work even if the residual is not zero. Hope this helps, Ravi. -- View this message in context: http://www.nabble.com/solving-system-of-equations-involving-non-linearities-tp24845136p24859703.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] A question regarding R scoping
__ 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] using cat()
Thanks, Bill bill.venab...@csiro.au wrote: fn - function(x) { j - x+1 cat(the value of j is , j, \n) j } fn(1:10) It is clear for me now the use of cat(). As Steve pointed out in his mail, I've failed at providing an example, one of the rules of thumb of this list! Sorry about that. Also as Steve says, I am trying to use cat() for something it's not meant to do. I am trying to pull out the value of a variable, well, some variables, without making them global by using - Following your example, I was guessing if something like fn.j could be used. Cheers, Ricardo -- Ricardo Rodríguez Your XEN ICT Team __ 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] using cat()
Thanks, Steve, Steve Lianoglou wrote: It seems like you're asking to use cat() for something it's not meant to do. cat() is generally used to write output, either to the screen or to a file. Sorry for not adding an example to my first post! And yes, I was trying to use it for something it is not meant to. You can use cat *in* a function to print the value of a variable, but you can't reach into a function to pull out a variable's value. Are you trying to debug something? See: ?debug to step through a function to examine what it's doing one step at a time. Yes, I am trying to discover why a function that Phil Spector sent to the list one year and a half ago doesn't do the trick for me (please, see http://tinyurl.com/lh3fh4). Here the function (it is intended to submit code stored in a restricted access web site accepting Basic Authentication; source() works nicely for free access sites, but it doesn't manage authentication): getauth = function(url,user,pass){ require(caTools) url = sub('^http://','',url) getexpr = function(s,g)substring(s,g,g + attr(g,'match.length') - 1) host = sub('^(.*?)/(.*)$','\\1',url,perl=TRUE) file = sub('^(.*?)/(.*)$','\\2',url,perl=TRUE) upb = base64encode(paste(user,pass,sep=':')) request = paste('GET /',file,' HTTP/1.1\nHost: ',host,'\nAuthorization: Basic ',upb,'\n\n',sep='') s = make.socket(host,port=80) write.socket(s,request) response = read.socket(s,8192) close.socket(s) header = sub('^(.*)\r\n\r\n(.*)$','\\1',response) rest = sub('^(.*)\r\n\r\n(.*)$','\\2',response) unlist(strsplit(rest,'\n')) } Here what Phil proposed to use instead of source() eval(parse(text=getauth('http://whatever.com/path/to/file',user,pass))) At this moment, what I am trying to do is to debug, thanks Steve, this function to see where it is failing. Given a real example... eval(parse(text=getauth('http://tinyurl.com/ne5bl3',user,pass))) I get NULL. Please, use DummyDummy as user and dummy as pass if you want to try it. Thanks. Thanks in advance for any insight! Greetings, Ricardo -- Ricardo Rodríguez Your XEN ICT Team __ 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] Is there a 'vi' mode in R?
I've no idea about vi. But there is one called ESS(emacs speaks statistics) in Emacs. I'm very curious how VI is going to work on generating X11 output. On Thu, Aug 6, 2009 at 2:54 PM, Peng Yupengyu...@gmail.com wrote: Hi, I'm wondering if R provide a vi mode in the command line just like other shells such as bash do. Can somebody let me know? Regards, Peng __ 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. -- 彭河森 Hesen Peng http://hesen.peng.googlepages.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] using cat()
Sorry, [Ricardo Rodriguez] Your XEN ICT Team wrote: eval(parse(text=getauth('http://tinyurl.com/ne5bl3',user,pass))) I get NULL. Please, use DummyDummy as user and dummy as pass if you want to try it. Thanks. I think the proposed URL could present some more problems. Please, use this one... eval(parse(text=getauth('http://xepecnet.environmentalchange.net/xwiki/bin/view/ICT/RGraphicSample02',user,pass))) Same result: NULL Thanks, Ricardo -- Ricardo Rodríguez Your XEN ICT Team __ 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 is 0 not an integer?
William Dunlap wdun...@tibco.com on Thu, 6 Aug 2009 15:06:08 -0700 writes: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Giovanni Petris Sent: Thursday, August 06, 2009 3:00 PM To: milton.ru...@gmail.com Cc: r-help@r-project.org; daniel.gerl...@geodecapital.com Subject: Re: [R] Why is 0 not an integer? I ran an instant experiment... typeof(0) [1] double typeof(-0) [1] double identical(0, -0) [1] TRUE Best, Giovanni But 0.0 and -0.0 have different reciprocals 1.0/0.0 [1] Inf 1.0/-0.0 [1] -Inf Yes, indeed! Finally something interesting in this boring thread ! A few of us have agreed in the past that indeed, it would be preferable if identical() *did* reflect this difference. I'm going to discuss this -- it's about technical details and future changes to R in the appropriate mailing list : --- R-devel Martin Maechler, ETH Zurich Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com By the way: Are there difference between -0 and 0? __ 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] Completion for custom $ operator?
On 08/04/2009 10:02 PM, Deepayan Sarkar wrote: On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.vitosm...@rambler.ru wrote: Dear UseRs, I declared a `$` method for a S4 class. Can I have ab automatic completion for this operator in R? Lists and environment objects provide this feature by default, but my object is an extension of function class which does not have subseting defined. How to be? Completion should be automatic if you define names() to return the valid names. -Deepayan Hi, Shouldn't this be delegated to a custom method. ie : complete - function( x, ... ){ UseMethod( complete ) } complete.default - function( x, ... ){ names( x ) } or maybe the equivalent S4 incantation. This would separate the completion from the names, and therefore give more flexibility to class writers. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/vzip : Code Snippet : List of CRAN packages |- http://tr.im/vsK1 : R parser package on CRAN `- http://tr.im/vshK : Transfer files through Rserve __ 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] Completion for custom $ operator?
On 8/7/09, Romain Francois romain.franc...@dbmail.com wrote: On 08/04/2009 10:02 PM, Deepayan Sarkar wrote: On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.vitosm...@rambler.ru wrote: Dear UseRs, I declared a `$` method for a S4 class. Can I have ab automatic completion for this operator in R? Lists and environment objects provide this feature by default, but my object is an extension of function class which does not have subseting defined. How to be? Completion should be automatic if you define names() to return the valid names. -Deepayan Hi, Shouldn't this be delegated to a custom method. ie : complete - function( x, ... ){ UseMethod( complete ) } complete.default - function( x, ... ){ names( x ) } or maybe the equivalent S4 incantation. This would separate the completion from the names, and therefore give more flexibility to class writers. Ideally yes (although complete doesn't seem the best choice; this is only for $ completion). It's an easy enough change, and I'll be happy to make it if there's interest (and a use case where names() has good reason to be different). -Deepayan __ 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] acf Significance
Your suggestion wasn't entirely useless - I didn't know about it before, so I learned something! I've had a look in the plot.acf source and found the bit I need, so it's all good now. Thanks for the suggestions. Steve. markle...@verizon.net wrote: Hi Steve: Clearly my str suggestions was useless So, my bad there. If you do stats:::plot.acf, that will show the source ( it looks complex as it always does ) but you can see how the ci piece is calculated. Also, the formula for it is in any reasonable time series book such as box jenkins or abraham ledolter etc. If you have MASS, it may be in there also. I'm surprised it's not part of some output somewhere ? hopefully someone else will say something because I'm not an R expert so it still might be somewhere ? On Aug 6, 2009, *Steve Jones* st...@squaregoldfish.co.uk wrote: Thanks for the pointer to the str function - very handy! The output for the acf object is below - it doesn't seem to contain anything that might tell me the significance level. List of 6 $ acf : num [1:27, 1, 1] 1 0.6309 0.2989 0.0612 -0.2105 ... $ type : chr correlation $ n.used: int 27 $ lag : num [1:27, 1, 1] 0 1 2 3 4 5 6 7 8 9 ... $ series: chr time_series $ snames: NULL - attr(*, class)= chr acf Does anyone have any more ideas? Steve. markle...@verizon.net mailto:markle...@verizon.net wrote: hi: set the acf to an object and then do str(object). that should show if and where they are ? If I knew I would just tell you so I'm not trying to be socratic. it's been a while since I used acf(). On Aug 5, 2009, *Steve Jones* st...@squaregoldfish.co.uk mailto:st...@squaregoldfish.co.uk wrote: Hi List, I'm trying to calculate the autocorrelation coefficients for a time series using acf at various lags. This is working well, and I can get the coefficients without any trouble. However, I don't seem to be able to obtain the significance of these coefficients from the returned acf object, largely because I don't know where I might find them. It's clear that the acf function knows the significance threshold of the autocorrelations, since it's shown in blue shown on the plot output from acf, but I can't figure out where to access it. Can anyone help? Thanks in advance, Steve. __ R-help@r-project.org mailto:R-help@r-project.org mailto:R-help@r-project.org mailto: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 mailto: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. signature.asc Description: OpenPGP digital signature __ 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] Completion for custom $ operator?
On 08/07/2009 09:38 AM, Deepayan Sarkar wrote: On 8/7/09, Romain Francoisromain.franc...@dbmail.com wrote: On 08/04/2009 10:02 PM, Deepayan Sarkar wrote: On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.vitosm...@rambler.ru wrote: Dear UseRs, I declared a `$` method for a S4 class. Can I have ab automatic completion for this operator in R? Lists and environment objects provide this feature by default, but my object is an extension of function class which does not have subseting defined. How to be? Completion should be automatic if you define names() to return the valid names. -Deepayan Hi, Shouldn't this be delegated to a custom method. ie : complete- function( x, ... ){ UseMethod( complete ) } complete.default- function( x, ... ){ names( x ) } or maybe the equivalent S4 incantation. This would separate the completion from the names, and therefore give more flexibility to class writers. Ideally yes (although complete doesn't seem the best choice; this is only for $ completion). It's an easy enough change, and I'll be happy to make it if there's interest (and a use case where names() has good reason to be different). -Deepayan The motivation for this was for java object references in rJava (jobjRef class). See this: http://tr.im/vQkf Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/vzip : Code Snippet : List of CRAN packages |- http://tr.im/vsK1 : R parser package on CRAN `- http://tr.im/vshK : Transfer files through Rserve __ 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 and R. Searching for a document that will get me started
Sweave was designed to embed R code within LaTeX documents. You REALLY need to learn a bit of LaTeX before using Sweave. There are many available documents on the Internet, e.g.: http://www.ctan.org/tex-archive/info/beginlatex/ http://tug.ctan.org/tex-archive/info/lshort/ 2009/8/7 John Sorkin jsor...@grecc.umaryland.edu: windows XP R 2.8.1 I would like to learn to use Sweave with R. I have no experience using Latex. I have looked at the sweave manual (http://www.statistik.lmu.de/~leisch/Sweave/Sweave-manual.pdf) and have found it difficult to understand, probably because I don't know Latex. Can someone recommend a document that will get me started with Sweave? Thanks John Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ 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. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ EDEN International Conference, Montpellier, 10-12 May 2010 http://international-conference2010.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://www.cirad.fr http://bluetongue.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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] Conditional randomization of groups
Hi unknown, As a quick patch, try something like mydata$Set - 1 mydata$Set[c(sample(mydata$ID[mydata$Type==A], ifelse(runif(1)1/2,2,3)), sample(mydata$ID[mydata$Type==B], 3) )[1:5] ] - 2 HTH, Michael -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yabado Sent: Donnerstag, 6. August 2009 23:29 To: r-help@r-project.org Subject: [R] Conditional randomization of groups Hi I have a data set which is like this: Data ID Type 1 A 2 B 3 A 4 A 5 A 6 B 7 B 8 A 9 B 10 B As you can see, there are 5 A and 5 B. Now, I want to a randomization of the data set which will assign 5 ID to a new group called Set1 and and the other 5 to Set2 The Set1 and Set2 will be either: Set1 (A A A B B ) and Set2 (A A B B B) or Set1(A A B B B) and Set2 (A A A B B). Each new group need to have at two A and two B, and one more B or A. Except this condition, everything else (ID, permutation, selection to Set1 and Set2) need to be random. Can anyone show me how to do the randomization? -- View this message in context: http://www.nabble.com/Conditional-randomization-of-groups-tp24854783p248 54783.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] sweave and R. Searching for a document that will get me started
Sweave/LaTeX is the most powerfull tool to write document with embedded R code. The hard task is to learn LaTeX. But you could also have a look to packages: - R2HTML or hwriter if you prefer HTML markup, - odfWeave if you prefer write document with OpenOffice for example, - or ascii, if you want to write document with a very simple markup and multiple outputs (html, pdf...). 2009/8/7 Renaud Lancelot renaud.lance...@gmail.com Sweave was designed to embed R code within LaTeX documents. You REALLY need to learn a bit of LaTeX before using Sweave. There are many available documents on the Internet, e.g.: http://www.ctan.org/tex-archive/info/beginlatex/ http://tug.ctan.org/tex-archive/info/lshort/ 2009/8/7 John Sorkin jsor...@grecc.umaryland.edu: windows XP R 2.8.1 I would like to learn to use Sweave with R. I have no experience using Latex. I have looked at the sweave manual ( http://www.statistik.lmu.de/~leisch/Sweave/Sweave-manual.pdfhttp://www.statistik.lmu.de/%7Eleisch/Sweave/Sweave-manual.pdf) and have found it difficult to understand, probably because I don't know Latex. Can someone recommend a document that will get me started with Sweave? Thanks John Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ 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. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ EDEN International Conference, Montpellier, 10-12 May 2010 http://international-conference2010.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://www.cirad.fr http://bluetongue.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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] Durbin-Watson
Thank you for all your reply, especially Alan Now I understand better how does the durbin watson test works. But this means that my residuals are not independent (note that I'm doing this test to validate the ANOVA assumption that the residuals are independent). The results were taken from a simulation result and each run are supposed to be independent to each other and I am grouping the data based on design points. The plot from residuals vs fitted and residuals vs time looks random enough although each groups has slightly different variance. Am I heading the correct way here, by testing the independence of the whole residuals (which resulting the failure of independence test) or should I test for the independence for each groups? (which resulting the passing of the test). Thank you very much, ~ Hardi - Original Message From: Alan Cohen coh...@smh.toronto.on.ca To: sky_dr...@yahoo.com Sent: Thursday, August 6, 2009 9:38:19 PM Subject: Durbin-Watson Hi Hardi, I saw the first reply you got to your question, which was correct but snippy and a bit over-technical. To say it more clearly (and nicely - appreciating that you will not become a statistical guru of every test you ever use), you have performed a two-tailed test with durbin.watson() and a one-tailed test with dwtest(), so the p-value for the former should be approximately twice that for the latter. Your one-tailed test was performed in the wrong direction - your autocorrelation is negative, but you were testing for a positive association. 1-p = 1-0.9964 = 0.0036. This is still not exactly the same as 0.018/2=0.0059, but the ranges are similar, and if you need to figure it out in more depth I'd refer back to the first response, which points out the differences in calculation methods. If you want to control the direction of the test in dwtest, use the alternative option, copied from the ?dwtest help file below: dwtest(formula, order.by = NULL, alternative = c(greater, two.sided, less), iterations = 15, exact = NULL, tol = 1e-10, data = list()) alternative - a character string specifying the alternative hypothesis. Cheers, Alan Cohen __ 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] plotting huge data
I have a data frame with 25000 rows containing two columns Time and Distance. When I plot a simple distance versus time plot, the plot is very confusing showing no general trend because of the large data. Is there any way I can improve the plot by lets say using moving average as in EXCEL ? please also suggest some other methods to make the graph smoother and better looking. Gaurav -- View this message in context: http://www.nabble.com/plotting-huge-data-tp24860155p24860155.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] plotting huge data
?supsmu ?filter Sent from my iPhone On Aug 7, 2009, at 3:28, gauravbhatti gaurav15...@hotmail.com wrote: I have a data frame with 25000 rows containing two columns Time and Distance. When I plot a simple distance versus time plot, the plot is very confusing showing no general trend because of the large data. Is there any way I can improve the plot by lets say using moving average as in EXCEL ? please also suggest some other methods to make the graph smoother and better looking. Gaurav -- View this message in context: http://www.nabble.com/plotting-huge-data-tp24860155p24860155.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] Durbin-Watson
On Fri, 7 Aug 2009, Hardi wrote: Now I understand better how does the durbin watson test works. But this means that my residuals are not independent (note that I'm doing this test to validate the ANOVA assumption that the residuals are independent). Yes. The autocorrelation is rather low, though, so it might be hard to see in visualizations that you mention below. The results were taken from a simulation result and each run are supposed to be independent to each other and I am grouping the data based on design points. The plot from residuals vs fitted and residuals vs time looks random enough although each groups has slightly different variance. I'm not sure that the Durbin-Watson test is appropriate at all for your data. This seems to be longitudinal or panel data, right? The standard Durbin-Watson test is for time series regressions. (Snippiness alert: This might have become more clear if a textbook would have been consulted more thoroughly as suggested in my previous mail...even though other respondents seem to feel that you do not need to understand the test, or read its manual, to apply it.) Am I heading the correct way here, by testing the independence of the whole residuals (which resulting the failure of independence test) or should I test for the independence for each groups? (which resulting the passing of the test). Hard to say from your description, but it seems that one of the following might help: using some sandwich covariances (see package sandwich) after a linear regression with lm() or using GEE (see package geepack) with a suitable dependence structure. hth, Z __ 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 and R. Searching for a document that will get me started
Hello, On Fri, Aug 7, 2009 at 9:26 AM, David Hajagedhajag...@gmail.com wrote: The hard task is to learn LaTeX. You can get around learning (much of) LaTeX by using Sweave with LyX. You will find information in the r-help and lyx ML archives, and on Google. Liviu __ 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] plotting huge data
Hello, On Fri, Aug 7, 2009 at 8:28 AM, gauravbhattigaurav15...@hotmail.com wrote: I have a data frame with 25000 rows containing two columns Time and Distance. When I plot a simple distance versus time plot, the plot is very confusing showing no general trend because of the large data. Is there any way I can improve the plot by lets say using moving average as in EXCEL ? please also suggest some other methods to make the graph smoother and better looking. library(playwith) may help with zooming the plots. Liviu __ 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] eval parent.frame() twice
Hi I want to use a function (update) that in its body uses eval(call, parent.frame()) I would like to use this function in a function that does not contain the variables referred to in 'call'. Those variables are instead in the parent.frame() of my function (named 'second' below) Like this: a - 2 evalu - function(obj) { call - obj$call eval(call, parent.frame()) } first - function() { a - 3 obj - list(call=expression(a)) second(obj) } second - function(obj) { eval(evalu(obj), parent.frame()) } first() #returns 2, but I want 3. How do I change 'second' such that the value of 'a' from 'first' is returned? -- Regards Rune Schjellerup Philosof Ph.d.-studerende, Statistik, IST, SDU Telefon: 6550 3607 E-mail: rphilo...@health.sdu.dk Adresse: J.B. Winsløwsvej 9, 5000 Odense C __ 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] Fitting Truncated Distribution
Dear All, I know that this topic has been already discussed on this list (see e.g. http://markmail.org/message/bq2bdxwblwl4rpgf?q=r+fit+truncated+lognormalpage=1refer=2ufc4fb2eftfwwml#query:r%20fit%20truncated%20lognormal+page:1+mid:7wxgkdxhixotorr5+state:results for the case of weibull distribution), but I am experiencing some problems. I deal with truncated distributions (that this to say data below/above a certain threshold are removed from the observations and I do not know any longer that there are any observations ruled out by a threshold). (1) Consider the following snippet (along the lines of the suggestion in the link above) rm(list=ls()) library(MASS) set.seed(1234) lt_lognormal - function(x, meanlog, sdlog ){ dlnorm(x, meanlog , sdlog )/plnorm(0.5, meanlog , sdlog ) } my_seq - rlnorm(1) my_fit - fitdistr(my_seq,lognormal) cut_low - my_seq[which(my_seq0.5)] my_fit_low - fitdistr(cut_low,lt_lognormal,list(meanlog=0.2,sdlog=0.7), lower=0.5 ) However, when I run it I get the following error Error in optim(x = c(1.31973273433717, 2.95778647676973, 1.53591253356589, : L-BFGS-B needs finite values of 'fn' Does anybody know what is going on? Am I making a mistake? (2) How about the case of simultaneously left- and right-truncated data? What is the easiest way to deal with them? Many thanks Lorenzo __ 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] xtable, sweave and resizebox
does anyone know to rezize a table produzed by xtable? The size of my table is too big and I would like to resize it like using resizebox but it gives an erros when I try using it using it its fine \SweaveOpts{echo=false} results=tex= xtable(stats0,caption='Número de transacções dos artigos frequentes e infrequentes',label='tab:INEStats') @ but the size is too big so I try echo=False,results=hide= load('stats.Rdata') library(xtable) \resizebox{\textwidth}{!}{ \SweaveOpts{echo=false} results=tex= xtable(stats0,caption='text',label='tab:Stats') @ } and it doesn t work anymore any hints? [[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] adding color bar to a graph
Monica Pisica wrote: Hi everybody, I am wondering how i can add a stretch color bar / legend to a graph that uses colorBrewer to define the colors in it. I will try to explain my graph, but i also uploaded it at: ftp://ftpext.usgs.gov/pub/er/fl/st.petersburg/Monica_pal/ The file is: robcor_training_pca.pdf - i will also attach this file in case some people accept attachments. So i took apart the cor.plot function from mvoutlier and i used instead of the scatter plot function the smooth scatter density plot from geneplotter, generating my own function called cordens.plot. Now i would like to add a colorbar on the right side of the graph with red as my highest density and purple as the lowest density and right next to the colors labels min for purple and max for red (i don't want actual numbers, although i suppose i can deal with that as well if need be). I've tried image.plot function but i cannot set correctly the colors in the bar since i am not using an orthodox rainbow set. Originally my colors in the graph are set with colorRampPalette(c(darkviolet, deepskyblue4, green, yellow, red)). Hi Monica, I think color.legend in the plotrix package will do what you want. color.legend(200,0,220,100,legend=c(min,max), rect.col=c(darkviolet,deepskyblue4,green,yellow,red)) and you will have to add some space on the right side par(mar=c(5,4,4,4)) Jim __ 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] eval parent.frame() twice
Rune Schjellerup Philosof wrote: Hi I want to use a function (update) that in its body uses eval(call, parent.frame()) I would like to use this function in a function that does not contain the variables referred to in 'call'. Those variables are instead in the parent.frame() of my function (named 'second' below) Like this: a - 2 evalu - function(obj) { call - obj$call eval(call, parent.frame()) } first - function() { a - 3 obj - list(call=expression(a)) second(obj) } second - function(obj) { eval(evalu(obj), parent.frame()) } first() #returns 2, but I want 3. How do I change 'second' such that the value of 'a' from 'first' is returned? You could use the n argument to parent.frame (or eval.parent) inside evalu and go two generations back instead of one. Somewhat neater, you could pass the desired environment directly to evalu, as in e - parent.frame() evalu(obj, e) (I'm not sure it is actually needed to separate out the calculation of e, but I tend to be paranoid about evaluating parent.frame() in function arguments.) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ 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] Ylim
Mohsen Jafarikia wrote: Hello All: Can anybody tell me what is the problem with my program please. I have an error message as appears below. My program is: ifn - Jul08_09.LM data - read.table(ifn) ofn - Jul.png bitmap(ofn, type = png256, width = 30, height = 30, pointsize = 30, bg = white,res=50) par(mar=c(5, 5, 3, 2),lwd=5) par(cex.main=1.6,cex.lab=1.6,cex.axis=1.6) par(mfrow = c(3,4)) ifn - T.dat trait - read.table(ifn) i - 1 j - 1 for(k in 1:12) { dat - data[i:(i+2), ] colnames(dat)-c(SM,E,NP) Ymin - if( min(dat$SM) 0.0 ) (dat$SM - dat$E) else 0.0 Ymax - if( max(dat$SM) 0.0 ) (dat$SM + dat$E) else 0.0 Graph-barplot(dat$SM, names.arg=dat$NP, main = trait[j:j,], xlab = data[i:i,1:1], ylim = c(Ymin,Ymax) ) segments(Graph, dat$SM + dat$E, Graph, dat$SM - dat$E) i - i + 3 j - j + 1 } dev.off() And the error message is: Error in plot.window(xlim, ylim, log = log, ...) : invalid 'ylim' value Calls: barplot - barplot.default - plot.window Execution halted Hi Mohsen, Try this: Ymin-ifelse(min(dat$SM)0.0,dat$SM-dat$SE,0) Ymax-ifelse(min(dat$SM)0.0,dat$SM+dat$SE,0) cat(Ymin,Ymax,\n) Jim __ 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] eval parent.frame() twice
Peter Dalgaard skrev: Rune Schjellerup Philosof wrote: Hi I want to use a function (update) that in its body uses eval(call, parent.frame()) I would like to use this function in a function that does not contain the variables referred to in 'call'. Those variables are instead in the parent.frame() of my function (named 'second' below) Like this: a - 2 evalu - function(obj) { call - obj$call eval(call, parent.frame()) } first - function() { a - 3 obj - list(call=expression(a)) second(obj) } second - function(obj) { eval(evalu(obj), parent.frame()) } first() #returns 2, but I want 3. How do I change 'second' such that the value of 'a' from 'first' is returned? You could use the n argument to parent.frame (or eval.parent) inside evalu and go two generations back instead of one. Somewhat neater, you could pass the desired environment directly to evalu, as in e - parent.frame() evalu(obj, e) (I'm not sure it is actually needed to separate out the calculation of e, but I tend to be paranoid about evaluating parent.frame() in function arguments.) Thanks for the answer, but it isn't what I need. 'evalu' is a replacement for a function that I cannot change (update.default). My question is: How do I accomplish this by only changing 'second'? -- Med venlig hilsen Rune Schjellerup Philosof Ph.d.-studerende, Statistik, IST, SDU Telefon: 6550 3607 E-mail: rphilo...@health.sdu.dk Adresse: J.B. Winsløwsvej 9, 5000 Odense C __ 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] plotting huge data
gauravbhatti wrote: I have a data frame with 25000 rows containing two columns Time and Distance. When I plot a simple distance versus time plot, the plot is very confusing showing no general trend because of the large data. Is there any way I can improve the plot by lets say using moving average as in EXCEL ? please also suggest some other methods to make the graph smoother and better looking. Gaurav I recommend using the quantreg package to fit a quantile regression model using a spline function of Time. Draw the estimated curves for selected quantiles such as 0.1 0.25 0.5 0.75 0.9. A new function Rq in the Design package makes this easier but you can do it with just quantreg. 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.
Re: [R] adding color bar to a graph
Hi Jim, Thanks for your answer. It does it but not quite as i would like it ;-) I need the colors to be blended as the colorRampPalette does it going from one color to the next in the list. Your legend will have 5 discreet colors and accept a vector of colors as the image.plot command does. If i can make the rainbow have my colors would be great. I will look more into that. Thanks again, i really appreciate your suggestion, Monica Date: Fri, 7 Aug 2009 21:11:46 +1000 From: j...@bitwrit.com.au To: pisican...@hotmail.com CC: r-h...@stat.math.ethz.ch Subject: Re: [R] adding color bar to a graph Monica Pisica wrote: Hi everybody, I am wondering how i can add a stretch color bar / legend to a graph that uses colorBrewer to define the colors in it. I will try to explain my graph, but i also uploaded it at: ftp://ftpext.usgs.gov/pub/er/fl/st.petersburg/Monica_pal/ The file is: robcor_training_pca.pdf - i will also attach this file in case some people accept attachments. So i took apart the cor.plot function from mvoutlier and i used instead of the scatter plot function the smooth scatter density plot from geneplotter, generating my own function called cordens.plot. Now i would like to add a colorbar on the right side of the graph with red as my highest density and purple as the lowest density and right next to the colors labels min for purple and max for red (i don't want actual numbers, although i suppose i can deal with that as well if need be). I've tried image.plot function but i cannot set correctly the colors in the bar since i am not using an orthodox rainbow set. Originally my colors in the graph are set with colorRampPalette(c(darkviolet, deepskyblue4, green, yellow, red)). Hi Monica, I think color.legend in the plotrix package will do what you want. color.legend(200,0,220,100,legend=c(min,max), rect.col=c(darkviolet,deepskyblue4,green,yellow,red)) and you will have to add some space on the right side par(mar=c(5,4,4,4)) Jim _ n-US:SI_PH_software:082009 __ 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] eval parent.frame() twice
On 8/7/2009 7:36 AM, Rune Schjellerup Philosof wrote: Peter Dalgaard skrev: Rune Schjellerup Philosof wrote: Hi I want to use a function (update) that in its body uses eval(call, parent.frame()) I would like to use this function in a function that does not contain the variables referred to in 'call'. Those variables are instead in the parent.frame() of my function (named 'second' below) Like this: a - 2 evalu - function(obj) { call - obj$call eval(call, parent.frame()) } first - function() { a - 3 obj - list(call=expression(a)) second(obj) } second - function(obj) { eval(evalu(obj), parent.frame()) } first() #returns 2, but I want 3. How do I change 'second' such that the value of 'a' from 'first' is returned? You could use the n argument to parent.frame (or eval.parent) inside evalu and go two generations back instead of one. Somewhat neater, you could pass the desired environment directly to evalu, as in e - parent.frame() evalu(obj, e) (I'm not sure it is actually needed to separate out the calculation of e, but I tend to be paranoid about evaluating parent.frame() in function arguments.) Thanks for the answer, but it isn't what I need. 'evalu' is a replacement for a function that I cannot change (update.default). My question is: How do I accomplish this by only changing 'second'? I don't think there is any clean way to do that, but you can call update.default with evaluate=FALSE, and then evaluate the result in whatever environment you like. If you are determined to do it uncleanly, then one way would be to create a little function that has no names that should clash to call update.default, and set its environment to the environment in which you want the evaluation to happen. E.g. second - function(obj, formula) { my.update.default - function(.safe.obj, .safe.formula) { update.default(.safe.obj, .safe.formula) } environment(my.update.default) - parent.frame() my.update.default(obj, formula) } If your user happens to use .safe.obj or .safe.formula as the name of a variable in their model, this will fail, but otherwise it should work, because update.default will look at the locals of my.update.default first, before it goes to the parent, which is parent.frame(). If you need to pass more arguments to update.default you need to worry about their name clashes as well. Personally, I'd stick to the clean solution. You could try lobbying for a change to update.default, but I think you'd fail, because the clean solution is available. 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] solving system of equations involving non-linearities
If you suspect multiple roots, you can try `multiStart' in BB, which runs `BBsolve' from multiple starting values (which you have to specify). If you want to convert it to an optimization problem, you can form the sum of squared residuals of the equations and then use `BBoptim'. However, I would not advise that approach when you have a square system (i.e. the number of equations is the same as the number of unknowns). The optimization approach is useful (and necessary) for over-determined systems. Best, Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Werner W. Sent: Friday, August 07, 2009 2:43 AM To: r-help@r-project.org Subject: Re: [R] solving system of equations involving non-linearities Many thanks, BBsolve works like a charm. First I thought I should use the squares of the equations because BBsolve would use some minimization objective function anyway but it actually only works if I don't use the squared equations. I'll check the documentation if I find something about the objective. Thanks for the help, Werner Ravi Varadhan wrote: You have two options: 1. The `BBsolve' function in the BB package to solve this system of 3 equations. 2. Try `nleqslv' function in the nleqslv package. These would work even if the residual is not zero. Hope this helps, Ravi. -- View this message in context: http://www.nabble.com/solving-system-of-equations-involving-non-linearities- tp24845136p24859703.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.
[R] Gauss-Laguerre using statmod
I believe this may be more related to analysis than it is to R, per se. Suppose I have the following function that I wish to integrate: ff - function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma) Then, given the parameters: mu - 300 sigma - 50 m - 250 target - 200 sigma_i - 50 I can use the function integrate as: integrate(ff, lower= -Inf, upper=target) 0.002169851 with absolute error 4.4e-05 I would like to also use Gauss-Laguerre methods to also integrate this function. In doing so, I believe the only change of variable needed when integrating from -Inf to target is x = target - y_i where y_i is node i. As such, I can implement the following: library(statmod) falsePos - function(target, m, mu, sigma, sigma_i, Q = 30){ gq - gauss.quad(Q, kind=laguerre) nodes - gq$nodes whts - gq$weights y - pnorm((target - nodes - m)/sigma_i) * dnorm(target - nodes, mu, sigma) sum(y * exp(nodes)* whts) } falsePos(target = 200, m = 250, mu = 300, sigma = 50, sigma_i = 50) [1] 0.002169317 Which yields the same value as the internal R function. Now suppose I want to integrate in the opposite direction going from target to Inf using the same parameters as previously used. Again, the internal integrate function yields: integrate(ff, lower=target, upper=Inf) 0.7580801 with absolute error 7.2e-05 Now, my understanding of the change of variable needed for Gauss-Laguerre in this instance is simple, x = y_i + target. As such, the integration should be truePos - function(target, m, mu, sigma, sigma_i, Q = 30){ gq - gauss.quad(Q, kind=laguerre) nodes - gq$nodes whts - gq$weights y - pnorm((nodes + target - m)/sigma_i) * dnorm(nodes + target, mu, sigma) sum(y * exp(nodes)* whts) } truePos(target = 200, m = 250, mu = 300, sigma = 50, sigma_i = 50) [1] 0.2533494 Clearly, there is not a match in this instance. Looking at the density we can see that R's internal function is correct: plot(ff, 0, 500) I've used Gauss-Laguerre in the past with this same change of variable and obtained correct results for the integral. However, I seem to have an error in this situation that I can't seem to identify. Can anyone point out whether I have an error in the way I am approaching the problem mathematically or is there a programming error I seem to be missing? Many thanks for your help. Harold sessionInfo() R version 2.9.0 (2009-04-17) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] MiscPsycho_1.4 statmod_1.3.8 xtable_1.5-5 lme4_0.999375-28 Matrix_0.999375-25 [6] VAM_0.8-5 lattice_0.17-22 loaded via a namespace (and not attached): [1] grid_2.9.0 tools_2.9.0 __ 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] install package version compatible with on older version of R
Hi, I'm trying to install Chipster (for microarray analysis: http://chipster.csc.fi/), which expressly relies on R 2.6.1 (for now). So I'd like to install automatically (i.e. using a 'install.packages' like function) the last version of a package compatible with the running R version. For example, when I'm running R-2.6.1 and want to install package 'lme4' I get the following warning: In install.packages(lme4, repos = contrib.url(http://cran.r-project.org;)) : package ‘lme4’ is not available Also: available.packages(contriburl = contrib.url(http://cran.r-project.org;)) does not return any line for package lme4. This is because the latest version of package lme4 on CRAN depends on R 2.9.0. However there is older versions stored on CRAN that are compatible with R version 2.6.1 (in subdirectory contrib/Archive/lme4). Is there a script/package out there that does the trick, retrieving the list of the older versions and download the latest version compatible with R 2.6.1? 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] plotting huge data
FEH == Frank E Harrell f.harr...@vanderbilt.edu on Fri, 07 Aug 2009 07:19:16 -0500 writes: FEH gauravbhatti wrote: I have a data frame with 25000 rows containing two columns Time and Distance. That's large by some standards, but definitely not huge ... When I plot a simple distance versus time plot, the plot is very confusing showing no general trend because of the large data. Is there any way I can improve the plot by lets say using moving average as in EXCEL ? please also suggest some other methods to make the graph smoother and better looking. Gaurav FEH I recommend using the quantreg package to fit a quantile regression FEH model using a spline function of Time. Draw the estimated curves for FEH selected quantiles such as 0.1 0.25 0.5 0.75 0.9. A new function Rq in FEH the Design package makes this easier but you can do it with just quantreg. Yes, modelling (with quantreg or also lowess(), runmed() ...) is certainly a good idea for such a Y ~ X situation. But to answer the original question: Please note that R has had for a while the very nice and useful smoothScatter() function, written exactly for such cases, but also for cases that are closer to huge: E.g. still working fast for n - 1e6 Martin Maechler, ETH Zurich __ 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] How do I plot a line followed by two forecast points?
Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled according to the existing y axis). An example is pasted below. Any ideas on how to achieve this would be much appreciated. Thanking you in advance, George. # Sample dates xValues = seq.Date(as.Date(1990-01-31),to=as.Date(1992-12-31),by=month); # Sample y value yValues-NULL; yValues[1:length(xValues)]=seq(0.1,length=length(xValues)) # Plot the series as a line plot(xValues,yValues,type=l); # Sample forecast dates that start from xValue's data point fcastDates=seq.Date(from=as.Date(xValues[length(xValues)]),length=12,by=month); fcastDates [1] 1992-12-31 1993-01-31 1993-03-03 1993-03-31 1993-05-01 1993-05-31 [7] 1993-07-01 1993-07-31 1993-08-31 1993-10-01 1993-10-31 1993-12-01 # Sample forecast (we only want the forecast point to be displayed) fcast-NULL; fcast[1:length(fcastDates)]=NA; fcast[length(fcast)]-20; fcast [1] NA NA NA NA NA NA NA NA NA NA NA 20 # Add the forecast plot to the original plot par(new=TRUE) plot(fcastDates,fcast,yaxt=n,xaxt=n,col=red) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion # The second forecast fcastDates2=seq.Date(from=as.Date(fcastDates[length(fcastDates)]),length=12,by=month); fcastDates2 [1] 1993-12-01 1994-01-01 1994-02-01 1994-03-01 1994-04-01 1994-05-01 [7] 1994-06-01 1994-07-01 1994-08-01 1994-09-01 1994-10-01 1994-11-01 fcast2-NULL; fcast2[1:length(fcastDates2)]=NA; fcast2[length(fcast2)]-15; par(new=TRUE);plot(fcastDates2,fcast2,yaxt=n,xaxt=n,col=blue) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion __ 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] Is there a 'vi' mode in R?
On Fri, Aug 7, 2009 at 5:04 AM, Jakson Alves de Aquinojaksonaqu...@gmail.com wrote: Peng Yu wrote: I'm wondering if R provide a vi mode in the command line just like other shells such as bash do. Can somebody let me know? I maintain a Vim plugin that makes the interaction with R easier: http://www.vim.org/scripts/script.php?script_id=2628 The commands are sent through a pipe, and this approach has some limitations which are explained in the plugin's documentation. The plugin has been discussed here: http://ubuntuforums.org/showthread.php?t=776492 I have difficulties in understanding how to use it. I have successfully installed it and I see the menu item 'R' after I open a .R file with gvim. I then press F2, but nothing happens. What I should do, for example, if I want run the script in .R file that I just opened? Regards, Peng __ 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] Repeatable, But Time Varying R GUI Crash
G'day all, running the script in : [R.app GUI 1.28 (5399) i386-apple-darwin9.6.0] R version 2.9.0 (2009-04-17) i386-apple-darwin9.6.0 locale: en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base returned : junk = 1 mjunk = -1 sum = 0 i = 522 junk = 1 mjunk = -1 sum = 0 i = 523 junk = 1 mjunk = -1 sum = 0 i = 524 junk = 1 mjunk = -1 sum = 0 i = 525 Error in mjunk[3, 30] : object of type 'closure' is not subsettable Running it in the terminal returned: junk = 1 mjunk = -1 sum = 0 i = 954 junk = 1 mjunk = -1 sum = 0 i = 955 junk = 1 mjunk = -1 sum = 0 i = 956 junk = 1 mjunk = -1 sum = 0 i = 957 junk = 1 mjunk = -1 sum = 0 i = 958 Error in junk[1, 5] : object of type 'closure' is not subsettable I don't know if this helps you at all... cheers Ben On 07/08/2009, at 6:00 PM, Duncan Murdoch wrote: On 8/6/2009 4:11 PM, Marilyn Rich Short wrote: Hello, I'm having a problem in R. The R GUI is crashing with a message to contact Microsoft for the solution. I've contacted Microsoft and they are of no help. Below is a distilled set of code that will cause the crash. As you will see, there are two do-loops within which is a load command. The crash usually occurs after 200*400 (=80,000) to 2,000*400(=800,000) iterations. Do you have any suggestions on work-arounds? I can confirm it in R-patched as well. It happens on the very first time through if you set gctorture() on, so it looks like somewhere in there is a missing PROTECT, and the garbage collector is reclaiming something that it shouldn't. I'll try to track it down, but I'm not sure how quick I'll be. (My house is full of contractors right now, so not a very nice place to work.) I don't know any workaround other than avoid doing the buggy thing. But I can't tell you what that is Duncan Murdoch -- Ben Madin REMOTE INFORMATION t : +61 8 9192 5455 f : +61 8 9192 5535 m : 0448 887 220 Broome WA 6725 b...@remoteinformation.com.au Out here, it pays to know... __ 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] Proper / Improper scoring Rules
Hi All, I am working on some ordinal logistic regresssions using LRM in the Design package. My response variable has three categories (1,2,3) and after using the creating my model and using a call to predict some values and I wanted to use a simple .5 cut-off to classify my probabilities into the categories. I had two questions: a) first, I am having trouble directly accessing the probabilities which may have more to do with my lack of experience with R For instance, my calls ologit.three.NoPerFor - lrm(Threshold.Three ~ TECI , data=CLD, na.action=na.pass) CLD$Threshold.Predict.Three.NoPerFor- predict(ologit.three.NoPerFor, newdata=CLD, type=fitted.ind) CLD$Threshold.Predict.Three.NoPerFor.Cats[CLD$Threshold.Predict.Three.NoPerFor.Threshold.Three=1 .5] - 1 Error: unexpected '=' in CLD$Threshold.Predict.Three.NoPerFor.Cats[CLD$Threshold.Predict.Three.NoPerFor.Threshold.Three= produce an error message and it seems as R does not like the equal sign at all. So how does one access the probabilities so I can classify them into the categories of 1,2,3 so I can look at performance of my model ? b) which leads me to my next question. I thought that simply calculating the percent correct off of my predictions would be sufficient to look at performance but since my question is very much in line with this thread http://tolstoy.newcastle.edu.au/R/e4/help/08/04/8987.html I am not so sure anymore. I am afraid I did not understand Frank Harrell's last suggestion regarding improper scoring rule - can someone point me to some internet resources that I might be able to review to see why my approach would not be valid ? -- -Don Don Catanzaro, PhD Landscape Ecologist dgcatanz...@gmail.com 16144 Sigmond Lane Lowell, AR 72745 479-751-3616 __ 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] Problem with area()
I'm using area() to evaluate the area under 2 functions (defined using approxfun()) and the result is in contradiction with visual inspection (please see: http://sites.google.com/site/eospansite/dummy/problem_area.jpg ) The area under the red curve should be larger than the one under the black curve, but I'm geting the opposite result using area(). This is what I'm doing: require(MASS) f1 - approxfun(x,y1) f2 - approxfun(x,y2) plot(x,y1,ylim=range(c(y1,y2))) lines(x,f1(x),col=black) points(x,y2) lines(x,f2(x),col=red) area1 - area(f1,min(x),max(x)) area2 - area(f2,min(x),max(x)) text(4.5,1.6,paste(f2:,round(area2,3)),col=red) text(5.5,0.1,paste(f1:,round(area1,3)),col=black) title(main=Areas under curves) grid(50,50) What am I doing wrong? Could this be a problem with an inappropriate use of approxfun() ? Data can be found here: http://sites.google.com/site/eospansite/dummy/areaproblem.rda Thanks Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 e-mail agustin.l...@ija.csic.es http://www.ija.csic.es/gt/obster __ 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] problem with recording numeric output into another dataframe
Thank you very much for the reply. The thing I want to achieve in the end is to use dataframe1 as a master dataframe, and get values from multiple dataframes to dataframe1, so that I can analyze the data altogether, like this: IDvalue1 value2 value3 a 100 123 456 b 321 654 c 200564 I first created an empty column in dataframe1, and then I tried to record the values into this column at the corresponding rows, but I had a problem. I was not able to tell R please do nothing when there's not a match. DF1-transform(DF1, value1=rep(NA, nrow(DF1))) for (i in seq(1:nrow(DF1))) { if (is.numeric(DF2[grep(DF1[i, ID], DF2$ID), value])==T) {DF1-transform(DF1, value1[i]-DF2[grep(DF1[i, ID], DF2$ID), value])} else {print(bingo!)} } but the is.numeric() test was TRUE even when there was not a match, and it resulted in an error. If I do it reversely, I'll get all bingo! for (i in seq(1:nrow(DF1))) { if (is.numeric(DF2[grep(DF1[i, ID], DF2$ID), value])==T) {print(bingo!)} else {DF1-transform(DF1, value1[i]-DF2[grep(DF1[i, ID], DF2$ID), value])} } Any ideas how I can get what I wanted? Henrique Dallazuanna wrote: Try this: g - sapply(DF1$ID, grep, x = DF2$ID) transform(DF2[unlist(g),],ID = DF1$ID[which(g 0)]) On Thu, Aug 6, 2009 at 1:41 PM, Rnewbie xua...@yahoo.com wrote: dear all, I have two dataframes dataframe1 ID a b c dataframe2 ID value a;W 100 X;c 200 Y;Z 300 I wanted to match the IDs from the two dataframes and record the values into a new column of dataframe1 at the corresponding rows. This is what I expect: dataframe1 ID value a 100 b c 200 I tried doing it like this: for (i in seq(1:nrow(dataframe1))) { dataframe1[i,value]-dataframe2[grep(dataframe1[i,ID], dataframe2$ID),value] } but I failed. I was able to extracted the values from dataframe2 but not able to record the values in the corresponding rows of dataframe1. I would appreciate any suggestions. Thanks in advance. Jim -- View this message in context: http://www.nabble.com/problem-with-recording-numeric-output-into-another-dataframe-tp24850155p24850155.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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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. -- View this message in context: http://www.nabble.com/problem-with-recording-numeric-output-into-another-dataframe-tp24850155p24865628.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] bug with subset and plot?
Hi! I have the following problem that I beleive is a bug: I have a dataframe with one categorical and one numerical vector. The categorical vector has three levels (uc, up and vc). A plot of the vectors with the categorical vector on the x-axis gives a boxplot with three boxes - exactly as expected. If I then use the subset function to make a dataset that only includes two of the levels of the categorical vector and do the plot again, all three levels are still shown on the x-axis even though one of them doesn't exist in the dataset. The plot shows correct number of boxes (2). The whole syntax for what I describe is as follows: exploration.df - read.table('clipboard', header=T) attach(exploration.df) plot(treatment,total.escapes) exp.df - subset(exploration.df, treatment!='up') attach(exp.df) plot(treatment, total.escapes) I use R version 2.9.1 (2009-06-26) for Debian. Knut Helge Jensen __ 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] cannot upgrade to R 2.9.1 in Ubuntu
R-help, At the moment the R version installed on my machine is 2.8.1. (Ubuntu 9.04) I wish to upgrade to R 2.9.1. I did: $ sudo apt-get upgrade ..but R is not upgraded although the sources.list file is updated with: deb http://cran.ii.uib.no/bin/linux/ubuntu jaunty/ When I run from the terminal I still get: $ R R version 2.8.1 (2008-12-22) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale .. .. Thanks in advance __ 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 ::Not able to Connect R to SQL Server 2000
Hi Simon, Now I am able to connect my SQL Server2000 from R using RODBC as you told me in the last line of your mail. Thanks a lot to you Simon for helping. Now I feel better than before. J Cheers!! BS -Original Message- From: Simon Urbanek [mailto:simon.urba...@r-project.org] Sent: Thursday, August 06, 2009 10:40 PM To: bed.si...@oracle.com Cc: r-help@r-project.org Subject: Re: Help ::Not able to Connect R to SQL Server 2000 On Aug 6, 2009, at 10:36 , bed.si...@oracle.com wrote: Hi Simon, I am using the R 2.9.1 with Window XP. I have one query related with R to the database. I have successfully connected R to MS-Access. But when I tried to connect R to SQL Server 2000 then it throwing some class not found error. I tried the below script for R and try to connect to SQL Server 2000. library(rJava) library(DBI) library(RJDBC) drv-JDBC(com.microsoft.jdbc.sqlserver.SQLServerDriver) Error in .jfindClass(as.character(driverClass)[1]) : class not found Can you please help me in this? Thanks to you. I suspect that you'll need to load the corresponding drivers. The message essentially tells you that the driver (class) you're trying to load is not known. I don't use Windows (and even less so SQL Server), so I'd suggest you search for JDBC and MS SQL Server and/or ask on the SIG-DB mailing list (although this is technically not an R question). With some luck there may be some MS SQL users on this list as well.. However, if you are on Windows, you may want to go directly to ODBC using RODBC instead of going through JDBC. Cheers, Simon [[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] A question regarding R scoping
Dear All, Sorry for the introduced confusion. My question is to have a function (in my case f1) that just takes an argument and modifies it (no copies, no returns). This can be done by: f1 = function(i){i - 1} Then this function is called by another function (in my case f2) that just initializes the above mentioned argument and calls f1, like this f2 = function(n){ ##whatever initialization on i f1(i) print(i) } Obviously in my code example f1 loses its ability to modify its argument, so the question is how to modify f2 so that it prints out 1. -ivo --- On Fri, 8/7/09, markle...@verizon.net markle...@verizon.net wrote: From: markle...@verizon.net markle...@verizon.net Subject: Re: Re: [R] A question regarding R scoping To: murd...@stats.uwo.ca Cc: idc...@yahoo.com, r-help@r-project.org Date: Friday, August 7, 2009, 8:33 AM Hi Gabor, Steve, Eric and Duncan: I played around with below because I've always find scope in R difficult and I think the confusion with the question is arising because it's not clear whether the person who asked it wants i to be changed in f2 or in the global environment. I didn't know this before I started playing but the first f1 below is quite different from the second and the third ( which are identical ) which I'm sure all of you are well aware of. But that's why there's confusion with the question I think. I apologize if this email ends up having a lot of control A's in it. I still haven't cracked that problem yet. f1 - function(i) assign('i', 1, envir=parent.frame()) f1 - function(i) assign('i', 1, envir=.GlobalEnv) f1 - function(i) { i - 1 } f2 - function(n) { i - length(n) f1(i) print(i) } f2(1:20) print(i) rm(i) On Aug 6, 2009, Duncan Murdoch murd...@stats.uwo.ca wrote: Ivo Shterev wrote: Hi, Perhaps I have to rephrase a bit my question. If we have the following: i = 10 f1 = function(i){ i - 1 } after calling f1, the value of i becomes 1. Now, suppose that f1 is called in another function f2, and i is initialized in f2 as well, i.e: f2 = function(n){ i = n f1(i) } The intention is, after executing f2, i=1 (not i=n). That is what you get. What is the question? Duncan Murdoch --- On Thu, 8/6/09, Steve Lianoglou mailinglist.honey...@gmail.com wrote: From: Steve Lianoglou mailinglist.honey...@gmail.com Subject: Re: [R] A question regarding R scoping To: Ivo Shterev idc...@yahoo.com Cc: r-help@r-project.org Date: Thursday, August 6, 2009, 10:23 PM Howdy, On Aug 6, 2009, at 4:11 PM, Ivo Shterev wrote: Hi, The intention is that after executing f2, the value of i to become 1. f1 = function(i){i = 1} f2 = function(n){ i = length(n) f1(i) print(i)} i.e. f2 should print 1, not length(n). Yeah, you can using parent.frame()'s and such: f1 - function(i) assign('i', 10, envir=parent.frame()) f2 - function(n) { i - length(n) f1(i) print(i) } R f2(1:20) [1] 10 Honestly, this just smells like a *really* bad idea, though ... just have f1() return a value that you use in f2. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ 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.
Re: [R] bug with subset and plot?
http://stackoverflow.com/questions/1195826/dropping-factor-levels-in-a-subsetted-data-frame-in-r -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Knut Helge Jensen Sent: Friday, August 07, 2009 5:02 AM To: r-h...@stat.math.ethz.ch Subject: [R] bug with subset and plot? Hi! I have the following problem that I beleive is a bug: I have a dataframe with one categorical and one numerical vector. The categorical vector has three levels (uc, up and vc). A plot of the vectors with the categorical vector on the x-axis gives a boxplot with three boxes - exactly as expected. If I then use the subset function to make a dataset that only includes two of the levels of the categorical vector and do the plot again, all three levels are still shown on the x-axis even though one of them doesn't exist in the dataset. The plot shows correct number of boxes (2). The whole syntax for what I describe is as follows: exploration.df - read.table('clipboard', header=T) attach(exploration.df) plot(treatment,total.escapes) exp.df - subset(exploration.df, treatment!='up') attach(exp.df) plot(treatment, total.escapes) I use R version 2.9.1 (2009-06-26) for Debian. Knut Helge Jensen __ 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] error installing bioconductor
Hi, I am new to R. I am downloaded the installer for R 2.9.1, and that installed just fine. Then I want to install Biocondcutor packages. According to bioconductor website, I input the following commands. source(http://bioconductor.org/biocLite.R;) bioLite() Error: could not find function bioLite What am I doing wrong here? Thanks -- View this message in context: http://www.nabble.com/error-installing-bioconductor-tp24866247p24866247.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] lattice dotplot: line height for multi-line labels
Dear R-users, I am looking for suggestions on how to control the line-height for multi-line labels in lattice dotplot. In particular, in the dotplot produced by library(lattice) aa - c('A'=10,'B\nb'=20,'C'=30) dotplot(aa) I would like to control the vertical separation between 'B' and 'b' in the second label on the y-axis. For multi-line axes labels, line height is controlled by the 'lineheight' elements of the 'par.ylab.text' and 'par.xlab.tex' lists provided by trellis.par.get(). However, 'lineheight' is not available in 'axis.text' list retuned by trellis.par.get(). Does lattice provided a 'lineheight' parameter to control line-heights in axis labels? Sincerely, Boris Vasiliev. __ 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] Proper / Improper scoring Rules
Donald Catanzaro, PhD wrote: Hi All, I am working on some ordinal logistic regresssions using LRM in the Design package. My response variable has three categories (1,2,3) and after using the creating my model and using a call to predict some values and I wanted to use a simple .5 cut-off to classify my probabilities into the categories. I had two questions: a) first, I am having trouble directly accessing the probabilities which may have more to do with my lack of experience with R For instance, my calls ologit.three.NoPerFor - lrm(Threshold.Three ~ TECI , data=CLD, na.action=na.pass) CLD$Threshold.Predict.Three.NoPerFor- predict(ologit.three.NoPerFor, newdata=CLD, type=fitted.ind) CLD$Threshold.Predict.Three.NoPerFor.Cats[CLD$Threshold.Predict.Three.NoPerFor.Threshold.Three=1 .5] - 1 Error: unexpected '=' in CLD$Threshold.Predict.Three.NoPerFor.Cats[CLD$Threshold.Predict.Three.NoPerFor.Threshold.Three= produce an error message and it seems as R does not like the equal sign at all. So how does one access the probabilities so I can classify them into the categories of 1,2,3 so I can look at performance of my model ? use == to check equality b) which leads me to my next question. I thought that simply calculating the percent correct off of my predictions would be sufficient to look at performance but since my question is very much in line with this thread http://tolstoy.newcastle.edu.au/R/e4/help/08/04/8987.html I am not so sure anymore. I am afraid I did not understand Frank Harrell's last suggestion regarding improper scoring rule - can someone point me to some internet resources that I might be able to review to see why my approach would not be valid ? Percent correct will give you misleading answers and is game-able. It is also ultra-high-variance. Though not a truly proper scoring rule, Somers' Dxy rank correlation (generalization of ROC area) is helpful. Better still: use the log-likelihood and related quantities (deviance, adequacy index as described in my book). 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.
Re: [R] Repeatable, But Time Varying R GUI Crash
The bug is now fixed in R-patched and R-devel. Duncan Murdoch On 8/7/2009 11:38 AM, Ben Madin wrote: G'day all, running the script in : [R.app GUI 1.28 (5399) i386-apple-darwin9.6.0] R version 2.9.0 (2009-04-17) i386-apple-darwin9.6.0 locale: en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base returned : junk = 1 mjunk = -1 sum = 0 i = 522 junk = 1 mjunk = -1 sum = 0 i = 523 junk = 1 mjunk = -1 sum = 0 i = 524 junk = 1 mjunk = -1 sum = 0 i = 525 Error in mjunk[3, 30] : object of type 'closure' is not subsettable Running it in the terminal returned: junk = 1 mjunk = -1 sum = 0 i = 954 junk = 1 mjunk = -1 sum = 0 i = 955 junk = 1 mjunk = -1 sum = 0 i = 956 junk = 1 mjunk = -1 sum = 0 i = 957 junk = 1 mjunk = -1 sum = 0 i = 958 Error in junk[1, 5] : object of type 'closure' is not subsettable I don't know if this helps you at all... cheers Ben On 07/08/2009, at 6:00 PM, Duncan Murdoch wrote: On 8/6/2009 4:11 PM, Marilyn Rich Short wrote: Hello, I'm having a problem in R. The R GUI is crashing with a message to contact Microsoft for the solution. I've contacted Microsoft and they are of no help. Below is a distilled set of code that will cause the crash. As you will see, there are two do-loops within which is a load command. The crash usually occurs after 200*400 (=80,000) to 2,000*400(=800,000) iterations. Do you have any suggestions on work-arounds? I can confirm it in R-patched as well. It happens on the very first time through if you set gctorture() on, so it looks like somewhere in there is a missing PROTECT, and the garbage collector is reclaiming something that it shouldn't. I'll try to track it down, but I'm not sure how quick I'll be. (My house is full of contractors right now, so not a very nice place to work.) I don't know any workaround other than avoid doing the buggy thing. But I can't tell you what that is 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] error installing bioconductor
On Aug 7, 2009, at 10:51 AM, foxhunt99 wrote: Hi, I am new to R. I am downloaded the installer for R 2.9.1, and that installed just fine. Then I want to install Biocondcutor packages. According to bioconductor website, I input the following commands. source(http://bioconductor.org/biocLite.R;) bioLite() Error: could not find function bioLite You misspelled biocLite. What am I doing wrong here? Thanks -- View this message in context: http://www.nabble.com/error-installing-bioconductor-tp24866247p24866247.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. David Winsemius, MD Heritage Laboratories 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] error installing bioconductor
First, there is a separate Bioconductor list for future Bioc questions.. Second, you're typing the wrong function name. biocLite(), not bioLite() -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of foxhunt99 Sent: Friday, August 07, 2009 9:51 AM To: r-help@r-project.org Subject: [R] error installing bioconductor Hi, I am new to R. I am downloaded the installer for R 2.9.1, and that installed just fine. Then I want to install Biocondcutor packages. According to bioconductor website, I input the following commands. source(http://bioconductor.org/biocLite.R;) bioLite() Error: could not find function bioLite What am I doing wrong here? Thanks -- View this message in context: http://www.nabble.com/error-installing-bioconductor-tp24866247p24866247.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] lattice dotplot: line height for multi-line labels
On 8/7/09, boris.vasil...@forces.gc.ca boris.vasil...@forces.gc.ca wrote: Dear R-users, I am looking for suggestions on how to control the line-height for multi-line labels in lattice dotplot. In particular, in the dotplot produced by library(lattice) aa - c('A'=10,'B\nb'=20,'C'=30) dotplot(aa) I would like to control the vertical separation between 'B' and 'b' in the second label on the y-axis. For multi-line axes labels, line height is controlled by the 'lineheight' elements of the 'par.ylab.text' and 'par.xlab.tex' lists provided by trellis.par.get(). However, 'lineheight' is not available in 'axis.text' list retuned by trellis.par.get(). Does lattice provided a 'lineheight' parameter to control line-heights in axis labels? No, but setting it globally as a grid parameter seems to work: dotplot(aa, par.settings = list(grid.pars = list(lineheight = 2))) -Deepayan __ 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] A question regarding R scoping
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivo Shterev Sent: Friday, August 07, 2009 9:36 AM To: murd...@stats.uwo.ca; markle...@verizon.net Cc: r-help@r-project.org Subject: Re: [R] A question regarding R scoping Dear All, Sorry for the introduced confusion. My question is to have a function (in my case f1) that just takes an argument and modifies it (no copies, no returns). This can be done by: f1 = function(i){i - 1} Then this function is called by another function (in my case f2) that just initializes the above mentioned argument and calls f1, like this f2 = function(n){ ##whatever initialization on i f1(i) print(i) } Obviously in my code example f1 loses its ability to modify its argument, so the question is how to modify f2 so that it prints out 1. In general, S functions do not modify their arguments. However functions defined in the form `f`1-` - function(x, ..., value) { # last argument must be called 'value' newx - someFunctionOf(x, ..., value) newx } and called as f1(x) - myValue will alter x, giving it the value of someFunctionOf(x,myValue). (Do not call `f1-` directly, as new-`f1-`(x,value=value).) In any case, only things on the left side of the assignment operator will be assigned to. If you write such a 'replacement function' it is good form to write an extraction function to do the inverse, as then you can nest the replacement function calls, as in f1(x)[1:2] - myValue. In your case you could write such a function that ignored the value argument and just returned 1 `f1-` - function(x, value) 1 but you would have to call it in the required form f1(x) - ignoredValue E.g., `f1-` - function(x, value) 1 x-c(pi, 1i, exp(1)) k [1] 3.141593+0i 0.00+1i 2.718282+0i f1(k) - ignored k [1] 1 You might make use of the value argument so that, e.g., 'initial' meant to give a suitable starting value and 'terminal' would give it whatever value meant the procedure was over. The extraction function could then return 'initial' or 'terminal' or 'in progress'. Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com -ivo ... __ 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] bug with subset and plot?
See http://wiki.r-project.org/rwiki/doku.php?id=tips:data-manip:drop_unused_levels -Ista Hi! I have the following problem that I beleive is a bug: I have a dataframe with one categorical and one numerical vector. The categorical vector has three levels (uc, up and vc). A plot of the vectors with the categorical vector on the x-axis gives a boxplot with three boxes - exactly as expected. If I then use the subset function to make a dataset that only includes two of the levels of the categorical vector and do the plot again, all three levels are still shown on the x-axis even though one of them doesn't exist in the dataset. The plot shows correct number of boxes (2). The whole syntax for what I describe is as follows: exploration.df - read.table('clipboard', header=T) attach(exploration.df) plot(treatment,total.escapes) exp.df - subset(exploration.df, treatment!='up') attach(exp.df) plot(treatment, total.escapes) I use R version 2.9.1 (2009-06-26) for Debian. Knut Helge Jensen __ 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] bug with subset and plot?
hi knut may be: treatment-factor(treatment) plot(...) cheers milton On Fri, Aug 7, 2009 at 6:02 AM, Knut Helge Jensen knut.jen...@bio.uib.nowrote: Hi! I have the following problem that I beleive is a bug: I have a dataframe with one categorical and one numerical vector. The categorical vector has three levels (uc, up and vc). A plot of the vectors with the categorical vector on the x-axis gives a boxplot with three boxes - exactly as expected. If I then use the subset function to make a dataset that only includes two of the levels of the categorical vector and do the plot again, all three levels are still shown on the x-axis even though one of them doesn't exist in the dataset. The plot shows correct number of boxes (2). The whole syntax for what I describe is as follows: exploration.df - read.table('clipboard', header=T) attach(exploration.df) plot(treatment,total.escapes) exp.df - subset(exploration.df, treatment!='up') attach(exp.df) plot(treatment, total.escapes) I use R version 2.9.1 (2009-06-26) for Debian. Knut Helge Jensen __ 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.htmlhttp://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] Time Series smoothing
My guess is that your data, 'x', has frequency 1, or is not a ts object altogether. In both cases there is no meaningful way of extracting a sesonal component from the data. However, as you can see in the help page, HoltWinters has an argument 'gamma' that, when given the value 0, allows to fit non-seasonal models. Cross your finger and try HoltWinters(x, gamma = 0) Best, Giovanni Date: Thu, 06 Aug 2009 15:06:26 -0700 (PDT) From: voidobscura nshah...@gmail.com Sender: r-help-boun...@r-project.org Precedence: list Hello, [5956] 10242.793600 10233.872700 10229.265400 10230.835200 10230.715500 [5961] 10233.706500 10231.821200 10235.511800 10232.515900 10240.365800 [5966] 10244.216100 10252.208800 10249.710600 10249.591500 10258.640800 [5971] 10263.172300 10263.327800 10271.161200 10268.512200 10268.465800 [5976] 10272.819000 10273.321700 10278.570500 10265.448300 10278.325400 [5981] 10274.21 10281.323700 10274.569600 10276.431600 10279.039900 [5986] 10279.232600 10276.020600 10271.650200 10267.213500 10262.682000 [5991] 10261.586500 10253.623600 10243.466400 10245.071800 10242.889200 [5996] 10241.417900 10240.785600 10234.565600 10236.755200 10229.893600 [6001] 10225.274200 There is a sample from the dataset (which happens to be quite large, a subset of energy release values from fusion reactions). HoltWinters(x) Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods Thanks. Giovanni Petris wrote: Please do read the posting guides and give us a reproducible example. We don't know what the errors you get from HoltWinters are. I guess we need to see the data you are using etc. Giovanni Petris Date: Thu, 06 Aug 2009 11:33:58 -0700 (PDT) From: voidobscura nshah...@gmail.com Sender: r-help-boun...@r-project.org Precedence: list I have a set of data (in a matrix). I spliced a column out and parsed it as.ts (time series). I then plotted the time series but I found that it was very noisy. I wanted to smooth it out. However, I am having some problems smoothing and plotting the smoothed version. A - as.ts(read.table(choose.files())) x - as.ts(A[,10]) plot(x) plot(smooth(x)) plot(smooth(x)) looks exactly like plot(x). Also, StructTS(x) Error in optim(init[mask], getLike, method = L-BFGS-B, lower = rep(0, : L-BFGS-B needs finite values of 'fn' The HoltWinters smoothing or the Kalman smoothing don't work either for various errors... I'm not quite sure what's wrong. Thanks. -- View this message in context: http://www.nabble.com/Time-Series-smoothing-tp24852054p24852054.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. -- View this message in context: http://www.nabble.com/Time-Series-smoothing-tp24852054p24855346.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] R book for economists
There is also Grant Farnsworth's Econometrics in R in the contributed documentation section of the R website: http://cran.r-project.org/doc/contrib/Farnsworth-EconometricsInR.pdf Best, Trevor Thiemo Fetzer wrote: Dear Group, I am an economics student starting with PhD work in London. As preparation I would like to get to know R a little bit better. For Stata there are tons of books, however, can you recommend a book for R? I have some substantiated econometrics knowledge, so it should be more a how-to book. Best regards Thiemo --- Thiemo Fetzer, Economist http://freigeist.devmag.net http://www.devmag.net __ 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] Is there a 'vi' mode in R?
If you are using R in a *nix machine then R is usually compiled with support for gnu-readline which does have a vi mode. You need a file called .inputrc in your home directory containing the following line: set editing-mode vi in order to activate it. It works exactly like the vi mode in bash (which also uses gnu-readline). I don't think you can get a vi mode for the R command prompt in Windows. Regards, Trevor Peng Yu wrote: Hi, I'm wondering if R provide a vi mode in the command line just like other shells such as bash do. Can somebody let me know? Regards, Peng __ 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] Is there a 'vi' mode in R?
On 8/6/09, Peng Yu pengyu...@gmail.com wrote: Hi, I'm wondering if R provide a vi mode in the command line just like other shells such as bash do. Can somebody let me know? I've never used vi-mode, but vi mode in bash (at least) is provided by the readline library, and R uses the same library. If you set up your bash to use vi-mode, e.g., by including set editing-mode vi in your ~/.inputrc, and then start R, you should get into vi-mode. Alternatively, if you start up R in emacs editing mode, M-C-j will change to vi mode. -Deepayan __ 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] RE xtable, sweave and resizebox
Hello In doc of xtable.pdf at page 7 : .../... ## Demonstration of longtable support. ## Remember to insert \usepackage{longtable} on your LaTeX preamble x - matrix(rnorm(1000), ncol = 10) x.big - xtable(x,label='tabbig',caption='Example of longtable spanning several pages') print(x.big,tabular.environment='longtable',floating=FALSE) x - x[1:30,] x.small - xtable(x,label='tabsmall',caption='regular table env') print(x.small) # default, no longtable ## Demonstration of sidewaystable support. ## Remember to insert \usepackage{rotating} on your LaTeX preamble print(x.small,floating.environment='sidewaystable') if(require(stats,quietly=TRUE)) { .../... HTH Denis Teysseyre __ 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] Gauss-Laguerre using statmod
Harold, I don't think there is any error in your code. The problem is with using Gauss-Laguerre quadrature for this integrand. I changed your function `ff' slightly so that it admits a closed-form integral (I took the means and sigmas to be the same): ff2 - function(x) pnorm(x, mu, sigma) * dnorm(x, mu, sigma) # exact anti-derivative of this is 0.5 * (pnorm(x, mu, sigma))^2 options(digits=6) xt - seq(200, 400, by=20) results - matrix(NA, length(xt), 4) colnames(results) - c(target, exact, integrate, laguerre) i - 0 for (target in xt) { i - i + 1 num1 - integrate(ff2, lower= -Inf, upper=target)$val exact - 0.5 * pnorm(target, mu, sigma)^2 num2 - falsePos(target = target, m = 300, mu = 300, sigma = 50, sigma_i = 50) results[i, ] - c(target, exact, num1, num2) } results xt - seq(200, 400, by=20) results2 - matrix(NA, length(xt), 4) colnames(results2) - c(target, exact, integrate, laguerre) i - 0 for (target in xt) { i - i + 1 num1 - integrate(ff2, lower= target, upper=Inf)$val exact - 0.5 - 0.5 * pnorm(target, mu, sigma)^2 num2 - truePos(target = target, m = 300, mu = 300, sigma = 50, sigma_i = 50) results2[i, ] - c(target, exact, num1, num2) } results2 These 2 experiments clearly show that you cannot accurately compute the integral that you want using Gauss-Laguerre quadrature. This problem perists even after you increase the number of quadrature points from Q=30 to Q=100. It is also clear that `integrate' does a good job. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold Sent: Friday, August 07, 2009 9:34 AM To: r-help@r-project.org Subject: [R] Gauss-Laguerre using statmod I believe this may be more related to analysis than it is to R, per se. Suppose I have the following function that I wish to integrate: ff - function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma) Then, given the parameters: mu - 300 sigma - 50 m - 250 target - 200 sigma_i - 50 I can use the function integrate as: integrate(ff, lower= -Inf, upper=target) 0.002169851 with absolute error 4.4e-05 I would like to also use Gauss-Laguerre methods to also integrate this function. In doing so, I believe the only change of variable needed when integrating from -Inf to target is x = target - y_i where y_i is node i. As such, I can implement the following: library(statmod) falsePos - function(target, m, mu, sigma, sigma_i, Q = 30){ gq - gauss.quad(Q, kind=laguerre) nodes - gq$nodes whts - gq$weights y - pnorm((target - nodes - m)/sigma_i) * dnorm(target - nodes, mu, sigma) sum(y * exp(nodes)* whts) } falsePos(target = 200, m = 250, mu = 300, sigma = 50, sigma_i = 50) [1] 0.002169317 Which yields the same value as the internal R function. Now suppose I want to integrate in the opposite direction going from target to Inf using the same parameters as previously used. Again, the internal integrate function yields: integrate(ff, lower=target, upper=Inf) 0.7580801 with absolute error 7.2e-05 Now, my understanding of the change of variable needed for Gauss-Laguerre in this instance is simple, x = y_i + target. As such, the integration should be truePos - function(target, m, mu, sigma, sigma_i, Q = 30){ gq - gauss.quad(Q, kind=laguerre) nodes - gq$nodes whts - gq$weights y - pnorm((nodes + target - m)/sigma_i) * dnorm(nodes + target, mu, sigma) sum(y * exp(nodes)* whts) } truePos(target = 200, m = 250, mu = 300, sigma = 50, sigma_i = 50) [1] 0.2533494 Clearly, there is not a match in this instance. Looking at the density we can see that R's internal function is correct: plot(ff, 0, 500) I've used Gauss-Laguerre in the past with this same change of variable and obtained correct results for the integral. However, I seem to have an error in this situation that I can't seem to identify. Can anyone point out whether I have an error in the way I am approaching the problem mathematically or is there a programming error I seem to be missing? Many thanks for your help. Harold sessionInfo() R version 2.9.0 (2009-04-17) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] MiscPsycho_1.4 statmod_1.3.8 xtable_1.5-5 lme4_0.999375-28 Matrix_0.999375-25 [6] VAM_0.8-5 lattice_0.17-22 loaded via a namespace (and not attached): [1] grid_2.9.0 tools_2.9.0 __ 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
Re: [R] A question regarding R scoping
Hi Mark, I think your suggestion to call rm(i) before or after calling f1 so that the local variable is removed, is the most straighforward solution to my problem. I was trying to implement some efficient C-style techniques in R, but the scoping principle in R is quite different than C. Thank you very much for the help! Best Regards Ivo --- On Fri, 8/7/09, markle...@verizon.net markle...@verizon.net wrote: From: markle...@verizon.net markle...@verizon.net Subject: Re: Re: Re: [R] A question regarding R scoping To: idc...@yahoo.com Date: Friday, August 7, 2009, 6:57 PM Hi Ivo: There's something wrong with my mailer so I'm not including the R-list on this email. I found your question interesting because scope in R has always been befuddling to me. But, I'm still not following you because if you run below , i does get changed ? I set it to 100 in the .GlobalEnv initially. Then I delete it. Then I run f2 and it's equal to 1 inside f2 and equal to 1 in .GlobalEnv. Is that not what you want ? f1 = function(i){i - 1} Then this function is called by another function (in my case f2) that just initializes the above mentioned argument and calls f1, like this f2 = function(n){ ##whatever initialization on i f1(i) print(i) } i - 100 rm(i) f2(1:20) print(i) On Aug 7, 2009, Ivo Shterev idc...@yahoo.com wrote: Dear All, Sorry for the introduced confusion. My question is to have a function (in my case f1) that just takes an argument and modifies it (no copies, no returns). This can be done by: f1 = function(i){i - 1} Then this function is called by another function (in my case f2) that just initializes the above mentioned argument and calls f1, like this f2 = function(n){ ##whatever initialization on i f1(i) print(i) } Obviously in my code example f1 loses its ability to modify its argument, so the question is how to modify f2 so that it prints out 1. -ivo --- On Fri, 8/7/09, markle...@verizon.net markle...@verizon.net wrote: From: markle...@verizon.net markle...@verizon.net Subject: Re: Re: [R] A question regarding R scoping To: murd...@stats.uwo.ca Cc: idc...@yahoo.com, r-help@r-project.org Date: Friday, August 7, 2009, 8:33 AM Hi Gabor, Steve, Eric and Duncan: I played around with below because I've always find scope in R difficult and I think the confusion with the question is arising because it's not clear whether the person who asked it wants i to be changed in f2 or in the global environment. I didn't know this before I started playing but the first f1 below is quite different from the second and the third ( which are identical ) which I'm sure all of you are well aware of. But that's why there's confusion with the question I think. I apologize if this email ends up having a lot of control A's in it. I still haven't cracked that problem yet. f1 - function(i) assign('i', 1, envir=parent.frame()) f1 - function(i) assign('i', 1, envir=.GlobalEnv) f1 - function(i) { i - 1 } f2 - function(n) { i - length(n) f1(i) print(i) } f2(1:20) print(i) rm(i) On Aug 6, 2009, Duncan Murdoch murd...@stats.uwo.ca wrote: Ivo Shterev wrote: Hi, Perhaps I have to rephrase a bit my question. If we have the following: i = 10 f1 = function(i){ i - 1 } after calling f1, the value of i becomes 1. Now, suppose that f1 is called in another function f2, and i is initialized in f2 as well, i.e: f2 = function(n){ i = n f1(i) } The intention is, after executing f2, i=1 (not i=n). That is what you get. What is the question? Duncan Murdoch --- On Thu, 8/6/09, Steve Lianoglou mailinglist.honey...@gmail.com wrote: From: Steve Lianoglou mailinglist.honey...@gmail.com Subject: Re: [R] A question regarding R scoping To: Ivo Shterev idc...@yahoo.com Cc: r-help@r-project.org Date: Thursday, August 6, 2009, 10:23 PM Howdy, On Aug 6, 2009, at 4:11 PM, Ivo Shterev wrote: Hi, The intention is that after executing f2, the value of i to become 1. f1 = function(i){i = 1} f2 = function(n){ i = length(n) f1(i) print(i)} i.e. f2 should print 1, not length(n). Yeah, you can using parent.frame()'s and such: f1 - function(i) assign('i', 10, envir=parent.frame()) f2 - function(n) { i - length(n) f1(i) print(i) } R f2(1:20) [1] 10 Honestly, this just smells like a *really* bad idea, though ... just have f1() return a value that you use in f2. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of
[R] lattice: simultaneously control aspect outer whitespace
Suppose we wish to achieve the following three aims: (1) Control the aspect ratio of our plot (i.e., tweak this till it looks great) (2) Save the plot as a PDF with zero or minimal white space outside it. (3) Preserve this in code, so that in the future the exact same plot can be reproduced by simply sourcing the code. I can almost achieve (1) and (2) on my MacBook Pro by pointing and clicking, as follows: Start with graphics.off(). Generate the plot on the computer screen; then the outer margins are pretty thin by default. Use the mouse to adjust the aspect ratio until it looks right. The fact that I pointed and clicked precludes (3). If, to avoid point-and-click, I attempt to control the aspect ratio with the aspect argument to xyplot, then a large whitespace appears outside the graphic in the plot on my computer screen. This whitespace is carried over to the saved *.pdf file. If, instead of first creating the graphic on the computer screen and then saving it, I create it in a postscript graphics device, trellis.device(postscript, file=junk.ps) then the right outer margin is zero. That is, the graphic ends exactly at the rightmost border of the box around the plot. But the bottom, left, and top contain extra whitespace outside the graphic region. Specifying par(oma=rep(0,4)) par(mar=rep(0,4)) after opening the Postscript device appears to have no effect whatsoever on this. What is the right approach? It would be nice to be able to specify both the aspect ratio and the amount of whitespace outside the plot, and then let the software compute the necessary dimensions of the graphic device that are necessary to accomodate these specs. Thanks for any ideas Jacob A. Wegelin Assistant Professor Department of Biostatistics Virginia Commonwealth University 730 East Broad Street Room 3006 P. O. Box 980032 Richmond VA 23298-0032 U.S.A. E-mail: jwege...@vcu.edu URL: http://www.people.vcu.edu/~jwegelin [[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] A question regarding R scoping
__ 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-ddply question
Hi all: I am trying to use the ddply function to estimate the mean of 'Total','Fry','Smolt' and 'Fry.Eq' columns without success. I have the dput of my dataset below. I wonder if someone can give me a hand with this function. # dput(winter) winter -structure(list(IDDate = structure(c(37L, 48L, 59L, 62L, 63L, 64L, 65L, 66L, 67L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 60L, 61L, 68L, 79L, 90L, 93L, 94L, 95L, 96L, 97L, 98L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L, 92L, 99L, 110L, 121L, 123L, 124L, 125L, 126L, 127L, 128L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 122L, 2L, 13L, 24L, 27L, 28L, 29L, 30L, 31L, 32L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 25L, 26L, 33L, 34L, 35L, 36L), .Label = c(, 10/1/2008, 10/10/2008, 10/11/2008, 10/12/2008, 10/13/2008, 10/14/2008, 10/15/2008, 10/16/2008, 10/17/2008, 10/18/2008, 10/19/2008, 10/2/2008, 10/20/2008, 10/21/2008, 10/22/2008, 10/23/2008, 10/24/2008, 10/25/2008, 10/26/2008, 10/27/2008, 10/28/2008, 10/29/2008, 10/3/2008, 10/30/2008, 10/31/2008, 10/4/2008, 10/5/2008, 10/6/2008, 10/7/2008, 10/8/2008, 10/9/2008, 11/1/2008, 11/2/2008, 11/3/2008, 11/4/2008, 7/1/2008, 7/10/2008, 7/11/2008, 7/12/2008, 7/13/2008, 7/14/2008, 7/15/2008, 7/16/2008, 7/17/2008, 7/18/2008, 7/19/2008, 7/2/2008, 7/20/2008, 7/21/2008, 7/22/2008, 7/23/2008, 7/24/2008, 7/25/2008, 7/26/2008, 7/27/2008, 7/28/2008, 7/29/2008, 7/3/2008, 7/30/2008, 7/31/2008, 7/4/2008, 7/5/2008, 7/6/2008, 7/7/2008, 7/8/2008, 7/9/2008, 8/1/2008, 8/10/2008, 8/11/2008, 8/12/2008, 8/13/2008, 8/14/2008, 8/15/2008, 8/16/2008, 8/17/2008, 8/18/2008, 8/19/2008, 8/2/2008, 8/20/2008, 8/21/2008, 8/22/2008, 8/23/2008, 8/24/2008, 8/25/2008, 8/26/2008, 8/27/2008, 8/28/2008, 8/29/2008, 8/3/2008, 8/30/2008, 8/31/2008, 8/4/2008, 8/5/2008, 8/6/2008, 8/7/2008, 8/8/2008, 8/9/2008, 9/1/2008, 9/10/2008, 9/11/2008, 9/12/2008, 9/13/2008, 9/14/2008, 9/15/2008, 9/16/2008, 9/17/2008, 9/18/2008, 9/19/2008, 9/2/2008, 9/20/2008, 9/21/2008, 9/22/2008, 9/23/2008, 9/24/2008, 9/25/2008, 9/26/2008, 9/27/2008, 9/28/2008, 9/29/2008, 9/3/2008, 9/30/2008, 9/4/2008, 9/5/2008, 9/6/2008, 9/7/2008, 9/8/2008, 9/9/2008), class = factor), Total = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57310, 53024, NA, NA, NA, NA, 34787, 28768, 25947, 23761, 18430, 13080, 14094, 13638, 14748, 11564, 8076, 15123, 14192, 13648, 14393, 19338, 25597, 26892, 28353, 18197, 18060, 11143, 13912, 9915, 12240, 20541, 6643, 7408, 5511, 10797, 10706, 9654, 6968, 4896, 4659, 5180, 4234.42, 5626, 3678, 2504, 1299, 957.07, 2296, 2318, 1942.19, 2703.78, 5183, 4286, 3201, 2617, 2118, 1633, 1740, 1791, 1023, 391, 884.97, 1214.5, 7927, 8462), Fry = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57090, 53024, NA, NA, NA, NA, 34405, 28563, 25947, 23664, 18391, 13009, 13992, 13442, 14678, 11564, 8012, 15123, 13990.16, 13372.5, 14205, 18687, 25003.66, 25927, 27596, 17755, 17438, 10630.83, 12879, 9389, 11882, 19368, 5936, 6182, 4462, 7606, 7933.89, 7010, 5052, 3199, 2894, 2395, 1253, 1994, 1180.62, 1024, 520, 410, 923, 547, 448, 674, 902, 1085, 559, 694, 200, 40, 41, 162.43, 0, 0, 88.09, 0, 79, 243), Smolt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, 0, 220, 0, NA, NA, NA, NA, 382, 204.45, 0, 98, 39, 70.74, 102.45, 196, 70, 0, 64, 0, 201.6, 276, 188, 650, 594, 965, 757, 442, 622, 512, 1033, 526, 357, 1173, 707, 1226, 1049, 3192, 2772, 2644, 1916.03, 1697.59, 1765.08, 2785.12, 2981, 3632, 2497, 1480, 778.94, 547.27, 1373, 1771, 1495, 2030, 4281, 3200, 2642.26, 1922.53, 1918, 1593, 1699, 1628, 1023, 391, 796.88, 1214.5, 7847, 8219), Fry.Eq = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57464, 53024, NA, NA, NA, NA, 35055, 28911, 25947, 23830, 18457.87, 13129, 14166, 13775.76, 14797, 11564, 8121, 15123, 14333, 13841, 14524, 19793, 26013,
Re: [R] ggplot2-ddply question
On Aug 7, 2009, at 3:36 PM, Felipe Carrillo wrote: Hi all: I am trying to use the ddply function to estimate the mean of 'Total','Fry','Smolt' and 'Fry.Eq' columns without success. I have the dput of my dataset below. I wonder if someone can give me a hand with this function. # dput(winter) winter -structure(list(IDDate = structure(c(37L, 48L, 59L, 62L, 63L, 64L, 65L, 66L, 67L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 60L, 61L, 68L, 79L, 90L, 93L, 94L, 95L, 96L, 97L, 98L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L, 92L, 99L, 110L, 121L, 123L, 124L, 125L, 126L, 127L, 128L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 122L, 2L, 13L, 24L, 27L, 28L, 29L, 30L, 31L, 32L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 25L, 26L, 33L, 34L, 35L, 36L), .Label = c(, 10/1/2008, 10/10/2008, 10/11/2008, 10/12/2008, 10/13/2008, 10/14/2008, 10/15/2008, 10/16/2008, 10/17/2008, 10/18/2008, 10/19/2008, 10/2/2008, 10/20/2008, 10/21/2008, 10/22/2008, 10/23/2008, 10/24/2008, 10/25/2008, 10/26/2008, 10/27/2008, 10/28/2008, 10/29/2008, 10/3/2008, 10/30/2008, 10/31/2008, 10/4/2008, 10/5/2008, 10/6/2008, 10/7/2008, 10/8/2008, 10/9/2008, 11/1/2008, 11/2/2008, 11/3/2008, 11/4/2008, 7/1/2008, 7/10/2008, 7/11/2008, 7/12/2008, 7/13/2008, 7/14/2008, 7/15/2008, 7/16/2008, 7/17/2008, 7/18/2008, 7/19/2008, 7/2/2008, 7/20/2008, 7/21/2008, 7/22/2008, 7/23/2008, 7/24/2008, 7/25/2008, 7/26/2008, 7/27/2008, 7/28/2008, 7/29/2008, 7/3/2008, 7/30/2008, 7/31/2008, 7/4/2008, 7/5/2008, 7/6/2008, 7/7/2008, 7/8/2008, 7/9/2008, 8/1/2008, 8/10/2008, 8/11/2008, 8/12/2008, 8/13/2008, 8/14/2008, 8/15/2008, 8/16/2008, 8/17/2008, 8/18/2008, 8/19/2008, 8/2/2008, 8/20/2008, 8/21/2008, 8/22/2008, 8/23/2008, 8/24/2008, 8/25/2008, 8/26/2008, 8/27/2008, 8/28/2008, 8/29/2008, 8/3/2008, 8/30/2008, 8/31/2008, 8/4/2008, 8/5/2008, 8/6/2008, 8/7/2008, 8/8/2008, 8/9/2008, 9/1/2008, 9/10/2008, 9/11/2008, 9/12/2008, 9/13/2008, 9/14/2008, 9/15/2008, 9/16/2008, 9/17/2008, 9/18/2008, 9/19/2008, 9/2/2008, 9/20/2008, 9/21/2008, 9/22/2008, 9/23/2008, 9/24/2008, 9/25/2008, 9/26/2008, 9/27/2008, 9/28/2008, 9/29/2008, 9/3/2008, 9/30/2008, 9/4/2008, 9/5/2008, 9/6/2008, 9/7/2008, 9/8/2008, 9/9/2008), class = factor), Total = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57310, 53024, NA, NA, NA, NA, 34787, 28768, 25947, 23761, 18430, 13080, 14094, 13638, 14748, 11564, 8076, 15123, 14192, 13648, 14393, 19338, 25597, 26892, 28353, 18197, 18060, 11143, 13912, 9915, 12240, 20541, 6643, 7408, 5511, 10797, 10706, 9654, 6968, 4896, 4659, 5180, 4234.42, 5626, 3678, 2504, 1299, 957.07, 2296, 2318, 1942.19, 2703.78, 5183, 4286, 3201, 2617, 2118, 1633, 1740, 1791, 1023, 391, 884.97, 1214.5, 7927, 8462), Fry = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57090, 53024, NA, NA, NA, NA, 34405, 28563, 25947, 23664, 18391, 13009, 13992, 13442, 14678, 11564, 8012, 15123, 13990.16, 13372.5, 14205, 18687, 25003.66, 25927, 27596, 17755, 17438, 10630.83, 12879, 9389, 11882, 19368, 5936, 6182, 4462, 7606, 7933.89, 7010, 5052, 3199, 2894, 2395, 1253, 1994, 1180.62, 1024, 520, 410, 923, 547, 448, 674, 902, 1085, 559, 694, 200, 40, 41, 162.43, 0, 0, 88.09, 0, 79, 243), Smolt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, 0, 220, 0, NA, NA, NA, NA, 382, 204.45, 0, 98, 39, 70.74, 102.45, 196, 70, 0, 64, 0, 201.6, 276, 188, 650, 594, 965, 757, 442, 622, 512, 1033, 526, 357, 1173, 707, 1226, 1049, 3192, 2772, 2644, 1916.03, 1697.59, 1765.08, 2785.12, 2981, 3632, 2497, 1480, 778.94, 547.27, 1373, 1771, 1495, 2030, 4281, 3200, 2642.26, 1922.53, 1918, 1593, 1699, 1628, 1023, 391, 796.88, 1214.5, 7847, 8219), Fry.Eq = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57464, 53024, NA, NA, NA, NA, 35055, 28911, 25947, 23830, 18457.87, 13129, 14166, 13775.76, 14797, 11564, 8121, 15123, 14333,
Re: [R] How do I plot a line followed by two forecast points?
Hi Jean, Thank you for the reply. I do have the forecast points before I plot, the example below was just for illustration purposes..If I am to add the forecast points to one y-series data plot however, is there a way of highlighting them? This is essentially what I'm trying to do below by plotting 3 separate series on the same graph... Any help would be much appreciated.. Regards, George. In addition, I can't add the forecasts to the original series because I need On Fri, Aug 7, 2009 at 8:36 PM, Jean V Adamsjvad...@usgs.gov wrote: Just wait until after you have the forecasts before you create the plot. # Sample dates xValues - seq.Date(as.Date(1990-01-31), to=as.Date(1992-12-31), by=month) # Sample y value yValues - seq(0.1, length=length(xValues)) # Sample forecast one year from xValue's end point fcastDate - seq.Date(from=as.Date(xValues[length(xValues)]), length=2, by=year)[2] fcast - 20 # The second forecast fcastDate2 - seq.Date(from=as.Date(fcastDate), length=2, by=year)[2] fcast2 - 15 plot(xValues, yValues, type=n, xlim=range(c(xValues, fcastDate, fcastDate2)), ylim=range(c(yValues, fcast, fcast2))) lines(xValues, yValues) points(fcastDate, fcast, col=red) points(fcastDate2, fcast2, col=blue) Jean - From: Jorgy Porgee jorgy.porgee at gmail.com Subject: How do I plot a line followed by two forecast points? Newsgroups: gmane.comp.lang.r.general Date: 2009-08-07 15:17:52 GMT (2 hours and 55 minutes ago) Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled according to the existing y axis). An example is pasted below. Any ideas on how to achieve this would be much appreciated. Thanking you in advance, George. # Sample dates xValues = seq.Date(as.Date(1990-01-31),to=as.Date(1992-12-31),by=month); # Sample y value yValues-NULL; yValues[1:length(xValues)]=seq(0.1,length=length(xValues)) # Plot the series as a line plot(xValues,yValues,type=l); # Sample forecast dates that start from xValue's data point fcastDates=seq.Date(from=as.Date(xValues[length(xValues)]),length=12,by=month); fcastDates [1] 1992-12-31 1993-01-31 1993-03-03 1993-03-31 1993-05-01 1993-05-31 [7] 1993-07-01 1993-07-31 1993-08-31 1993-10-01 1993-10-31 1993-12-01 # Sample forecast (we only want the forecast point to be displayed) fcast-NULL; fcast[1:length(fcastDates)]=NA; fcast[length(fcast)]-20; fcast [1] NA NA NA NA NA NA NA NA NA NA NA 20 # Add the forecast plot to the original plot par(new=TRUE) plot(fcastDates,fcast,yaxt=n,xaxt=n,col=red) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion # The second forecast fcastDates2=seq.Date(from=as.Date(fcastDates[length(fcastDates)]),length=12,by=month); fcastDates2 [1] 1993-12-01 1994-01-01 1994-02-01 1994-03-01 1994-04-01 1994-05-01 [7] 1994-06-01 1994-07-01 1994-08-01 1994-09-01 1994-10-01 1994-11-01 fcast2-NULL; fcast2[1:length(fcastDates2)]=NA; fcast2[length(fcast2)]-15; par(new=TRUE);plot(fcastDates2,fcast2,yaxt=n,xaxt=n,col=blue) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion __ 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 do I plot a line followed by two forecast points?
Because you know a priori the dates associated with your forecast points you could use the col= in the plot function to change colors for the last two points (may require some mathmatical gymnastics to specify the colors desired--I've set up a vector and created an index from either the x or y values to obtain the desired effect). Clint BowmanINTERNET: cl...@ecy.wa.gov Air Dispersion Modeler INTERNET: cl...@math.utah.edu Air Quality Program VOICE: (360) 407-6815 Department of Ecology FAX:(360) 407-7534 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Fri, 7 Aug 2009, Jorgy Porgee wrote: Hi Jean, Thank you for the reply. I do have the forecast points before I plot, the example below was just for illustration purposes..If I am to add the forecast points to one y-series data plot however, is there a way of highlighting them? This is essentially what I'm trying to do below by plotting 3 separate series on the same graph... Any help would be much appreciated.. Regards, George. In addition, I can't add the forecasts to the original series because I need On Fri, Aug 7, 2009 at 8:36 PM, Jean V Adamsjvad...@usgs.gov wrote: Just wait until after you have the forecasts before you create the plot. # Sample dates xValues - seq.Date(as.Date(1990-01-31), to=as.Date(1992-12-31), by=month) # Sample y value yValues - seq(0.1, length=length(xValues)) # Sample forecast one year from xValue's end point fcastDate - seq.Date(from=as.Date(xValues[length(xValues)]), length=2, by=year)[2] fcast - 20 # The second forecast fcastDate2 - seq.Date(from=as.Date(fcastDate), length=2, by=year)[2] fcast2 - 15 plot(xValues, yValues, type=n, xlim=range(c(xValues, fcastDate, fcastDate2)), ylim=range(c(yValues, fcast, fcast2))) lines(xValues, yValues) points(fcastDate, fcast, col=red) points(fcastDate2, fcast2, col=blue) Jean - From: Jorgy Porgee jorgy.porgee at gmail.com Subject: How do I plot a line followed by two forecast points? Newsgroups: gmane.comp.lang.r.general Date: 2009-08-07 15:17:52 GMT (2 hours and 55 minutes ago) Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled according to the existing y axis). An example is pasted below. Any ideas on how to achieve this would be much appreciated. Thanking you in advance, George. # Sample dates xValues = seq.Date(as.Date(1990-01-31),to=as.Date(1992-12-31),by=month); # Sample y value yValues-NULL; yValues[1:length(xValues)]=seq(0.1,length=length(xValues)) # Plot the series as a line plot(xValues,yValues,type=l); # Sample forecast dates that start from xValue's data point fcastDates=seq.Date(from=as.Date(xValues[length(xValues)]),length=12,by=month); fcastDates [1] 1992-12-31 1993-01-31 1993-03-03 1993-03-31 1993-05-01 1993-05-31 [7] 1993-07-01 1993-07-31 1993-08-31 1993-10-01 1993-10-31 1993-12-01 # Sample forecast (we only want the forecast point to be displayed) fcast-NULL; fcast[1:length(fcastDates)]=NA; fcast[length(fcast)]-20; fcast [1] NA NA NA NA NA NA NA NA NA NA NA 20 # Add the forecast plot to the original plot par(new=TRUE) plot(fcastDates,fcast,yaxt=n,xaxt=n,col=red) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion # The second forecast fcastDates2=seq.Date(from=as.Date(fcastDates[length(fcastDates)]),length=12,by=month); fcastDates2 [1] 1993-12-01 1994-01-01 1994-02-01 1994-03-01 1994-04-01 1994-05-01 [7] 1994-06-01 1994-07-01 1994-08-01 1994-09-01 1994-10-01 1994-11-01 fcast2-NULL; fcast2[1:length(fcastDates2)]=NA; fcast2[length(fcast2)]-15; par(new=TRUE);plot(fcastDates2,fcast2,yaxt=n,xaxt=n,col=blue) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion __ 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] ggplot2-ddply question
On Aug 7, 2009, at 3:36 PM, Felipe Carrillo wrote: Hi all: I am trying to use the ddply function to estimate the mean of 'Total','Fry','Smolt' and 'Fry.Eq' columns without success. I have the dput of my dataset below. I wonder if someone can give me a hand with this function. # dput(winter) winter -structure(list(IDDate = structure(c(37L, 48L, 59L, 62L, 63L, 64L, 65L, 66L, 67L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 60L, 61L, 68L, 79L, 90L, 93L, 94L, 95L, 96L, 97L, 98L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L, 92L, 99L, 110L, 121L, 123L, 124L, 125L, 126L, 127L, 128L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 122L, 2L, 13L, 24L, 27L, 28L, 29L, 30L, 31L, 32L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 25L, 26L, 33L, 34L, 35L, 36L), .Label = c(, 10/1/2008, 10/10/2008, 10/11/2008, 10/12/2008, 10/13/2008, 10/14/2008, 10/15/2008, 10/16/2008, 10/17/2008, 10/18/2008, 10/19/2008, 10/2/2008, 10/20/2008, 10/21/2008, 10/22/2008, 10/23/2008, 10/24/2008, 10/25/2008, 10/26/2008, 10/27/2008, 10/28/2008, 10/29/2008, 10/3/2008, 10/30/2008, 10/31/2008, 10/4/2008, 10/5/2008, 10/6/2008, 10/7/2008, 10/8/2008, 10/9/2008, 11/1/2008, 11/2/2008, 11/3/2008, 11/4/2008, 7/1/2008, 7/10/2008, 7/11/2008, 7/12/2008, 7/13/2008, 7/14/2008, 7/15/2008, 7/16/2008, 7/17/2008, 7/18/2008, 7/19/2008, 7/2/2008, 7/20/2008, 7/21/2008, 7/22/2008, 7/23/2008, 7/24/2008, 7/25/2008, 7/26/2008, 7/27/2008, 7/28/2008, 7/29/2008, 7/3/2008, 7/30/2008, 7/31/2008, 7/4/2008, 7/5/2008, 7/6/2008, 7/7/2008, 7/8/2008, 7/9/2008, 8/1/2008, 8/10/2008, 8/11/2008, 8/12/2008, 8/13/2008, 8/14/2008, 8/15/2008, 8/16/2008, 8/17/2008, 8/18/2008, 8/19/2008, 8/2/2008, 8/20/2008, 8/21/2008, 8/22/2008, 8/23/2008, 8/24/2008, 8/25/2008, 8/26/2008, 8/27/2008, 8/28/2008, 8/29/2008, 8/3/2008, 8/30/2008, 8/31/2008, 8/4/2008, 8/5/2008, 8/6/2008, 8/7/2008, 8/8/2008, 8/9/2008, 9/1/2008, 9/10/2008, 9/11/2008, 9/12/2008, 9/13/2008, 9/14/2008, 9/15/2008, 9/16/2008, 9/17/2008, 9/18/2008, 9/19/2008, 9/2/2008, 9/20/2008, 9/21/2008, 9/22/2008, 9/23/2008, 9/24/2008, 9/25/2008, 9/26/2008, 9/27/2008, 9/28/2008, 9/29/2008, 9/3/2008, 9/30/2008, 9/4/2008, 9/5/2008, 9/6/2008, 9/7/2008, 9/8/2008, 9/9/2008), class = factor), Total = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57310, 53024, NA, NA, NA, NA, 34787, 28768, 25947, 23761, 18430, 13080, 14094, 13638, 14748, 11564, 8076, 15123, 14192, 13648, 14393, 19338, 25597, 26892, 28353, 18197, 18060, 11143, 13912, 9915, 12240, 20541, 6643, 7408, 5511, 10797, 10706, 9654, 6968, 4896, 4659, 5180, 4234.42, 5626, 3678, 2504, 1299, 957.07, 2296, 2318, 1942.19, 2703.78, 5183, 4286, 3201, 2617, 2118, 1633, 1740, 1791, 1023, 391, 884.97, 1214.5, 7927, 8462), Fry = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57090, 53024, NA, NA, NA, NA, 34405, 28563, 25947, 23664, 18391, 13009, 13992, 13442, 14678, 11564, 8012, 15123, 13990.16, 13372.5, 14205, 18687, 25003.66, 25927, 27596, 17755, 17438, 10630.83, 12879, 9389, 11882, 19368, 5936, 6182, 4462, 7606, 7933.89, 7010, 5052, 3199, 2894, 2395, 1253, 1994, 1180.62, 1024, 520, 410, 923, 547, 448, 674, 902, 1085, 559, 694, 200, 40, 41, 162.43, 0, 0, 88.09, 0, 79, 243), Smolt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA, NA, 0, 220, 0, NA, NA, NA, NA, 382, 204.45, 0, 98, 39, 70.74, 102.45, 196, 70, 0, 64, 0, 201.6, 276, 188, 650, 594, 965, 757, 442, 622, 512, 1033, 526, 357, 1173, 707, 1226, 1049, 3192, 2772, 2644, 1916.03, 1697.59, 1765.08, 2785.12, 2981, 3632, 2497, 1480, 778.94, 547.27, 1373, 1771, 1495, 2030, 4281, 3200, 2642.26, 1922.53, 1918, 1593, 1699, 1628, 1023, 391, 796.88, 1214.5, 7847, 8219), Fry.Eq = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32, 2235, 3184, 2897, 3325.59, 908.77,
[R] Seeing negative numbers to zero
Hi, I am also new to R and I have a related question. I am trying to set negative values in a single column of a dataframe to zero and I can't seem to do it. I have tried: KN1-subset(KN,select=c(5)) # Here I am selecting the column of the dataframe KN1 and assigning it the name KN2 - this step works KN2-ifelse(KN1=0,0,KN1) # Here I am trying to set negative numbers to zero and leave all other numbers the same - this doesn't work Any help would be appreciated. Thanks, Debbie tonybreyal wrote: see ?ifelse you didn't specify what happens if a value is exactly zero in the dataset and so i've just bundled it in with the negative case: x - rnorm(20, 0, 1) y-ifelse(x=0, 10, 5) HTH, Tony Breyal cmga20 wrote: Hi i am very new to R and I have been trying to change each individual piece of data in a data set to 10 if it is below 0 and 5 if it is above 0. I know this sounds very easy but i am struggling!! -- View this message in context: http://www.nabble.com/For-loop-for-distinguishing-negative-numbers-tp24499872p24870518.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 do I plot a line followed by two forecast points?
Just wait until after you have the forecasts before you create the plot. # Sample dates xValues - seq.Date(as.Date(1990-01-31), to=as.Date(1992-12-31), by=month) # Sample y value yValues - seq(0.1, length=length(xValues)) # Sample forecast one year from xValue's end point fcastDate - seq.Date(from=as.Date(xValues[length(xValues)]), length=2, by=year)[2] fcast - 20 # The second forecast fcastDate2 - seq.Date(from=as.Date(fcastDate), length=2, by=year)[2] fcast2 - 15 plot(xValues, yValues, type=n, xlim=range(c(xValues, fcastDate, fcastDate2)), ylim=range(c(yValues, fcast, fcast2))) lines(xValues, yValues) points(fcastDate, fcast, col=red) points(fcastDate2, fcast2, col=blue) Jean - From: Jorgy Porgee jorgy.porgee at gmail.com Subject: How do I plot a line followed by two forecast points? Newsgroups: gmane.comp.lang.r.general Date: 2009-08-07 15:17:52 GMT (2 hours and 55 minutes ago) Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled according to the existing y axis). An example is pasted below. Any ideas on how to achieve this would be much appreciated. Thanking you in advance, George. # Sample dates xValues = seq.Date(as.Date(1990-01-31),to=as.Date(1992-12-31),by=month); # Sample y value yValues-NULL; yValues[1:length(xValues)]=seq(0.1,length=length(xValues)) # Plot the series as a line plot(xValues,yValues,type=l); # Sample forecast dates that start from xValue's data point fcastDates=seq.Date(from=as.Date(xValues[length(xValues)]),length=12,by=month); fcastDates [1] 1992-12-31 1993-01-31 1993-03-03 1993-03-31 1993-05-01 1993-05-31 [7] 1993-07-01 1993-07-31 1993-08-31 1993-10-01 1993-10-31 1993-12-01 # Sample forecast (we only want the forecast point to be displayed) fcast-NULL; fcast[1:length(fcastDates)]=NA; fcast[length(fcast)]-20; fcast [1] NA NA NA NA NA NA NA NA NA NA NA 20 # Add the forecast plot to the original plot par(new=TRUE) plot(fcastDates,fcast,yaxt=n,xaxt=n,col=red) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion # The second forecast fcastDates2=seq.Date(from=as.Date(fcastDates[length(fcastDates)]),length=12,by=month); fcastDates2 [1] 1993-12-01 1994-01-01 1994-02-01 1994-03-01 1994-04-01 1994-05-01 [7] 1994-06-01 1994-07-01 1994-08-01 1994-09-01 1994-10-01 1994-11-01 fcast2-NULL; fcast2[1:length(fcastDates2)]=NA; fcast2[length(fcast2)]-15; par(new=TRUE);plot(fcastDates2,fcast2,yaxt=n,xaxt=n,col=blue) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion [[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] RMySQL - overwrite record, not table
Hi, useR- In RMySQL, how do I overwrite records? (equivalent to replace query). For example, suppose that dat2 is a newer data.frame than dat1. con - dbConnect(MySQL()) res - dbWriteTable(con, DBname, dat1, row.names=F, append=T, replace=T) res - dbWriteTable(con, DBname, dat2, row.names=F, append=T, replace=T) This would not update/replace the dat1 records in DBname with newer records from dat2. How would you solve the problem? Thanks= -- View this message in context: http://www.nabble.com/RMySQL---overwrite-record%2C-not-table-tp24870097p24870097.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] Bar plots with stacked columns marked with askterisks
Hi, I'm trying to plot bar graphs with stacked columns marked with askterisks for certain columns, which follow certain criteria. I've gotten the stacked bar plots with Data set A (please refer to code below). However, I haven't figured how to put asterisks on columns based on some extra information (such as used/unused) as in Data set B i.e. asterisks at the top of the Index1 and Index3 columns. R code title = 'frequency' filename = 'testdata2.txt' sample_output = 'sequences' # read in data my.data - read.delim(filename, sep=\t) # data from second column onward my.dataM - my.data[,2:ncol(my.data)] # rownames in first column rownames - my.data[,1] # define colours for the categories col = c (red ,orange ,yellow ,green ,violet ,cyan,blue,pink,peachpuff,tomato,seagreen,salmon) my.dataNcol - ncol(my.data[,2:ncol(my.data)]) my.dataColour - col[1:my.dataNcol] # a bar plot with stacked bars if (is.null(sample_output)) { pdf( BarPlot.pdf) } else { pdf(file=paste(BarPlot_, sample_output, .pdf, sep=)) } barplot(as.matrix(my.dataM), main=title, legend=rownames, col=c(my.dataColour) ) dev.off() --Dataset A: data used with code above-- Index1Index2Index3 matched 0.819 0.174 0.007 errors0.619 0.314 0.067 unmatched 0.479 0.385 0.136 --Dataset B: data intended to use - --(last row used/unused for determining whether to mark column with asterisk or not)--- Index1Index2Index3 matched 0.819 0.174 0.007 errors0.619 0.314 0.067 unmatched 0.479 0.385 0.136 used/unused y n y --- Thanks, Dorothy [[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] how to partitioning a clustered heatmap
Hello all, I'm doing heatmap.2 graphics of matrix x with hclust clustering in the rows, as an argument in heatmap.2 . The problem is that the heatmap contains 1000 genes, and I want to cut it in several pieces, but after the clustering. If I use x[1:100,] as delimiting argument for the first 100 clustered rows(genes) in the matrix, it doesn't work, it takes the 100 first rows in the matrix and does the clustering over them, and not first the clustering over the 1000 genes and then graph the first 100 rows of the clustered matrix. The entire argument of heatmap I'm using is something like this: heatmap.2(x, scale=none, cexRow=0.1, keysize=0.8, hclustfun = hclust, sepcolor=none,Colv=FALSE, dendrogram=row, trace=c(none),density.info=c(none)) If you can help me, will be great. Thanks in advance, juan Juan Pablo Fededa Institute of Biochemistry-ETH Zurich HPM,D11.1 Schafmattstrasse 18 CH-8093, Zurich Switzerland +41 44 633 60 26 phone +41 44 632 12 69 fax jpfed...@bc.biol.ethz.ch www.lmc.ethz.ch/IBC/ __ 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 do I plot a line followed by two forecast points?
Run this codes: plot( 1:20, type='l') lines( 0.5*1:20, col=2) If you use par(new=T), this will call a new high-level graphic device, which is why the axes do not match. Alternatively, you can set ylim and pass the arguments to two plot functions: plot( rnorm(100), type='h', ylim=c(-3,3)) par(new=T, mar=c(3,4,3,3)) plot( 0.25*rnorm(100), type='l', col=2, ylim=c(-3,3), ylab='') axis(4) Jorgy Porgee wrote: Good day all, I'm trying to plot a continuous line plot, which is followed by two forecast points eg. one forecast point is 12 months out, and another 24 months out from the last date of the line plot. In my attempts so far, the second plot (the forecast points) is scaled against a new axis scale, thus the two plots are not directly comparable (I need the forecast points to be scaled according to the existing y axis). An example is pasted below. Any ideas on how to achieve this would be much appreciated. Thanking you in advance, George. # Sample dates xValues = seq.Date(as.Date(1990-01-31),to=as.Date(1992-12-31),by=month); # Sample y value yValues-NULL; yValues[1:length(xValues)]=seq(0.1,length=length(xValues)) # Plot the series as a line plot(xValues,yValues,type=l); # Sample forecast dates that start from xValue's data point fcastDates=seq.Date(from=as.Date(xValues[length(xValues)]),length=12,by=month); fcastDates [1] 1992-12-31 1993-01-31 1993-03-03 1993-03-31 1993-05-01 1993-05-31 [7] 1993-07-01 1993-07-31 1993-08-31 1993-10-01 1993-10-31 1993-12-01 # Sample forecast (we only want the forecast point to be displayed) fcast-NULL; fcast[1:length(fcastDates)]=NA; fcast[length(fcast)]-20; fcast [1] NA NA NA NA NA NA NA NA NA NA NA 20 # Add the forecast plot to the original plot par(new=TRUE) plot(fcastDates,fcast,yaxt=n,xaxt=n,col=red) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion # The second forecast fcastDates2=seq.Date(from=as.Date(fcastDates[length(fcastDates)]),length=12,by=month); fcastDates2 [1] 1993-12-01 1994-01-01 1994-02-01 1994-03-01 1994-04-01 1994-05-01 [7] 1994-06-01 1994-07-01 1994-08-01 1994-09-01 1994-10-01 1994-11-01 fcast2-NULL; fcast2[1:length(fcastDates2)]=NA; fcast2[length(fcast2)]-15; par(new=TRUE);plot(fcastDates2,fcast2,yaxt=n,xaxt=n,col=blue) Warning message: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion __ 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. -- View this message in context: http://www.nabble.com/How-do-I-plot-a-line-followed-by-two-forecast-points--tp24866692p24870219.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] create separate plots by factors
Hello, I am attempting to create several plots based on site (~300 total) and am having trouble with the code. I simply want to create a plot using the code, plot(year, peak), for the following dataset. I would like for each site to be plotted on a separate page and the plots saved in a directory. Would a foreach loop work? I tried a by statement, but it doesn't seem to work with plotting functions. I would really appreciate any leads. Ingrid site year peak ALBEN 5 101529.6 ALBEN 10 117483.4 ALBEN 20 132960.9 ALBEN 50 153251.2 ALBEN 100 168647.8 ALBEN 200 184153.6 ALBEN 500 204866.5 ALDER 56561.3 ALDER 107897.1 ALDER 209208.1 ALDER 50 10949.3 ALDER 100 12287.6 ALDER 200 13650.2 ALDER 500 15493.6 AMERI 5 43656.5 AMERI 10 51475.3 AMERI 20 58854.4 AMERI 50 68233.3 AMERI 100 75135.9 AMERI 200 81908.3 Ingrid M Tohver Research Scientist, Climate Impacts Group University of Washington __ 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] Seeing negative numbers to zero
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of DebbieMB Sent: Friday, August 07, 2009 1:29 PM To: r-help@r-project.org Subject: [R] Seeing negative numbers to zero Hi, I am also new to R and I have a related question. I am trying to set negative values in a single column of a dataframe to zero and I can't seem to do it. I have tried: KN1-subset(KN,select=c(5)) # Here I am selecting the column of the dataframe KN1 and assigning it the name KN2 - this step works KN2-ifelse(KN1=0,0,KN1) # Here I am trying to set negative numbers to zero and leave all other numbers the same - this doesn't work Any help would be appreciated. Thanks, Debbie Debbie, When you say it doesn't work, what does that mean? Do you get an error message? Are you left with negative numbers? What? A minimal, self-contained, reproducible example would help us help you. KN1 - rnorm(100) KN2 - ifelse(KN1 0, 0, KN1) Works fine for fine for me. Dan Daniel Nordlund Bothell, WA USA __ 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] Seeing negative numbers to zero
On 07-Aug-09 20:29:16, DebbieMB wrote: Hi, I am also new to R and I have a related question. I am trying to set negative values in a single column of a dataframe to zero and I can't seem to do it. I have tried: KN1-subset(KN,select=c(5)) # Here I am selecting the column of the dataframe KN1 and assigning it # the name KN2 - this step works KN2-ifelse(KN1=0,0,KN1) # Here I am trying to set negative numbers to zero and leave all other numbers the same - this doesn't work Any help would be appreciated. Thanks, Debbie How about something on the lines of: KN1 - data.frame(c1=c(1,-2,3,-4,5),c2=c(-1,2,-3,4,-5),c3=c(- KN1 # c1 c2 c3 # 1 1 -1 -2 # 2 -2 2 -1 # 3 3 -3 0 # 4 -4 4 1 # 5 5 -5 2 KN2 - KN1 KN2$c2 - (KN2$c20)*KN2$c2 ## ** See below KN2 # c1 c2 c3 # 1 1 0 -2 # 2 -2 2 -1 # 3 3 0 0 # 4 -4 4 1 # 5 5 0 2 The logic of the ** line is that: 1: (KN2$c20) is FALSE wherever (KN2$c2 = 0), otherwise TRUE. 2: If x is a number, then TRUE*x = x and FALSE*x = 0 3: Hence (KN2$c20)*KN2$c2 is 0 wherever (KN2$c2 = 0), and is the same as KN2$c2 wherever (KN2$c2 0) Does this help? Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 07-Aug-09 Time: 22:59:42 -- XFMail -- __ 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] Seeing negative numbers to zero
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Daniel Nordlund Sent: Friday, August 07, 2009 2:50 PM To: r-help@r-project.org Subject: Re: [R] Seeing negative numbers to zero -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of DebbieMB Sent: Friday, August 07, 2009 1:29 PM To: r-help@r-project.org Subject: [R] Seeing negative numbers to zero Hi, I am also new to R and I have a related question. I am trying to set negative values in a single column of a dataframe to zero and I can't seem to do it. I have tried: KN1-subset(KN,select=c(5)) # Here I am selecting the column of the dataframe KN1 and assigning it the name KN2 - this step works KN2-ifelse(KN1=0,0,KN1) # Here I am trying to set negative numbers to zero and leave all other numbers the same - this doesn't work Any help would be appreciated. Thanks, Debbie Debbie, When you say it doesn't work, what does that mean? Do you get an error message? Are you left with negative numbers? What? A minimal, self-contained, reproducible example would help us help you. KN1 - rnorm(100) KN2 - ifelse(KN1 0, 0, KN1) Works fine for fine for me. Mark Leeds kindly pointed out to me offline that Debbie's KN1 would be a data frame and my solution doesn't work. I don't know whether KN1 and KN2 need to be data frames or whether vectors would work. If a vector is ok then how about KN1 - KN[[5]] KN2 - ifelse(KN1 0, 0, KN1) KN2 Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA __ 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] Seeing negative numbers to zero
On Aug 7, 2009, at 4:29 PM, DebbieMB wrote: Hi, I am also new to R and I have a related question. I am trying to set negative values in a single column of a dataframe to zero and I can't seem to do it. I have tried: KN1-subset(KN,select=c(5)) # Here I am selecting the column of the dataframe KN1 and assigning it the name KN2 - this step works KN2-ifelse(KN1=0,0,KN1) # Here I am trying to set negative numbers to zero and leave all other numbers the same - this doesn't work KN1 is probably still a dataframe (albeit with only one column) and you really meant to be working on that column instead of the whole dataframey-listy-thing with all of its attached attributes and classes. You need to refer to the name of the column, let's say its col1 KN2 - ifelse(KN1$col1=0,0,KN1$col1) Any help would be appreciated. Thanks, Debbie tonybreyal wrote: see ?ifelse you didn't specify what happens if a value is exactly zero in the dataset and so i've just bundled it in with the negative case: x - rnorm(20, 0, 1) y-ifelse(x=0, 10, 5) HTH, Tony Breyal cmga20 wrote: Hi i am very new to R and I have been trying to change each individual piece of data in a data set to 10 if it is below 0 and 5 if it is above 0. I know this sounds very easy but i am struggling!! -- View this message in context: http://www.nabble.com/For-loop-for-distinguishing-negative-numbers-tp24499872p24870518.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. David Winsemius, MD Heritage Laboratories 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] Simple Question: adding points to a boxplot
I apologize in advance for the simplicity of this question. I use R 2-3 times a year, and I seem to forget more in the intervening months than I learn during my days of panicked reading I HAVE tried looking at the help resources; I'm just not very good at understanding them. I have a dataframe with 18 observations of 5 different things, and a second dataframe with and estimate for those 5 things. I'm trying to add the estimated points to the boxplot of observations. I THINK I'm failing because I need to decompose my estimated dataframe into two vectors. I can't seem to figure out how to do that properly, or if I'm suffering from a different misunderstanding == The following code creates the box plot, but the points are not added == Obs1 Blue GreenRed Gold Orange 1 77902 32911 117543 18245 NA 2 77294 32204 114927 18377 NA 3 75737 31484 115265 18529 NA 4 73366 31130 112371 14748 NA 5 77061 33601 118113 16910 16360 6 75177 32383 113825 14417 15492 7 76766 35697 124304 16318 16100 8 80378 36374 128091 15325 17636 9 84078 37473 138219 15769 18242 10 81704 37247 136345 15587 18700 11 84554 39134 143830 18078 21828 12 80411 37487 137583 18771 20844 13 76103 34734 131469 20329 20760 14 76246 34591 127921 18874 19531 15 72025 33645 118279 20972 21005 16 72295 35153 121752 18035 20217 17 71287 32961 121958 17768 20659 18 71778 32833 123990 17956 19004 Est1 Blue GreenRed Gold Orange 1 72289 32444 107121 20900 21962 boxplot(Obs1) points(Est1, pch=23, col=red) == Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax:(213)922-2868 www.Metro.net [[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] multiple lty on same panel in xyplot
Hi RUsers I like to keep the plots self contained and avoid changing the current device parameters by using the par.settings. To see what I could achieve by using par settings I tried the following and several variants but could not get black points. xyplot(yM + yF ~ x, panel = panel.superpose, type = c(l, p), distribute.type = TRUE, par.settings = list(superpose.line = list(lty = c(1,2), col = c(black,black)), superpose.points = list(pch = c(1,1), col = c(black,black)), plot.symbol = list(pch = c(1,1), col = c(black,black)) ), key = list(text = list(c(male, female)), lines = Rows(pset$superpose.line, 1:2), pch = 1, type = c(l, p))) What am I missing? Does the points reference refer to Grid settings? Regards Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2350 Email Home: mac...@northnet.com.au R version 2.9.1 (2009-06-26) i386-pc-mingw32 attached base packages: [1] datasets utils stats graphics grDevices grid methods base other attached packages: [1] R.oo_1.4.8R.methodsS3_1.0.3 foreign_0.8-36chron_2.3-30 MASS_7.2-47 lattice_0.17-25 At 11:48 6/08/2009, Deepayan Sarkar wrote: On Wed, Aug 5, 2009 at 2:24 PM, Jacob Wegelinjacob.wege...@gmail.com wrote: On Wed, 5 Aug 2009, Deepayan Sarkar wrote: On 8/5/09, Jacob Wegelin jacob.wege...@gmail.com wrote: I would like to use lattice graphics to plot multiple functions (or groups  or subpopulations) on the same plot region, using different line types lty  or colors col to distinguish the functions (or groups).  In traditional graphics, this seems straightforward: First plot all the data  using 'type=n', and subsequently execute a series of points or lines  commands, one for each different group or function.  What is the elegant way to do this using xyplot?  To make this concrete, consider the following toy example:  k- 10  x- (1:k)/3  yM-6 + x^2  yF-12 + x^(1.5)  xNA-x[length(x)]  # Insertion of NA row is necessary to prevent a meaningless line  # from being drawn from the females to the males across the entire plot.  DAT-data.frame(  x=c(x, xNA, x)  ,  y=c(yF, NA, yM)  ,  sex=c( rep(0, k ), 0,  rep(1, k))  ) It's much simpler in lattice, and you don't need to play such tricks. Option 1: xyplot(yM + yF ~ x, type = l, auto.key = list(points = FALSE, lines = TRUE)) and if you want to control lty etc: xyplot(yM + yF ~ x, type = l, auto.key = list(points = FALSE, lines = TRUE),    par.settings = simpleTheme(lty = c(2, 3)))Option 2 (a bit more work, but less mysterious under the hood): DAT-   data.frame(x = c(x, x), y=c(yF, yM),        sex= rep(c(Female, Male), each = length(x))) xyplot(y ~ x, data = DAT, groups = sex, type = l) Dear Bill and Deepayan, Thanks. This is helpful. Where can one find a thorough documentation of all these features like par.settings, simpleTheme, the options for where to place the legend or key, auto.key, the different locations besides top where one can place the auto.key, etc.?  I don't think this is all clearly laid out in the R help files or latticeLab.pdf. (Almost) everything is mentioned in the help pages (?Lattice is a good place to start). Of course finding the thing you are looking for is another matter. The book does try to present things more systematically. But using your hints I found that the following worked: xyplot( y ~ x , groups= ~ sex , type=l , auto.key = list(columns=2, points = FALSE, lines = TRUE) , par.settings = simpleTheme(lty = c(1, 2), col=black) , data=DAT ) Now, how would I use lattice tools to plot males with a line and females with points--and still get an informative autokey? xyplot(yM + yF ~ x, type = c(l, p), distribute.type = TRUE, par.settings = simpleTheme(lty = c(1, 2), col=black), auto.key = list(points = FALSE, lines = TRUE, type = c(l, p))) ...but this is pretty much impossible to figure out for a beginner. On the other hand, reading the documentation carefully should lead you to the following, which is almost there: pset - simpleTheme(lty = c(1, 2), col=black) xyplot(yM + yF ~ x, panel = panel.superpose, type = c(l, p), distribute.type = TRUE, par.settings = pset, key = list(text = list(c(male, female)), lines = Rows(pset$superpose.line, 1:2), pch = 1, type = c(l, p))) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] Simple Question: adding points to a boxplot
On Aug 7, 2009, at 6:43 PM, Farley, Robert wrote: I apologize in advance for the simplicity of this question. I use R 2-3 times a year, and I seem to forget more in the intervening months than I learn during my days of panicked reading I HAVE tried looking at the help resources; I'm just not very good at understanding them. I have a dataframe with 18 observations of 5 different things, and a second dataframe with and estimate for those 5 things. I'm trying to add the estimated points to the boxplot of observations. I THINK I'm failing because I need to decompose my estimated dataframe into two vectors. I can't seem to figure out how to do that properly, or if I'm suffering from a different misunderstanding Obs1 -read.table(textConnection( Blue GreenRed Gold Orange 1 77902 32911 117543 18245 NA 2 77294 32204 114927 18377 NA 3 75737 31484 115265 18529 NA 4 73366 31130 112371 14748 NA 5 77061 33601 118113 16910 16360 6 75177 32383 113825 14417 15492 7 76766 35697 124304 16318 16100 8 80378 36374 128091 15325 17636 9 84078 37473 138219 15769 18242 10 81704 37247 136345 15587 18700 11 84554 39134 143830 18078 21828 12 80411 37487 137583 18771 20844 13 76103 34734 131469 20329 20760 14 76246 34591 127921 18874 19531 15 72025 33645 118279 20972 21005 16 72295 35153 121752 18035 20217 17 71287 32961 121958 17768 20659 18 71778 32833 123990 17956 19004), header=TRUE) Est1-read.table(textConnection( Blue GreenRed Gold Orange 1 72289 32444 107121 20900 21962), header=TRUE) boxplot(Obs1) points(1:5, Est1, pch=23, col=red) points(Est1, pch=23, col=red) I think you are only supplying y values with no x values: Try: points(1:5, Est1, pch=23, col=red) == Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax:(213)922-2868 www.Metro.net [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories 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] how to limit output to console beyond options(max.print) ?
I have code that generates a structure that includes in it 30 data frames of size 57*1004. It isn't so important why I needed shape of data frame, maybe I didn't I have options(max.print) set to a low number but it seems that this does not have much effect - printing my structure still takes hours, as does str()-ing it. here is short code that exhibits and doesn't exhibit the problem: z=matrix(0,20,1000) x=list(1:10,1:10,list(z,z,z,z,z,z,z,z,z,z,z,z)) This causes no problem. But z=matrix(0,20,1000) z=data.frame(z) x=list(1:10,1:10,list(z,z,z,z,z,z,z,z,z,z,z,z,z)) now print(x) takes a long time - I'm not sure why, and still prints quite a lot of stuff even when max.print is 100, since it prints all the column names. str(x) really prints too much - it doesn't seem to really be limited by max.options in this case. Is there any way to really limit how much is printed on the output beyond max.print? --- The specific problem I had is this: I'm working with TeXmacs as the front end to R, which sadly crashes or gets slow or stuck when too much is printed as output. I was trying to understand code I wrote some time ago which generates this big structure, and I couldn't easily even find what the structure contains, how big the different parts are, because too much was printed, and my front end got stuck on every trial. I tried to limit the output with max.print, but that didn't help in this case. Setting some global option to limit R output would help the TeXmacs frontend a lot... -- Thanks, Michael __ 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] generalized linear models
Hi, R users, I am trying to use glm to do logistic regression. I know generally when I have two covariates, say x1 and x2, then I do fit - glm(y~x1+x2,famliy='binomial') But now my covariates form a n*p matrix, say x, so actually each column is a covariate. So I think I should do fit - glm(y~x,family='binomial') Then I need to predict new data. How should I write the newdata? I tried several thing, all failed. The x in the fit is a matrix, but is a vector for the new data. Thank you, Annie [[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] Simple Question: adding points to a boxplot
Sorry to keep bothering you all. Phil's easy fix got my code working and I have my graphic. Just for my education: Is there a SIMPLE way to verify/ensure that the ordering of the data is the same in both dataframes? Is this done within the plotting routines, or is it usually as a data checking process before data analysis? == boxplot(ObsRpdData) points(1:length(EstRpdData),EstRpdData, pch=16, col=red) === Robert Farley Metro www.Metro.net -Original Message- From: Farley, Robert Sent: Friday, August 07, 2009 15:56 To: 'Phil Spector' Subject: RE: [R] Simple Question: adding points to a boxplot Whoo-hoo, I get the points! Thanks! I guess I was over-thinking it. :-) Robert Farley Metro www.Metro.net -Original Message- From: Phil Spector [mailto:spec...@stat.berkeley.edu] Sent: Friday, August 07, 2009 15:53 To: Farley, Robert Subject: Re: [R] Simple Question: adding points to a boxplot Robert - What happens when you try points(1:length(Est1),Est1, pch=23, col=red) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 7 Aug 2009, Farley, Robert wrote: I apologize in advance for the simplicity of this question. I use R 2-3 times a year, and I seem to forget more in the intervening months than I learn during my days of panicked reading I HAVE tried looking at the help resources; I'm just not very good at understanding them. I have a dataframe with 18 observations of 5 different things, and a second dataframe with and estimate for those 5 things. I'm trying to add the estimated points to the boxplot of observations. I THINK I'm failing because I need to decompose my estimated dataframe into two vectors. I can't seem to figure out how to do that properly, or if I'm suffering from a different misunderstanding == The following code creates the box plot, but the points are not added == Obs1 Blue GreenRed Gold Orange 1 77902 32911 117543 18245 NA 2 77294 32204 114927 18377 NA 3 75737 31484 115265 18529 NA 4 73366 31130 112371 14748 NA 5 77061 33601 118113 16910 16360 6 75177 32383 113825 14417 15492 7 76766 35697 124304 16318 16100 8 80378 36374 128091 15325 17636 9 84078 37473 138219 15769 18242 10 81704 37247 136345 15587 18700 11 84554 39134 143830 18078 21828 12 80411 37487 137583 18771 20844 13 76103 34734 131469 20329 20760 14 76246 34591 127921 18874 19531 15 72025 33645 118279 20972 21005 16 72295 35153 121752 18035 20217 17 71287 32961 121958 17768 20659 18 71778 32833 123990 17956 19004 Est1 Blue GreenRed Gold Orange 1 72289 32444 107121 20900 21962 boxplot(Obs1) points(Est1, pch=23, col=red) == Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax:(213)922-2868 www.Metro.net [[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] Is there a 'vi' mode in R?
On Fri, Aug 7, 2009 at 5:04 AM, Jakson Alves de Aquinojaksonaqu...@gmail.com wrote: Peng Yu wrote: I'm wondering if R provide a vi mode in the command line just like other shells such as bash do. Can somebody let me know? I maintain a Vim plugin that makes the interaction with R easier: http://www.vim.org/scripts/script.php?script_id=2628 The commands are sent through a pipe, and this approach has some limitations which are explained in the plugin's documentation. The plugin has been discussed here: http://ubuntuforums.org/showthread.php?t=776492 Regards, Jakson Hi, After I installed your package, then I run the following command. gvim run.R 21 But I got the error below. Do you know what the problem was? Regards, Peng 1 ToolBar 10 Open n* :browse confirm eCR v* C-C:browse confirm eCRC-\C-G s* C-C:browse confirm eCRC-\C-G o* C-C:browse confirm eCRC-\C-G 20 Save n*s :if expand(%) == |browse confirm w|else|confirm w|endifCR v*s C-C:if expand(%) == |browse confirm w|else|confirm w|endifCRC-\C-G s*s C-C:if expand(%) == |browse confirm w|else|confirm w|endifCRC-\C-G o*s C-C:if expand(%) == |browse confirm w|else|confirm w|endifCRC-\C-G 30 SaveAll n* :browse confirm waCR v* C-C:browse confirm waCRC-\C-G s* C-C:browse confirm waCRC-\C-G o* C-C:browse confirm waCRC-\C-G 40 Print n* :hardcopyCR v* :hardcopyCR s* :hardcopyCR o* C-C:hardcopyCRC-\C-G 45 -sep1- n* Nop v* Nop s* Nop o* Nop 50 Undo n* u v* C-CuC-\C-G s* C-CuC-\C-G o* C-CuC-\C-G 60 Redo n* C-R v* C-CC-RC-\C-G s* C-CC-RC-\C-G o* C-CC-RC-\C-G 65 -sep2- n* Nop v* Nop s* Nop o* Nop 70 Cut v* +x s* +x 80 Copy v* +y s* +y 90 Paste n* +gP v -cEsc:call paste#Paste()CR s -cEsc:call paste#Paste()CR 95 -sep3- n* Nop v* Nop s* Nop o* Nop 100 Replace n* :promptreplCR v* y:promptrepl C-R=SNR3_FixFText()CRCR s* y:promptrepl C-R=SNR3_FixFText()CRCR o* C-C:promptreplCRC-\C-G 110 FindNext n* n v* C-CnC-\C-G s* C-CnC-\C-G o* C-CnC-\C-G 120 FindPrev n* N v* C-CNC-\C-G ...(truncated) __ 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] frequency of numbers in a list
Hi, I have two vectors, mag and i, and I want to generate a of vector where each element is the frequency of mag which is greater than i. i produced the following code. However I get the following error: mag-rnorm(40,5,3) i-seq(floor(min(mag)),max(mag), 0.5) freq-sum(mag=i) Warning message: In mag = i : longer object length is not a multiple of shorter object length What's wrong with this code? Thank you very much. Cheers, Julius Tesoro __ 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 Question: adding points to a boxplot
On Aug 7, 2009, at 8:33 PM, Farley, Robert wrote: Sorry to keep bothering you all. Phil's easy fix got my code working and I have my graphic. Just for my education: Is there a SIMPLE way to verify/ensure that the ordering of the data is the same in both dataframes? Is this done within the plotting routines, or is it usually as a data checking process before data analysis? One way: == boxplot(ObsRpdData[ , c(Blue, Green, Red, Gold, Orange)] ) points(1:length(EstRpdData),EstRpdData[ , c(Blue, Green, Red, Gold, Orange)], pch=16, col=red) === -- Regards; DW Robert Farley -Original Message- From: Farley, Robert Sent: Friday, August 07, 2009 15:56 To: 'Phil Spector' Subject: RE: [R] Simple Question: adding points to a boxplot Whoo-hoo, I get the points! Thanks! I guess I was over-thinking it. :-) Robert Farley Metro www.Metro.net -Original Message- From: Phil Spector [mailto:spec...@stat.berkeley.edu] Sent: Friday, August 07, 2009 15:53 To: Farley, Robert Subject: Re: [R] Simple Question: adding points to a boxplot Robert - What happens when you try points(1:length(Est1),Est1, pch=23, col=red) - Phil Spector Statistical Computing Facility On Fri, 7 Aug 2009, Farley, Robert wrote: I apologize in advance for the simplicity of this question. I use R 2-3 times a year, and I seem to forget more in the intervening months than I learn during my days of panicked reading I HAVE tried looking at the help resources; I'm just not very good at understanding them. I have a dataframe with 18 observations of 5 different things, and a second dataframe with and estimate for those 5 things. I'm trying to add the estimated points to the boxplot of observations. I THINK I'm failing because I need to decompose my estimated dataframe into two vectors. I can't seem to figure out how to do that properly, or if I'm suffering from a different misunderstanding == The following code creates the box plot, but the points are not added == Obs1 Blue GreenRed Gold Orange 1 77902 32911 117543 18245 NA 2 77294 32204 114927 18377 NA 3 75737 31484 115265 18529 NA 4 73366 31130 112371 14748 NA 5 77061 33601 118113 16910 16360 6 75177 32383 113825 14417 15492 7 76766 35697 124304 16318 16100 8 80378 36374 128091 15325 17636 9 84078 37473 138219 15769 18242 10 81704 37247 136345 15587 18700 11 84554 39134 143830 18078 21828 12 80411 37487 137583 18771 20844 13 76103 34734 131469 20329 20760 14 76246 34591 127921 18874 19531 15 72025 33645 118279 20972 21005 16 72295 35153 121752 18035 20217 17 71287 32961 121958 17768 20659 18 71778 32833 123990 17956 19004 Est1 Blue GreenRed Gold Orange 1 72289 32444 107121 20900 21962 boxplot(Obs1) points(Est1, pch=23, col=red) == Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax:(213)922-2868 www.Metro.net David Winsemius, MD Heritage Laboratories 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] generalized linear models
Hi Annie, create a new data.frame with input variables having all predictors variables on it. after give a look at ?predict best wishes milton On Fri, Aug 7, 2009 at 8:19 PM, annie Zhang annie.zhang2...@gmail.comwrote: Hi, R users, I am trying to use glm to do logistic regression. I know generally when I have two covariates, say x1 and x2, then I do fit - glm(y~x1+x2,famliy='binomial') But now my covariates form a n*p matrix, say x, so actually each column is a covariate. So I think I should do fit - glm(y~x,family='binomial') Then I need to predict new data. How should I write the newdata? I tried several thing, all failed. The x in the fit is a matrix, but is a vector for the new data. Thank you, Annie [[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.htmlhttp://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] interesting statistics article in NYT
__ 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] interesting statistics article in NYT
Dear all, I noticed something wrong my Mark's email so I am sending the link to the article he mentioned: http://www.nytimes.com/2009/08/06/technology/06stats.html?_r=1ref=technology Best, Jorge On 8/7/09, Mark Leeds wrote: __ 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. -- HTH, Jorge Jorge Ivan Velez Jorge Ivan VELEZ Jorge Ivan Velez, M.S. http://www.google.com/profiles/jorgeivanvelez Jorge Ivan Velez, M.S. [E] jorgeivanvelez [at] gmail [dot] com [W] http://tinyurl.com/rhelp Jorge I. Velez, M.S. | NHGRI, USA | [E] velezjo [at] mail [dot] nih [dot] gov Jorge I. Velez, M.S. Visiting Fellow [T] +1 (301) 451-7406 MGB/NHGRI/NIH/DHHS [F] +1 (301) 496-7184 35 Convent Drive, MSC 3717 [M] +1 (301) 300-3732 Building 35, Room 1B-209 [E] vele...@mail.nih.gov Bethesda, MD, US 20892 [W] www.genome.gov NOTE: This e-mail may contain sensitive and/or privileged information. If you are not the intended recipient (or have received this email in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure, or distribution of the material in this e-mail is strictly forbidden. Under the Privacy Act of 1974, all data of a private nature must be protected from unauthorized disclosure. __ 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.