Re: [R] generating random samples of IG distribution
I don't read R-help these days so have just seen this. Both generalized inverse Gaussian and normal inverse Gaussian are in GeneralizedHyperbolic. HyperbolicDist is no longer being maintained. David Scott On 12/06/2012 5:41 a.m., David L Carlson wrote: Should have been For the normal inverse Gaussian: Package 'GeneralizedHyperbolic' For the generalized inverse Gaussian: Package 'HyperbolicDist' -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Monday, June 11, 2012 10:26 AM To: 'shirin nezampour'; 'r-help@r-project.org' Subject: RE: [R] generating random samples of IG distribution For the normal inverse Gaussian: Package 'GeneralizedHyperbolic' For the generalized inverse Gaussian: Package 'GeneralizedHyperbolic' -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of shirin nezampour Sent: Sunday, June 10, 2012 11:37 AM To: r-help@r-project.org Subject: [R] generating random samples of IG distribution Dear R users, I want to generating random samples from Inverse Gaussian distribution . How can I do? and what package should I install? Thanks. Shirin [[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. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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] Accents and special character using hwriter (on Windows)
The safest way to include special characters is to use a character code. You are at the mercy of the browser otherwise and browsers behave very differently when confronted with unusual things. You don't mention which browser you are using on Windows, which is a severe gap in the information you provided. Here is an example which has been tested on Windows using IE, Firefox, Safari and Chrome (recent versions of all, I can't be bothered checking the versions). It also renders correctly if the file is opened in Word (versions based on xml). require(hwriter) pg - openPage(specialcharacters.html) hwrite(Test Special Characters, pg, heading = 1, br = TRUE) hwrite(Ciencias Sociales y Juriacute;dicas n:74 | 33.94%, pg, br = TRUE) hwrite(Ciencias Sociales y Jur#237;dicas n:74 | 33.94%, pg, br = TRUE) closePage(pg) For other special character codes, see for example http://www.ascii.cl/htmlcodes.htm David Scott On 31/07/2012 9:21 p.m., ramonovelar wrote: Thanks Arun, Yes, I have Windows 7. I have tried 2 versions of R, 2.14.1 and 2.15.x, but it did not change anything. Right now I can't try a different version of win. Ramón On Tuesday, July 31, 2012, arun kirshna [via R] wrote: Hello, I tried your code in R 2.15 with Ubuntu 12.04. It looks okay to me. datosdv-Ciencias Sociales y JurÃdicas n:74 | 33.94% print(datosdv) #[1] Ciencias Sociales y JurÃdicas n:74 | 33.94% library(hwriter) p=openPage('test.html') hwrite(datosdv,p,br=TRUE) #test.html output Ciencias Sociales y JurÃdicas n:74 | 33.94% Probably, it must be specific with the windows. Are you using windows7? A.K. - Original Message - From: ramonovelar[hidden email]http://user/SendEmail.jtp?type=nodenode=4638501i=0 To: [hidden email]http://user/SendEmail.jtp?type=nodenode=4638501i=1 Cc: Sent: Monday, July 30, 2012 7:11 PM Subject: [R] Accents and special character using hwriter (on Windows) Hello, I have a problem with special characters such as à or ñ when using hwriter. This only happens when I use windows, it works fine on mac. If I do: print(datosdv) Ciencias Sociales y JurÃdicas n:74 | 33.94% but: hwrite(datosdv, p, br=TRUE) Ciencias Sociales y Jur�dicas n:74 | 33.94% The bad sign is in the code, is not a problem of the encoding of the html page, that is in UTF-8. Does anybody have found this? Many thanks in advance. Ramón -- View this message in context: http://r.789695.n4.nabble.com/Accents-and-special-character-using-hwriter-on-Windows-tp4638474.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email]http://user/SendEmail.jtp?type=nodenode=4638501i=2mailing 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. __ [hidden email]http://user/SendEmail.jtp?type=nodenode=4638501i=3mailing 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. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Accents-and-special-character-using-hwriter-on-Windows-tp4638474p4638501.html To unsubscribe from Accents and special character using hwriter (on Windows), click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4638474code=cmFtb24ub3ZlbGFyQGdtYWlsLmNvbXw0NjM4NDc0fC0xNzk0Mjk1MDc3 . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 [[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
Re: [R] R report generator (for Word)?
The html route is one I have used quite a lot, but rather than R2HTML I far prefer hwriter. I have spent some time on enhancing hwriter and you can find my hwriterPlus on R-forge. It has fairly extensive examples and a vignette in the inst directory. I am still working on some improvements to the package. David Scott From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of Joshua Wiley [jwiley.ps...@gmail.com] Sent: Monday, January 02, 2012 9:31 AM To: Michael Cc: r-help Subject: Re: [R] R report generator (for Word)? Hi Michael, I like Sweave and LaTeX, but I can appreciate the difficulty using it with collaborators. What about something similar using HTML? Certainly integrates to any webpages nicely. There are two packages I think do this nicely, one is the R2HTML package (on CRAN). Another one that is not on CRAN yet, but I think has a lot of potential is the knitr package. You can find it on github. I am not personally familiar with any good ways to integrate R with MS Office products. Cheers, Josh On Sun, Jan 1, 2012 at 7:50 AM, Michael comtech@gmail.com wrote: Happy New Year all! I am looking for a good solution for keeping record of my experiments - could you please help me? My work is about analysing data... My current work-flow: 1. Everyday my bosses give me some small steps/tasks for analysing data - which are parts of one bigger/whole project. 2. Everyday I send tens of emails to bosses/colleagues to report my findings in each step. 3. Bosses/colleagues often respond to my findings in real-time and suggest new experiments/steps and ask what-if questions. 4. I often have to manually copy and paste the results from R console and put them into an Excel and decorate a bit and send out. 5. Every one week and 2 weeks, we need to present to more senior bosses with more nice-looking presentations which is a summary of our findings in those 1-2 weeks. It's this time that is most chaotic because my colleagues and I have to dig into all the hundreds of emails in the past 1-2 weeks and copy and paste and organize those data again and make a nice overall summary for presentation... 6. As I am a hard-working guy, I myself often run my own random/ad-hoc experiments using out-of-work time and whenever I have interesting findings, I will send to immediate bosses and colleagues to seek their comments. 7. All these experiments are in fact variations of different versions/ideas of one big/whole project. Lets say in one big project bosses/colleagues and I have come up with a few big ideas, then we have a few sub-projects: MyProjectIdea1 MyProjectIdea2 ... MyProjectIdeaN And each idea has a few variations, mostly are for answering what-if questions by varying the parameters here and there ... For example: MyProjectIdea1_Variation1_WhatIfParam1ChangedTo1.2? ... ... etc. 8. Most experiments run tens of minutes to many hours... and some of them have to run on Linux, and some others can be run on Windows. Fortunately we have universal paths accessible on both Windows and Linux, so those won't be problem... 9. Because of the time-consuming nature of these experiments, I also save the images as rData whenever I can. However, it's necessary to keep track of the context where these data were generated. Otherwise even the records of these images won't help recall the scenario we have run... --- Keeping track of these changes and all kinds of what-ifs now becomes increasingly a problem for me. Some times in order to respond to a query, although I have done it before already, but because I didn't keep record and save the result, or even though I have saved the memory image yet I am not completely sure about the cleanness of the results/data,I have to redo it and wait for another few hours. Is there a way that I can manage these whole processes better and be more productive? I have been digging and thinking about this for while and I guess Sweave is the right way to go? The problem for Sweave is that it's hard to make Latex generated pdf appealing to business managers... so if I keep records in Sweave/Latex for my own record/benefit (that's already a big benefit)... I still need to somehow manually copy/paste the data from Sweave/Latex/pdf into Word/Excel/Powerpoint in order to make a nice presentation... I know there are some Open Office and Word version of Sweave... the problem is that I couldn't find many demonstrations on these topics and my question is: are they good and can they fulfill what we needed? Your thoughts are greatly appreciated! Thanks a lot! [[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
Re: [R] Fitting a Harmonic Function to Time Series Data
On 14/10/2011 1:00 a.m., ashz wrote: Dear All, I have some time series data where X=month and Y=nutrient concentration (I can have several concentration data for one month). Is there a way to fit for it an Harmonic Function. Is there a package, script,etc which I can use? Thx Possibly there is this functionality in Rob Hyndman's forecast package. See this post by him: http://robjhyndman.com/researchtips/longseasonality/ which has some code which should also be of use. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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] Tinn-R
On 5/10/2011 7:25 a.m., Charles McClure wrote: I am new to R and have recently tried Tinn-R with very mixed and unexpected results. Can you point me to a Tinn-R tutorial on the web or a decent reference book? Thank you for your help; Charles McClure cmccl...@atrcorp.com cfmccl...@verizon.net There is a free eBook on tinn-R available from Rmetrics: https://www.rmetrics.org/ebooks-tinnr Written by the authors of tinn-R. Please consider a donation to the Rmetrics Association. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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] Printing an xtable with type = html
I have been playing around with producing tables using xtable and the type = html argument when printing. For example, if xtbl is the output of a dataframe which has been run through xtable, using the command: print(xtbl, type = html, html.table.attributes = border = '1', align = 'center') I would be interested to see other examples of the use of xtable to produce html. There is a whole vignette on using xtable to produce all sorts of tables for incorporation into a TeX document but I have found no examples of producing html with any table attributes. Ideally xtable should be able to access a css file but I don't see any mechanism for doing that. Perhaps someone can enlighten me. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 RODBC
On 20/07/11 18:56, Dieter Menne wrote: David Scott-6 wrote: I have been trying to read some data from an Excel workbook without success. ... faults- sqlFetch(channel, sqtable = 'Data', +colnames = FALSE, as.is = TRUE) faults [1] HY001 -1040 [Microsoft][ODBC Excel Driver] Too many fields defined. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$]' I have given up using odbc/Excel without named ranges, but I know it works sometimes. xlsReadWrite works well for whole sheets, while the gdata/Perl solutions can be terribly slow (minutes instead of seconds) with large files. I had seen the message above before, and it had to do with some invisible characters in the fields. I managed to get it to work by exporting value of the sheet, which seems to do a cleanup. Alternatively, a Copy/PasteValue. After that, my curiosity was satisfied, and I returned to named ranges or xlsReadWrite. Dieter Thanks Dieter. Your reply prompted me to carry out some experimentation which confirmed to me the validity of your conclusions. I was unable to read the data satisfactorily using RODBC without creating a named range. Once I created a named range all was fine. I did some searching for unusual characters in the data set, but couldn't find anything untoward. I tried removing the 1st row which had drop down lists but to no avail. Another approach which worked was to copy the data from the existing sheet to a new sheet, retaining values and number formats. Finally, I decided to save the workbook in .xlsx format, and use odbcConnectExcel2007. I was then able to read the data successfully, with one problem being that 255 columns were read, when only 20 actually contained data. The read also seemed a bit slow. So, a few workarounds for anyone facing this problem in the future: named range; copy the data values to a new sheet; or use .xlsx format. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 RODBC
I have been trying to read some data from an Excel workbook without success. The workbook is in .xls format and has multiple sheets, one with the sheet name Data, which is the sheet I wish to read from. One complication is that the header row of this sheet is comprised of dropdown boxes. I tried what I normally would do plus some variations. Here is the output. require(RODBC) options(stringsAsFactors = FALSE) fileName - paste(getwd(), + /../Data/10_11 Quality Threshold Calculations v3.xls, + sep = ) channel - odbcConnectExcel(fileName) sqlTables(channel)$TABLE_NAME [1] Data$ [2] PBC$ [3] SQL$ [4] '10_11 Summary$' [5] '10_11 Summary$'Print_Area [6] 'Cust Nos$' [7] Data$_ [8] 'Diagnostic Pivot$' [9] 'Historic summary$' [10] 'MED Supporting Evidence$' [11] 'MED Supporting Evidence$'Print_Area faults - sqlFetch(channel, sqtable = 'Data', +colnames = FALSE, as.is = TRUE) faults [1] HY001 -1040 [Microsoft][ODBC Excel Driver] Too many fields defined. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$]' faults - sqlFetch(channel, sqtable = 'Data$', +colnames = FALSE, as.is = TRUE) faults [1] HY001 -1040 [Microsoft][ODBC Excel Driver] Too many fields defined. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$]' faults - sqlFetch(channel, sqtable = 'Data$_', +colnames = FALSE, as.is = TRUE) faults [1] 42S02 -1305 [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'Data$_'. Make sure the object exists and that you spell its name and the path name correctly. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$_]' odbcCloseAll() I was able to read the data in using xlsReadWrite by skipping the header row and specifying the sheet name, so I have a workaround. I would like to hear any advice on what might be wrong though since usually RODBC has been extremely reliable. Data is confidential (and in a 14Mb file) so I can't provide it. My session info is: sessionInfo() R version 2.13.0 Patched (2011-06-09 r56106) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_New Zealand.1252 LC_CTYPE=English_New Zealand.1252 [3] LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C [5] LC_TIME=English_New Zealand.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-2 djsmisc_1.0-1 loaded via a namespace (and not attached): [1] tools_2.13.0 David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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] extract worksheet names from an Excel file
On 24/06/11 16:55, bill.venab...@csiro.au wrote: Package XLConnect appears to provide this kind of thing. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Shi, Tao Sent: Friday, 24 June 2011 2:42 PM To: r-help@r-project.org Subject: [R] extract worksheet names from an Excel file Hi list, Is there a R function I can use to extract the worksheet names from an Excel file? If no, any other automatic ways (not using R) to do this? thanks! ...Tao __ 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. If you use RODBC to connect to an xls or xlsx file you can use sqlTables to show not only the worksheet names, but the presence of any named data ranges. Sample code from a student exercise: require(RODBC) channel - odbcConnectExcel(bikesWithDate.xls) sqlTables(channel) David -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 a choice model (Bradley-Terry generalization)
I have some data I would like to model which involves choice of food by dung beetles. There are a number of experiments where in each case, there are five choices. Overall there are more than 5 different foods being compared (including a placebo) and different experiments use different comparisons. The problem is a generalization of Bradley-Terry but it differs from some generalizations in that the comparisons are not pairwise, and they don't produce a full ordering, just that one is preferred to the other four possibilities. I have had a look at the BradleyTerry2, eba, pmr and MLCM packages, none of which appear to provide the required functionality. I have also looked at a number of papers (Hunter, 2004; Firth, 2005; Huang Weng and Lin, 2006; and Fujimoto, Hino and Murata 2011). I think fitting using maximum likelihood should be possible, but would welcome any pointers to useful code, relevant ideas, or similar analyses. David Scott __ 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] computer name
On 13/06/11 15:19, pdb wrote: Is there an r function that will be able to identify the computer the code is running on? I have some common code that I run on several computers and each has a database with a different server name - although the content is identical. I need to set thisServer depending on which machine the code is running on... something like... if(pcname = pc1) thisServer = 'SERVER1' if(pcname = pc2) thisServer = 'SERVER2' conn- odbcDriverConnect(driver=SQL Server;database=x;server=thisServer;) ...rest of code will now run OK. I know I could set the DSN names the same and use... conn- odbcConnect(commonDSNname) but I was wondering if there was another way -- View this message in context: http://r.789695.n4.nabble.com/computer-name-tp3593120p3593120.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. Does Sys.info()[nodename] give you what you want? David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 from functions
On 02/06/11 10:13, Duncan Murdoch wrote: On 01/06/2011 4:06 PM, Yang Zhang wrote: On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhangyanghates...@gmail.com wrote: I can plot to png's fine when i run this directly from the top-level script/console: png('diamonds.png');qplot(carat,price,data=diamonds);dev.off() But for some reason it's not working when that's in a function: (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})() I suspect this is because the qplot's return value must be returned to the top-level, because this works: (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off() Any hints on how I can plot from within a function? Thanks in advance. Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions? If the plotting function is using grid graphics you do. I don't know where the qplot() function is from, but it looks as though it must be from a package that uses grid. Duncan Murdoch _ qplot is from ggplot2, and is a simpler form of ggplot with limited features. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 as.numeric()
On 25/05/2011 9:20 a.m., Lutz Fischer wrote: Hi, I have a bit of a problem with as.numeric or as.double. I read in an excel-file (either xlsx::read.xlsx2 or gdata::read.xls). Select a subset and then try to make it numeric: # read in the excel-file alldata-read.xlsx2(input.xls,1) # select the subset s-subset(alldata, select=c(cI,cII,cIII,cIV,cV)) # unluckily we have n/a for missing values in the file - so we turn it into proper missing values s[s == n/a]-NA n-data.matrix(s); The problem I have is that it does not convert the date the way I would expect. just as an example: s[1,2] [1] 30.94346629 3136 Levels: 0.026307482 0.028239812 0.02849896 0.029054564 0.029540352 0.030248034 0.030841352 0.032966308 ... n/a turned into: n[1,2] [1] 3020 And I would like to have there 30.94346629 as well. I assume that has to do with the Levels attribute - but not sure what to make of these in the first place. I also tried to convert each value on its own: #make some space that holds the actual numeric data n - array(dim=c(length(s[,1]),length(s))) # now turn everything into doubles for (c in 1:length(s)) { for (r in 1:length(s[,1])) { n[r,c]-as.double(s[r,c]) } } but that gave the same result - just a lot slower. Thanks Lutz Your problem is the conversion to factors when the data is read. Use options(stringsAsFactors = FALSE) before you read the data, then the mixed columns of numeric and missing will be read as character data and the conversion to numeric will go as you expect. (But I haven't tested this.) David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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 Style Guide -- Was Post-hoc tests in MASS using glm.nb
Another style guide is at: http://www1.maths.lth.se/help/R/RCC/ Listed as a first draft and dated 2005, but still worth a read. Has some references also. I think I recall Hadley having a style guide which he requested his students followed, but I didn't like it too much (sorry Hadley) . I am with Bill that style guides should be consulted and their recommendations considered, but it is personal preference as to which rules one accepts. I don't find it objectionable if someone has written in a style I don't particularly like, but it is objectionable if no thought has been given to programming style. David Scott On 19/05/11 10:26, bill.venab...@csiro.au wrote: Hi Bert, I think people should know about the Google Sytle Guide for R because, as I said, it represents a thoughtful contribution to the debate. Most of its advice is very good (meaning I agree with it!) but some is a bit too much (for example, the blanket advice never to use S4 classes and methods - that's just resisting progress, in my view). The advice on using- for the (normal) assingment operator rather than = is also good advice, (according to me), but people who have to program in both C and R about equally often may find it a bit tedious. We can argue over that one. I suggest it has a place in the R FAQ but with a suitable warning that this is just one view, albeit a thougtful one. I don't think it need be included in the posting guide, though. It would take away some of the fun. :-) Bill Venables. -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: Wednesday, 18 May 2011 11:47 PM To: Venables, Bill (CMIS, Dutton Park) Cc: r-help@r-project.org Subject: R Style Guide -- Was Post-hoc tests in MASS using glm.nb Thanks Bill. Do you and others think that a link to this guide (or another)should be included in the Posting Guide and/or R FAQ? -- Bert On Tue, May 17, 2011 at 4:07 PM,bill.venab...@csiro.au wrote: Amen to all of that, Bert. Nicely put. The google style guide (not perfect, but a thoughtful contribution on these kinds of issues, has avoiding attach() as its very first line. See http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html) I would add, though, that not enough people seem yet to be aware of within(...), a companion of with(...) in a way, but used for modifying data frames or other kinds of list objects. It should be seen as a more flexible replacement for transform() (well, almost). The difference between with() and within() is as follows: with(data, expr, ...) allows you to evaluate 'expr' with 'data' providing the primary source for variables, and returns *the evaluated expression* as the result. By contrast within(data, expr, ...) again uses 'data' as the primary source for variables when evaluating 'expr', but now 'expr' is used to modify the varibles in 'data' and returns *the modified data set* as the result. I use this a lot in the data preparation phase of a project, especially, which is usually the longest, trickiest, most important, but least discussed aspect of any data analysis project. Here is a simple example using within() for something you cannot do in one step with transform(): polyData- within(data.frame(x = runif(500)), { x2- x^2 x3- x*x2 b- runif(4) eta- cbind(1,x,x2,x3) %*% b y- eta + rnorm(x, sd = 0.5) rm(b) }) check: str(polyData) 'data.frame': 500 obs. of 5 variables: $ x : num 0.5185 0.185 0.5566 0.2467 0.0178 ... $ y : num [1:500, 1] 1.343 0.888 0.583 0.187 0.855 ... $ eta: num [1:500, 1] 1.258 0.788 1.331 0.856 0.63 ... $ x3 : num 1.39e-01 6.33e-03 1.72e-01 1.50e-02 5.60e-06 ... $ x2 : num 0.268811 0.034224 0.309802 0.060844 0.000315 ... Bill Venables. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Wednesday, 18 May 2011 12:08 AM To: Peter Ehlers Cc: R list Subject: Re: [R] Post-hoc tests in MASS using glm.nb Folks: Only if the user hasn't yet been introduced to the with() function, which is linked to on the ?attach page. Note also this sentence from the ?attach page: attach can lead to confusion. I can't remember the last time I needed attach(). Peter Ehlers Yes. But perhaps it might be useful to flesh this out with a bit of commentary. To this end, I invite others to correct or clarify the following. The potential confusion comes from requiring R to search for the data. There is a rigorous process by which this is done, of course, but it requires that the runtime environment be consistent with that process, and the programmer who wrote the code may not have control over that environment. The usual example is that one has an object named,say, a in the formula and in the attached data and another a also in the global environment. Then the wrong a would be found. The same thing can happen if another data set gets attached in a position before the one
Re: [R] converting a matrix or data.frame into an html table
On 9/05/2011 10:40 p.m., Samuel Le wrote: Dear all, Is there a function in R to convert a matrix or a data.frame into an html table? Many thanks, Samuel xtable() in the xtable package can do this (at least to some extent). It is commonly used to write LaTeX but there is an option to produce html as well. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ 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: how to center a subtitle?
On 6/04/2011 12:47 a.m., Deepayan Sarkar wrote: On Tue, Apr 5, 2011 at 6:12 AM, David Scottd.sc...@auckland.ac.nz wrote: [...] I am not sure where I read it and I can't find it again, but my understanding is that expressions using bquote with lattice need to be enclosed in as.expression() to work. That is in contrast to what happens in base graphics. Here is a simple example. a- 2 plot(1:10, a*(1:10), main = bquote(alpha == .(a))) require(lattice) xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a))) xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a Which produces: a- 2 plot(1:10, a*(1:10), main = bquote(alpha == .(a))) require(lattice) Loading required package: lattice xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a))) Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L, : object 'alpha' not found xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a Using expression() rather than as.expression() doesn't produce the desired affect. Try it yourself. As to why this is the case . Let's see: ?xyplot says 'main': Typically a character string or expression describing the main title to be placed on top of each page. [...] So, lattice is fairly explicit, by R standards, in requiring 'main' to be character or expression. On the other hand, ?title says The labels passed to 'title' can be character strings or language objects (names, calls or expressions), or [...] so it additionally accepts names and calls. Now, we have a- 2 foo- bquote(alpha == .(a)) foo # Looks OK alpha == 2 mode(foo) # But [1] call is.expression(foo) # not an expression [1] FALSE is.expression(expression(foo)) ## YES, but [1] TRUE expression(foo) ## not what we want expression(foo) is.expression(as.expression(foo)) [1] TRUE as.expression(foo) ## This IS what we want expression(alpha == 2) So I submit that lattice is behaving exactly as suggested by its documentation. Now you would naturally argue that this is hiding behind technicalities, and if call objects work for plot(), it should work for lattice as well. But watch this: plot(1:10, main = foo) # works perfectly arglist- list(1:10, main = foo) arglist # Looks like what we want [[1]] [1] 1 2 3 4 5 6 7 8 9 10 $main alpha == 2 do.call(plot, arglist) Error in as.graphicsAnnot(main) : object 'alpha' not found ...which I would say is unexpected behaviour, if not a bug. The moral of the story is that unevaluated calls are dangerous objects (try this one out for fun: foo- bquote(q(.(x)), list(x = no)) do.call(plot, list(1:10, main = foo)) ), and carrying them around is not a good idea. Lattice does use the do.call paradigm quite a bit, and I think it might be quite difficult to fix it up to handle non-expression language objects (which will still not fix the type of problem shown above). -Deepayan Thanks very much for this explanation Deepayan. Part of my intention in contributing to this thread was to have something explicit in the archives for future reference, and your reply is excellent in that regard. And many thanks for your work on lattice. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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: how to center a subtitle?
On 05/04/11 05:58, David Winsemius wrote: On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote: Dear David, do you know how to get plotmath-like symbols in both rows? I tried s.th. like: lab- expression(paste(alpha==1, , , beta==2, sep=)) xlab- substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab)) xyplot(0 ~ 0, xlab = xlab) I _did_ have plotmath functions in both rows: But here is your solution: xyplot(0 ~ 0, xlab = expression( atop(paste(alpha==1,, beta==2), bold(bla) )) ) ) Note that `paste` in plotmath is different than `paste` in regular R. It has no `sep` argument. I did try both substitute and bquote on you externally expression, but lattice seems to be doing some non- standard evaluation and I never got it to work. Using what I thought _should_ work, does work with `plot`: x=1;y=2 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) ) + ) But the same expression throws an error with xyplot: x=1;y=2 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) ) + ) Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill, : could not find function atop I am not sure where I read it and I can't find it again, but my understanding is that expressions using bquote with lattice need to be enclosed in as.expression() to work. That is in contrast to what happens in base graphics. Here is a simple example. a - 2 plot(1:10, a*(1:10), main = bquote(alpha == .(a))) require(lattice) xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a))) xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a Which produces: a - 2 plot(1:10, a*(1:10), main = bquote(alpha == .(a))) require(lattice) Loading required package: lattice xyplot(a*(1:10)~ 1:10, main = bquote(alpha == .(a))) Error in trellis.skeleton(formula = a * (1:10) ~ 1:10, cond = list(c(1L, : object 'alpha' not found xyplot(a*(1:10)~ 1:10, main = as.expression(bquote(alpha == .(a Using expression() rather than as.expression() doesn't produce the desired affect. Try it yourself. As to why this is the case . David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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: how to center a subtitle?
On 05/04/11 13:14, David Winsemius wrote: On Apr 4, 2011, at 9:03 PM, David Winsemius wrote: On Apr 4, 2011, at 8:42 PM, David Scott wrote: On 05/04/11 05:58, David Winsemius wrote: On Apr 4, 2011, at 1:27 PM, Marius Hofert wrote: Dear David, do you know how to get plotmath-like symbols in both rows? I tried s.th. like: lab- expression(paste(alpha==1, , , beta==2, sep=)) xlab- substitute(expression( atop(lab==lab., bold(foo)) ), list(lab.=lab)) xyplot(0 ~ 0, xlab = xlab) I _did_ have plotmath functions in both rows: But here is your solution: xyplot(0 ~ 0, xlab = expression( atop(paste(alpha==1,, beta==2), bold(bla) )) ) ) Note that `paste` in plotmath is different than `paste` in regular R. It has no `sep` argument. I did try both substitute and bquote on you externally expression, but lattice seems to be doing some non- standard evaluation and I never got it to work. Using what I thought _should_ work, does work with `plot`: x=1;y=2 plot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) ) + ) But the same expression throws an error with xyplot: x=1;y=2 xyplot(0 ~ 0, xlab = bquote( atop(alpha==.(x)*,~beta==.(y), bold(foo) ) ) + ) Error in trellis.skeleton(formula = 0 ~ 0, cond = list(1L), aspect = fill, : could not find function atop I am not sure where I read it and I can't find it again, but my understanding is that expressions using bquote with lattice need to be enclosed in as.expression() to work. That is in contrast to what happens in base graphics. Perhaps here: http://finzi.psych.upenn.edu/Rhelp10/2010-August/250832.html I am pretty sure that was where I saw it. I knew it was out there somewhere. Or here: http://finzi.psych.upenn.edu/Rhelp10/2009-July/203714.html Although I disagree with Heimstra that reading the help(bquote) provides more details that might shed light on why this is so. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] generate random numbers
On 01/04/11 08:50, Ted Harding wrote: On 31-Mar-11 19:23:33, Anna Lee wrote: Hey List, does anyone know how I can generate a vector of random numbers from a given distribution? Something like rnorm just for non normal distributions??? Thanks a lot! Anna SUppose we give your distribution the name Dist. The generic approach would start by defining a function for the inverse of its cumulative distribution. Call this qDist. Then qDist(runif(1000)) would generate 1000 values from the distribution Dist. As a ready-made example, qnorm is the inverse of pnorm, the cumulative distribution function of the Normal distribution. Then qnorm(runif(1000)) would act just like rnorm(1000), though the sequence of values would be different (a different algorithm) -- and also rnorm() would be more efficient (being specially written). Depending on what your desired distribution is, you may find that an rDist has already been written for it. There are many distributions already in R for which the family of functions dDist, pDist, qDist and rDist are provided. For more specific advice, please give us information about the specific distribution you want to sample from! Ted. I can point to one general implementation which might be helpful, and even the function names are the same. In the version of DistributionUtils on R-Forge you will find functions pDist and qDist which should give the distribution function and quantile function of any continuous unimodal distribution. Provisos: there may be problems with distributions with very heavy tails, and generally the routines could be slow. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Storing user-defined R functions
On 25/03/11 09:08, Thomas Lumley wrote: On Fri, Mar 25, 2011 at 5:11 AM, David.Epstein david.epst...@warwick.ac.uk wrote: Hello, I don't want to find out how to make packages unless that becomes necessary. Also, I don't want to clog up the computer memory with functions that I'm not using. (It would be great if someone in this forum would explain how memory is used when I type library(MASS) and then use only one function from MASS. Are all the many MASS functions then residing in memory, or only the one I called?) There is a lazy-loading system that loads functions and datasets only on demand. Not all packages use it, but MASS does. Is there some standard way of 1. storing the R functions that I define, each in a separate file in some standard directory, and then 2. calling one of these functions without having to include the path to the relevant directory? 3. If so, are there conventional places to keep such files, akin to /usr/local/bin in Unix? No. You really do want to learn to make packages. It isn't that hard. However, another possibility is to use save() to save a file containing all your functions and then use attach() to make these functions available. This works like making a package except that you don't get lazy-loading, you don't get documentation, and you don't get the package checks. -thomas Another work around would involve defining a little function in your .Rprofile, as follows. Choose a location for your code. The function would take the name of the file, prepend the path to the directory where your code is located and then call source. Two or three lines would do it. Also, who knows, maybe Gabor has something clever in his batch files, he usually seems to. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Difference in numeric Dates between Excel and R
On 2/03/2011 12:31 p.m., Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Luis Felipe Parra Sent: Tuesday, March 01, 2011 3:07 PM To: r-help Subject: [R] Difference in numeric Dates between Excel and R Hello. I am using some dates I read in excel in R. I know the excel origin is supposed to be 1900-1-1. But when I used as.Date with origin=1900-1- 1 the dates that R reported me where two days ahead than the ones I read from Excel. I noticed that when I did in R the following: as.Date(2011-3-4)-as.Date(1900-1-1) Time difference of 40604 days but if I do the same operation in Excel the answer is 40605. Does anybody know what can be going on? I think so. It is a known problem that Excel thinks 1900 was a leap year, but it was not. So Excel counts an extra day (for nonexistent Feb 29, 1900). In addition, Excel considers 1900-01-01 as day 1, not day 0. Hope this is helpful, Dan An explanation which seems reasonably authoritative is given here: http://www.cpearson.com/excel/datetime.htm David Scott Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 in different OS
Not sure exactly what the original poster was after, but for distinguishing when I am working on different machines with different OS, I use something like this: ### Set some state variables opSys - Sys.info()[sysname] if (opSys == Windows){ linux - FALSE } else { linux - TRUE } David Scott On 26/02/2011 10:00 a.m., Ista Zahn wrote: Hi, see ?R.version Something like if(version$os == mingw32) { path = /ABC} else { path = /DEF } might do it, but I'm not sure exactly what possible values version$os can take or what determines the value exactly. Best, Ista On Fri, Feb 25, 2011 at 1:23 PM, Hui Duhui...@dataventures.com wrote: Hi All, I have two Rs, one has been installed in Windows system and another one has been installed under UNIX system. Is there any environmental variable or function to tell me which R I am using? The reason that I need to know it is under different system, the data path could be different. I want to do something like if it is R under Windows path = /ABC else if it is R under UNIX, path = /DEF Any idea? Thanks. Best Regards, HXD [[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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 in different OS
Thanks Brian, I stand corrected. David Scott On 27/02/2011 12:32 a.m., Prof Brian Ripley wrote: It is less clear what you are after, but the canonical way to decide if your R session is on Windows is .Platform$OS.type == windows Unlike {R.}version$os and Sys.info()[sysname], the set of values here is known and documented. As ?R.version does say: Do _not_ use ‘R.version$os’ to test the platform the code is running on: use ‘.Platform$OS.type’ instead. Slightly different versions of the OS may report different values of ‘R.version$os’, as may different versions of R. On Sun, 27 Feb 2011, David Scott wrote: Not sure exactly what the original poster was after, but for distinguishing when I am working on different machines with different OS, I use something like this: ### Set some state variables opSys- Sys.info()[sysname] if (opSys == Windows){ linux- FALSE } else { linux- TRUE } David Scott On 26/02/2011 10:00 a.m., Ista Zahn wrote: Hi, see ?R.version Something like if(version$os == mingw32) { path = /ABC} else { path = /DEF } might do it, but I'm not sure exactly what possible values version$os can take or what determines the value exactly. Best, Ista On Fri, Feb 25, 2011 at 1:23 PM, Hui Duhui...@dataventures.com wrote: Hi All, I have two Rs, one has been installed in Windows system and another one has been installed under UNIX system. Is there any environmental variable or function to tell me which R I am using? The reason that I need to know it is under different system, the data path could be different. I want to do something like if it is R under Windows path = /ABC else if it is R under UNIX, path = /DEF Any idea? Thanks. Best Regards, HXD [[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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Writing R packages in an easier way?
On 12/02/2011 1:27 p.m., Yihui Xie wrote: I guess Emacs + ESS + roxygen might be the easiest way to write an R package. Writing or modifying Rd files/templates, in my eyes, is really time-consuming and the Rd files are difficult to maintain (unless you really have a good memory). I became reluctant to maintain my R packages simply because I felt painful to maintain the documentation. After I learned a bit about roxygen and ESS a few months ago, several of my packages came back to life again (e.g. this picture is a piece of evidence: https://github.com/yihui/animation/graphs/impact). The feeling was probably like when Dr Harrell switched from SAS to S (see library(fortunes); fortune('I quit using SAS')). Anyway, prompt() and package.skeleton() are very helpful in the short run. Regards, Yihui -- There is also the slackers way of producing R packages without writing any documentation. You create a file PackageName-internal.Rd in which you then put the name of the package and all the functions as aliases: \name{PackageName-internal} \alias{function1} \alias{function2} . . . \title{Internal PackageName objects} \description{Internal PackageName objects.} \details{These are not to be called by the user.} \keyword{internal} I only mention this possibility for the sake of intellectual completeness of the discussion of this topic. It of course totally subverts the whole philosophy of package construction in R, so I wouldn't dream of using it myself. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Title
On 9/02/2011 6:25 a.m., David Winsemius wrote: On Feb 8, 2011, at 11:43 AM, kateF87 wrote: I have a relatively simple question. I am trying to post a title to a plot using a symbol and multiple lines. Right now I have: title(main = c('Hazard Ratio for women with score', expression('='), 'Across /nQuintiles of Activity') I am going to anticipate the next question, which I assume to be how to insert a value after the = sign: b=5 plot(1,1) title(main = bquote(atop(paste(Hazard Ratio for women with score, =.(b)) , Across Quintiles of Activity) ) ) Wow, where did you get that idea from! In my mind atop had always been for use in such things as the expression for a combination, basically a fraction without the dividing line between numerator and denominator. To use it to put whole lines of text on top of each other is ... creative! I was going to offer the conventional advice which is to use mtext because of the restriction in plotmath that \n is not allowed: Control characters (e.g. \n) are not interpreted in character strings in plotmath, unlike normal plotting. But atop works as you suggest. A very useful trick, because mtext with multiple lines can take time to get right. It does offer a bit more control over line spacing which could be a concern with atop. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 list within a list?
On 6/02/2011 3:38 p.m., Jim Silverton wrote: Hello, I am planning of building a list of lists specifically, my first list is some what of the sort: lidta- list(m, p, r, s, q, A, B) where A and B are matrices that may be of different number of rows . The number of rows in matrix A and matrix B depends on the the values of m. The question is I don;t know how to put all the 1000 or so of these lists into a 'mega' list. Can you help me? I use the following for this sort of thing. megaList - vector(list, length = 1000) testList - list(x=1:3, y=c(a,b)) for (i in 1:1000){ megaList[[i]] - testList } head(megaList) David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Extract NA data rows
On 25/01/2011 8:07 p.m., typhoong wrote: hi i have the following dataframe x y 1 345 6 NA 8 123 32 123 12 NA 6 124 7 NA and i want to extract the data rows which contains NA data, I tried subset(dataframe,y==NA) but fail. if you know the answers, please let me know thanks. typhoong Your test is wrong for NA. You must use is.na: df x y 1 1 345 2 6 NA 3 8 123 4 32 123 5 12 NA 6 6 124 7 7 NA subset(df, is.na(y)) x y 2 6 NA 5 12 NA 7 7 NA -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 with expression
I have a problem with expressions. I am trying to create a title where the parameter of interest is displayed as a Greek character. Which parameter is being considered is stored in a character variable. As an example, if I have param - alpha and then do plot(0, 0, main = bquote(Parameter==.(param))) then in the title I get Parameter = alpha, whereas I want the Greek character alpha. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 with expression
Thanks. Exactly what I wanted. As usual, I played around with all sorts of things to try and get the expression right, but never thought of as.name. David Scott On 25/01/2011 4:32 a.m., Charles C. Berry wrote: On Tue, 25 Jan 2011, David Scott wrote: I have a problem with expressions. I am trying to create a title where the parameter of interest is displayed as a Greek character. Which parameter is being considered is stored in a character variable. As an example, if I have param- alpha param- as.name(alpha) HTH, Chuck and then do plot(0, 0, main = bquote(Parameter==.(param))) then in the title I get Parameter = alpha, whereas I want the Greek character alpha. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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. Charles C. BerryDept of Family/Preventive Medicine cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Obtaining a quadratic function igven three points on a curve
I think you need poly(X, 2, raw = TRUE) to interpret the coefficients in the manner described below. poly uses orthogonal polynomials by default: poly package:stats R Documentation Compute Orthogonal Polynomials Description: Returns or evaluates orthogonal polynomials of degree 1 to 'degree' over the specified set of points 'x'. These are all orthogonal to the constant polynomial of degree 0. Alternatively, evaluate raw polynomials. David Scott On 21/01/2011 3:50 a.m., Joshua Wiley wrote: Hi Barth, Here is an option fitting a linear model toa second order polynomial and extracting the coefficients. The Intercept corresponds to c in your email, then poly(...)1 to b and poly(...)2 to a. dat- read.table(textConnection( Y X 0.159529 0 0.5 0.773019 1 1), header = TRUE) closeAllConnections() coef(lm(Y ~ poly(X, 2), data = dat)) # For details see: ?poly ?lm ?coef Hope this helps, Josh On Thu, Jan 20, 2011 at 6:42 AM, Barth B. Rileybbri...@chestnut.org wrote: Hello I would like to obtain the coefficients for a quadratic function (ax^2 + bx + c) given three sets of points on the quadratic curve. For instance: Y X 0.1595290 0.5 0.773019 1 1 Is there a function in R to obtain the a, b and c ceofficients? Thanks Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] CSV value not being read as it appears
As a further note, this is a reminder that whenever you get data via a spreadsheet the first thing to do is examine it and clean up any problems. A basic requirement is to tabulate any categorical variable. Spreadsheets allow any sort of data to be entered, with no controls. My experience is that those who enter data into spreadsheets enter all sorts of variations of what a human would wish to treat as the same (Open, Open , open, etc.), even when told not to. David Scott On 14/01/2011 4:03 p.m., Jim Holtman wrote: try strip.white=TRUE to strip out white space Sent from my iPad On Jan 13, 2011, at 21:44, bgr...@dyson.brisnet.org.au wrote: I have a frustrating issue which I am hoping someone may have a suggestion about. I am running XP and R 2.12.0 and saved an EXCEL file that I was sent as a csv file. The initial code I ran follows. dec- read.csv(g://FMH/FO30122010.csv,header=T) dec.open- subset (dec, Status == Open) table(dec.open$AMHS) I was checking the output and noticed a difference between my manual count and R output. Two subject's rows were not being detected by the subset command: For the AMHS where there was a discrepancy I then ran: wm- subset (dec, AMHS == WM) The problem appears to be that there is a space before the 'Open value for two indivduals, as per the example below. 10/02/2010 Open 22/08/2007 Open Checking in EXCEL there does not appear to be a space and the format is the same (e.g 'general'). I resolved the problem by copying over the values for the two individuals where I identified a problem. Given this problem was not detected by visual scanning I would appreciate advice on how this problem can be detected in future without my having to manually check raw data against R output. Any assistance is appreciated, Bob __ 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. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] CSV value not being read as it appears
I am a bit confused by this. You are doing a transfer from Excel (.xls or .xlsx) to .csv, then a subset in R and ending up with a couple of entries which are Open rather than Open. So where are they coming from? You say they are not in the original Excel, so that suggests the transfer to .csv is the problem. I would be very surprised if the subset was a problem, but as others have indicated transfer to .csv can be downright ugly. You can check the .csv file by opening it in an editor (I use Emacs). Just go to the line and have a look if the extra space is there nestling between two commas. The other advice is, don't go through .csv. Go directly from Excel to R. My favourite tools are RODBC and xlsReadWrite for that step. Both work extremely well. As others have indicated, the big bugbear in the .csv route is dates, or what Excel decides are dates. My experience was the conversion of New Zealand health ID numbers to dates. They are three letters then 4 digits, so AUG2699 became a date. David Scott On 14/01/2011 10:58 p.m., bgr...@dyson.brisnet.org.au wrote: Hello David, Thanks for your e-mail. The data was a report derived from a statewide database, saved in EXCEL format, so the usual issue of the vagaries of human data entry variation wasn't the issue as the data was an automated report, which is run every three months. I would not have even noticed this problem if I hadn't been double checking the numbers of people by district. Visual inspection didn't reveal this problem - no white space was obvious and the spelling was identical. Tabulation via R wouldn't have detected this - I was obtaining the EXCEL totals via filter which I then compared with R output. I'm hoping I can skip this step, in future, with Jim's suggestion. regards Bob As a further note, this is a reminder that whenever you get data via a spreadsheet the first thing to do is examine it and clean up any problems. A basic requirement is to tabulate any categorical variable. Spreadsheets allow any sort of data to be entered, with no controls. My experience is that those who enter data into spreadsheets enter all sorts of variations of what a human would wish to treat as the same (Open, Open , open, etc.), even when told not to. David Scott On 14/01/2011 4:03 p.m., Jim Holtman wrote: try strip.white=TRUE to strip out white space Sent from my iPad On Jan 13, 2011, at 21:44, bgr...@dyson.brisnet.org.au wrote: I have a frustrating issue which I am hoping someone may have a suggestion about. I am running XP and R 2.12.0 and saved an EXCEL file that I was sent as a csv file. The initial code I ran follows. dec- read.csv(g://FMH/FO30122010.csv,header=T) dec.open- subset (dec, Status == Open) table(dec.open$AMHS) I was checking the output and noticed a difference between my manual count and R output. Two subject's rows were not being detected by the subset command: For the AMHS where there was a discrepancy I then ran: wm- subset (dec, AMHS == WM) The problem appears to be that there is a space before the 'Open value for two indivduals, as per the example below. 10/02/2010 Open 22/08/2007 Open Checking in EXCEL there does not appear to be a space and the format is the same (e.g 'general'). I resolved the problem by copying over the values for the two individuals where I identified a problem. Given this problem was not detected by visual scanning I would appreciate advice on how this problem can be detected in future without my having to manually check raw data against R output. Any assistance is appreciated, Bob __ 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. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help
Re: [R] Fitting an Inverse Gamma Distribution
On 14/01/2011 11:46 a.m., emorway wrote: http://r.789695.n4.nabble.com/file/n3216865/Inverse_Gamma.png Hello, I am seeking help in estimating the parameters of an inverse gamma distribution (from the 'actuar' package) using a function like 'fitdistr'. Unfortunately I haven't found such a package using findFn('fit Inverse Gamma') from the 'sos' package and was therefore hoping someone might be aware of such a function? In my package GeneralizedHyperbolic on R-Forge (not yet in the CRAN version) you will find a fitting routine for the generalized inverse Gaussian distribution which has the inverse Gaussian as a special case. David Scott Secondly, is there a way to shift the pdf (code below) to the right (rather than the data to the left)? I tried: par(new=T) shift-1 hist(iniSal_US_forHist,breaks=seq(1.1,21,by=0.625),col=grey,freq=F,xlim=c(0-shift,21-shift),plot=F) curve(dinvgamma(x,scale=11.835,shape=4.4242),from=0,to=20,add=T,col=purple,lwd=2) but this failed in shifting the curve. More broadly, the data plotted in the histogram represents a calibration target for output generated by a finite difference solute transport model. The values that will be generated by the finite difference model would ideally fit the shifted (if that can be figured out) inverse gamma pdf. To the extent that fit is deemed poor, the parameter estimation software associated with the finite difference model will adjust parameters until a better fit is found. I will try to use a goodness of fit test to determine if one set of parameter values in the finite difference model produce output that fits the inv. gamma curve herein better than another. But first I need to establish the curve the finite difference model output should target and would greatly appreciate any leads on how it might be shifted and/or fit more precisely by a fitdistr-like function. library(MASS) library(actuar) iniSal_US_forHist-c(2.368000,3.532614,3.064330,3.347069,3.066333,4.233636,3.465650,2.858553, 2.946731,2.945417,2.415000,2.873019,5.521000,5.788148,5.314630,5.509672,6.032840,6.009310, 4.110833,6.073182,5.652833,4.425733,6.481852,4.076857,3.289310,4.524000,3.985811,5.399714, 4.490606,6.956729,5.270933,8.099107,5.058250,6.394500,5.644000,5.202459,5.67,3.152680, 3.220952,2.777381,3.115467,3.642759,3.488333,3.022439,2.610290,2.618571,3.218000,3.417634, 10.327317,7.344270,6.886154,4.015800,3.063103,6.832292,4.600238,2.939000,5.999027,7.894878, 4.411538,2.384762,6.816154,2.782500,2.475333,2.799138,2.739063,2.619917,2.892545,2.468167, 2.577079,2.821875,2.502500,2.969032,2.046023,3.073077,4.408000,3.411774,3.50,4.283607, 4.284000,4.276714,3.228103,2.639875,3.453194,2.821200,3.838723,1.714253,2.273750,2.611882, 2.321781,2.567500,2.557045,1.288875,2.175211,1.736000,2.250781,7.433366,7.033553,5.47, 7.132727,8.505937,9.174545,6.554487,7.060286,6.617160,8.210986,4.404045,6.062381,5.149625, 2.972105,5.358889,3.910968,3.715873,1.728966,2.843667,4.413906,3.016346,7.168636,3.839394, 3.930141,7.019882,3.459429,5.050250,3.492714,3.226667,3.987667,2.770227,3.661167,1.553000, 2.867391,2.897193,2.611707,2.577167,2.904697,2.733077,2.507241,11.044865,6.425484,8.567222, 8.552344,7.493396,4.807381,9.697869,9.471333,6.783175,4.563571,8.059649,9.448679,5.803778, 4.769423,4.424634,7.586042,4.451556,3.622373,6.390152,4.424375,4.135806,5.025400,5.410635, 7.012292,2.961071,3.192188,2.989643,3.471429,2.867966,1.980541,3.172344,2.574783,2.958983, 1.708140,3.604853,3.479000,2.845000,2.742603,2.923968,3.620308,2.452500,2.721375,3.166333, 2.742162,2.793000,3.337000,5.192025,5.365875,3.079000,8.415970,6.612277,6.734706,4.856857, 5.164783,7.743667,6.894151,4.666538,9.227167,8.077581,6.109833,6.621724,18.098182,12.705600, 15.490784,17.394750,12.422364,14.832727,8.326000,11.352400,3.431429,2.658261,3.219773,3.605185, 4.030299,3.262241,3.503250,3.522763,2.847312,2.996618,3.075769,3.387731,3.066923,3.078200, 2.466957,3.214167,2.707778,3.384839,2.283556,2.912258,3.378000,2.726750,2.95,2.195000, 4.819063,3.604578,3.694906,5.068000,4.676582,3.028831,4.261042,3.593235,4.501224,2.880317, 5.750333,3.257833,3.967458,2.522292,2.725738,2.549231,2.591389,2.990488,2.681222,2.685854, 2.284750,2.585938,2.432824,3.108875,2.611340,3.916667,2.418095,2.476406,2.801235,3.278000, 2.434921,2.617826,3.133939,2.774321,4.196173,3.764286,3.555833,5.317361,3.970800,4.136400, 4.487013,3.746393,4.754000,3.854316,3.742353,3.044079,2.817821,3.995179,3.643134,3.642593, 3.604533,2.935902,4.088310,5.344407,3.076883,3.287105,3.720870,2.032258,2.872593,5.787313, 6.017838,5.425205,4.880600,3.582295,4.90,3.489016,4.603030,5.344407,6.184286,4.047083, 4.788304,4.661325,4.815938,4.056790,3.765595,5.348772,5.200222,4.906311,3.900147,3.782897, 3.767313,3.417732,3.725455,2.888750,2.552333,2.521613,2.531522,2.510833,2.710208,2.445273, 2.619750,2.094737,2.399355,2.758000,2.317077,2.247755,3.594333,4.607805,2.69,3.084706
Re: [R] Discriminant Correspondence Analysis
On 15/12/2010 9:36 a.m., Wayne Sawtell wrote: Hello everyone, I am totally new to the R program. I have had a look at some pdf documents that I downloaded and that explain how to do many things in R; however, I still cannot figure out how to do what I want to do, which is to perform Discriminant Correspondence Analysis on a rectangular matrix of data that I have in an Excel file. I know R users frown upon Excel and recommend converting Excel files to .csv format, which I have done, no problem. That is not an issue. Actually one of the things we don't like about Excel is how it writes .csv files, so many R users find it much more reliable to read data directly from Excel files. In my case, the two major tools I use on Windows with great satisfaction are xlsReadWrite and RODBC. There are other suitable options if you are working on linux. For more comprehensive information see: http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows David Scott There are several parts to my problem. 1) When I try the read.table command, even if I include the directory name in the filename, R still cannot read the file, even if it is in .csv format 2) I was able to copy my file and then read the clipboard contents into R but then I do not know to assign a name to the data frame in order to conduct any operations on it 3) I need the ADE4 program in order to perform Discriminant Correspondence Analysis, so I used the install.packages command to install it. It installed no problem but I do not know how to access the ADE4 program in R. I am unable to open it directly, either. 4) I thought that using the ADE4 GUI (called ade4TkGUI) would be easier because I do not know many of the R commands; but, again, I downloaded it but cannot open or access it. The following is the suggested coding that I found through the R website, but when I try to use this code, I don't know how to assign a name for the df, or what to put for fac, and what is worse, I get an error message saying that the program cannot find the discrimin.coa command. Usage discrimin.coa(df, fac, scannf = TRUE, nf = 2) Arguments df a data frame containing positive or null values fac a factor defining the classes of discriminant analysis scannf a logical value indicating whether the eigenvalues bar plot should be displayed nf if scannf FALSE, an integer indicating the number of kept axes Examples data(perthi02) plot(discrimin.coa(perthi02$tab, perthi02$cla, scan = FALSE)) For clarification, my data consists of measurements of morphological characters of an assemblage of biological specimens. I have already performed Principal Co-ordinates Analysis, Principal Compionents Analysis and Cluster Analysis in another program (PAST) in order to see if the data fall into distinct groupings that might represent different morphological species. I now want to test the groupings that I found on my test data set using Discriminant Correspondence Analysis.There are both continuous and categorical characters, which is the reason why I need to perform Discriminant Correspondence Analysis, instead of Linear Discriminant Analysis, which is only valid for continuous measurements. R seems to be the only program in which I can perform Discriminant Correspondence Analysis. Thanks for any help offered on any of these points. Wayne [[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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] The behaviour of read.csv().
On 03/12/10 14:33, Duncan Murdoch wrote: On 02/12/2010 8:04 PM, Peter Ehlers wrote: On 2010-12-02 16:26, Rolf Turner wrote: On 3/12/2010, at 1:08 PM, Phil Spector wrote: Rolf - I'd suggest using junk- read.csv(junk.csv,header=TRUE,fill=FALSE) if you don't want the behaviour you're seeing. The point is not that I don't want this kind of behaviour. The point is that it seems to me to be unexpected and dangerous. I can indeed take precautions against it, now that I know about it, by specifying fill=FALSE. Given that I remember to do so. Now that you've pointed it out I can see that this is the reason for the different behaviour between read.table() and read.csv(); in read.table() fill=FALSE is effectively the default. Having fill=TRUE being the default in read.csv() strikes me as being counter-intuitive and dangerous. Rolf, This is not to argue with your point re counter-intuitive, but I always run a count.fields() first if I haven't seen (or can't easily see) the file in my editor. I must have learned that the hard way a long time ago. I think the fill=TRUE option arrived about 10 years ago, in R 1.2.0. The comment in the NEWS file suggests it was in response to some strange csv file coming out of Excel. The real problem with the CSV format is that there really isn't a well defined standard for it. The first RFC about it was published in 2005, and it doesn't claim to be authoritative. Excel is kind of a standard, but it does some very weird things. (For example: enter the string 01 into a field. To keep the leading 0, you need to type it as '01. Save the file, read it back: goodbye 0. At least that's what a website I was just on says about Excel, and what OpenOffice does.) I've been burned so many times by storing data in .csv files, that I just avoid them whenever I can. Absolutely agree with this Duncan. Playing around with .csv files is like playing with some sort of unstable explosive. I also avoid them as much as possible. David Scott 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. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] looking for the RMySQL package for R 2.12.0 under XP
On 25/11/2010 4:55 a.m., Henrique Dallazuanna wrote: You need compile it from source code. An alternative is to use RODBC. There are instructions on my page here: http://www.stat.auckland.ac.nz/~dscott/779/index.php Look in the MySQL section (obviously). You may need to pester your admin guy to add the MySQL/ODBC connector. The instructions may not be quite up to date but hopefully you can find your way through. Our students generally manage to set it all up on their own computers. David Scott On Wed, Nov 24, 2010 at 1:48 PM, PtitBleuptit_b...@yahoo.fr wrote: Hello, I convinced our new Ph student to work with R and I managed to convince the guy in charge of the computer networks to install R 2.12.0 (we haven't the admin rights). I wanted to install on his computer the same packages I use (but I have R 2.11) and especially RMySQL. Problem : there is no more RMySQL package in the list pf the packages. I've tried to install my version but it is not compatible. I saw on a website a possible solution using rtools but it was very unclear to me (I'm only an end-user and French ...) and with no admin rights, I think I won't be able to follow the proposed procedure. Do you know where I can find a zip file of the RMySQL package for R 2.12 ? Thanks in advance, Ptit Bleu. PS : everybody around me is using matlab. If I say that I have a problem to connect R to MySQL, I will have to move to matlab. So please, help !!! :-) -- View this message in context: http://r.789695.n4.nabble.com/looking-for-the-RMySQL-package-for-R-2-12-0-under-XP-tp3057537p3057537.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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] cpgram: access data, confidence bands
On 22/11/10 22:54, Henri Mone wrote: Dear R experts, beginners and everyone else, I'm calculating cumulative periodogram using the command cpgram [1] from the MASS library. Here is a short example with the lh (hormone level) dataset: library(MASS) plot(lh,type=l,ylab=value,xlab=time, main=Hormone Levels (lh)) spectrum(lh, main=Hormone Levels (lh)) # periodigram cpgram(lh, main=Hormone Levels (lh)) # cumul. periodigram I got following two questions: 1. The command cpgram plots the cumulative periodogram without any problem. But I could not figure out any way to access the data of the plot (save it in a variable). the following command fails (contains no data): myObject-cpgram(lh, main=Hormone Levels (lh)) summary(myObject) Length Class Mode 0 NULL NULL Is there an easy way to access the data of the cumulative periodogram, or do I need to rewrite the cpgram function? You need to rewrite cpgram. Have a look at the last line of the function, it is invisible() meaning it doesn't return anything. It is easy to change it, replace the last line by for example return(list(pgram = y, cum = cumsum(y)/sum(y))) or whatever you actually want to return. 2. The cpgram function plots with the default options the 95% confidence bands in the plot. The confidence band are defined such that in 95% of the cases the true value will lie inside the bands. For most cases which I tested the cumulative periodogram is outside the confidence band. Does cpgram plot the confidence band of the the cumulative periodogram or for the periodogram (I think it is the cumulative periodigram, is this correct?). How should the confidence band in cpgram be interpreted? Some more description on this would be great. It is the cumulative periodogram (as the name suggests). What did you test? Only a white noise process should stay inside the confidence bands. There is some information about the use of the cumulative periodogram in Venables and Ripley's book for which cpgram was written (but admittedly not a lot). David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to start default browser on R
On 23/11/10 14:20, Stephen Liu wrote: Hi folks, Win7 64 bit IE 64 bit How to start IE on R? TIA B.R. Stephen L ?browseURL -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to start default browser on R
On 23/11/10 16:59, Stephen Liu wrote: Hi Ista, I see. Your advice works. Thanks even without: browser=C:/Program Files/Internet Explorer/iexplore.exe) For non default browser it needs; browser=C:/Program Files/Mozilla Firefoe/firefox.exe What will be file: used for? B.R. Stephen L You can use it to open a local file on your machine as well. I use this all the time with hwriter which writes html reports. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] power spectrum of eeg
On 21/11/10 21:18, Az Ha wrote: Hi, I need to find the power spectrum of an eeg and display frequency in hz. I found two functions, spectrum or auspec but they give me frequency from 0.0 - 0.5. How do i get frequency in Hz or KHz? Also, is it possible to plot two overlapping spectra in order to compare their peaks etc? Thanks for any help. Well you you have the spectrum already, you just need to change the scale on the x-axis. The change that needs to be made is not really an R question, though how to do it is an R question. The scale used by R is cycles per unit time, where the time unit is the sampling interval of your time series. Thus the value at 0.25 say is the spectral density at 0.25 cycles per time interval, or for a period of 4 time units. To convert to Hertz, you need to know the size of your time unit in seconds. If your time unit (sampling interval) is say 1/1000 seconds (0.001 of a second), then 0.25 cycles per time interval corresponds to 1000*0.25 cycles per second, or 250 Hertz. Since kHz denotes the number of thousands of cycles per second, 250 Hz is 205/1000=0.25 Khz. Here is an example: par(mfrow = c(1,2)) w0 - 0.2 n - 100 x - cos(2*pi*w0*(0:(n-1))) specx - spec.pgram(x, plot = FALSE) spec.pgram(x) spec.pgram(x, xaxt = n, xlab = frequency (Hz), sub = paste(bandwidth = , round(1000*specx$bandwidth,2))) axis(side = 1, at = (0:5)/10, labels = 1000*(0:5)/10) David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] previous business day
On 23/10/2010 4:59 a.m., David Reiner wrote: Look at the documentation for timeDate and try ?timeNdayOnOrBefore after loading the package. -- David If you are dealing with such problems I suggest you obtain A Discussion of Time Series Objects for R in Finance available from Rmetrics for free. timeDate is an Rmetrics package. Go to https://www.rmetrics.org/ebooks to see what is available from Rmetrics. David Scott -Original Message- From: Li, Jing Yi [mailto:jingyi...@credit-suisse.com] Sent: Friday, October 22, 2010 9:38 AM To: David Reiner; David Winsemius Cc: r-help@r-project.org Subject: RE: [R] previous business day yes. do you know the name of related functions in the timeDate package? Thanks! -Original Message- From: David Reiner [mailto:david.rei...@xrtrading.com] Sent: Friday, October 22, 2010 10:10 AM To: Li, Jing Yi; David Winsemius Cc: r-help@r-project.org Subject: RE: [R] previous business day you may be thinking of the timeDate package, which has some holiday calendars. HTH, David L. Reiner, PhD Head Quant XR Trading LLC -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Li, Jing Yi Sent: Thursday, October 21, 2010 3:51 PM To: David Winsemius Cc: r-help@r-project.org Subject: Re: [R] previous business day Thanks a lot for all your reply! It really helps! Somehow I remember there is some package which can provide financial exchange calendars, like NYSE holidays, not sure where to find it. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Thursday, October 21, 2010 4:34 PM To: Li, Jing Yi Cc: Clint Bowman; Henrique Dallazuanna; r-help@r-project.org Subject: Re: [R] previous business day On Oct 21, 2010, at 4:20 PM, Li, Jing Yi wrote: Yeah, thanks Henrique for the code. It works! But I also have the questions for the holidays. require(tis) previousBusinessDay(Sys.Date()-1:3) [1] 20101019 20101018 20101015 class: ti It runs on US business days. You might be able to hack the holidays function if you were trying to transpose to another locale. -- David. Please follow the attached hyperlink to an important disclosure: http://www.credit-suisse.com/legal/marketcommentary -Original Message- From: Clint Bowman [mailto:cl...@ecy.wa.gov] Sent: Thursday, October 21, 2010 4:16 PM To: Henrique Dallazuanna Cc: Li, Jing Yi; r-help@r-project.org Subject: Re: [R] previous business day May also wish to or in a check for holidays. -- Clint Bowman INTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX:(360) 407-7534 Olympia, WA 98504-7600 On Thu, 21 Oct 2010, Henrique Dallazuanna wrote: Try this: f- function(d)if(format(d - 1, '%w') %in% c(0, 6)) Recall(d - 1) else d - 1 d- Sys.Date() f(d) On Thu, Oct 21, 2010 at 5:38 PM, Li, Jing Yi jingyi...@credit-suisse.comwrote: How to get the previous business day in R? I saw some post about using functions in timeSeries package before but can not find it anymore. Thanks! = == Please access the attached hyperlink for an important el...{{dropped:8}} __ 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. = = = = = = = = = == Please access the attached hyperlink for an important el...{{dropped: 4}} __ 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 West Hartford, CT === Please access the attached hyperlink for an important el...{{dropped:4}} __ 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. This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, XR Content) are confidential and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are protected by intellectual property laws. Without the prior written consent of XR, the XR Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of XR
Re: [R] efficient equivalent to read.csv / write.csv
On 29/09/2010 6:24 a.m., statquant2 wrote: Hi, after testing R) system.time(read.csv(myfile.csv)) user system elapsed 1.126 0.038 1.177 R) system.time(read.csv.sql(myfile.csv)) user system elapsed 1.405 0.025 1.439 Warning messages: 1: closing unused connection 4 () 2: closing unused connection 3 () It seems that the function is less efficient that the base one ... so ... I presume you have had a good look at the R Data Import/Export manual? It does there warn of inefficiency with read.table (hence also read.csv) and suggest more direct use of scan which in your case might be via connections and readLines and writeLines. If that doesn't work, why not go to a database. Use RODBC or some such to read and write tables in the database. There are many options for databases to use (MySQL works for me). You can easily read data in and out of the database in .csv format. If the .csv files are similar there shouldn't be too much overhead in defining table formats for the database. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Need help for EM algorithm ASAP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The urgency and the vague description of your problem strongly suggest that this is homework. This list is not for homework---see the posting guide at the bottom of every message. Nonetheless since I know this problem reasonably well I will offer some comments. QRMlib is a package created to accompany a book. If you read that book you would see that it fits the generalized hyperbolic to data using the EM algorithm. If you have QRMlib you have an implementation of the EM algorithm. Also why write code to simulate from the generalized hyperbolic (y in your simulation function below) when you have QRMlib and ghyp, both of which have functions for simulating from the generalized hyperbolic? Your code is pretty difficult to follow, with random indenting and zero comments. The structure of the iteration is totally confused as well. Not too many marks if you handed something like this in to me to grade. David Scott On 21/09/2010 5:32 p.m., snes1...@hotmail.com wrote: I created a EM algorithm for Generalized hyperbolic distribution. I want to estimate mutheldaplus, sigmatheldaplus, betasigmaplus in my code. After getting use these value , then my iteration have to be begin of this code. But I can not to do iteration part. Can you help me use my code and get iteration ? Do know any useful code for EM algorithm for Generalized Hyperbolic library(QRMlib) library(ghyp) simulation part simulation-function(n,lambda,mu,thelda,gamma,sigma,beta){ set.seed(235) chi-thelda^2 psi-gamma^2 W- rGIG(n, lambda, chi, psi); Z- rnorm(n,0,1); y-mu + beta * W + sqrt(W) * Z *gamma; for (i in 1:n){ theldastar-rep(0,n) zi-rep(0,n) ti-rep(0,n) muthelda-mu gammathelda-thelda*gamma sigmathelda-(thelda^2)*sigma betathelda-(thelda^2)*sigma*beta lambdastar-lambda-0.5 theldastar[i]-sqrt(1+((y[i]-muthelda)/sigmathelda)^2) gammastar-sqrt((gammathelda^2)+((betathelda/sigmathelda)^2)) klambda1-besselM3(lambdastar+1, x=2, logvalue=FALSE) klambda-besselM3(lambdastar,x=2,logvalue=FALSE) klambda2-besselM3(lambdastar-1,x=2,logvalue=FALSE) zi[i]-((theldastar[i]*klambda1*(theldastar[i]*gammastar))/(gammastar*klambda*theldastar[i]*gammastar)) ti[i]-((gammastar*klambda2*(theldastar[i]*gammastar))/(theldastar[i]*klambda*theldastar[i]*gammastar)) zimean-sum(zi)/n timean-sum(ti)/n mutheldaplus-(zimean*(1/n)* sum((ti[i]*y[i])-mean(y)))/((zimean*timean)-1) betatheldaplus- sum(y[i]- mutheldaplus)/(n*zimean) sigmatheldaplus-((1/n)*sum((ti[i]*((y[i]-mutheldaplus)^2))-(2*betatheldaplus*(y[i]-mutheldaplus))-((betatheldaplus^2)*zi[i]))) print(muthelda) print(mutheldaplus) print(betathelda) print(betatheldaplus) print(sigmathelda) print(sigmatheldaplus) return(ti) } } a-simulation(2,-0.5,0,1,1,1,0) [[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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Reproducible research
I am investigating some approaches to reproducible research. I need in the end to produce .html or .doc or .docx. I have used hwriter in the past but have had some problems with verbatim output from R. Tables are also not particularly convenient. I am interested in R2HTML and R2wd in particular, and possibly odfWeave. Does anyone have sample documents using any of these approaches which they could let me have? David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] weird to me interaction between time() and %%, %/%
Steve is undoubtedly right about this being a floating point problem. One comment I would make is that I think floor is a bit nicer for this, both conceptually and for readability. Also you don't need a really small value to add, half the sampling interval will work: junk - ts(1:125, start=c(1999,2), frequency=12) floor(time(junk)) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2005 2004 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2006 2005 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2007 2006 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2008 2007 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2009 2008 2009 2009 2009 2009 2009 floor(time(junk) + 1/24) Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2009 2009 2009 2009 2009 2009 2009 David Scott On 1/09/2010 11:04 a.m., Alistair Gray wrote: Dear List, I'm getting weird and unexpected behaviour using time and %%, or %/%. It's likely I'm not appreciating the nuances of floating point arithmetic. Or it could be a bug. I'm running R.version _ platform x86_64-redhat-linux-gnu kernel 2.6.33.8-149.fc13.x86_64 arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 11.1 year 2010 month 05 day31 svn rev52157 language R version.string R version 2.11.1 (2010-05-31) I was trying to extract the year from a ts object using time and %/%. It has always seemed to work previously but today I got this peculiar result. junk- ts(1:125, start=c(1999,2), frequency=12) time(junk) Jan Feb Mar Apr May Jun Jul Aug 1999 1999.083 1999.167 1999.250 1999.333 1999.417 1999.500 1999.583 2000 2000.000 2000.083 2000.167 2000.250 2000.333 2000.417 2000.500 2000.583 2001 2001.000 2001.083 2001.167 2001.250 2001.333 2001.417 2001.500 2001.583 2002 2002.000 2002.083 2002.167 2002.250 2002.333 2002.417 2002.500 2002.583 2003 2003.000 2003.083 2003.167 2003.250 2003.333 2003.417 2003.500 2003.583 2004 2004.000 2004.083 2004.167 2004.250 2004.333 2004.417 2004.500 2004.583 2005 2005.000 2005.083 2005.167 2005.250 2005.333 2005.417 2005.500 2005.583 2006 2006.000 2006.083 2006.167 2006.250 2006.333 2006.417 2006.500 2006.583 2007 2007.000 2007.083 2007.167 2007.250 2007.333 2007.417 2007.500 2007.583 2008 2008.000 2008.083 2008.167 2008.250 2008.333 2008.417 2008.500 2008.583 2009 2009.000 2009.083 2009.167 2009.250 2009.333 2009.417 Sep Oct Nov Dec 1999 1999.667 1999.750 1999.833 1999.917 2000 2000.667 2000.750 2000.833 2000.917 2001 2001.667 2001.750 2001.833 2001.917 2002 2002.667 2002.750 2002.833 2002.917 2003 2003.667 2003.750 2003.833 2003.917 2004 2004.667 2004.750 2004.833 2004.917 2005 2005.667 2005.750 2005.833 2005.917 2006 2006.667 2006.750 2006.833 2006.917 2007 2007.667 2007.750 2007.833 2007.917 2008 2008.667 2008.750 2008.833 2008.917 2009 This looks fine but time(junk)%/%1L Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 1999 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2001 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2004 2005 2004 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 2006 2005 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2006 2007 2006 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 2008 2007 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2008 2009 2008 2009 2009 2009 2009 2009 Note the incorrect year for January after 2004. Also time(junk)%%1L JanFebMarApr
Re: [R] log y 'axis' of histogram
On 30/08/2010 1:58 p.m., Derek M Jones wrote: All, I have been trying to get calls to hist(...) to be plotted with the y-axis having a log scale. I have tried: par(ylog=TRUE) I have also looked at the histogram package. Suggestions welcome. You appear to be looking for a log-histogram function. There is one (logHist) in my package DistributionUtils on CRAN. You don't need the rest of the package to use it. You could just extract that particular function. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] log y 'axis' of histogram
On 31/08/10 03:37, Derek M Jones wrote: Hadley, I have counts ranging over 4-6 orders of magnitude with peaks occurring at various 'magic' values. Using a log scale for the y-axis enables the smaller peaks, which would otherwise be almost invisible bumps along the x-axis, to be seen That doesn't justify the use of a _histogram_ - and regardless of The usage highlights meaningful characteristics of the data. What better justification for any method of analysis and display is there? what distributional display you use, logging the counts imposes some pretty heavy restrictions on the shape of the distribution (e.g. that it must not drop to zero). Does there have to be a recognized statistical distribution to use R? In my case I am using R for all of the analysis and graphics in a new book. This means that sometimes I have to deal with data sets that are more or less a jumble of numbers with patterns in a few places. For instance, the numeric value of integer constants appearing as one operand of the binary bitwise-AND operator (see figure 1224.1 of www.knosof.co.uk/cbook/usefigtab.pdf, raw data at: www.knosof.co.uk/cbook/bandcons.hist.gz) qplot(band, binwidth=8, geom=histogram) + scale_y_log() does a good job of highlighting the peaks. It may be useful for your purposes, but that doesn't necessarily make it a meaningful graphic. Doesn't being useful for my purpose make it meaningful, at least for me and I hope my readers? Hadley is correct about the problem of where to end the bars when trying to draw a log-histogram: basically you have to decide to cut them off somewhere. He is also right that a log-histogram is perhaps not a great graphic to use. However, they are used and indeed there is one in the Fieller, Flenley, Olbricht paper (published in Applied Statistics, now JRSS C) for example. I haven't searched for others, but certainly when I wrote a log-histogram routine it wasn't because I thought of doing such a plot all on my own. A number of authors, including Barndorff-Nielsen in at least some of his papers (I haven't gone back and checked all his older work) just plot the midpoints of the tops of the log-histogram. (That is an option in logHist). Another approach is to fit an empirical density to the data and plot the log-density. That matches the advice often seen in this forum that plotting empirical density functions is preferable to drawing histograms. My feeling is that either of these two approaches is probably preferable to using log-histograms for the reasons Hadley enunciated. When plotting data plus a fitted curve, the midpoints approach does have the advantage of distinguishing data and theoretical curve more clearly. Overall the idea of a plot with a logged y-axis is definitely a good one and its use is endemic in literature concerned with heavy-tailed distributions, particularly finance. The advantage is the clarity offered regarding tail behaviour, where for example exponential tails in the density correspond to straight lines in the logged y-axis plot. Hope this helps. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Engle Granger Test in R
Aditya Damani wrote: Hi, Please tell me the R codes for Engle Granger Test of cointegration. TIA Aditya Enough already. That must be 5 or more posts which basically say 'write the code for me to do my work so I don't have to bother'. Firstly, read the posting guide (the url is at the bottom on every post), particularly the bit about homework, since your questions have that ring about them. Secondly, try some self study before launching into posting. In your case, I believe even a cursory scan of Kleiber/Zeileis: Applied Econometrics with R would answer a lot of your questions. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] RGoogleDocs ability to write to spreadsheets broken as of yesterday
Henrique Dallazuanna wrote: On Wed, Jul 21, 2010 at 11:24 AM, Ben Bolker bbol...@gmail.com wrote: Harlan Harris harlan at harris.name writes: Hi, I'm using RGoogleDocs/RCurl to update a Google Spreadsheet. Everything worked OK until this morning, when my ability to write into spreadsheet cells went away. I get the following weird error: Error in els[[type + 1]] : subscript out of bounds Looking at the Google Docs API changelog, I see the following: http://code.google.com/apis/spreadsheets/changelog.html Release 2010-01 (July 14, 2010) This is an advanced notice about an upcoming change. - Starting July 19, 2010, all links returned by all Spreadsheets API feeds will use HTTPS. This is being done in the interests of increased security. If you require the use of HTTP, we recommend that you remove the replace https with http in these links. Another announcement will be made on July 19, 2010, when this change goes to production. I suspect this is the problem. Fixing it is above my head, I'm afraid. Could anyone help? This is urgent. Thank you, This is an Omegahat package (took me a little while to find it). Perhaps you should write to the package maintainer? library(RGoogleDocs) help(package=RGoogleDocs) or, more obscurely: help(package=RGoogleDocs)$info[[1]][9] (there may be a better way to deal with objects of type packageInfo but I can't figure it out right at the moment). Maybe: packageDescription('RGoogleDocs', fields = 'Author') From the News file for 2.11.0: o maintainer() has been added, to give convenient access to the name of the maintainer of a package It looks as though one might be able to fix this by hacking the hard-coded URLs in the code, but as you suggest that might be above your head. good luck ... Ben Bolker __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Use of .Fortran
I have no experience with incorporating Fortran code and am probably doing something pretty stupid. I want to use the following Fortran subroutine (not written by me) in the file SSFcoef.f subroutine SSFcoef(nmax,nu,A,nrowA,ncolA) implicit double precision(a-h,o-z) implicit integer (i-n) integer l,i,nmax double precision nu,A(0:nmax,0:nmax) A(0,0) = 1D0 do l=1,nmax do i=1,l-1 A(l,i) = (-nu+i+l-1D0)*A(l-1,i)+A(l-1,i-1) end do A(l,0) = (-nu+l-1D0)*A(l-1,0) A(l,l) = 1D0 end do return end I created a dll (this is windows) using R CMD SHLIB SSFcoef.f Then my R code is: ### Load the compiled shared library in. dyn.load(SSFcoef.dll) ### Write a function that calls the Fortran subroutine SSFcoef - function(nmax, nu){ .Fortran(SSFcoef, as.integer(nmax), as.integer(nu) )$A } SSFcoef(10,2) which when run gives SSFcoef(10,2) NULL I am pretty sure the problem is that I am not dealing with the matrix A properly. I also tried this on linux and got a segfault. Can anyone supply the appropriate modification to my call (and possibly to the subroutine) to make this work? David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 library(SSPA)
Samuel Okoye wrote: I can't find his email and I have asked the same question to bioconduc...@stat.math.ethz.ch Regards, Samuel So you need the handy function maintainer() added to 2.11.0: require(GeneralizedHyperbolic) maintainer(GeneralizedHyperbolic) [1] David Scott d.sc...@auckland.ac.nz David Scott --- On Wed, 9/6/10, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: From: Uwe Ligges lig...@statistik.tu-dortmund.de Subject: Re: [R] Problem with library(SSPA) To: Samuel Okoye samu...@yahoo.com Cc: r-help@r-project.org Date: Wednesday, 9 June, 2010, 5:43 Same for me, but since this is a BioC package, why do you ask here? First you may report to the package maintainer or if that fails to the BioC mailing list. Best, Uwe Ligges On 09.06.2010 12:01, Samuel Okoye wrote: Hello, I have the fellowing problem and I am thankful for any advice! Regards, Samuel source(http://bioconductor.org/biocLite.R;) BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). biocLite(SSPA) Using R version 2.11.0, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] SSPA Please wait... trying URL 'http://www.bioconductor.org/packages/2.6/bioc/bin/windows/contrib/2.11/SSPA_1.4.0.zip' Content type 'application/zip' length 305310 bytes (298 Kb) opened URL downloaded 298 Kb package 'SSPA' successfully unpacked and MD5 sums checked library(SSPA) Loading required package: qvalue Loading required package: tcltk Loading Tcl/Tk interface ... done Error : .onAttach failed in attachNamespace() for 'SSPA', details: call: fun(...) error: could not find function addVigs2WinMenu Error: package/namespace load failed for 'SSPA' sessionInfo() R version 2.11.0 (2010-04-22) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=CLC_TIME=English_United Kingdom.1252 attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base other attached packages: [1] qvalue_1.22.0 loaded via a namespace (and not attached): [1] limma_3.4.3 SSPA_1.4.0 tools_2.11.0 ## [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] ARIMA order
nuncio m wrote: Hi all, Is there any way in R to select the order of an ARIMA model automatically nuncio Rob Hyndman's package forecast has a function auto.arima which produces an automatic arima fit, including for seasonal models. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Installed directory of a package
Ron Burns wrote: Hi all- Is there an R function that returns the directory in which a package has been installed? Thanks Ron ?system.file For example: system.file(package=DistributionUtils) [1] C:/Users/dsco036/R/win-library/2.10/DistributionUtils David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] zipped files as a data type
Ron Burns wrote: Hi all- I have a lot of small (xml) data files that are saved by classification in directories named in accordance with the classification. I would like to zip up these directories and include the zipped file as part of the data in a package (which I know how to do.) Are there R functions for dealing with zipped files as a data type? Thanks for any suggestions. Ron help.search(zip) gives base::connections Functions to Manipulate Connections base::environment variables Environment Variables base::memCompress In-memory Compression and Decompression utils::unzipExtract or List Zip Archives utils::zip.file.extract Extract File from a Zip Archive utils::win.version Auxiliary Functions for the Windows Port which seems to provide some leads David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] summary of arima model in R
Joris Meys wrote: Check http://cran.r-project.org/doc/contrib/Ricci-refcard-ts.pdf for some ideas on testing time series in R. I'd go with the acf() and pacf() on the residuals of the arima model. If arima works, both plots will indicate absence of autocorrelation. also check ?tsdiag And if you're really going to use those more often, I really can recommend this book : http://www.amazon.com/Time-Analysis-Its-Applications-Statistics/dp/0387293175 Cheers Joris On Tue, May 25, 2010 at 9:34 AM, Fred jianyun.fred...@gmail.com wrote: Hi, I want to give a summary or anova for arima model in R, as summary, and anova for lm. As including various intervention factors in arima(xreg = ) part, I want to assess the significancy of thse factors. I can do it using interrupted analysis of time series by linear regression, but want to see whether arima model works for the data first. summary, anova do not work for arima, any alternatives ??? Thank you very much. Fred If you want a summary method for arima models then I suggest you use Rob Hyndman's package 'forecast'. This has a method summary.Arima. Note that the function arima returns an object of class Arima (not arima). Curiously, there seems to be no help on summary.arima: require(forecast) Loading required package: forecast Loading required package: fracdiff This is forecast 2.05 methods(summary) [1] summary.aovsummary.aovlistsummary.Arima* [4] summary.arma* summary.aspell*summary.connection [7] summary.data.frame summary.Date summary.default [10] summary.ecdf* summary.ets* summary.factor [13] summary.forecast* summary.fracdiff* summary.garch* [16] summary.glmsummary.infl summary.lm [19] summary.loess* summary.manova summary.matrix [22] summary.mlmsummary.nls* summary.packageStatus* [25] summary.POSIXctsummary.POSIXltsummary.ppr* [28] summary.prcomp*summary.princomp* summary.shingle* [31] summary.stepfunsummary.stl* summary.table [34] summary.trellis* summary.tukeysmooth* summary.yearmon* [37] summary.yearqtr* summary.zoo* Non-visible functions are asterisked ?summary.Arima No documentation for 'summary.Arima' in specified packages and libraries: you could try '??summary.Arima' David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Path to R script
Sharpie wrote: Johannes W. Dietrich wrote: There is certainly a trivial solution for my question, but I can't find the answer in the documentation. I need a platform independent method to obtain the file path of the current R script. My working group uses R on several machines with different operating systems including Mac OS X, Windows and Linux, and for obvious reasons the file hierarchies are very different. Therefore, it would be useful to be able to address data files and external procedures relative to the path of the script. Thank you for any suggestion, J. W. D. -- The best recipie I have for dealing with this situation is: 1. Place R scripts in a package (a very good idea anyway if you are distributing code to others). 2. Place a configuration file in the package that contains info such as paths to data directories. 3. Customize the configuration file after installing the package (if necessary). Then your script accesses the configuration file, which is in a known fixed location, and uses the information inside to find other files that may be in unknown and changing locations. You could also place the configuration file in a location such as: ~/.MyPackageConf Since: path.expand( '~/' ) Has a pretty predictable behavior across platforms. This would save it from being overwritten every time you updated the package. Hope this helps! -Charlie I also was about to suggest putting the code in a package because then you have system.file available, which I presume works across platforms: system.file(RunTests.R,package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils system.file(unitTests/runTests.R,package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils/unitTests/runTests.R David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Path to R script
David Scott wrote: Sharpie wrote: Johannes W. Dietrich wrote: There is certainly a trivial solution for my question, but I can't find the answer in the documentation. I need a platform independent method to obtain the file path of the current R script. My working group uses R on several machines with different operating systems including Mac OS X, Windows and Linux, and for obvious reasons the file hierarchies are very different. Therefore, it would be useful to be able to address data files and external procedures relative to the path of the script. Thank you for any suggestion, J. W. D. -- The best recipie I have for dealing with this situation is: 1. Place R scripts in a package (a very good idea anyway if you are distributing code to others). 2. Place a configuration file in the package that contains info such as paths to data directories. 3. Customize the configuration file after installing the package (if necessary). Then your script accesses the configuration file, which is in a known fixed location, and uses the information inside to find other files that may be in unknown and changing locations. You could also place the configuration file in a location such as: ~/.MyPackageConf Since: path.expand( '~/' ) Has a pretty predictable behavior across platforms. This would save it from being overwritten every time you updated the package. Hope this helps! -Charlie I also was about to suggest putting the code in a package because then you have system.file available, which I presume works across platforms: system.file(RunTests.R,package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils system.file(unitTests/runTests.R,package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils/unitTests/runTests.R Sorry, I copied that incorrectly. Should be: system.file(package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils system.file(unitTests/runTests.R,package=DistributionUtils) [1] /usr/local/david/R/DistributionUtils/unitTests/runTests.R David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Problems plotting date and time column from excel using R
David Winsemius wrote: On May 11, 2010, at 9:00 AM, Terry Bassett wrote: I am using R to read from an excel(csv) file. Within the excel file is a column with the date set that looks likes this: 53:40.2 and in the Insert function box it looks likes this: 9/21/2006 4:53:40 PM This is really an Excel question, rather than an R one. You need to format the data in Excel so that it gets output to the CSV properly. I tired separating the time and date using the function below and then plotting again which fail to read properly =TEXT(B2,hh:mm:ss) and =TEXT(B9,mm/dd/) As I said, it's an Excel question. The R script am using is plot.time_vs_id- function(start,end){ setwd(C:/Documents and Settings/terry/Desktop/r_stuff) x=read.table(MAV.csv,header=T, sep=,) plot(x$time[start:end],x$packet_id[start:end],ylab=Packet ID, xlab=Time, type=p) } and plot.hov_Points - function(start,end){ setwd(C:/Documents and Settings/terry/Desktop/r_stuff) library(rgl) t=read.table(MAV.csv,header=T, sep=,) plot3d(t$time[start:end],t$packet_length[start:end],t $date[start:end], main=potential, xlab=time, ylab=length,zlab=date, type=p) } How can i get R to properly display the time in my graphs Thanks Terry Bassett David Winsemius, MD West Hartford, CT Excel has a mind of its own in many things, particularly dates. You need to look at exactly what is coming in to R as x. Do str(x) and let us know what it is then you might get some useful advice. As a general rule these days, when using Windows, I prefer to avoid the .xls or .xlsx to .csv route to getting data into R from Excel and use either RODBC or xlsReadWrite. Getting Excel to write a .csv file is just adding some random noise to the process. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] What is the best way to have R output tables in an MS Word format?
Greg Snow wrote: When I work with clients who want to cut and paste to word or powerpoint I usually use the odfWeave package, set up a template file with the tables and graphs (possibly other output), then I run that through odfWeave and then use openoffice to save the results as a word file that I can send to the client (and they happily copy and paste from it). There is also development on Sword (still in beta) from the people who brought us Rexcel. It works similarly, but directly with word, I will probably start using it more in the future. Hope this helps, Another option if you don't want to go the whole route of learning odfWeave is hwriter. Not sure how it works for a lot of text, but if you just want graphs and tables, it is very straightforward. I just used it recently and found it pretty simple. Another option for producing html is R2html but I didn't try it because I tried hwriter first and it worked for what I wanted. The advantages supplying in this form for those who just live in the Microsoft World are that you can output graphs in windows metafile format and they can see them in IE (not Firefox), and copy and paste into MS Office applications. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] What is the best way to have R output tables in an MS Word format?
Greg Snow wrote: When I work with clients who want to cut and paste to word or powerpoint I usually use the odfWeave package, set up a template file with the tables and graphs (possibly other output), then I run that through odfWeave and then use openoffice to save the results as a word file that I can send to the client (and they happily copy and paste from it). There is also development on Sword (still in beta) from the people who brought us Rexcel. It works similarly, but directly with word, I will probably start using it more in the future. Hope this helps, Another option if you don't want to go the whole route of learning odfWeave is hwriter. Not sure how it works for a lot of text, but if you just want graphs and tables, it is very straightforward. I just used it recently and found it pretty simple. Another option for producing html is R2html but I didn't try it because I tried hwriter first and it worked for what I wanted. The advantages supplying in this form for those who just live in the Microsoft World are that you can output graphs in windows metafile format and they can see them in IE (not Firefox), and copy and paste into MS Office applications. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 installing RODBC
I have a problem with some missing headers when trying to install RODBC on my linux box. install.packages(RODBC, + lib=/usr/local/david/R) trying URL 'http://cran.stat.auckland.ac.nz/src/contrib/RODBC_1.3-1.tar.gz' Content type 'application/x-gzip' length 990220 bytes (967 Kb) opened URL == downloaded 967 Kb Read .Rprofile * installing *source* package ‘RODBC’ ... checking for gcc... gcc -m32 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -m32 -std=gnu99 accepts -g... yes checking for gcc -m32 -std=gnu99 option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -m32 -std=gnu99 -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package ‘RODBC’ * removing ‘/usr/local/david/R/RODBC’ Details of my setup are: R.version _ platform i386-redhat-linux-gnu arch i386 os linux-gnu system i386, linux-gnu status major 2 minor 10.0 year 2009 month 10 day26 svn rev50208 language R version.string R version 2.10.0 (2009-10-26) I have the following mysql setup mysql status; -- mysql Ver 14.12 Distrib 5.0.88, for redhat-linux-gnu (i386) using readline 5.1 Connection id: 9 Current database: Current user: r...@localhost SSL:Not in use Current pager: stdout Using outfile: '' Using delimiter:; Server version: 5.0.88 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset:latin1 Db characterset:latin1 Client characterset:latin1 Conn. characterset:latin1 UNIX socket:/var/lib/mysql/mysql.sock Uptime: 95 days 19 hours 18 min 27 sec I am guessing my MySQL is getting a bit decrepit and needs updating, but welcome any suggestions about sorting this out. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 installing RODBC
Marc Schwartz wrote: On Apr 19, 2010, at 7:02 PM, David Scott wrote: I have a problem with some missing headers when trying to install RODBC on my linux box. install.packages(RODBC, + lib=/usr/local/david/R) trying URL 'http://cran.stat.auckland.ac.nz/src/contrib/RODBC_1.3-1.tar.gz' Content type 'application/x-gzip' length 990220 bytes (967 Kb) opened URL == downloaded 967 Kb Read .Rprofile * installing *source* package ‘RODBC’ ... checking for gcc... gcc -m32 -std=gnu99 checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc -m32 -std=gnu99 accepts -g... yes checking for gcc -m32 -std=gnu99 option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -m32 -std=gnu99 -E checking for egrep... grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package ‘RODBC’ * removing ‘/usr/local/david/R/RODBC’ Details of my setup are: R.version _ platform i386-redhat-linux-gnu arch i386 os linux-gnu system i386, linux-gnu status major 2 minor 10.0 year 2009 month 10 day26 svn rev50208 language R version.string R version 2.10.0 (2009-10-26) I have the following mysql setup mysql status; -- mysql Ver 14.12 Distrib 5.0.88, for redhat-linux-gnu (i386) using readline 5.1 Connection id: 9 Current database: Current user: r...@localhost SSL:Not in use Current pager: stdout Using outfile: '' Using delimiter:; Server version: 5.0.88 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset:latin1 Db characterset:latin1 Client characterset:latin1 Conn. characterset:latin1 UNIX socket:/var/lib/mysql/mysql.sock Uptime: 95 days 19 hours 18 min 27 sec I am guessing my MySQL is getting a bit decrepit and needs updating, but welcome any suggestions about sorting this out. David Scott The missing header files are contained in the unixODBC-devel RPM, which you will need to install and then you should be able to install RODBC. Recent RH/Fedora installations use 'yum' for package management, so something like: yum install unixODBC-devel as root, should get you what you need. Also, there is the R package RMySQL which provides an alternative interface to MySQL, if you should wish to investigate that approach. Finally, there is the R-SIG-DB list which provides a focused audience for R and DB related matters: https://stat.ethz.ch/mailman/listinfo/r-sig-db HTH, Marc Schwartz Thanks Marc, super helpful and quick as well. Worked a treat. David -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] interpreting acf plot
Giovanni Azua wrote: Hello Denis, (1) I appreciate your feedback, however, I feel I have all the right to ask a specific question related R namely what's the interpretation of the acf function plot. I gave away the information that it is a homework because many times people before helping ask what's the context for the question at hand. If I don't understand something I will for sure ask. I don't have anything to hide so I don't care if there are professors subscribed to this list. My ultimate goal is to learn and it doesn't really matter whether it is studying a book, asking an assistant or asking in a forum. (2) After looking in many references and not finding any clue ... I Googled for information and found that I should be looking for cyclic patterns i.e. oscillations? There are none in this dataset so I presume there would not be any autocorrelation, oder? (3) This is something very unfortunate ... the course Lectures are great, the course script is very comprehensive, however, the assignments many times include questions that are a bit off topic like in this case of Time Series and includes no actual reference ... so it is no surprise that even after diligently attending all lectures and doing all exercises I get stuck. Please recommend what's the best book in this topic of Time Series analysis maybe with R. I will buy it. (4) Yes they mentioned something like this in the assignment Dependency can be verified by showing that under the model, Cov(X_t^2,X_{t-h}^2) \neq 0, h 0 (complicated). Plot and interpret the autocorrelation functions of X_t and X_t^2 for the BMW-dataset. http://stat.ethz.ch/teaching/lectures/FS_2010/CompStat/series4.pdf Thank you. Best regards, Giovanni There are at least three R-specific time series books, all of which would deal with interpretation of an acf. Shumway and Stoffer Cowpertwait and Metcalfe Cryer and Chan See the books page: http://www.r-project.org/doc/bib/R-books.html Shumway and Stoffer is probably the most advanced of these but in no way difficult. There are a number of other more specialized and advanced texts also. Off the top of my head, Pfaff, Hyndman, ... David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] read.table behavior for Dates.
Jeroen Ooms wrote: Ah Phil Spector is right, nothing is converted. I'm almost too embarrassed to admit it, but actually, it was Excel that tricked me. It displays date fields differently than they are stored in the csv file, and once you press 'save', it saves everything to a different format, completely unasked. Exactly. There are some devastating gotchas with Excel and dates. For example, in a medical study I was analysing, Excel decided that a NZ National Health Index number of AUG1838 was a date and converted it to Aug-99. My rule is never, ever, ever save a .csv file from within Excel. Use .csv files created by other software, yes, but not one saved from within Excel. David Scott Nevertheless I got some valuable insight in the topic. What I'm trying to do here is make it easier for people to upload files that might contain dates to my webapp at yeroon.net/ggplot2. Currently, dates are imported as factors. I would like to implement something that Henrique described, to automatically convert variables to Date that are obviously dates. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 package documentation
Sébastien Bihorel wrote: Thanks David, After a bit of research, I believe that I've found the post you are referring to: http://tolstoy.newcastle.edu.au/R/e9/help/10/03/8779.html I will look into the proposed solutions. Sebastien Yes, that is the thread I was referring to. David _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 package documentation
Sébastien Bihorel wrote: Thanks Tobias, If there is no automated way to combine both documents, I will stack them manually... that will likely cause some problems with page numbering tough. Sebastien There was a thread a while back (this year) about someone who wanted to incorporate his package manual in his thesis. A solution was offered to this as I recall and it seems like the same problem to me. What you need is the LaTeX that comes out of the package check. Just add it to your vignette LaTeX and that should do the trick. David _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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 interactive input like C++
Erik Iverson wrote: ?? wrote: Thank you for your reply. My objective is simple. Assume I have a constant vector, say Vector. in C++ code, I want to do: int index; coutPlease enter the index of the element you want to look at Vector :; cinindex coutVector[index] I want every user to be able to do this. As I understand, scan can only read data from a fixed file. Can I just get the input from the shell directly? Isn't that what the file argument of ?scan says? I think? file: the name of a file to read data values from. If the specified file is ‘’, then input is taken from the keyboard (or whatever ‘stdin()’ reads if input is redirected or R is embedded). I think the required function is readline which prompts for user input. ?readline David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Statistical test for stationarity-how
Velappan Periasamy wrote: How to find out if EURGBP is stationary? Post the R codes for the same. You have posted three similar messages which basically say, do my work for me, I'm not prepared to even bother explaining my problem or situation. You are unlikely to get any help without more work on your behalf. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Matching pairs of values
I am sure someone can come up with a clever way of doing what I want---I don't seem to be able to. I want to check if a pair of numbers occurs as one of the rows of an n by 2 matrix. If I was only checking whether a single number was in a vector of numbers I would use %in% but I can't see how to generalize to this case. Any pointers? David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Matching pairs of values
Many thanks Peter and Berend. I think I can make this work for my problem. Apologies for not giving an example: I was a bit tired and frustrated when I posted to R-help and only on later reflection realised that I didn't really follow the posting guidelines. David Peter Ehlers wrote: (Sorry, I think that I just hit a wrong button and managed to send a non-reply.) I think that David might have meant that the column order of the numbers in lookfor is unimportant. In that case, a simple fix would be either to check both lookfor and rev(lookfor) (since the matrix is nX2) or to sort before testing: vtest - function(x, lookfor){ any(apply(x, 1, function(v) {identical(sort(v), sort(lookfor))}))} -Peter Ehlers On 2010-03-27 2:46, Berend Hasselman wrote: David Scott-6 wrote: I am sure someone can come up with a clever way of doing what I want---I don't seem to be able to. I want to check if a pair of numbers occurs as one of the rows of an n by 2 matrix. If I was only checking whether a single number was in a vector of numbers I would use %in% but I can't see how to generalize to this case. Would this help? vtest- function(x, lookfor) any(apply(x,1, function(v) identical(v,lookfor))) ma- matrix(c(2,3,1,5,7,3),ncol=2) ma [,1] [,2] [1,]25 [2,]37 [3,]13 vtest(ma,c(3,7)) [1] TRUE vtest(ma,c(1,7)) [1] FALSE Berend -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] emacs: reformat \items paragraph in .Rd
Hans-Peter Suter wrote: (emacs newb here) After having made some changes in an \items paragraph of \arguments the lines are no longer nicely wrapped. I was looking for a command to reindent/rewrap/reformat the whole \items paragraph but couldn't find anything. The only way, I found, was to go to the end of the first line, do 'c-j' (or RET) which wraps *this* line nicely, but now there is a hard line-break to the next line. So I go back with 'c-p', delete the gap to the next line with 'c-k' and some 'c-d' s. Then got to the end of this line and start again with 'c-j', ... There certainly must be some easier way to reformat a paragraph? (I tried 'm-c-q' (not defined) and 'm-c-\' (but was not able to input the backslash); I'm on GNU Emacs 23.1.1 (i386-mingw-nt5.1.2600). Thanks for your help! Hans-Peter Esc-q or M-q will wrap a whole paragraph. The only problem is that you need to make sure the paragraph you want to wrap is separated from other paragraphs by blank lines, i.e. it must be clear it is a paragraph. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] colname of ... arguments
ManInMoon wrote: I have writtn a function where I pass a variable number of arguments. I They are vectors and I can manipulate them, but I need to get hold of the name for a legend. niceplot-function(...) { parms=list(...) for (x in parms) { DoSomethingWith(x) } } BUT how how can I get something like namestring(...) of nameofvector(x)? I use the following syntax to get the name of a data object to use in a title, label or whatever. xname - paste(deparse(substitute(x), 500), collapse = \n) This is taken from hist.default so at least has some provenance as an appropriate method. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Importing Access 2007 data with ROBC
Ryan Utz wrote: Hi all, I'm trying to import Microsoft Access data into R. It looks like I'm supposed to use the ROBC package, and this works fine with old Access files (those with an .mdb extension). However, lovely Microsoft must constantly update their software. Modern Access files have an .ACCDB extension. I cannot seem to coerce R to import data from such a file. Any advice? I've been using this code: testdb - file.path(c:/Salmon_data.mdb) channel - odbcConnectAccess(testdb) Data - sqlFetch(channel,Table1) When I replace it with an Access 2007 file: testdb - file.path(c:/Salmon_data.accdb) channel - odbcConnectAccess(testdb) Data - sqlFetch(channel,Table1) Try odbcConnectAccess2007 instead. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to make R plot under Linux
Saeed Abu Nimeh wrote: Try to install xming in your windows box http://www.straightrunning.com/XmingNotes/. Make sure to run xming before plotting. Saeed On Mon, Feb 22, 2010 at 12:46 PM, xin wei xin...@stat.psu.edu wrote: hi, Guys: thank you so much for all the suggestion. Now I seem to be able to set up x11 forwarding in PUTTY. however, I still could not get plot and I get the following error msg: Error in function (display = , width, height, pointsize, gamma, bg, : X11 I/O error while opening X11 connection to 'localhost:20.0' Is this error msg indication of lack of appropriate plotting package on the server or the server is not properly set up for X11 forwarding? thanks The main point here is that none of this is to do with R. It is all about setting up the ssh connection properly. You are at a university and there should be a linux guru or at least someone else in the department who can assist. Someone set up the linux machine where R is running, they will know this stuff. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] typo in contrast package's vignettes
hadley wickham wrote: Really? Where exactly is the loophole in 'If the question relates to a contributed package ... try contacting the package maintainer first.'? How about the general R philosophy that if you dare to mistakenly submit a bug report that turns out to be a feature, not a bug, you shall be well and truly chastised? Hadley I think you are being a bit provocative here Hadley. Chastisement of false bug reports occurs with base R functions because it causes unnecessary work for R-core and also when a bug is reported in a package as a bug in base R and chastisement is again understandable because it is incorrect practice. I think others have come into this debate because they see David has been responding to Peng Yu's questions quite reasonably considering that Peng Yu seems unable to do the least bit of self-help. Given the time Peng Yu has been asking questions he should be able to find his way around the help system and other documentation by now. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] typo in contrast package's vignettes
Peng Yu wrote: On Wed, Feb 3, 2010 at 3:48 PM, Max Kuhn mxk...@gmail.com wrote: Wait, what were we talking about? Right...it is a typo. It should be c'beta in the numerator. Peng: As the package maintainer, you really should send me a quick email about it instead of posting to the list. Let's not waste the bandwidth anymore. Given the number of typos in my documentation, this amount of email bring down the whole system. Would you please put the email in the vignette? As I don't find it. I sometime did take the long way to find the emails of the authors, but a lot of the time they just don't reply. There were no guarantee you would reply. But I know that you will reply and will send you the message if I found any other problems with the packages. Regards, Peng This is becoming quite vexatious Peng Yu. How long have you been using R? You are not a total newbie. R is an environment which rewards a bit of exploration and experimentation. Every package has a maintainer whose email is given on CRAN. In the case of the contrast package that is at http://cran.r-project.org/web/packages/contrast/index.html It ain't that hard. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Microsoft SQL Server and R
I have a client running Microsoft SQL Server. I am interested in ways of accessing data from this server using R. I would welcome any information about how this can be done. I have a reasonable grasp of SQL and have experience with MySQL and RODBC but don't know anything much about Microsoft SQL Server. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Greek letters on a multi-line plot title
Jason Rupert wrote: I have an instance where I need to include Greek letters on a plot title that is multiple lines. I've searched the forums for an approach to do this, but most of the previous posts and replies seem to just address instances of single line examples and problems:, e.g. https://stat.ethz.ch/pipermail/r-help/1999-October/005096.html I tried implementing those suggestions, e.g. expression(paste(...)), but that seemed to remove all the line split formating, i.e. \n. In the example code below I would like the sigma to be the lower case Greek symbol for sigma. Actually I would like the x and y to be subscripts of the lower case Greek symbol, but I suppose that is the next step. I guess the key is that I would like to maintain the multiple line title while having the Greek letters. Thanks again for any feedback. and insights. number_vals-100 x-rnorm(number_vals) y-rnorm(number_vals) plot(1, 1, xlim= c(min(x), max(x)), ylim= c(min(y), max(y)), col=0) points(x, y) the_expression-paste(Plotting y vs. x, \n sigma x = , format(sd(x), digits=4, scientific=F), \n sigma y = , format(sd(y), digits=4, scientific=F), sep=) title(the_expression) grid() When confronted with this problem, after many failed attempts, I have had to resort to mtext. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Yet another question about importing Excel *.xls files
Jerry Floren wrote: Hi Gabor, Thanks for your insights and suggestions. There was a post on the Wiki you mentioned that makes me think this will work. Unfortunately, the spreadsheet was designed to make it easy for lab staff to enter their results, but not so easy for another program to read in the data. That is why I copy and paste the original spreadsheet into a second spreadsheet with a separate page that could be read beginning at the top (A1) cell. Here is a link to the spreadsheet the labs use. http://www.mda.state.mn.us/en/sitecore/content/Global/MDADocs/licensing/map/mapreportform.aspx A big problem with this format is that the lab's ID code ends up in each column while the data is organized by rows. Also, there are three different samples with three different replicates. The spreadsheet is set up so that the replicates are not identified. Even if the data had to be copied to a second spreadsheet (with the conversion page), it would be a significant improvement over the current method. I just learned that it is possible to hide a worksheet in Excel. (I do not want the lab staff to see the hidden worksheet as then the replicates can be identified). The spreadsheets are e-mailed to me. I have to open them up and save them with a different file name. If the first worksheet is hidden, but has the data arranged properly starting in cell A1, it looks like the entire(hidden) worksheet be read in according to this from the Wiki: Entire Worksheets Use the following code to import in all of worksheet called “Sheet 1”. The hazard with this approach is that any and all data in that worksheet will be copied in, this includes data that are hidden or that you otherwise were not intending to bring in. library(RODBC) MyExcelData - sqlFetch(odbcConnectExcel(Test.xls), sqtable = Sheet1, na.strings = NA, as.is = T) odbcCloseAll()Caution Excel 2003 (and earlier?) use the first 0-16 rows to guess the data type. Consider a column of international postal codes where the first 20 rows contain 50010 and the next two rows contain 500A1 and 500E1. The value of ‘500A1’ is likely to be interpreted as a missing value and the value of ‘500E1’ may be interpreted as a numeric value that is in exponential format. More information can be found here: http://www.dicks-blog.com/archives/2004/06/03/external-data-mixed-data-types/. I'm going to play around with this and see if I can get it to work for my data. Thanks, Jerry Floren Minnesota Department of Agriculture As an alternative to Gabor's suggestions, I have always had excellent results from xlsReadWrite which is back on CRAN. The author, Hans-Peter Suter, also offers xlsReadWritePro at http://www.swissr.org/ which can write native xls files with multiple sheets. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Greek letters on a multi-line plot title
Jason Rupert wrote: David, Thank you very much for your response. Is there any chance you can provide your example where mtext is used? I also tried to use mtext, but I did not have any luck, so any help with the example below working with mtext or otherwise is greatly appreciated. Thanks again, Jason This code works for me and should give the general idea. It is taken from code I use for testing in one of my packages. ### Change spacing to allow for multiline title par(oma=c(2, 0, 4, 0)) ### Some greek letters mu - 0 alpha - 1 beta - 2 delta - 3 lambda - 4 ### Some graph or other plot(1:10,1:10) mtext(expression(bold(Meaningless Title)), line=3.5,cex=1.15) mtext(bquote(paste(lambda==.(lambda),, , alpha==.(alpha),, , beta==.(beta),, , delta==.(delta),, , mu==.(mu),sep=)), line=2.25,cex=1.15) Best wishes David Scott - Original Message From: David Scott d.sc...@auckland.ac.nz To: Jason Rupert jasonkrup...@yahoo.com Cc: R-help@r-project.org R-help@r-project.org Sent: Wed, January 20, 2010 3:49:40 PM Subject: Re: [R] Greek letters on a multi-line plot title Jason Rupert wrote: I have an instance where I need to include Greek letters on a plot title that is multiple lines. I've searched the forums for an approach to do this, but most of the previous posts and replies seem to just address instances of single line examples and problems:, e.g. https://stat.ethz.ch/pipermail/r-help/1999-October/005096.html I tried implementing those suggestions, e.g. expression(paste(...)), but that seemed to remove all the line split formating, i.e. \n. In the example code below I would like the sigma to be the lower case Greek symbol for sigma. Actually I would like the x and y to be subscripts of the lower case Greek symbol, but I suppose that is the next step. I guess the key is that I would like to maintain the multiple line title while having the Greek letters. Thanks again for any feedback. and insights. number_vals-100 x-rnorm(number_vals) y-rnorm(number_vals) plot(1, 1, xlim= c(min(x), max(x)), ylim= c(min(y), max(y)), col=0) points(x, y) the_expression-paste(Plotting y vs. x, \n sigma x = , format(sd(x), digits=4, scientific=F), \n sigma y = , format(sd(y), digits=4, scientific=F), sep=) title(the_expression) grid() When confronted with this problem, after many failed attempts, I have had to resort to mtext. David Scott -- _ David ScottDepartment of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email:d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to install old randomForest?
Julian Ramirez wrote: Hi Ted, You need to unzip and untar the files that are inside that file, and then build the package using R CMD build --binary PackageName. However, for compiling a package under a windows environment you will need Rtools2.10 from Duncan Murdoch, along with Miktex, and html workshop from microsoft. All that is free. I suggest you to read tutorials on how to build packages from sources in Windows. This website might be a good start point http://www.biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html. Hope this helps, Julian Ramirez Research Assistant International Centre for Tropical Agriculture, CIAT On Wed, Jan 13, 2010 at 11:29 PM, Chang, C-Y. changcy.m...@gmail.comwrote: Hi all, I'm using windowsXP and R 2.10.0. I downloaded randomForest 4.5-33.tar.gz from its archive, but how do I make it into a installation ZIP file? Thanks, Ted As an alternative guide to the build process, have a look at Rob Hyndman's instructions: http://robjhyndman.com/researchtips/building-r-packages-for-windows/ David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Return values in fExtremes package
Tim Smith wrote: Hi, I was usuing the fExtemes package, and wanted to obtain some of the values returned from the function gumbelFit(). For example, in the following code, I would like to access 'mu' and 'beta' from the object 'para'. How should I go about doing this? Is there any generic method to access the object? --- library(fExtremes) ss - gumbelSim(model = list(mu = 0, beta = 1), n = 1000, seed = NULL) para - gumbelFit(ss) print(para) Title: Gumbel Parameter Estimation Call: gumbelFit(x = ss) Estimation Type: gum mle Estimated Parameters: mubeta 0.005449572 1.010874131 Description Thu Jan 07 13:14:28 2010 class(para) [1] fGEVFIT attr(,package) [1] fExtremes --- You could track back through the functions gumbelFit and .gevFit to see what is returned by gumbelFit, or spend some time reading documentation, but as in many such cases str is your friend: ss - gumbelSim(model = list(mu = 0, beta = 1), n = 1000, seed = NULL) para - gumbelFit(ss) str(para) Formal class 'fGEVFIT' [package fExtremes] with 8 slots ..@ call : language gumbelFit(x = ss) ..@ method : chr [1:2] gum mle ..@ parameter :List of 3 .. ..$ block : num 1 .. ..$ type : chr mle .. ..$ gumbel: logi TRUE ..@ data :List of 2 .. ..$ x :Time Series: Name: object Data Matrix: Dimension: 1000 1 Column Names: GUMBEL Row Names: ... Positions: Start: End: With: Format: counts FinCenter: Units: GUMBEL Title: Signal Series Object Documentation: Fri Jan 08 11:12:09 2010 .. ..$ blockmaxima:Time Series: Name: object Data Matrix: Dimension: 1000 1 Column Names: GUMBEL Row Names: ... Positions: Start: End: With: Format: counts FinCenter: Units: GUMBEL Title: Signal Series Object Documentation: Fri Jan 08 11:12:32 2010 ..@ fit:List of 8 .. ..$ n : int 1000 .. ..$ data : num [1:1000] 1.134 0.215 2.011 -0.352 5.048 ... .. ..$ par.ests : Named num [1:2] 0.0352 0.9929 .. .. ..- attr(*, names)= chr [1:2] mu beta .. ..$ par.ses : Named num [1:2] 0.0331 0.0244 .. .. ..- attr(*, names)= chr [1:2] mu beta .. ..$ varcov: num [1:2, 1:2] 0.001094 0.000254 0.000254 0.000597 .. .. ..- attr(*, dimnames)=List of 2 .. .. .. ..$ : chr [1:2] mu beta .. .. .. ..$ : chr [1:2] mu beta .. ..$ converged : int 0 .. ..$ nllh.final: num 1567 .. ..$ llh : num 1567 ..@ residuals : num [1:1000] 0.718 0.434 0.872 0.228 0.994 ... ..@ title : chr Gumbel Parameter Estimation ..@ description: chr Fri Jan 08 11:12:32 2010 p...@fit$par.ests mu beta 0.03515609 0.99286204 David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Maximum spacing method
mxm.margarida wrote: Hi! I'm trying to compare maximum likelihood estimator with maximum spacing estimator (in Generalized extreme value distribution). My problem is the following: i know how to determinate maximum likelihood estimator on R, but i dont find a way to do the maximum spacing estimator...:-( Any help would be great:-) You can see an implementation of mps for the normal inverse Gaussian in fBasics on R-Forge. Have a look at the function .nigFit.mps in the file dist-nigFit.R David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Stata files
I have a client who uses Stata 11. Can anyone advise me on ways of transferring data from this version of Stata to R? Reading the documentation for read.dta in package foreign it seems it only allows for versions up to Stata 10. I don't know Stata at all but a bit of poking around on their website led me to believe Stata 11 couldn't write in Stata 10 format. However Stata 11 can write Excel files in XML, so presumably .xlsx files. Any advice, correction of my misconceptions, etc. gladly received. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Stata files
Thank you both (JRG and BDR) for the advice. Just to clarify Brian, I don't actually have any example .dta files yet to test. I wanted to be prepared and be able to advise the client what to do. I don't see anything about 'Stata 11 help for dta' Brian: must have a different URL. But I did note already that Stata 11 uses format 114 which I agree indicates 10 and 11 use the same format. David JRG wrote: On 16 Dec 2009 at 10:24, Prof Brian Ripley wrote: Have you tried read.dta? The URL on the help page for read.dta now says 'Stata 11 help for dta', but it seems to document the same format (114) as Stata 10 (see the value section). So in so far as Stata is telling us, it looks like Stata 10 and 11 use the same format (as Stata 8 and 9 did). That's correct: Stata 10 and Stata 11 use the same file format. If you need a still older format, the -saveold- command in Version 11 of Stata will save a Version 10/11 file in the format that was used by Versions 8 and 9 of Stata. ---JRG On Wed, 16 Dec 2009, David Scott wrote: I have a client who uses Stata 11. Can anyone advise me on ways of transferring data from this version of Stata to R? Reading the documentation for read.dta in package foreign it seems it only allows for versions up to Stata 10. I don't know Stata at all but a bit of poking around on their website led me to believe Stata 11 couldn't write in Stata 10 format. However Stata 11 can write Excel files in XML, so presumably .xlsx files. I suspect it can write .csv files. See for example http://www.stata.com/help.cgi?outsheet Any advice, correction of my misconceptions, etc. gladly received. David Scott _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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. John R. Gleason Associate Professor Syracuse University 430 Huntington Hall Voice: 315-443-3107 Syracuse, NY 13244-2340 USA FAX: 315-443-4085 PGP public key at keyservers __ 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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] estimate inverse gaussian in R
Jorge Ivan Velez wrote: Hi Tim, Take a look at http://bm2.genes.nig.ac.jp/RGM2/R_current/library/fBasics/man/dist-nigFit.html HTH, Jorge' i don't think this is what the OP wanted. The nig is the normal inverse Gaussian distribution, which is a special case of the generalized inverse Gaussian distribution. Its support is the real line and it has 4 parameters. The inverse Gaussian is a special case of the generalized inverse Gaussian. It has support the positive half line and 2 parameters. David Scott On Sun, Dec 6, 2009 at 12:48 PM, noclue_ wrote: I have a one-variable data set in R. The plot of histogram of my numerical variable suggests an inverse gaussian distribution. How can I obtain best estimation for the two parameters of inverse gaussian based on my data? Thanks. -- View this message in context: http://n4.nabble.com/estimate-inverse-gaussian-in-R-tp949692p949692.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] estimate inverse gaussian in R
David Scott wrote: Jorge Ivan Velez wrote: Hi Tim, Take a look at http://bm2.genes.nig.ac.jp/RGM2/R_current/library/fBasics/man/dist-nigFit.html HTH, Jorge' i don't think this is what the OP wanted. The nig is the normal inverse Gaussian distribution, which is a special case of the generalized inverse Gaussian distribution. Its support is the real line and it has 4 parameters. The inverse Gaussian is a special case of the generalized inverse Gaussian. It has support the positive half line and 2 parameters. Sorry, that must look like nonsense. I meant to say: The nig is a special case of the generalized hyperbolic distribution. David Scott David Scott On Sun, Dec 6, 2009 at 12:48 PM, noclue_ wrote: I have a one-variable data set in R. The plot of histogram of my numerical variable suggests an inverse gaussian distribution. How can I obtain best estimation for the two parameters of inverse gaussian based on my data? Thanks. -- View this message in context: http://n4.nabble.com/estimate-inverse-gaussian-in-R-tp949692p949692.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to interpret the phase spectrum?
Peter Dalgaard wrote: sdlywjl666 wrote: Dear all, I would like to know whether positive or negative values of the phase spectrum indicate that the time series leads or lags. In my work, x and y have peak nearly at the same frequency,(eg:f=1/56);and the coherency is peak where f=1/56,the phase is 0.5 where f=1/56. Can I get the conclusion that x lead y 0.5*56=28 at the frquency f=1/56? if not,how can I compute the lag/lead by phase and frequency. Are you referring to a particular piece of software? As far as I know, this is completely dependent on choice of notation, so the question really only makes sense in a specified context. In the cases I remember seeing (I'm no time series expert, though), the phase is an _angle_ between 0 and 2*pi or between -pi and +pi, or sometimes in degrees, but I suppose it could be scaled to (-1 , 1) or (0, 1) as well. Also lead/lag for cyclic functions is a matter of convention; in particular, there's no difference between leading and lagging by half a cycle. Following up on Peter's comment. Different authors define the cross-covariance and hence cross-spectrum differently. Time series seems to me to be plagued by inconsistencies in definitions. There is a way out though, and when faced with different software, it is a step which should always be undertaken before any interpretation is attempted. Generate a series, a simple sinusoid will do, change the phase to generate a leading or lagged series, and see how the cospectrum looks. That is really the only infallible way of determining what the software is doing. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Bessel function with large index value
I am looking for a method of dealing with the modified Bessel function K_\nu(x) for large \nu. The besselK function implementation of this allows for dealing with large values of x by allowing for exponential scaling, but there is no facility for dealing with large \nu. What would work for me would be an lbesselK function in the manner of lgamma which returned the log of K_\nu(x) for large \nu. Does anybody have any leads on this? Note that I have trawled through Abramowitz and Stegun and found 9.7.8 which doesn't work for me because of the complication in the definition of the x argument. I have also seen a result of Ismail (1977) reported by Barndorff-Nielsen and Blaesild which has the other problem, the treatment of the x argument is too simple. To do the calculation I am attempting, I need to have the Bessel function in a form that will allow a cancellation with a Gamma function of high order in the denominator. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Bessel function with large index value
This is a reply to my own question. I thought I had found an answer but it seems not so (some analysis follows below). Maybe Martin Maechler or Robin Hankin or Duncan Murdoch may have some ideas---I know the question is a bit specialized. David Scott wrote: I am looking for a method of dealing with the modified Bessel function K_\nu(x) for large \nu. The besselK function implementation of this allows for dealing with large values of x by allowing for exponential scaling, but there is no facility for dealing with large \nu. What would work for me would be an lbesselK function in the manner of lgamma which returned the log of K_\nu(x) for large \nu. Does anybody have any leads on this? Note that I have trawled through Abramowitz and Stegun and found 9.7.8 which doesn't work for me because of the complication in the definition of the x argument. I have also seen a result of Ismail (1977) reported by Barndorff-Nielsen and Blaesild which has the other problem, the treatment of the x argument is too simple. To do the calculation I am attempting, I need to have the Bessel function in a form that will allow a cancellation with a Gamma function of high order in the denominator. David Scott After posting I checked the GNU Scientific Library (http://www.gnu.org/software/gsl/) and found: — Function: double gsl_sf_bessel_lnKnu (double nu, double x) — Function: int gsl_sf_bessel_lnKnu_e (double nu, double x, gsl_sf_result * result) These routines compute the logarithm of the irregular modified Bessel function of fractional order \nu, \ln(K_\nu(x)) for x0, \nu0. I then recalled that Robin Hankin and Duncan Murdoch had made the GSL available. I installed the package gsl and investigated the function bessel_lnKnu. Unfortunately, it appears that this function has *smaller* range than besselK when it comes to the index. The following shows it: library(plyr) library(gsl) ### Check calculations using both methods lnKnu - maply(expand.grid(x = 100*(1:7), nu = 10*(1:100)), bessel_lnKnu) lnKnu Knu - maply(expand.grid(x = 100*(1:7), nu = 10*(1:100)), besselK) Knu lnKnu/log(Knu) I was expecting what happens with gamma and lgamma ### Compare gamma function lgam - lgamma(100*(1:7)) lgam gam - gamma(100*(1:7)) gam lgam/log(gam) It seems that bessel_lnKnu is set up to protect against infinity when x becomes small: ### Does lnKnu protect against Inf when x goes to zero? lnnear0 - maply(expand.grid(x = 0.0001*(1:10), nu = 10*(0:5)), bessel_lnKnu) lnnear0 near0 - maply(expand.grid(x = 0.0001*(1:10), nu = 10*(0:5)), besselK) near0 lnnear0/log(near0) So, I am still in need of a solution: an implementation of log of Bessel K which protects against the index nu becoming large. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] (exact) confidence bounds for lognormal parameters \mu and \sigma
Krusty the Klown wrote: Dear all, a statistical question: how can I compute exact confidence intervals for the lognormal distribution parameters? I found something only on www.weibull.com www.weibull.com . Does exist a package in R which can compute them? Thanks in advance, KTK I think fitdistrplus can do this David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Non-normal residuals.
Karl Ove Hufthammer wrote: On Tue, 27 Oct 2009 18:06:02 -0400 Ben Bolker bol...@ufl.edu wrote: If transforming your data brings you closer to satisfying the assumptions of your analytic methods and having a sensible analysis, then that's good. If it makes things worse, that's bad. Other choices, depending on the situation, include robust methods (for outlier problems); generalized linear models etc. (for discrete data from standard distributions); models using t- instead of normally distributed residuals; I have sometimes wondered about this: Which functions/packages do you use to fit a (perhaps just a simple linear) model with t-distributed residuals (or residuals of a different distribution)? Package sn has this facility I believe. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Non-normal residuals.
Kjetil Halvorsen wrote: On Wed, Oct 28, 2009 at 7:25 AM, David Scott d.sc...@auckland.ac.nz wrote: Karl Ove Hufthammer wrote: On Tue, 27 Oct 2009 18:06:02 -0400 Ben Bolker bol...@ufl.edu wrote: If transforming your data brings you closer to satisfying the assumptions of your analytic methods and having a sensible analysis, then that's good. If it makes things worse, that's bad. Other choices, depending on the situation, include robust methods (for outlier problems); generalized linear models etc. (for discrete data from standard distributions); models using t- instead of normally distributed residuals; I have sometimes wondered about this: Which functions/packages do you use to fit a (perhaps just a simple linear) model with t-distributed residuals (or residuals of a different distribution)? Package sn has this facility I believe. Yes, for independent data, but for time series??? Kjetil No, not for time series---I was responding to fit a (perhaps just a simple linear) model with t-distributed residuals David _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Frequencies, proportions cumulative proportions
Muenchen, Robert A (Bob) wrote: Ted, I know how to do that. It's just such a standard display in SAS, SPSS and Stata that I figured someone had done it and I had just overlooked it. Thanks! Bob I don't think there is a ready-made one, but it is very little effort to make your own: mkMyTable - function(X){ Table - data.frame( table(X) ) Table$Prop - prop.table( Table$Freq ) Table$CumProp - cumsum( Table$Prop ) Table } myTable - mkMyTable(Score) Hoping this helps! Ted. I think CrossTable in gmodels does what Bob is after: CrossTable(gmodels) R Documentation Cross Tabulation with Tests for Factor Independence Description An implementation of a cross-tabulation function with output similar to S-Plus crosstabs() and SAS Proc Freq (or SPSS format) with Chi-square, Fisher and McNemar tests of the independence of all table factors. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Odp: : Question about correlation between data.
Petr PIKAL wrote: Hi r-help-boun...@r-project.org napsal dne 16.10.2009 15:24:05: hi everybody, I'm a student, and I'm new using R! I'm looking for statistical help hoping somebody can answer me! This is my problem: I have 2 temporal series. The firstone is a series of mesured data (height of monitorated points), the second is a series of temperature (in Celsius degree). Using Matlab I have built the two graphs (Measured Data - Time Temperature - Time). Looking those graphs I can surely say that there is a clear correlation beetween theme, and also that the measured data are surely influenced by the variations of temperature. Unfortunately my statistical knowledges are not that large so using R seems quite difficult to me. My question is: is there a code already written the can compare the 2 temporal series and can find the correlation between the data??? If the relationship is linear than lm(values~temperature, ...) shall suffice if it is nonlinear than you can look e.g. to ?nls And also: is there a code that can correct the Measured Data from the influence of temperature and return a clean data??? maybe ?predict. Regards Petr This sounds a little dangerous to me. Antonio is wanting to determine correlations between *time series* if I understand correctly. The time series need to be prewhitened or the correlations between successive observations modeled in some way. Just using lm can be very misleading because of the violation of the independence assumption. If Antonio does not understand these comments he needs to consult a local statistician. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] histogram
Henrique Dallazuanna wrote: Change the breaks argument: t1 - hist(1:5, 0:5) t1$counts On Thu, Oct 8, 2009 at 4:47 PM, Khanh Nguyen kngu...@cs.umb.edu wrote: Hi all, I have a question about hist() 1) t1 - hist(c(1,2,3,4,5)) t1 $breaks [1] 1 2 3 4 5 $counts [1] 2 1 1 1 why is there 2 counts for 1? And should the counts be '1 1 1 1 1' ? Is there any other function to count frequency of discrete data? Thanks. -k Nobody has mentioned what I think is the important point here, that histogram is not intended for the purpose of dealing with discrete data. To expect that it will give you the counts you want is just wrong. As others have pointed out if you make things more explicit and don't take the defaults it will do so. Using hist to obtain counts like this is like using a hammer to drive in a screw. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Running an ANOVA with a BY
baxterj wrote: I have a simple 1 way anova coded like summary(ANOVA1way - aov(Value ~ WellID, data = welldata)) How can I use the BY function to do this ANOVA for each group using another variable in the dataset?? I tried coding it like this, but it doesn't seem to work. summary(ANOVA1way - by(welldata, Analyte, function(x) aov(Value ~ WellID, data = welldata))) In SAS I would code it like this: Proc sort data=welldata; by analyte; run; Proc glm data=welldata; by analyte; class wellid; model value = wellid; run; Any suggestions??? Given you have asked two questions on translating SAS idioms to R, you might be a candidate for Bob Muenchen's book which some people have previously recommended: [3] Robert A. Muenchen. R for SAS and SPSS Users. Springer Series in Statistics and Computing. Springer, 2009. ISBN: 978-0-387-09417-5. [ bib | Discount Info | Publisher Info ] This book demonstrates which of the add-on packages are most like SAS and SPSS and compares them to R's built-in functions. It steps through over 30 programs written in all three packages, comparing and contrasting the packages' differing approaches. The programs and practice datasets are available for download. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Equivalence of Mann-Whitney test and Kruskal-Wallis test with k=2
Thomas Farrar wrote: Hi all, The Kruskal-Wallis test is a generalization of the two-sample Mann-Whitney test to *k* samples. That being the case, the Kruskal-Wallis test with *k*=2 should give an identical p-value to the Mann-Whitney test, should it not? x1-c(1:5) x2-c(6,8,9,11) a-wilcox.test(x1,x2,paired=FALSE) b-kruskal.test(list(x1,x2),paired=FALSE) a$p.value [1] 0.01587302 b$p.value [1] 0.01430588 The p-values are slightly different (note that there are no ties in the data, so computed p-values should be exact). Can anyone explain the discrepancy? It's been awhile since I studied nonparametric stats and this one has me scratching my head. Many thanks! Tom The continuity correction? It is true by default for wilcox.test and is not apparent in the help for kruskal.test. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] Google's R Style Guide
(Ted Harding) wrote: On 29-Aug-09 17:51:54, diegol wrote: Max Kuhn wrote: Perhaps this is obvious, but Ive never understood why this is the general convention: An opening curly brace should never go on its own line; I tend to do this: f - function() { if (TRUE) { cat(TRUE!!\n) } else { cat(FALSE!!\n) } } I favor your approach. BUT I add one more level of indentation. Your function would look like: f - function() { if (TRUE) { cat(TRUE!!\n) } else { cat(FALSE!!\n) } } This way I quickly identify the beginning of the function, which is the one line at the top of the expression AND sticking to the left margin. In your code you use this same indentation in the if/else construct. I find it also useful for the function itself. When I want to rely on indentation and vertical alignments to keep track of program structure, I would tend to write the above like f - function() { if (TRUE) { cat(TRUE!!\n) } else { cat(FALSE!!\n) } } so that an opening { is aligned with the keyword it is associated with, and then at the end of the block so also is the closing }. However, in this case (if I keep all the {...} for the sake of structure) I would also tend to save on lines with f - function() { if (TRUE) { cat(TRUE!!\n) } else { cat(FALSE!!\n) } } which is still clear enough for me. This probably breaks most guidelines! But in practice it depends on what it is, and on how readily I find I can read it. Ted. I have to say Ted, I find this as ugly as sin and you would have to break my legs to make me code like this. I am with Hadley on not taking extra lines and I think this is really unclear because it is so disjointed. And the 'else' way over to the right I just think is crazy. It just goes to show how personal this can be because despite my loathing this code I know Ted to be a thoughtful and experienced R user. I think this discussion is valuable, and have previously asked about style which I think is very important. Base R does suffer from very inconsistent naming and as I think Duncan said it makes it very difficult sometimes to remember names when you have variations in case and separators as with things related to system. David _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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] test for bimodality
Rolf Turner wrote: On 31/08/2009, at 9:40 AM, John Sansom wrote: Has a test for bimodality been implemented in R? Doing RSiteSearch(test for bimodality) yields one hit, which points to http://finzi.psych.upenn.edu/Rhelp08/2008-September/173308.html It looks like it might be *some* help to you. cheers, Rolf Turner I have used the dip test for testing if a distribution is *unimodal*. Possibly that is what John needs. See package diptest. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ 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.