[R] Revert a factor to its numeric values
I'm trying a recommendation on the help page for 'factor': x - c(1, 2, 1, 2) x - factor(x, labels = c(one, two)) x [1] one two one two Levels: one two as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion Also, as.numeric(as.character(x)) [1] NA NA NA NA Warning message: NAs introduced by coercion What am I doing wrong? This is R-1.9.1, Linux (debian installation) Another question: I have a factor with four levels, which I want to collapse to two. How do I do it in the simplest possible way? Thanks, Göran -- Göran Broströmtel: +46 90 786 5223 Department of Statistics fax: +46 90 786 6614 Umeå University http://www.stat.umu.se/egna/gb/ SE-90187 Umeå, Sweden e-mail: [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] (no subject)
Hi Does anybody know from an R-package devoted to sample selection problems (Heckman's lambda, Lewbel, ...)? Thanks and best regards Marc Wildi __ [EMAIL PROTECTED] 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] Revert a factor to its numeric values
On Wed, 18 Aug 2004, Göran Broström wrote: I'm trying a recommendation on the help page for 'factor': x - c(1, 2, 1, 2) x - factor(x, labels = c(one, two)) x [1] one two one two Levels: one two as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion Also, as.numeric(as.character(x)) [1] NA NA NA NA Warning message: NAs introduced by coercion What am I doing wrong? This is R-1.9.1, Linux (debian installation) Your factor is made up of one, two, which are not numeric -- don't expect R to speak English (or Swedish). You could just as easily have used labels = c(apples, oranges). Another question: I have a factor with four levels, which I want to collapse to two. How do I do it in the simplest possible way? via levels- : there is an example on the help page for levels. -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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] Revert a factor to its numeric values
On Wed, Aug 18, 2004 at 09:30:50AM +0100, Prof Brian Ripley wrote: On Wed, 18 Aug 2004, Göran Broström wrote: I'm trying a recommendation on the help page for 'factor': x - c(1, 2, 1, 2) x - factor(x, labels = c(one, two)) x [1] one two one two Levels: one two as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion Also, as.numeric(as.character(x)) [1] NA NA NA NA Warning message: NAs introduced by coercion What am I doing wrong? This is R-1.9.1, Linux (debian installation) Your factor is made up of one, two, which are not numeric -- don't expect R to speak English (or Swedish). You could just as easily have used labels = c(apples, oranges). Didn't work either. :-) I really want the underlying numeric codes (convert the variable to numeric). 'as.integer(x)' seems to do the trick, is that correct? Also 'as.numeric(x)', although it is meaningless according to the help page. Another question: I have a factor with four levels, which I want to collapse to two. How do I do it in the simplest possible way? via levels- : there is an example on the help page for levels. Thanks; exactly what I was looking for. Göran __ [EMAIL PROTECTED] 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] Revert a factor to its numeric values
On Wed, 18 Aug 2004, Göran Broström wrote: On Wed, Aug 18, 2004 at 09:30:50AM +0100, Prof Brian Ripley wrote: On Wed, 18 Aug 2004, Göran Broström wrote: I'm trying a recommendation on the help page for 'factor': x - c(1, 2, 1, 2) x - factor(x, labels = c(one, two)) x [1] one two one two Levels: one two as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion Also, as.numeric(as.character(x)) [1] NA NA NA NA Warning message: NAs introduced by coercion What am I doing wrong? This is R-1.9.1, Linux (debian installation) Your factor is made up of one, two, which are not numeric -- don't expect R to speak English (or Swedish). You could just as easily have used labels = c(apples, oranges). Didn't work either. :-) I really want the underlying numeric codes (convert the variable to numeric). 'as.integer(x)' seems to do the trick, is that correct? Also 'as.numeric(x)', although it is meaningless according to the help page. as.integer is OK, but unclass() is the usual way (it doesn't lose the other attributes such as names). x - factor(1:10) names(x) - letters[1:10] as.integer(x) [1] 1 2 3 4 5 6 7 8 9 10 unclass(x) a b c d e f g h i j 1 2 3 4 5 6 7 8 9 10 attr(,levels) [1] 1 2 3 4 5 6 7 8 9 10 Another question: I have a factor with four levels, which I want to collapse to two. How do I do it in the simplest possible way? via levels- : there is an example on the help page for levels. Thanks; exactly what I was looking for. -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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] logistic -normal model
1. Have you also tried glmmPQL in library(MASS)? It is supposed to do the same thing. I had better luck with GLMM, but you might try glmmPQL if you haven't already. 2. PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html;. It may help you find answers to some questions yourself. Failing that, it may help you express your question in a form that more likely elicit a more informative response. hope this helps. spencer graves syl dan wrote: I am working with a logistic-normal model (i.e, GLMM with random intercept model) by Bayesian method. BUt I met some difficulities for programming by R. Is there anyone have experience of this model or the R code I can refer as example? Thanks for your help. Syl __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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] Re: Thanks Frank, setting graph parameters, and why social scientists don't use R
There are answers that could and should be applied in specific situations. At least in academia and in substantial research teams, statisticians ought to have a prominent part in many of the research teams. Senior statisticians should have a prominent role in deciding the teams to which this applies. why should it be ok to do combine high levels of chemical expertise with truly appalling statistical misunderstandings, to the extent that the suppose chemical insights are not what they appear to be? There should be a major focus on training application area students on training them to understand important ideas, to recognize when they are out of their depth, and to work with statisticians. There should be much more use of statisticians in the refereeing of published papers. Editors need to seek advice from experienced statisticians (some do) on what sorts of papers are candidates for statistical refereeing. Publication in an archive of the data that have been used for a paper could be a huge help, so that others can check whether the data really do support the conclusion. Even better, as Robert Gentleman has argued, would/will be papers that can be processed through Sweave or its equivalent. Really enlightened people (in the statistical sense) in the applied communities will latch onto R, as some are doing, because the limitations inherent in much other software so often lead to crippled and/or misleading analyses. Increasingly, we can hope that it will become difficult for statistics to in various applied area communities to proceed on its merry way, ignorant of or ignoring most of what has happened in the mainstream statistical community in the past 20 years. The statistical community needs to be a lot more aggressive in demanding adequate standards of data analysis in applied areas, at the same time suggesting ways in which it can work with application area people to improve standards. It is also fair to comment that the situation is very uneven. There are some areas where the standards are pretty reasonable, at least for the types of problems that typically come up in those areas. John Maindonald. John Maindonald email: [EMAIL PROTECTED] phone : +61 2 (6125)3473fax : +61 2(6125)5549 Centre for Bioinformation Science, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200. On 18 Aug 2004, Bert Gunter wrote: So we see fairly frequently indications of misunderstanding and confusion in using R. But the problem isn't R -- it's that users don't know enough statistics. . . . . I wish I could say I had an answer for this, but I don't have a clue. I do not thing it's fair to expect a mechnical engineer or psychologist or biologist to have the numerous math and statistical courses and experience in their training that would provide the base they need. For one thing, they don't have the time in their studies for this; for another, they may not have the background or interest -- they are, after all, mechanical engineers or biologists, not statisticians. Unfortunately, they could do their jobs as engineers and scientists a lot better if they did know more statistics. To me, it's a fundamental conundrum, and no one is to blame. It's just the reality, but it is the source for all kinds of frustrations on both sides of the statistical divide, which both you and Roger expressed in your own ways. . . . . __ [EMAIL PROTECTED] 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] Re: Thanks Frank, setting graph parameters, and why socialscientists don't use R
Medicine in the UK uses (or used, it's changing) the 'apprenticeship model' which in my case meant my own datasets (providing the motivation) the programme and its supporting written documentation (SPSS manuals double as quite good statistical textbooks, so I could link the concepts to the software) and various supervisors and referees (providing ego-bruising feedback). I found the courses I attended distinctly unmemorable, no matter how ego-syntonic they were, largely because I didn't care about the sample datasets supplied. Other students I have known and taught/supervised report similar experiences. __ [EMAIL PROTECTED] 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] function(...) {}
Luis Rideau Cruz Luisr at frs.fo writes: R-help Assignments within functions are local and temporary,right?(function 1) If arguments to another function (function 2) are objects created in function 1 and need to call function 2,,,then it won't work,Am i right? I have nested the functions but still do not work. How can this (it may be simple but I don' know how to get around this) be done?? Try this: f1 - function() { f2 - function(x) assign(as.character(substitute(x)), x+1, parent.frame()) z - 1 f2(z) z # x has value } f1() # 2 # Actually, you don't have to nest them since parent.frame refers to the # environment of the caller: f2 - function(x) assign(as.character(substitute(x)), x+1, parent.frame()) f1 - function() { z - 1 f2(z) z # x has value } f1() # 2 __ [EMAIL PROTECTED] 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] all.equal and names?
On Wed, 18 Aug 2004 10:27:49 -0400, Spencer Graves [EMAIL PROTECTED] wrote : How can I compare two objects for structure, names, values, etc.? With R 1.9.1 under Windows 2000, the obvious choice all.equal ignores names and compares only values: all.equal(1, c(a=1)) [1] TRUE Under S-Plus 6.2, I get the comparison I expected: all.equal(1, c(a = 1)) [1] target, current classes differ: integer : named [2] class of target is \integer\, class of current is \named\ (coercing current to class of target) If you want the explanation you're out of luck, but identical() does the test: identical(1, c(a = 1)) [1] FALSE Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] downloading the R program
I am trying to download the R program, but am having trouble. I have read through the instructions, but do not seem to be able to do it properly. Can you tell me the step-by-step instructions? Joanne L. Butler, Post-doctoral Fellow Equity and Technology Research Project c/o Department of Sociology Acadia University Wolfville, N.S. B4P 2R6 phone (902) 585-1535 fax (902) 585-1769 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Xtable method for coxph, bug?
Hi There is a xtable method for coxph. It bombs, however, when applied to my coxph object. It cannot find 'nse' which I think is sqrt(diag(coxph.object$naive.var)). Adding 'nse' to the coxph object cures the problem. Is this a bug in xtable.coxph? There is no xtable method for summary.coxph. How can I access the result of summary(coxph.object) so that I can create a matrix object for which there is an xtable method? Thanks Alex Alex Hanke Department of Fisheries and Oceans St. Andrews Biological Station 531 Brandy Cove Road St. Andrews, NB Canada E5B 2L9 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] 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] downloading the R program
Joanne Butler wrote: I am trying to download the R program, but am having trouble. I have read through the instructions, but do not seem to be able to do it properly. Can you tell me the step-by-step instructions? Either look at http://cran.r-project.org/ or read the R Installation and Administration manual for more information, it is available at the page mentioned above. Uwe Ligges Joanne L. Butler, Post-doctoral Fellow Equity and Technology Research Project c/o Department of Sociology Acadia University Wolfville, N.S. B4P 2R6 phone (902) 585-1535 fax (902) 585-1769 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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] downloading the R program
What difficulties, instruction and operating system are you talking about ? 1. Go to www.r-project.org 2. Click on CRAN under downloads 3. Choose a mirror 4. Go to pre-compiled binaries and select your OS 5. If windows, choose base and right click and save on the exe file On Wed, 2004-08-18 at 15:48, Joanne Butler wrote: I am trying to download the R program, but am having trouble. I have read through the instructions, but do not seem to be able to do it properly. Can you tell me the step-by-step instructions? Joanne L. Butler, Post-doctoral Fellow Equity and Technology Research Project c/o Department of Sociology Acadia University Wolfville, N.S. B4P 2R6 phone (902) 585-1535 fax (902) 585-1769 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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] downloading the R program
I am not sure which platform you are on. However, if you go to CRAN (cran.us.r-project.org/) you should be able to get step-by-step instruction. Please read the posting guide. It can answer a lot of questions for you. HTH, Partha Joanne Butler [EMAIL PROTECTED] Sent by: [EMAIL PROTECTED] 08/18/2004 11:48 AM To: [EMAIL PROTECTED] cc: Subject:[R] downloading the R program I am trying to download the R program, but am having trouble. I have read through the instructions, but do not seem to be able to do it properly. Can you tell me the step-by-step instructions? Joanne L. Butler, Post-doctoral Fellow Equity and Technology Research Project c/o Department of Sociology Acadia University Wolfville, N.S. B4P 2R6 phone (902) 585-1535 fax (902) 585-1769 [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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] table and getting rownames
exactly what i needed thanks a lot soren - Original Message - From: Peter Dalgaard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: R-help [EMAIL PROTECTED] Sent: Tuesday, August 17, 2004 2:35 PM Subject: Re: [R] table and getting rownames [EMAIL PROTECTED] writes: hi there say that i have this table x-table(adoc, oarb) x oarb 0 1 adoc ab1 0 am5 1 ba 14 1 cc 271 3 ch 87 2 dz 362 6 fl7 0 fs 84 2 is there an easy way to get the row names or row numbers of rows with oarb==0 i.e. (ab, fl) or (1, 7) Something like which(x[,1]==0) rownames(x)[x[,1]==0] -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] 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] survdiff
On Tue, 17 Aug 2004, Peter Dalgaard wrote: You really need to read a theory book for this, but here's the basic idea: V is the theoretical variance of O-E for the first group. If O-E is approximately normally distributed, as it will be in large samples, then (O-E)^2/V will be approximately chi-squared distributed on 1 DF. In *other* models, notably those for contingency tables, the same idea works out as the familiar sum((O-E)^2/E) formula. That formula has historically been used for the logrank test too, and it still appears in some textbooks, but as it turns out, it is not actually correct (although often quite close). You don't necessarily need a theory book --- sufficiently old biostat textbooks may have this. For example, Fisher van Belle (1993) Biostatistics: a methodology for the health sciences gives both formulas and explains that the simpler one is a useful approximation for hand calculation, with a worked example. Now that we have computers no-one needs to use the approximation, and most of that information has been taken out of the second edition. -thomas __ [EMAIL PROTECTED] 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] Revert a factor to its numeric values
On Wed, 18 Aug 2004, Göran Broström wrote: I'm trying a recommendation on the help page for 'factor': x - c(1, 2, 1, 2) x - factor(x, labels = c(one, two)) x [1] one two one two Levels: one two as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion usually when people want to revert a factor to its numeric values they mean that the labels are numbers and they want those numbers. In that case as.numeric(x) or unclass(x) are wrong because they give you the underlying codes. You, somewhat unusually, actually want the underlying codes, which you get with unclass(x). -thomas __ [EMAIL PROTECTED] 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] all.equal and names?
Hi, Duncan: Thanks much. I think I remember reading about both all.equal and identical in Venables and Ripley (2002) MASS. Unfortunately, I don't have MASS handy now, and I could not find it otherwise, so I asked. What needs to happen to upgrade the all.equal documentation to add identical to the see also? Best Wishes, Spencer Duncan Murdoch wrote: On Wed, 18 Aug 2004 10:27:49 -0400, Spencer Graves [EMAIL PROTECTED] wrote : How can I compare two objects for structure, names, values, etc.? With R 1.9.1 under Windows 2000, the obvious choice all.equal ignores names and compares only values: all.equal(1, c(a=1)) [1] TRUE Under S-Plus 6.2, I get the comparison I expected: all.equal(1, c(a = 1)) [1] target, current classes differ: integer : named [2] class of target is \integer\, class of current is \named\ (coercing current to class of target) If you want the explanation you're out of luck, but identical() does the test: identical(1, c(a = 1)) [1] FALSE Duncan Murdoch __ [EMAIL PROTECTED] 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] all.equal and names?
It is in the Description now (at least for 1.9.1 patched): all.equal(x,y) is a utility to compare R objects x and y testing near equality. If they are different, comparison is still made to some extent, and a report of the differences is returned. Don't use all.equal directly in if expressionseither use identical or combine the two, as shown in the documentation for identical. There is also a reference to: attr.all.equal(target, current, ...) on the same help page, which returns the following using the example: attr.all.equal(1, c(a=1)) [1] names for current but not for target Not quite the same message as S-PLUS however. HTH, Marc On Wed, 2004-08-18 at 11:02, Spencer Graves wrote: Hi, Duncan: Thanks much. I think I remember reading about both all.equal and identical in Venables and Ripley (2002) MASS. Unfortunately, I don't have MASS handy now, and I could not find it otherwise, so I asked. What needs to happen to upgrade the all.equal documentation to add identical to the see also? Best Wishes, Spencer Duncan Murdoch wrote: On Wed, 18 Aug 2004 10:27:49 -0400, Spencer Graves [EMAIL PROTECTED] wrote : How can I compare two objects for structure, names, values, etc.? With R 1.9.1 under Windows 2000, the obvious choice all.equal ignores names and compares only values: all.equal(1, c(a=1)) [1] TRUE Under S-Plus 6.2, I get the comparison I expected: all.equal(1, c(a = 1)) [1] target, current classes differ: integer : named [2] class of target is \integer\, class of current is \named\ (coercing current to class of target) If you want the explanation you're out of luck, but identical() does the test: identical(1, c(a = 1)) [1] FALSE Duncan Murdoch __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Memory Problems in R
Hello everyone - I have a couple of questions about memory management of large objects. Thanks in advance for your response. I'm running R version 1.9.1 on solaris 8, compiled as a 32 bit app. My system has 12.0 GB of memory, with usually ~ 11GB free. I checked system limits using ulimit, and there is nothing set that would limit the maximum amount of memory for a process (with the exception of an 8MB stack size). I've also checked the amount of memory available to R using mem.limits(), and there is no limit set. I'm running into two problems. The first is the error cannot allocate vector of size X - I know this has been discussed several times on this mailing list, but it usually seems the user does not have enough memory on their system, or does not have the memory limits set correctly. I don't believe this is the case in this situation. I verified that I don't have any objects in memory when R starts up, and that memory limits are set to NA. Here is some output: ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 v-rep(0,268435431) Error: cannot allocate vector of size 2097151 Kb v-rep(0,268435430) object.size(v) [1] 2147483468 gc() used (Mb) gc trigger (Mb) Ncells432214 11.6 741108 19.8 Vcells 268552029 2048.9 268939773 2051.9 Does R have a limit set on the size of an object that it will allocate? I know that the entire application will only be able to use 4GB of memory (because it's only 32bit), but I haven't found anything in the R documentation or the help lists that indicates there is maximum on the size of an object. I understand there will be problems if an object is greater than 2GB and needs to be copied - but will R limit the creation of such an object? It's also my understanding that the garbage collector won't move objects and this may cause memory to become fragmented - but I'm seeing these issues on startup when there are no objects in memory. My second problem is with matrices and the garbage collector, and the limits it sets for gc trigger after a matrix is created. When I create a vector of approximately 500MB, R sets the gc trigger to be slightly above this amount. The gc trigger also seems to correspond to the process size (as output by top). When I create a matrix of approximately 500MB, R sets the gc trigger to be roughly 3 times the size of the matrix (and the process size is ~ 1.5GB). Therefor, when I try to create larger matrices, where 3x the size of the matrix is greater than 4GB, R gives me an error. Is there anything I can do to create large matrices? Or do I have to manipulate large objects as a vector? Output from the 3 different scenarios is below: 1) - can't create a matrix, but can create a vector [Previously saved workspace restored] m-matrix(rep(0,25000*1),nrow=1) Error: cannot allocate vector of size 1953125 Kb v-rep(0,25000*1) object.size(v)/1024 [1] 1953125 2) gc trigger is set slightly higher than the size of the vector ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 v-rep(0,(2510)*(25000)) object.size(v) [1] 5.02e+08 gc() used (Mb) gc trigger (Mb) Ncells 432210 11.6 667722 17.9 Vcells 62866589 479.7 63247172 482.6 3) gc trigger is set ~ 3x the size of the matrix ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 A-matrix(rep(0,(2510)*(25000)),nrow=(2510),ncol=(25000)) object.size(A) [1] 502000120 gc() used (Mb) gc trigger (Mb) Ncells 432213 11.6 741108 19.8 Vcells 62866590 479.7 188640940 1439.3 __ [EMAIL PROTECTED] 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] Memory Problems in R
There is a limit on how long a single vector can be, and I think it's 2GB (even on 64-bit platforms). Not sure on how the gc trigger is set -roger Scott Gilpin wrote: Hello everyone - I have a couple of questions about memory management of large objects. Thanks in advance for your response. I'm running R version 1.9.1 on solaris 8, compiled as a 32 bit app. My system has 12.0 GB of memory, with usually ~ 11GB free. I checked system limits using ulimit, and there is nothing set that would limit the maximum amount of memory for a process (with the exception of an 8MB stack size). I've also checked the amount of memory available to R using mem.limits(), and there is no limit set. I'm running into two problems. The first is the error cannot allocate vector of size X - I know this has been discussed several times on this mailing list, but it usually seems the user does not have enough memory on their system, or does not have the memory limits set correctly. I don't believe this is the case in this situation. I verified that I don't have any objects in memory when R starts up, and that memory limits are set to NA. Here is some output: ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 v-rep(0,268435431) Error: cannot allocate vector of size 2097151 Kb v-rep(0,268435430) object.size(v) [1] 2147483468 gc() used (Mb) gc trigger (Mb) Ncells432214 11.6 741108 19.8 Vcells 268552029 2048.9 268939773 2051.9 Does R have a limit set on the size of an object that it will allocate? I know that the entire application will only be able to use 4GB of memory (because it's only 32bit), but I haven't found anything in the R documentation or the help lists that indicates there is maximum on the size of an object. I understand there will be problems if an object is greater than 2GB and needs to be copied - but will R limit the creation of such an object? It's also my understanding that the garbage collector won't move objects and this may cause memory to become fragmented - but I'm seeing these issues on startup when there are no objects in memory. My second problem is with matrices and the garbage collector, and the limits it sets for gc trigger after a matrix is created. When I create a vector of approximately 500MB, R sets the gc trigger to be slightly above this amount. The gc trigger also seems to correspond to the process size (as output by top). When I create a matrix of approximately 500MB, R sets the gc trigger to be roughly 3 times the size of the matrix (and the process size is ~ 1.5GB). Therefor, when I try to create larger matrices, where 3x the size of the matrix is greater than 4GB, R gives me an error. Is there anything I can do to create large matrices? Or do I have to manipulate large objects as a vector? Output from the 3 different scenarios is below: 1) - can't create a matrix, but can create a vector [Previously saved workspace restored] m-matrix(rep(0,25000*1),nrow=1) Error: cannot allocate vector of size 1953125 Kb v-rep(0,25000*1) object.size(v)/1024 [1] 1953125 2) gc trigger is set slightly higher than the size of the vector ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 v-rep(0,(2510)*(25000)) object.size(v) [1] 5.02e+08 gc() used (Mb) gc trigger (Mb) Ncells 432210 11.6 667722 17.9 Vcells 62866589 479.7 63247172 482.6 3) gc trigger is set ~ 3x the size of the matrix ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 A-matrix(rep(0,(2510)*(25000)),nrow=(2510),ncol=(25000)) object.size(A) [1] 502000120 gc() used (Mb) gc trigger (Mb) Ncells 432213 11.6 741108 19.8 Vcells 62866590 479.7 188640940 1439.3 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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] Memory Problems in R
On Wed, 18 Aug 2004, Roger D. Peng wrote: There is a limit on how long a single vector can be, and I think it's 2GB (even on 64-bit platforms). Not sure on how the gc trigger is set There is a limit of R_SIZE_T_MAX bytes, but that is defined as ULONG_MAX which should be 4GB-1 on a 32-bit platform, and much more on a 64-bit platform. The example works on a 64-bit platform, which demonstrates that there is no 2GB limit there. If you hit the length limit, the message is of the form cannot allocate vector of length ... Looking at the code in memory.c it seems that if (size = (LONG_MAX / sizeof(VECREC)) - sizeof(SEXPREC_ALIGN) || (s = malloc(sizeof(SEXPREC_ALIGN) + size * sizeof(VECREC))) == NULL) { /* reset the vector heap limit */ R_VSize = old_R_VSize; errorcall(R_NilValue, cannot allocate vector of size %lu Kb, (size * sizeof(VECREC))/1024); } has a limit of LONG_MAX bytes for a vector. I think that is unintentional, and you might like to try ULONG_MAX there and re-compile. But it really doesn't make much difference as there is very little you can do with an object taking up more than half the maximum memory size except access bits of it (and that is what DBMSes are for). A few comments: 1) Of course R does have objects in memory, 12.5Mb of them according to gc. You are not starting with a clean slate. Hopefully malloc has allocated them in a compact group. 2) Solaris has been a 64-bit OS for at least 7 years and you really should be using a 64-bit build of R if you plan on exceeding 1Gb. 3) To create a matrix efficiently, create a vector and assign a dim. I gave an example on R-help yesterday, so please check the archives. matrix() makes a copy of the data and so needs double the space you are thinking it does. Take a look at the source code: PROTECT(snr = allocMatrix(TYPEOF(vals), nr, nc)); if(lendat) { if (isVector(vals)) copyMatrix(snr, vals, byrow); else copyListMatrix(snr, vals, byrow); 4) The source code is the documentation here. I suspect no one person knows all the details. Scott Gilpin wrote: Hello everyone - I have a couple of questions about memory management of large objects. Thanks in advance for your response. I'm running R version 1.9.1 on solaris 8, compiled as a 32 bit app. My system has 12.0 GB of memory, with usually ~ 11GB free. I checked system limits using ulimit, and there is nothing set that would limit the maximum amount of memory for a process (with the exception of an 8MB stack size). I've also checked the amount of memory available to R using mem.limits(), and there is no limit set. I'm running into two problems. The first is the error cannot allocate vector of size X - I know this has been discussed several times on this mailing list, but it usually seems the user does not have enough memory on their system, or does not have the memory limits set correctly. I don't believe this is the case in this situation. I verified that I don't have any objects in memory when R starts up, and that memory limits are set to NA. Here is some output: ls() character(0) mem.limits() nsize vsize NANA gc() used (Mb) gc trigger (Mb) Ncells 432197 11.6 531268 14.2 Vcells 116586 0.9 786432 6.0 v-rep(0,268435431) Error: cannot allocate vector of size 2097151 Kb v-rep(0,268435430) object.size(v) [1] 2147483468 gc() used (Mb) gc trigger (Mb) Ncells432214 11.6 741108 19.8 Vcells 268552029 2048.9 268939773 2051.9 Does R have a limit set on the size of an object that it will allocate? I know that the entire application will only be able to use 4GB of memory (because it's only 32bit), but I haven't found anything in the R documentation or the help lists that indicates there is maximum on the size of an object. I understand there will be problems if an object is greater than 2GB and needs to be copied - but will R limit the creation of such an object? It's also my understanding that the garbage collector won't move objects and this may cause memory to become fragmented - but I'm seeing these issues on startup when there are no objects in memory. My second problem is with matrices and the garbage collector, and the limits it sets for gc trigger after a matrix is created. When I create a vector of approximately 500MB, R sets the gc trigger to be slightly above this amount. The gc trigger also seems to correspond to the process size (as output by top). When I create a matrix of approximately 500MB, R sets the gc trigger to be roughly 3 times the size of the matrix (and the process size is ~ 1.5GB). Therefor, when I try to create larger matrices, where 3x the
[R] labeled break statements in R?
Hi, Are there labeled break statements in R? i.e., something along the lines of TOPLOOP: for(i in 1:m) { for(j in 1:n) { ... if(condition) { break TOPLOOP } } } Thanks, Roger __ [EMAIL PROTECTED] 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] Does anybody runs R on the hp ML 370 or ML570 servers?
From: Prof Brian Ripley On Mon, 16 Aug 2004, Li, Aiguo (NIH/NCI) wrote: I am trying to buy a hp server to run R and to complete some other tasks with limited bugets. The r-project.org site recommended that R will run on hppa-hp-hpux. I don't think they are _recommended_ there. However this system is out of our buget and ML system from hp is much cheaper. Is there anybody running R on ML370 or ML 570 systems? If you can provide me with some other information related that will be appreciated. Those are just Xeon processors in a standard Wintel box. What OS? (They run Linux, Solaris, SCO Unix, Windows ) I believe one of ours is a ML530 (dual Xeon 2.4 GHz). We've been putting Mandrake on it (currently 9.0; have not had a chance to upgrade yet). Had no problem running/compiling R at all. For a limited budget, IMHO these are hardly a good choice. We got our first dual Opterons with twice the RAM (but IDE instead of SCSI HDD) at around the same price as the Compaq/HP, and that Opteron-based box will run rings around the Compaq. Andy -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] calling R from Perl
Hello, I am trying to call R from Perl running on Windows 2000. I have looked through the previous posts regarding running R from Perl and all have referred to the RSPerl package at Omegahat. Unfortunately the documentation for this package specifically states that it only works in Unix at the moment. Does anyone else have any suggestions about the best way to do this in the Windows environment? Thanks Clive __ [EMAIL PROTECTED] 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] labeled break statements in R?
On 18 Aug 2004, Roger Levy wrote: Are there labeled break statements in R? i.e., something along the lines of TOPLOOP: for(i in 1:m) { for(j in 1:n) { ... if(condition) { break TOPLOOP } } } No, but if you find yourself using nested for loops it is very likely that you are not thinking in the right way for a vector language. R does have a `R Language Definition' manual. It's long been an unfinished draft but it is not so incomplete as to omit reserved words. It and the S reference books are the places to research questions like this. -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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]...Why social scientists don't use R
Berton Gunter has written in part: A few comments: First, your remarks are interesting and, I would say, mainly well founded. However, I think they are in many respects irrelevant, although they do point to the much bigger underlying issue, which Roger Peng also hinted at in his reply. I think they are sensible because R IS difficult; the documentation is often challenging, which is not surprising given (a) the inherent complexity of R; (b) the difficulty in writing good documentation, especially when many of the functions being documented are inherently technical, so subject matter knowledge (CS, statistics, numerical analysis ,...) must be assumed; My experience has been that the real challenge is not understanding the documentation, but finding it. Once I know the names of one or more candidate functions I am happily on my way. One of the delights of reading r-help is that one keeps discovering useful functions. In the best of all possible worlds I could ask an intelligent agent to summon up the k-nearest neighbor functions that would do X. Not likely. Years ago StatSci Europe published a handy little Complete Listing of S-PLUS Functions, categorized in some way. I found it useful. Something similar for R would not go amiss. I know, it would want to be 420 pages rather than 42. ** Cliff Lunneborg, Professor Emeritus, Statistics Psychology, University of Washington, Seattle [EMAIL PROTECTED] __ [EMAIL PROTECTED] 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]...Why social scientists don't use R
On Wed, 18 Aug 2004 12:16:21 -0700, Cliff Lunneborg [EMAIL PROTECTED] wrote : Years ago StatSci Europe published a handy little Complete Listing of S-PLUS Functions, categorized in some way. I found it useful. Something similar for R would not go amiss. I know, it would want to be 420 pages rather than 42. The R Reference manual does this for the base packages. The HTML help pages come sort of close for other packages, though they're on a separate page for each package. If you really want it all in one place, it would presumably be fairly easy to modify the code that produces those and have everything appear on one big page, or write a script that glued together all the RHOME/library/html/00Index.html files. Duncan Murdoch __ [EMAIL PROTECTED] 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] calling R from Perl
Clive, Have a look at Statistics::R (http://search.cpan.org/~gmpassos/Statistics-R-0.02). I'm not sure if it works well with Windows, but it is the only other option that I know of to work directly with the R-interpreter. However, you can always create a batch file and write it to a file and then call R. Sean On Aug 18, 2004, at 3:09 PM, Clive Glover wrote: Hello, I am trying to call R from Perl running on Windows 2000. I have looked through the previous posts regarding running R from Perl and all have referred to the RSPerl package at Omegahat. Unfortunately the documentation for this package specifically states that it only works in Unix at the moment. Does anyone else have any suggestions about the best way to do this in the Windows environment? Thanks Clive __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] 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]...Why social scientists don't use R
On 08/18/04 12:16, Cliff Lunneborg wrote: My experience has been that the real challenge is not understanding the documentation, but finding it. Once I know the names of one or more candidate functions I am happily on my way. One of the delights of reading r-help is that one keeps discovering useful functions. In the best of all possible worlds I could ask an intelligent agent to summon up the k-nearest neighbor functions that would do X. I have found the HtDig search engine at my site (accessible through Search on the left side of the main R page, or directly as http://finzi.psych.upenn.edu) to be pretty useful in this regard, although it is a long way from artificial intelligence, which would recognize similar meanings. It fails for me mostly when different disciplines have different names for the same thing. (Economists hate to admit that many of the statistical ideas they use were invented/discovered by psychologists.) That said, I'm thinking of switching to the Xapian search engine (http://www.redhat.com/archives/fedora-devel-list/2004-July/msg01576.html), and I would welcome any opinions about it. HtDig is a pain; only one version of it (an old one) seems to work on Fedora Core 2, and it now takes almost 10 hours to update each month on a very fast computer (Pentium 4 2.80GHz with Serial ATA disk controller). Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron __ [EMAIL PROTECTED] 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]...Why social scientists don't use R
On Wed, 18 Aug 2004, Cliff Lunneborg wrote: Berton Gunter has written in part: A few comments: First, your remarks are interesting and, I would say, mainly well founded. However, I think they are in many respects irrelevant, although they do point to the much bigger underlying issue, which Roger Peng also hinted at in his reply. I think they are sensible because R IS difficult; the documentation is often challenging, which is not surprising given (a) the inherent complexity of R; (b) the difficulty in writing good documentation, especially when many of the functions being documented are inherently technical, so subject matter knowledge (CS, statistics, numerical analysis ,...) must be assumed; My experience has been that the real challenge is not understanding the documentation, but finding it. Once I know the names of one or more candidate functions I am happily on my way. One of the delights of reading r-help is that one keeps discovering useful functions. In the best of all possible worlds I could ask an intelligent agent to summon up the k-nearest neighbor functions that would do X. Not likely. help.search does a better job than it is given credit for. Years ago StatSci Europe published a handy little Complete Listing of S-PLUS Functions, categorized in some way. I found it useful. Something similar for R would not go amiss. I know, it would want to be 420 pages rather than 42. What is R in this context? There are several hundred addons on CRAN, BioC and elsewhere. R's HTML search or help.search will give you a complete listing over installed packages by `keyword', which is what the `Complete Listing of S-PLUS Functions' I saw was about. Windows users should try the full-text searches in CHM help, especially for package stats. The problem is to know what to search for. To pick a recent example, to use `logistic-normal model' for a random-intercept GLMM is not going to work, but Googling will usually bring up synonyms. -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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] Incremental operator
Hi group, I am trying to get the LocusID numbers from my affy expression matrix. I instantiated rownames function to get an object with all the probe IDs. where.affy.at - rownames(gliexp) Now I wanted to get another object with the LocusIDs in it like the following. However, I get the following error. How come i = i +1 is not considered as incrementation here. I know there is some trouble in defining. I come from Python background so I am stuck. Could any one help me please. for (i in where.affy.at){ + gene.locusid.affy - get(i,env= hgu95av2LOCUSID) + i = i + 1 + gene.locusid.affy + } Error in i + 1 : non-numeric argument to binary operator Thank you. PS __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] paired t-test vs pairwise t-test
What's the difference between t.test(x, y) and pairwise.t.test()? Is it just that the former takes two vectors, whereas the latter takes a vector and a factor? __ [EMAIL PROTECTED] 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] Incremental operator
What is gliexp? str(gliexp) would have been useful information to give. Assuming it is an R matrix, the rownames are _names_, not numbers. Surely in all languages with for loops it is bad idea to manipulate the loop index inside the loop, but you definitely cannot do arithmetic on character strings. R does have debugging facilities and it would be a good idea to get used to them. options(error=dump.frames) ... some work debugger() choose an environment i -- will tell you what it is. On Wed, 18 Aug 2004, S Peri wrote: I am trying to get the LocusID numbers from my affy expression matrix. I instantiated rownames function to get an object with all the probe IDs. where.affy.at - rownames(gliexp) Now I wanted to get another object with the LocusIDs in it like the following. However, I get the following error. How come i = i +1 is not considered as incrementation here. I know there is some trouble in defining. I come from Python background so I am stuck. Could any one help me please. for (i in where.affy.at){ + gene.locusid.affy - get(i,env= hgu95av2LOCUSID) + i = i + 1 + gene.locusid.affy + } Error in i + 1 : non-numeric argument to binary operator -- Brian D. Ripley, [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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] paired t-test vs pairwise t-test
Jack Tanner [EMAIL PROTECTED] writes: What's the difference between t.test(x, y) and pairwise.t.test()? Is it just that the former takes two vectors, whereas the latter takes a vector and a factor? No. You might try reading the help pages and run the examples there... -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] distance to cluster center
Is there a way to get the distance between each point and the center of the cluster it was assigned to in cluster methods such as agnes, pam, and clara. Thanks! - Moises [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] header line generated write.table
I want to write following data frame into a CSV file: Col1 Col2 Col3 Row1 1 1 1 Row2 2 2 2 where Row1, Row2 are the row names and Col1, Col2, Col3 are the column names. The correct CSV file should be: ,Col1,Col2,Col3 Row1,1,1,1 Row2,2,2,2 However, the one generated by R using write.table(x, file=xyz.csv, sep=,) has a header line that reads: Col1,Col2,Col3 without the comma at the very beginning. As a result, if you open the file in Excel, the column names are not correct (shifted to the left by one column). Is there a way to get around this? Thanks! - [[alternative HTML version deleted]] __ [EMAIL PROTECTED] 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] calling R from Perl
On Wed, Aug 18, 2004 at 03:44:04PM -0400, Sean Davis wrote: Clive, Have a look at Statistics::R (http://search.cpan.org/~gmpassos/Statistics-R-0.02). I'm not sure if it works well with Windows, but it is the only other option that I know of to work directly with the R-interpreter. However, you can always create a batch file and write it to a file and then call R. Or you can pipe to R from Perl, and collect the results from the same (two-way) pipe. Tedious to write, but reliable once setup. Should work on Windoze too. For a concrete example, here is a part of something I did last month: my $pid = open2(*READ_R, *WRITE_R, 'R', '--slave', '--silent'); print WRITE_R stopifnot(require(reposTools, quiet=TRUE)) [... more R commands ...] q('no') ; while ($line = READ_R) { chomp $line; print [$line]\n if $debug; [... more Perl commands ...] } close(WRITE_R); close(READ_R); You need to be careful about quoting: I used outer and inner '' for strings which works. You also need to escape the $ used to access data.frame elements, or Perl will try to expand it. Data transfer to and fro is a bit an issue -- here I simply printed as csv-style file to stdout, and read it in Perl. Quick and dirty. Statistics::R is much closer to this paradigm than to RSPerl. RSPerl is promising, but, alas, like so many things on omegahat not quite finished. Dirk Sean On Aug 18, 2004, at 3:09 PM, Clive Glover wrote: Hello, I am trying to call R from Perl running on Windows 2000. I have looked through the previous posts regarding running R from Perl and all have referred to the RSPerl package at Omegahat. Unfortunately the documentation for this package specifically states that it only works in Unix at the moment. Does anyone else have any suggestions about the best way to do this in the Windows environment? Thanks Clive __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Those are my principles, and if you don't like them... well, I have others. -- Groucho Marx __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Gee
I am trying to learn the gee function in R. So I try to generate some data and use this function. I have the following lines: Gee # Generating lny=10+2*Si-Si^2+eta # eta ~ N(0,1) # Si ~ U(0,11) eta - vector(mode=numeric,100) eta - rnorm(100) Si - vector(mode=numeric,100) Si - runif(100, min=0, max=11) lny - vector(mode=numeric,100) lny - 10+2*Si-Si^2+eta id - vector(mode=numeric,100) id - (1:100) cons - vector(mode=numeric,100) for(i in 1:100) { cons[i] - 1 } Si2 - vector(mode=numeric,100) for(j in 1:100) { Si2[j] - Si[j]^2 } geedat - data.frame(Si=Si,Si2=Si2,lny=lny,id=id,cons=cons) lnyhat - gee(lny~cons+Si-Si2, id=id, data=geedat, na.action) And I received the following error message: [1] Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27 Error in [.data.frame(structure(list(lny = c (9.92388214744737, 2.54332321404939, : invalid subscript type I don't know what I am doing wrong. May someone help me? Thanks Ana __ [EMAIL PROTECTED] 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] header line generated write.table
On Wed, 2004-08-18 at 16:42, Y C Tao wrote: I want to write following data frame into a CSV file: Col1 Col2 Col3 Row1 1 1 1 Row2 2 2 2 where Row1, Row2 are the row names and Col1, Col2, Col3 are the column names. The correct CSV file should be: ,Col1,Col2,Col3 Row1,1,1,1 Row2,2,2,2 However, the one generated by R using write.table(x, file=xyz.csv, sep=,) has a header line that reads: Col1,Col2,Col3 without the comma at the very beginning. As a result, if you open the file in Excel, the column names are not correct (shifted to the left by one column). Is there a way to get around this? Thanks! The solution is on the help page for ?write.table: Details Normally there is no column name for a column of row names. If col.names=NA a blank column name is added. This can be used to write CSV files for input to spreadsheets. Also, the first example on that page gives you: ## To write a CSV file for input to Excel one might use write.table(x, file = foo.csv, sep = ,, col.names = NA) Thus: write.table(x, col.names = NA, sep = ,) ,Col1,Col2,Col3 Row1,1,1,1 Row2,2,2,2 HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How do I add rows to a table?
if I read from 1 file: inp1 - scan(data1,list(0,0)) inp2 - scan(data2,list(0,0)) allInp - c(inp1,inp2) I get a table with 4 columns. How can I get a table with 2 columns and more rows? __ [EMAIL PROTECTED] 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] How do I add rows to a table?
Hi, On Wed, 18 Aug 2004, Beverly Seavey wrote: inp1 - scan(data1,list(0,0)) inp2 - scan(data2,list(0,0)) allInp - c(inp1,inp2) I get a table with 4 columns. If I understand you correctly... Have you tried cbind()? Cheers, Kevin Ko-Kang Kevin Wang PhD Student Centre for Mathematics and its Applications Building 27, Room 1004 Mathematical Sciences Institute (MSI) Australian National University Canberra, ACT 0200 Australia Homepage: http://wwwmaths.anu.edu.au/~wangk/ Ph (W): +61-2-6125-2431 Ph (H): +61-2-6125-7407 Ph (M): +61-40-451-8301 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Do you know if you can map a large minmum spanning tree in R?
Do you know if you can map in R? I have my minimum spanning tree, but as there are 1371 nodes (all over Australia) I'd like to be able to graph them as they actually would be on the map. Do you know if this is possible? __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Getting data loaded
Hi, I have been informed of a bug in the concord package, in that the data files containing the tabulated critical values for Kendall's W are not loaded on the command library(concord). I had assumed that the lines in install.R would correspond to the commands to load data in R, e.g. data(Wcrit01) data(Wcrit05) While these work on the command line, I get the errors: library(concord) Warning messages: 1: Data set 'Wcrit01' not found in: data(Wcrit01) 2: Data set 'Wcrit05' not found in: data(Wcrit05) The section on this in R-exts doesn't seem to have any information on how to write the lines in install.R, nor does Checking and Building Packages. I managed to locate a few install.R files in other packages, but they were all empty. Any hints? Jim Dr Jim Lemon Research Psychologist Health Psychology Unit University of Technology, Sydney Feel free to ignore any garbage beneath this line. -- DISCLAIMER: This email message and any accompanying attachme...{{dropped}} __ [EMAIL PROTECTED] 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] Do you know if you can map a large minmum spanning tree in R?
At 09:47 AM 8/19/2004, Briggs, Meredith M wrote: Do you know if you can map in R? I have my minimum spanning tree, but as there are 1371 nodes (all over Australia) I'd like to be able to graph them as they actually would be on the map. Do you know if this is possible? You can certainly map in R. Depending on the coordinate system of your data . . . but, e.g. - if it's lat/lon - perhaps the easiest way is to install the maps package and you can add the continental outlines to an existing plot: ## display nodes code here . . . library(maps) map('world',add=T,xlim=c(109,157),ylim=c(-47,-7)) There are plenty of other options, if you have your own map data (or want to use another source). Feel free to provide more detail about your current plotting methods and coordinate system. Also, the package mapdata contains a high resolution continental dataset -worldHires Hope that helps, Mike. ### Michael Sumner - PhD. candidate Maths and Physics (ACE CRC IASOS) and Zoology (AWRU) University of Tasmania Private Bag 77, Hobart, Tas 7001, Australia Phone: 6226 1752 __ [EMAIL PROTECTED] 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] all.equal and names?
On Wed, 18 Aug 2004 12:02:02 -0400, Spencer Graves [EMAIL PROTECTED] wrote: Hi, Duncan: Thanks much. I think I remember reading about both all.equal and identical in Venables and Ripley (2002) MASS. Unfortunately, I don't have MASS handy now, and I could not find it otherwise, so I asked. What needs to happen to upgrade the all.equal documentation to add identical to the see also? I just did it. It was there in the text, but should also have been in see-also. In general to get something added to the docs, the best way is to collect a few similar things, classify them as doc errors, suggested improvements, etc, and post them to R-devel (if you're not sure they'll be accepted) or to R-bugs (if they are sure things). It's definitely best to submit suggested replacement text. Duncan Murdoch __ [EMAIL PROTECTED] 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] Do you know if you can map a large minimum spanning tree in R?
Thanks Mike. My data has longitude and latitude coords and I used distAB {clim.pact} then mst {ape} to calculate my minimum spanning tree. The nodes are telecoms sites from all over Australia. My goal is to determine the minimum cost of linking them via cabling, and I'm starting by calculating the distance as the crow flies, but will probably eventually need to calculate the rectilinear distances also. I am a very newbie user of R, but have had experience with other stats/programming software such as SAS, however no longer have access to SAS so I've turned to R. I also have tried using MapInfo with the data exported from R, but have found that not so intuitive to learn on the fly. Back to R - I'm using W2K, and have managed to graph the tree using plot(mdist,graph=nsca) where mdist is the output matrix from my mst command, however this is not terribly map-like, so I'm looking for a better display that can be embedded in a document. Any assistance gratefully received! Fiona. Fiona Wade Project Manager MARA FA Telstra Corporation Limited Tel: 03 9634 5674 Fax: 03 9634 2874 Email: [EMAIL PROTECTED] The information contained in this e-mail message may be confidential. If you are not the intended recipient, any use of, interference with, disclosure or copying of this material is unauthorised and prohibited. If you have received this message in error, please notify me by reply e-mail and then delete the message. -Original Message- From: Michael Sumner [mailto:[EMAIL PROTECTED] Sent: Thursday, 19 August 2004 10:18 AM To: Briggs, Meredith M; [EMAIL PROTECTED] Cc: Wade, Fiona M Subject: Re: [R] Do you know if you can map a large minmum spanning tree in R? At 09:47 AM 8/19/2004, Briggs, Meredith M wrote: Do you know if you can map in R? I have my minimum spanning tree, but as there are 1371 nodes (all over Australia) I'd like to be able to graph them as they actually would be on the map. Do you know if this is possible? You can certainly map in R. Depending on the coordinate system of your data . . . but, e.g. - if it's lat/lon - perhaps the easiest way is to install the maps package and you can add the continental outlines to an existing plot: ## display nodes code here . . . library(maps) map('world',add=T,xlim=c(109,157),ylim=c(-47,-7)) There are plenty of other options, if you have your own map data (or want to use another source). Feel free to provide more detail about your current plotting methods and coordinate system. Also, the package mapdata contains a high resolution continental dataset -worldHires Hope that helps, Mike. ### Michael Sumner - PhD. candidate Maths and Physics (ACE CRC IASOS) and Zoology (AWRU) University of Tasmania Private Bag 77, Hobart, Tas 7001, Australia Phone: 6226 1752 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] glmmPQL in R and S-PLUS 6 - differing results
Greetings R-ers, A colleague and I have been exploring the behaviour of glmmPQL in R and S-PLUS 6 and we appear to get different results using the same code and the same data set, which worries us. I have checked the behaviour in R 1.7.1 (MacOS 9.2) and R. 1.9.0 (Windows 2000) and the results are the same, but differ from S-PLUS 6 with the latest Mass and nlme libraries (Windows XP). Here is the R output: fit - glmmPQL(cbind(alive, setup-alive)~ inout, random=~1|family, family=binomial, data=dat) Loading required package: nlme iteration 1 fit2 - glmmPQL(cbind(alive, setup-alive)~ 1, random=~1|family, family=binomial, data=dat) iteration 1 iteration 2 anova(fit) numDF denDF F-value p-value (Intercept) 117 4.711629 0.0444 inout 117 1.260877 0.2771 anova(fit2) numDF denDF F-value p-value (Intercept) 118 4.800814 0.0418 anova(fit, fit2) Model df AIC BIClogLik Test L.Ratio p-value fit 1 4 87.79085 94.12493 -39.89543 fit2 2 3 86.41927 91.16983 -40.20964 1 vs 2 0.628421 0.4279 Here is the S-PLUS output: m1 - glmmPQL(cbind(alive, setup - alive)~ inout, data=dat, random=~1|family, family = binomial) iteration 1 iteration 2 iteration 3 anova(m1) numDF denDF F-value p-value (Intercept) 117 3.859334 0.0660 inout 117 1.971763 0.1783 m2 - glmmPQL(cbind(alive, setup - alive) ~ 1, data = dat, random = ~ 1 | family, family = binomial) iteration 1 iteration 2 iteration 3 iteration 4 anova(m1, m2) Model df AIC BIClogLik Test L.Ratio p-value m1 1 4 87.00400 93.33808 -39.50200 m2 2 3 91.75447 96.50503 -42.87724 1 vs 2 6.75047 0.0094 Note that R and S-PLUS differ in the number of iterations. Also the logLikelihoods differ considerably too. Pinheiro and Bates argue that a likelihood-ratio test for fixed effects is not reliable (anticonservative), but I think that both packages should at least give the same answer!! I checked lmeControl() in R and S-PLUS and the settings for lme look the same on both platforms. Which output (if any) should we believe? Any insight would be greatly appreciated. Thanks in advance, Simon Blomberg. School of Botany and Zoology The Australian National University Canberra, Australia. [[alternative HTML version deleted]] __ [EMAIL PROTECTED] 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] labeled break statements in R?
Prof Brian Ripley [EMAIL PROTECTED] writes: On 18 Aug 2004, Roger Levy wrote: Are there labeled break statements in R? i.e., something along the lines of TOPLOOP: for(i in 1:m) { for(j in 1:n) { ... if(condition) { break TOPLOOP } } } No, but if you find yourself using nested for loops it is very likely that you are not thinking in the right way for a vector language. R does have a `R Language Definition' manual. It's long been an unfinished draft but it is not so incomplete as to omit reserved words. It and the S reference books are the places to research questions like this. Many thanks for the fast response -- I actually had looked in the R language manual, and nothing was said about labeled breaks one way or the other. The section on looping was terse enough that I thought it might have been omitted. Roger __ [EMAIL PROTECTED] 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] Getting data loaded
I think you should load data in a .First.lib() function, or if you have a namespace, in a .onLoad() function. -roger Jim Lemon wrote: Hi, I have been informed of a bug in the concord package, in that the data files containing the tabulated critical values for Kendall's W are not loaded on the command library(concord). I had assumed that the lines in install.R would correspond to the commands to load data in R, e.g. data(Wcrit01) data(Wcrit05) While these work on the command line, I get the errors: library(concord) Warning messages: 1: Data set 'Wcrit01' not found in: data(Wcrit01) 2: Data set 'Wcrit05' not found in: data(Wcrit05) The section on this in R-exts doesn't seem to have any information on how to write the lines in install.R, nor does Checking and Building Packages. I managed to locate a few install.R files in other packages, but they were all empty. Any hints? Jim Dr Jim Lemon Research Psychologist Health Psychology Unit University of Technology, Sydney Feel free to ignore any garbage beneath this line. __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] OS X specific question: help.start() won't launch
It's been a while since I used R, and have certainly applied a few system patches. Since I installed the latest R.bin, when I type help.start() nothing happens anymore. It used to launch a browser with the R help system. Anyone know of any issues here, or ways to re-enable this? Didn't see anything searching the FAQ, just stuff on the java-based search. I don't need that, just need to open the help! Thanks, Dave VB __ [EMAIL PROTECTED] 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] labeled break statements in R?
Roger Levy rog at stanford.edu writes: : : Hi, : : Are there labeled break statements in R? i.e., something along the : lines of : : TOPLOOP: for(i in 1:m) { : for(j in 1:n) { : ... : if(condition) { :break TOPLOOP : } : } : } Assuming that your labelled break is supposed to break out of both loops, unlike an ordinary break that just breaks out of the inner loop, this is how it would be done: a - matrix(0, nr=3, nc=3) local({ for(i in 1:3) for(j in 1:3) if (i+j4) return() else a[i,j] - i+j }) a Be aware that assigning variables within the local will assign local copies unless you use -, assign(..., ..., parent.frame()) or eval.parent(...). Of course this style is not recommended for R, and as someone else already mentioned, you should try to vectorize your code eliminating the loops altogether. For example, the above could be written without loops like this: a - matrix(0, nr=3, nc=3) rc - row(a) + col(a) a - ifelse(rc 4, a, rc) a __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] nlme R vs S plus
Hi all, I'm a PhD student at sydney uni and am trying to run a non linear mixed model program to obtain estimates of parameters describing dairy cow lactation curves. At present, I have been able to get the data to converge using the S plus (S plus 2000) nlme function. However, when I put the same data into R (R 1.9.0), add in the nlme package and run the code, it does not converge by the max 50 iterations. Is this because the nlme function is slightly different and if so, is there a way to solve this problem? The code I am using is below: W3-deriv(~A*ti^exp(logB)*exp(-exp(logC)*ti),c(A,logB,logC), function(ti,A,logB,logC){}) Lact.nlme-{nlme(model=MLKYLD~W3(DIM,A,logB,logC), fixed=A+logB+logC~1, random=A+logB+logC~1|ID, data=LacData.x0, start=c(13.41143,log(0.152792),log(0.002494)), control=nlmeControl(msMaxIter=200), verbose=T) } Any help or advice would be greatly appreciated, Evelyn -- Evelyn Hall PhD Student Faculty of Veterinary Science C01 JL Shute Building Camden University of Sydney __ [EMAIL PROTECTED] 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] labeled break statements in R?
Gabor Grothendieck ggrothendieck at myway.com writes: : : Roger Levy rog at stanford.edu writes: : : : : : Hi, : : : : Are there labeled break statements in R? i.e., something along the : : lines of : : : : TOPLOOP: for(i in 1:m) { : : for(j in 1:n) { : : ... : : if(condition) { : :break TOPLOOP : : } : : } : : } : : Assuming that your labelled break is supposed to break out of : both loops, unlike an ordinary break that just breaks out of : the inner loop, this is how it would be done: : : a - matrix(0, nr=3, nc=3) : local({ : for(i in 1:3) : for(j in 1:3) : if (i+j4) return() else a[i,j] - i+j : }) : a : : Be aware that assigning variables within the local will assign : local copies unless you use -, assign(..., ..., parent.frame()) : or eval.parent(...). : : Of course this style is not recommended for R, and as someone else : already mentioned, you should try to vectorize your code eliminating : the loops altogether. For example, the above could be written : without loops like this: : : a - matrix(0, nr=3, nc=3) : rc - row(a) + col(a) : a - ifelse(rc 4, a, rc) : a : Sorry, the ifelse line should have been: ifelse( t(matrix(cumsum(rc4),3,3)), a, rc) __ [EMAIL PROTECTED] 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] labeled break statements in R?
Gabor Grothendieck ggrothendieck at myway.com writes: : : Gabor Grothendieck ggrothendieck at myway.com writes: : : : : : Roger Levy rog at stanford.edu writes: : : : : : : : : Hi, : : : : : : Are there labeled break statements in R? i.e., something along the : : : lines of : : : : : : TOPLOOP: for(i in 1:m) { : : : for(j in 1:n) { : : : ... : : : if(condition) { : : :break TOPLOOP : : : } : : : } : : : } : : : : Assuming that your labelled break is supposed to break out of : : both loops, unlike an ordinary break that just breaks out of : : the inner loop, this is how it would be done: : : : : a - matrix(0, nr=3, nc=3) : : local({ : : for(i in 1:3) : : for(j in 1:3) : : if (i+j4) return() else a[i,j] - i+j : : }) : : a : : : : Be aware that assigning variables within the local will assign : : local copies unless you use -, assign(..., ..., parent.frame()) : : or eval.parent(...). : : : : Of course this style is not recommended for R, and as someone else : : already mentioned, you should try to vectorize your code eliminating : : the loops altogether. For example, the above could be written : : without loops like this: : : : : a - matrix(0, nr=3, nc=3) : : rc - row(a) + col(a) : : a - ifelse(rc 4, a, rc) : : a : : : Sorry, the ifelse line should have been: : : ifelse( t(matrix(cumsum(rc4),3,3)), a, rc) or even simpler: a - ifelse( matrix(cumsum(rc4),3,byrow=T), a, rc) __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html