[R] R Group forming on LinkedIn
Greetings: I am forming an R Group on LinkedIn.Com for job seekers and potential employers. Please consider joining. http://www.linkedin.com/e/gis/77616/0AEFE3574537 Regards, Ajit __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Moving data between R and Matlab back and forth?
On Thu, 27 Mar 2008, Tribo Laboy wrote: I realized that not everyone has Matlab and that basically the issue is purely how to deal with the returned data in R, so I have revised my example code and made it easier to copy-paste and run: Only for those with matlab! The rest of us have little clue what the format of the output is -- it looks like a list array, which is not what the help page for readMat says it is. I would try as.data.frame(drop(labpcimport)) #Make a data frame in R Maker - factor(c(HP, HP, Sony, DELL, whitebox, whitebox)) CPUspeed - c(2,4,2.5,2.5,2,5) HDD - c(80, 250, 100, 100, 80, 300) RAM - c(2, 2, 1, 2, 2, 4) labpc - data.frame(Maker, CPUspeed, HDD, RAM) labpc #Save in Matlab v6 format with 'writeMat' library(R.matlab) writeMat(labpc.mat, labpcexport = labpc) #Load the file in R with 'readMat' labpcfile - readMat(labpc.mat) labpcimport - labpcfile$labpcexport labpcimport # This is the last line output #, , 1 # # [,1] #MakerList,6 #CPUspeed Numeric,6 #HDD Numeric,6 #RAM Numeric,6 Now, how do I convert the result held in labpcimport back to a data frame? Thanks in advance, TL On Thu, Mar 27, 2008 at 1:27 AM, Tribo Laboy [EMAIL PROTECTED] wrote: Hi to the list, I am trying to find a way to painlessly move structured data back and forth between R and Matlab (also Octave). For this purpose I found the R.matlab package great help. I wish to use a Matlab -v6 MAT file as an intermediary format, because it is well read by both Matlab and Octave. It is also well read by 'readMat' function in R.matlab package, but that is where I run into problems because of poor knowledge of R. By structured data I mean data in data frames in R and the closest equivalent - structures in Matlab. Here is what I have done. - Make a data frame in R and export it - Maker - factor(c(HP, HP, Sony, DELL, whitebox, whitebox)) CPUspeed - c(2,4,2.5,2.5,2,5) HDD - c(80, 250, 100, 100, 80, 300) RAM - c(2, 2, 1, 2, 2, 4) labpc - data.frame(Maker, CPUspeed, HDD, RAM) labpc Maker CPUspeed HDD RAM 1 HP 2.0 80 2 2 HP 4.0 250 2 3 Sony 2.5 100 1 4 DELL 2.5 100 2 5 whitebox 2.0 80 2 6 whitebox 5.0 300 4 library(R.matlab) writeMat(labpc.mat, labpcdata = labpc) -- -- In MATLAB - everything is as expected -- load('labpc.mat') labpcdata labpcdata = Maker: {6x1 cell} CPUspeed: [6x1 double] HDD: [6x1 double] RAM: [6x1 double] class(labpcdata) ans = struct labpcstruct = labpcdata save('labpcstruct.mat', 'labpcstruct') - --- Back in R - how to rebuild the data frame from the list labpcstruct? --- labpcfile - readMat(labpcstruct.mat) labpcfile $labpcstruct , , 1 [,1] MakerList,6 CPUspeed Numeric,6 HDD Numeric,6 RAM Numeric,6 attr(,header) attr(,header)$description [1] MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Wed Mar 26 15:49:21 2008 attr(,header)$version [1] 5 attr(,header)$endian [1] little labpcstruct - labpcfile$labpcstruct labpcstruct , , 1 [,1] MakerList,6 CPUspeed Numeric,6 HDD Numeric,6 RAM Numeric,6 typeof(labpcstruct) [1] list So if there is any kind soul that will tell me how to get back the original data frame from the imported list 'labpcstruct', that would be great. Regards, TL __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] question about Randonization
Dear all; I want to know if I can make a two way MANONA , Manova, and Anovas with randonization using the R program, if possible, How I can make my matrix for perform this tests. Thanks Catalina Lopez-Ospina __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Statistical Models in S by Chambers
Could someone please tell me if this book is still worth buying and using or is it outdated and not very practical for use in R. Thank you. -- View this message in context: http://www.nabble.com/Statistical-Models-in-S-by-Chambers-tp16320131p16320131.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 argument handling odd
Hi! In this case you are better off moving away from qplot (which does various substitute tricks to assemble the named variables in a data frame) to a more explicit form of ggplot: pl2[[obs]] - ggplot(cData, aes_string(x=x3, y=obs)) + geom_point() + opts(title = obs) Ok, I will try that, thanks. BTW, where is this aes_string option documented, sounds useful? How could I do the same thing with facetting? If I want to save something like . ~ groupVar as a string in a variable, could I pass it with facet_string to ggplot? But anyway, I would be curious how to do it with qplot. The basic question is: How to pass the string of a variable to a function which is supposed to interpret it. Aka: var - magicVar fun(doSomeMagic(var)) doSomeMagic should then write magicVar at the place. Greetings, Sebastian Weber Hadley __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
So am I to understand that the only realy _correct_ and _recommended_ way of accessing the attributes is through attr(someobject, attributename) ? Regards, TL On Thu, Mar 27, 2008 at 4:16 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Significance of confidence intervals in the Non-Linear Least Squares Program.
On Wed, 26 Mar 2008, glenn andrews wrote: I am using the non-linear least squares routine in R -- nls. I have a dataset where the nls routine outputs tight confidence intervals on the 2 parameters I am solving for. nls() does not ouptut confidence intervals, so what precisely did you do? I would recommend using confint(). BTW, as in most things in R, nls() is 'a' non-linear least squares routine: there are others in other packages. As a check on my results, I used the Python SciPy leastsq module on the same data set and it yields the same answer as R for the coefficients. However, what was somewhat surprising was the the condition number of the covariance matrix reported by the SciPy leastsq program = 379. Is it possible to have what appear to be tight confidence intervals that are reported by nls, while in reality they mean nothing because of the ill-conditioned covariance matrix? The covariance matrix is not relevant to profile-based confidence intervals, and its condition number is scale-dependent whereas the estimation process is very much less so. This is really off-topic here (it is about misunderstandings about least-squares estimation), so please take it up with your statistical advisor. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Moving data between R and Matlab back and forth?
Hello, Thanks for the input. I thought it wasn't much fun to talk to myself on the public forums. ;-) Trying the line you suggested generated and error: as.data.frame(drop(labpcimport)) Error in data.frame(Maker = list(HP, HP, Sony, DELL, whitebox, : arguments imply differing number of rows: 1, 6 However I think I found how to do it. Here is the snippets that works for me. Code begin --- labpc - drop(labpcimport) # Drops all the unnecessary indexes with length 1 and the list becomes much simpler # If any of the contents of each cell is a list then rbind its elements into a single vector and treat it as a factor # These elements were represented as cell elements of a cell array in the MATLAB structure. for (k in 1:length(labpc)){ if (mode(labpc[[k]]) == list) { labpc[[k]]- as.factor(do.call(rbind, labpc[[k]])) } } labpcdata - as.data.frame(labpc) ---Code end Regards, TL On Thu, Mar 27, 2008 at 4:08 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Thu, 27 Mar 2008, Tribo Laboy wrote: I realized that not everyone has Matlab and that basically the issue is purely how to deal with the returned data in R, so I have revised my example code and made it easier to copy-paste and run: Only for those with matlab! The rest of us have little clue what the format of the output is -- it looks like a list array, which is not what the help page for readMat says it is. I would try as.data.frame(drop(labpcimport)) #Make a data frame in R Maker - factor(c(HP, HP, Sony, DELL, whitebox, whitebox)) CPUspeed - c(2,4,2.5,2.5,2,5) HDD - c(80, 250, 100, 100, 80, 300) RAM - c(2, 2, 1, 2, 2, 4) labpc - data.frame(Maker, CPUspeed, HDD, RAM) labpc #Save in Matlab v6 format with 'writeMat' library(R.matlab) writeMat(labpc.mat, labpcexport = labpc) #Load the file in R with 'readMat' labpcfile - readMat(labpc.mat) labpcimport - labpcfile$labpcexport labpcimport # This is the last line output #, , 1 # # [,1] #MakerList,6 #CPUspeed Numeric,6 #HDD Numeric,6 #RAM Numeric,6 Now, how do I convert the result held in labpcimport back to a data frame? Thanks in advance, TL On Thu, Mar 27, 2008 at 1:27 AM, Tribo Laboy [EMAIL PROTECTED] wrote: Hi to the list, I am trying to find a way to painlessly move structured data back and forth between R and Matlab (also Octave). For this purpose I found the R.matlab package great help. I wish to use a Matlab -v6 MAT file as an intermediary format, because it is well read by both Matlab and Octave. It is also well read by 'readMat' function in R.matlab package, but that is where I run into problems because of poor knowledge of R. By structured data I mean data in data frames in R and the closest equivalent - structures in Matlab. Here is what I have done. - Make a data frame in R and export it - Maker - factor(c(HP, HP, Sony, DELL, whitebox, whitebox)) CPUspeed - c(2,4,2.5,2.5,2,5) HDD - c(80, 250, 100, 100, 80, 300) RAM - c(2, 2, 1, 2, 2, 4) labpc - data.frame(Maker, CPUspeed, HDD, RAM) labpc Maker CPUspeed HDD RAM 1 HP 2.0 80 2 2 HP 4.0 250 2 3 Sony 2.5 100 1 4 DELL 2.5 100 2 5 whitebox 2.0 80 2 6 whitebox 5.0 300 4 library(R.matlab) writeMat(labpc.mat, labpcdata = labpc) -- -- In MATLAB - everything is as expected -- load('labpc.mat') labpcdata labpcdata = Maker: {6x1 cell} CPUspeed: [6x1 double] HDD: [6x1 double] RAM: [6x1 double] class(labpcdata) ans = struct labpcstruct = labpcdata save('labpcstruct.mat', 'labpcstruct') - --- Back in R - how to rebuild the data frame from the list labpcstruct? --- labpcfile - readMat(labpcstruct.mat) labpcfile $labpcstruct , , 1 [,1] MakerList,6 CPUspeed Numeric,6 HDD Numeric,6 RAM Numeric,6 attr(,header) attr(,header)$description [1] MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Wed Mar 26 15:49:21 2008 attr(,header)$version [1] 5 attr(,header)$endian [1] little
Re: [R] Rule for accessing attributes?
Now, how is it that I can access the contents of a named list by dynamically computed name? To go back to my previous example I have a list and I know the names. Now I want do something with that named data in a loop. lst - list(x = 1:3, y = 4:6, z = 7:9) nm -names(lst) nm [1] x y z I can access the list elements by name directly: lst$x; lst$y; lst$z, But I want to do for (k in 1:3) { lst$nm[k] } But this doesn't work, basically because lst$nm[1] returns a NULL. So what do I do? Thanks for helping, TL On Thu, Mar 27, 2008 at 4:30 PM, Tribo Laboy [EMAIL PROTECTED] wrote: So am I to understand that the only realy _correct_ and _recommended_ way of accessing the attributes is through attr(someobject, attributename) ? Regards, TL On Thu, Mar 27, 2008 at 4:16 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 subject to constraints
At 05:06 PM 3/26/2008, Ted Harding wrote: On 26-Mar-08 21:26:59, Ala' Jaouni wrote: X1,X2,X3,X4 should have independent distributions. They should be between 0 and 1 and all add up to 1. Is this still possible with Robert's method? Thanks I don't think so. A whileago you wrote The numbers should be uniformly distributed (but in the context of an example where you had 5 variable; now you are back to 4 variables). Let's take the 4-case first. The two linear constraints confine the point (X1,X2,X3,X4) to a triangular region within the 4-dimensional unit cube. Say it has vertices A, B, C. You could then start by generating points uniformly distributed over a specific triangle in 2 dimentions, say the one with vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. Then you need to find a linear transformation which will map this triangle (A0,B0,C0) onto the triangle (A,B,C). Then the points you have sampled in (A0,B0,C0) will map into points which are uniformly distributed over the triangle (A,B,C). More generally, you will be seeking to generate points uniformly distributed over a simplex. For example, the case (your earlier post) of 5 points with 2 linear constraints requires a tetrahedron with vertices (A,B,C,D) in 5 dimensions whose coordinates you will have to find. Then take an easy tetrahedron with vertices (A0,B0,C0,D0) and sample uniformly within this. Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) and apply this to the sampled points. This raises a general question: Does anyone know of an R function to sample uniformly in the interior of a general (k-r)-dimensional simplex embedded in k dimensions, with (k+1) given vertices? snip The method of rejection: 1. Generate numbers randomly in the hypercube. 2. Test to see if the point falls within the prescribed area. 3. Accept the point if it does. 4. Repeat if it doesn't. Efficiency depends upon the ratio of volumes involved. Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [EMAIL PROTECTED] Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 Vere scire est per causas scire __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
Thanks, this really solved my problem. Actually, I do have a good introduction to R - a book co-authored by some W.N. Venables and some B.D. Ripley, colloquially called 'MASS' is on my desk. I find it really very helpful. Still, as it is a book on statistics, some details on R are only mentioned in passing. I also use some other books and online resources, but obviously will need to delve a bit deeper. One of the reasons I am moving to R is because it has a great user community. I hope I am not abusing it with too many questions. Regards, TL On Thu, Mar 27, 2008 at 5:16 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: Use [[ ]]. It seems it is time for you to study a good introduction to R. On Thu, 27 Mar 2008, Tribo Laboy wrote: Now, how is it that I can access the contents of a named list by dynamically computed name? To go back to my previous example I have a list and I know the names. Now I want do something with that named data in a loop. lst - list(x = 1:3, y = 4:6, z = 7:9) nm -names(lst) nm [1] x y z I can access the list elements by name directly: lst$x; lst$y; lst$z, But I want to do for (k in 1:3) { lst$nm[k] } But this doesn't work, basically because lst$nm[1] returns a NULL. So what do I do? Thanks for helping, TL On Thu, Mar 27, 2008 at 4:30 PM, Tribo Laboy [EMAIL PROTECTED] wrote: So am I to understand that the only realy _correct_ and _recommended_ way of accessing the attributes is through attr(someobject, attributename) ? Regards, TL On Thu, Mar 27, 2008 at 4:16 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 -- 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
Re: [R] Moving data between R and Matlab back and forth?
I have packaged the above posted code as a function and I am posting it here in case someonw would find it useful in the future. --function begin - readMat2df - function(readfiledata, datastr){ tmpdata - readfiledata[[datastr]] # use the string contained in 'datastr' to acccess the data with that name tmpdata - drop(tmpdata) # Drops all the unnecessary indexes with length 1 and the list becomes much simpler # If any of the contents of each cell is a list then rbind its elements into a single vector and treat it as a factor # These elements were represented as cell elements of a cell array in the MATLAB structure. for (k in 1:length(tmpdata)){ if (mode(tmpdata[[k]]) == list) { tmpdata[[k]]- as.factor(do.call(rbind, tmpdata[[k]])) } } tmpdf - as.data.frame(tmpdata) return(tmpdf) } --function end How to use this thing? Well suppose you had an R data frame and exported it into Matlab MAT v6 format with 'writeMat' function of R.matlab like this: library(R.matlab) writeMat(labpc.mat, labpcexport = labpc) #This give the name 'labpcexport' to the ML structure holding the data Re-load the file in R with 'readMat' like this labpcfile - readMat(labpc.mat) To get back a data frame from the imported MAT file: 1. Find the name of the variable that holds it. To get of all the variables that were in the MAT file: names(labpcfile) 2. Pass this name and the name of the list that holds all imported MAT data to the function, get a data frame out: myFavoriteDataFrame - readMat2df(labpcfile, labpcexport) Hope this is useful for someone. Regards, TL __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Moving data between R and Matlab back and forth?
I realized that not everyone has Matlab and that basically the issue is purely how to deal with the returned data in R, so I have revised my example code and made it easier to copy-paste and run: #Make a data frame in R Maker - factor(c(HP, HP, Sony, DELL, whitebox, whitebox)) CPUspeed - c(2,4,2.5,2.5,2,5) HDD - c(80, 250, 100, 100, 80, 300) RAM - c(2, 2, 1, 2, 2, 4) labpc - data.frame(Maker, CPUspeed, HDD, RAM) labpc #Save in Matlab v6 format with 'writeMat' library(R.matlab) writeMat(labpc.mat, labpcexport = labpc) #Load the file in R with 'readMat' labpcfile - readMat(labpc.mat) labpcimport - labpcfile$labpcexport labpcimport # This is the last line output #, , 1 # # [,1] #MakerList,6 #CPUspeed Numeric,6 #HDD Numeric,6 #RAM Numeric,6 Now, how do I convert the result held in labpcimport back to a data frame? This works, but I don't know how well it will generalise to other imported matrices. as.data.frame(lapply(drop(labpcimport), unlist)) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Execute R with *.RData argument
Dear R developers, i would like to start R with a *.RData argument under Linux. Something like R -f /home/user/workspace.RData Is this possible? Thanks in advance for any answers. -- View this message in context: http://www.nabble.com/Execute-R-with-*.RData-argument-tp16323374p16323374.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lme equivalent of formula aov
Hi R people, In lme package, I'm searching to find equivalent formula of: aov(frt~consistency*length*context+Error(subject/(consistency*length*context),data=agE1B4) I try this : lme(fixed=frt~consistency*length*context, random=~1|subject, data=agE1B4) but I did not obtain same F value with anova(). Thanks in advance Guillaume [[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] Standard error values returned by lm()
Hi, This may be a stupid question, but how are the std. error values returned by lm() calculated? For example summary(lm) Call: lm(formula = log10(moments[2, 1:10]) ~ log10(L_vals[1:10])) Residuals: Min 1Q Median 3QMax -0.0052534 -0.0019473 0.0006785 0.0011740 0.0059541 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.520639 0.002488 -209.2 3.05e-16 *** log10(L_vals[1:10]) 0.112666 0.00344632.7 8.35e-10 *** I can't find any documentation on this. Regards, Nicky Chorley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] inheritence in S4
Sorry to come back on callNextMethod, I am still not very confident about it. Consideres the following (there is a lot of code, but very simple with almost only some cat) : -- setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) .Object - callNextMethod() return(.Object) }) setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object){ cat( Init B \n) .Object - callNextMethod() return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # * Valid A * #*** Valid B *** # An object of class B # Slot b: # [1] 2 # # Slot a: # [1] 3 new(B) will go trought - initialize B that will call the nextMethod that is : - initialize A that will call the nextMethod that is : - initialize ANY call validObject A. This would be perfect... But there is also a call to validObject B. Where does it come from ? This is anoying because : In an object-oriented sense, initialize,B-method should really just deal with it's own slots; it shouldn't have to 'know' about either classes that it extends (A) or classes that extend it. I completly agree with that. But if the author of A change its code : - setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) [EMAIL PROTECTED] - 10 return(.Object) }) setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object){ cat( Init B \n) .Object - callNextMethod() return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # An object of class B # Slot b: # numeric(0) # # Slot a: # [1] 10 - Then validObject of B is no longer call, and B is no longueur correctly set... So if A is changed by its author, the comportement of B is change as well... Anoying, isn't it ? But I agree with the initialize,B-method should really just deal with it's own slots; So may be something like : - setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) #[EMAIL PROTECTED] - 10 .Object - callNextMethod() return(.Object) }) setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object,a,b){ cat( Init B \n) as(.Object,A) - new(A,a=a) [EMAIL PROTECTED] - b return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # An object of class B # Slot b: # [1] 2 # # Slot a: # [1] 10 - The call to validObject of B is no longer dependent of the A code. Christophe [EMAIL PROTECTED] wrote: Hi Martin I am re reading all the mail we exchange with new eyes because of all the thing I learn in the past few weeks. That very interesting and some new question occurs... *** Once, you speak about callGeneric : setClass(A, representation(x=numeric)) setClass(C, contains=c(A)) setMethod(show, A, function(object) cat(A\n)) setMethod(show, C, function(object) { callGeneric(as(object, A)) cat(C\n) }) new(C) Considere the following definition (that you more or less teach me with your yesterday remarques...) : setMethod(show, C, function(object) { callNextMethod() cat(C\n) }) In this case, is there any difference between the former and the latter ? Which one would you use ? callNextMethod is the right thing to do for this case. callGeneric is useful in a very specific case -- when dispatching from within a so-called 'group generic' function. But this is an advanced topic. (I get that in more complicate case, for example if setClass(C, contains=c(A,B)), it might be more complicate to use the latter, right ?) The right thing to do in this case is to sit down with the rules of method dispatch, and figure out what the 'next' method will be. A common alternative paradigm is to have a plain function (not visible to the user, e.g., not exported in a package name space) that several different methods all invoke, after mapping their arguments appropriately. The methods provide a kind of structured interface to the function, making sure arguments are of the appropriate type, etc. The function does the work, confident that the arguments are appropriate. * This works : setMethod(initialize,B,
[R] snow, stopping cluster
Hello, is there any function in the package snow to check for a really running cluster? The function checkCluster only checks the variable cl. And the variable is still available after stopping the cluster! ( a simple solution would be deleting the cluster variable cl in the function stopCluster) library(snow) cl - makeCluster(5) 5 slaves are spawned successfully. 0 failed. clusterApply(cl, 1:2, get(+), 3) [[1]] [1] 4 [[2]] [1] 5 stopCluster(c1) [1] 1 clusterApply(cl, 1:2, get(+), 3) Fehler in mpi.probe(source, tag, comm, status) : MPI_Error_string: invalid communicator sessionInfo() R version 2.6.0 (2007-10-03) x86_64-unknown-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] affyPara_0.99.2 affy_1.16.0 preprocessCore_1.0.0 [4] affyio_1.6.1 Biobase_1.16.1 Rmpi_0.5-5 [7] snow_0.2-9 loaded via a namespace (and not attached): [1] rcompgen_0.1-15 Best Markus -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Standard error values returned by lm()
Type summary.lm and read the code. Best, Uwe Ligges Nick Chorley wrote: Hi, This may be a stupid question, but how are the std. error values returned by lm() calculated? For example summary(lm) Call: lm(formula = log10(moments[2, 1:10]) ~ log10(L_vals[1:10])) Residuals: Min 1Q Median 3QMax -0.0052534 -0.0019473 0.0006785 0.0011740 0.0059541 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.520639 0.002488 -209.2 3.05e-16 *** log10(L_vals[1:10]) 0.112666 0.00344632.7 8.35e-10 *** I can't find any documentation on this. Regards, Nicky Chorley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading library lme4
Reinstall Matrix. Uwe Ligges Guy Forrester wrote: Dear all, I an running R on a Windows 2000 machine (1.5Gb RAM) and am trying to load the lme4 package, however, whenever I attempt to load the library lme4 I get the following error message I have installed lme4 and Matrix locally from the zip file with no problems. R version 2.6.2 (2008-02-08) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 ##snip the blurb library(lme4) Loading required package: Matrix Loading required package: lattice Error in dyn.load(file, ...) : unable to load shared library 'C:/PROGRA~1/R/R-26~1.2/library/Matrix/libs/Matrix.dll': LoadLibrary failure: The specified module could not be found. Error: package 'Matrix' could not be loaded I am using lme4 v0.99875-9 and Matrix v0.999375-7 Any pointers would be appreciated Many thanks in advance Guy J Forrester Guy J Forrester Biometrician Manaaki Whenua - Landcare Research PO Box 40, Lincoln 7640, New Zealand. Tel. +64 3 321 9670 Fax +64 3 321 9998 E-mail [EMAIL PROTECTED] www.LandcareResearch.co.nz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Execute R with *.RData argument
On Thu, 27 Mar 2008, Bio7 wrote: Dear R developers, i would like to start R with a *.RData argument under Linux. Something like R -f /home/user/workspace.RData Is this possible? $ R ... load(/home/user/workspace.RData) or put that line in your .Rprofile -- see ?Startup. (My guess is that you are used to the facility for drag-and-drop on Windows. Also, please re-read 'An Introduction to R' for the supported command-line arguments -- '-f' is supported but this is not what it does.) Thanks in advance for any answers. -- View this message in context: http://www.nabble.com/Execute-R-with-*.RData-argument-tp16323374p16323374.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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Nothing happened when I using t.test throuth RSPerl
That is a *Perl* error, and my guess is that you haven't set your environment variables correctly. R was not even started. RSPerl is an Omegahat package, and as the Omegahat mailing lists were down (last time I looked) I suggest you contact the author. The R posting guide asks that non-R programming questions are not sent here (to R-devel, if an R list is appropriate). On Thu, 27 Mar 2008, zhushanshan wrote: Hi, I've just started using RSPerl. Though also tests in directory /usr/local/lib/R/library/RSPerl/tests/ are passed successfully, I meet the problem with the following codes; use strict; use warnings; use R; use RReferences; my @array1=1..10; my @array2=1..39; R::initR(--silent); R::library(RSPerl); my $tt=R::call(t.test, ([EMAIL PROTECTED], [EMAIL PROTECTED])) print $tt; I got the messages: Can't locate package RFunctionReference for @RReferences::ISA at testR.pl line 4. Use of uninitialized value in print at testR.pl line 11. Thanks in advance Zhu Shanshan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loop problem
Jamie Ledingham wrote: Dear all, I have a problem with a loop, if anyone has any knowledge on these things I would appreciate some comments. The code below is designed to allow me to extract the top record of the data frame, and them remove rows from the data frame which have an index close to the extracted top record. topstorm-subset(rankeddataset[1,]) ## Extracts the top storm topstormindex-rankeddataset[1,1] ## Finds the top storm start index startindex-topstormindex-48 ## sets the start and end indexes endindex-topstorminde+48 rankeddataset-rankeddataset[-1,] ## Creates a new list with the top storm removed ##This section of code needs looped. It removes storms from the list which are too close to the extracted storm for (i in 1:30){ if (rankeddataset[i,1]startindex rankeddataset[i,1]endindex) {rankeddataset-rankeddataset[-i,]} } Here is some example data: 82856 15 / 6 / 1966 82856:8287925.9 82857 15 / 6 / 1966 82857:8288020.5 83036 23 / 6 / 1966 83036:8305917.3 87250 15 / 12 / 1966 87250:8727315.9 Hi again Jamie, I had a bit of time tonight and recognized your problem. I think the following function will do what you want, although it is probably not the most elegant solution. I would check it manually with a small data file and a small howmany argument to make sure that it is picking up the maxima you want. find.max.rain-function(raindata,howmany) { # a lazy way of getting the same structure as raindata # it assumes that raindata has the data structure that you want maxrain-raindata[1:howmany,] for(i in 1:howmany) { # get the current number of rows nrows-dim(raindata)[1] # find the first maximum value thismax-which.max(raindata$cumrain) # transfer it to the return data frame maxrain[i,]-raindata[thismax,] # calculate the minimum index for the 48 hour gap mindex-thismax-48 # make sure it is at least 1 if(mindex 1) mindex - 1 # calculate the maximum index for the gap maxdex-thismax+48 # make sure it doesn't go past the end of the data frame if(maxdex nrows) maxdex-nrows # chop out that time period raindata-raindata[-(mindex:maxdex),] } return(maxrain) } Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re place with previous value
Maybe something like: f - function(x,y) ifelse(sign(y[x])==-1,return(y[x-1]), return(y[x])) test[,3] - sapply(seq_along(test[,3]),f,test[,3]) Ravi S. Shankar wrote: Hi R, I have a dataframe with dim(test) [1] 435150 4 class(test) [1] data.frame In the third column every time a number with - appears I need to replace with previous value I am using the following code s=which(substr(as.character(test[,3]),1,1)==-) for(i in 1:length(s)) test[s[i],3] = test[s[i]-1,3] Is there a faster way of doing this? sessionInfo() R version 2.5.1 (2007-06-27) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base Thanks in advance Ravi Shankar S This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Replace-with-previous-value-tp16310560p16323983.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop problem
Oops, missed the first line of the example: storm.data-data.frame(meas.index=10001:2,cumrain=runif(1,-10,10)+10) You can generalize the function to whatever column names you have like this: find.max.rain-function(raindata,howmany,raincol) { # a lazy way of getting the same structure as raindata # it assumes that raindata has the data structure that you want maxrain-raindata[1:howmany,] for(i in 1:howmany) { raindim-dim(raindata) thismax-which.max(raindata[[raincol]]) cat(thismax, ) maxrain[i,]-raindata[thismax,] mindex-thismax-48 if(mindex 1) mindex - 1 maxdex-thismax+48 cat(mindex,maxdex, ) if(maxdex raindim[1]) maxdex-raindim[1] raindata-raindata[-(mindex:maxdex),] cat(raindim[1], ) } cat(\n) return(maxrain) } find.max.rain(storm.data,50,cumrain) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] Update of TeachingDemos package
This is to announce that versio 2.0 of the TeachingDemos package is now on CRAN (and hopefully soon to a mirror near you). This is a major upgrade of the package, some of the improvements include: The package now uses an NAMESPACE so it is easier to load just the parts that you need. Some of the GUI demonstrations now use tkrplot so that the graph is in the same window as the controls (there are still 'old' versions of these functions available if you want the old functionality). The rest of the GUI demos will be updated to use tkrplot as well, and after R2.7 comes out they all will be upgraded to use the themed widgets to give a more uniform look with your OS. Many of the examples sections of the help pages have replaced \dontrun{ with if(interactive()){ so that they will be run by the example function, but still not block in the automatic checking. I recommend running example with the argument ask=FALSE, otherwise you will need to hit enter 2-4 times each time a diolog pops up and every time you update something in the dialog. There are several new functions including: tkexamp, a tool for creating interactive Tk based examples of what options to functions do (mainly for plots, but one example shows a non-plotting function). dynIdentify and TkIdentify, tools that create a scatterplot with labels, then allow you to drag the labels with the mouse to better locations. col2grey, a tool to convert your colors to greyscale so you can get a general feel of how they would look when printed non-color, or copied, etc. SensSpec.demo, a demonstration of how to compute positive and negative predictive value from sensitivity, specificity, and prevelance using a virtual population rather than Bayes Theorem and algebra. TkApprox and TkSpline, GUI wrappers to the approxfun and splinfun functions that graph your data, the predictions, and allow you to drag reference lines on the plot to show the predicted values, differences, and derivatives. tkprogress, a utility to create and update a progress bar to show how far through a loop or other iterative process you are. A set of functions (see txtStart and etxtStart) that will create a plain text transcript of your R session including both commands and output (think glorified sink + history). The 'etxt' versions add markup so that the text file can be processed by the enscript program to create a postscript file with some syntax coloring and inclusion of graphs. The postscript file can then be converted to pdf or other formats. Hope others find this helpful, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mac OS X 10.4.11 - R2.6.2 - Problem with proxy
Hello Vincent, On Thu, Mar 27, 2008 at 11:25 AM, Vincent Alcouffe [EMAIL PROTECTED] wrote: I have 60 Macintoshs on Mac OS X 10.4.11 for learn R to studient of University and i want to Install New Packages. I click on the button access list Mirrors and it propose me a list of mirrors. None work correctly. All the mirrors take an error. Recent versions of R have introduced some bug related to accessing the Internet through a transparent proxy. It has been discussed recently, twice, for the Windows and Linux platforms. Please check these threads [1] [2]. Basically, you would need to install wget, make sure that it can access the Internet (tweak the config files and make it aware of the transparent proxy) and use method=wget when installing packages within R. Regards, Liviu [1] http://www.nabble.com/internet-proxy-settings-(win)-td15956010.html [2] http://tolstoy.newcastle.edu.au/R/e3/help/07/10/1395.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Covariates in LME?
Hi, Im using lme to calculate a mixed factors ANOVA according to: px_anova = anova(lme(dep~music*time*group, random = ~1|id, data = px_data)) where dep is a threshold, time is a repeated measures variable (2 levels) group is a between subjects variable (2 levels) id is a random factor (subject id) music is a between subjects variable (2 levels) indicating if a person has a musical experience, or not Musical experience is now decided by categorizing depending on the number of years practicing playing an instrument. I would like to use the years of playing an instrument as a covariate instead of creating categories. How can I do this in a simple way? Thanks and have a nice day! Kristoffer [[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] adding bwplot to existing bwplot
Hello. I have made many normal boxplots where I have added a new boxplot to an existing one. When I have done this, I have used the at command to move the boxplots a bit so that they could fit next to eachother, like this: boxplot(data.., at = number_of_categories-0.15) boxplot(data.., at = number_of_categoreis+0.15, add =TRUE) Now I am wondering if it is possible to do the same in some way with bwplot. The data I want to plot is like this: operonthings[1:5,] phylum pid type no_clust no_seqs 1 Acidobacteria 15771 5S1 1 2 Acidobacteria 12638 5S1 2 3 Actinobacteria 16321 5S2 6 4 Actinobacteria92 5S2 2 5 Actinobacteria87 5S1 5 where phylum and types are the factors I would like to plot no_clust and no_seqs against.I basically want these in the same plot: bwplot(no_clust~type|phylum, data = operonthings) and bwplot(no_seqs~type|phylum, data = operonthings) Any thoughts on how to do this? Thanks! Karin -- Karin Lagesen, PhD student [EMAIL PROTECTED] http://folk.uio.no/karinlag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Covariates in LME
Hi, Im using lme to calculate a mixed factors ANOVA according to: px_anova = anova(lme(dep~music*time*group, random = ~1|id, data = px_data)) where dep is a threshold, time is a repeated measures variable (2 levels) group is a between subjects variable (2 levels) id is a random factor (subject id) music is a between subjects variable (2 levels) indicating if a person has a musical experience, or not Musical experience is now decided by categorizing depending on the number of years practicing playing an instrument. I would like to use the years of playing an instrument as a covariate instead of creating categories. How can I do this in a simple way? Thanks and have a nice day! Kristoffer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] options in 'rnorm' to set the lower bound of normal distribution to 0 ?
Dear list, I have a dataset containing values obtained from two different instruments (x and y). I want to generate 5 samples from normal distribution for each instrument based on their means and standard deviations. The problem is values from both instruments are non-negative, so if using rnorm I would get some negative values. Is there any options to determine the lower bound of normal distribution to be 0 or can I simulate the samples in different ways to avoid the negative values? dat id x y 75 101 0.134 0.1911315 79 102 0.170 0.1610306 76 103 0.134 0.1911315 84 104 0.170 0.1610306 74 105 0.134 0.1911315 80 106 0.170 0.1610306 77 107 0.134 0.1911315 81 108 0.170 0.1610306 82 109 0.170 0.1610306 78 111 0.170 0.1610306 83 112 0.170 0.1610306 85 113 0.097 0.278 2 201 1.032 1.5510434 1 202 0.803 1.0631001 5 203 1.032 1.5510434 mu-apply(dat[,-1],2,mean) sigma-apply(dat[,-1],2,sd) len-5 n-20 s1-vector(list,len) set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=rnorm(n*i,mean=mu[1],sd=sigma[1]), y=rnorm(n*i,mean=mu[2],sd=sigma[2])) } Thanks for any help, Tom - Sök efter kärleken! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 argument handling odd
Ok, I will try that, thanks. BTW, where is this aes_string option documented, sounds useful? How could I do the same thing with facetting? If I want to save something like . ~ groupVar as a string in a variable, could I pass it with facet_string to ggplot? It's a see also from ?aes (or at least it is in the development version). facet_grid should already accept a string instead of a function, so it should just work. But anyway, I would be curious how to do it with qplot. The basic question is: How to pass the string of a variable to a function which is supposed to interpret it. Aka: var - magicVar fun(doSomeMagic(var)) doSomeMagic should then write magicVar at the place. In general, you can use as.name, substitute and eval: x - as.name(mpg) y - as.name(wt) eval(substitute(qplot(x, y, data=mtcars), list(x=x, y=y))) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt This is rather poorly documented, but the preferred way of setting the title is now: p + opts(title = My Title) All options should be documented under ?opts (but aren't, unfortunately). Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 between 2 ecdfs
Thanks to David and Zaihra for their help. Besides plotting the difference between 2 ecdfs, I also would like it to *look like* a step function. Any suggestion? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Winsemius Sent: Friday, March 21, 2008 8:51 PM To: [EMAIL PROTECTED] Subject: Re: [R] difference between 2 ecdfs In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: hi, a) i have something like: ecdfgrp1-ecdf(subset(mydata,TMT_GRP==1)$Y); ecdfgrp2-ecdf(subset(mydata,TMT_GRP==2)$Y); how can i plot the difference between these 2 step functions? i could begin with ecdfrefl-function(x){ecdfgrp2(x)-ecdfgrp1(x);} ... what next? #not tested ...mydata not provided ecrange-range(mydata$Y) plot(ecdfrefl(seq(from=ecrange[1],to=ecrange[2],by=0.2)) b) if i have a vector with repeated numeric values how can i get the subset without repeated values .e.g (0,4,0,2,2) (0,4,2) ? ?unique ttt-c(1,3,5,5,5,7) unique(ttt) [1] 1 3 5 7 -- David Winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] options in 'rnorm' to set the lower bound of normal distribution to 0 ?
On Thu, 27 Mar 2008, Tom Cohen wrote: Dear list, I have a dataset containing values obtained from two different instruments (x and y). I want to generate 5 samples from normal distribution for each instrument based on their means and standard deviations. The problem is values from both instruments are non-negative, so if using rnorm I would get some negative values. Is there any options to determine the lower bound of normal distribution to be 0 or can I simulate the samples in different ways to avoid the negative values? Well, that would not be a normal distribution. If you want a _truncated_ normal distribution it is very easy by inversion. E.g. trunc_rnorm - function(n, mean = 0, sd = 1, lb = 0) { lb - pnorm(lb, mean, sd) qnorm(runif(n, lb, 1), mean, sd) } but I suggest you may rather want samples from a lognormal. dat id x y 75 101 0.134 0.1911315 79 102 0.170 0.1610306 76 103 0.134 0.1911315 84 104 0.170 0.1610306 74 105 0.134 0.1911315 80 106 0.170 0.1610306 77 107 0.134 0.1911315 81 108 0.170 0.1610306 82 109 0.170 0.1610306 78 111 0.170 0.1610306 83 112 0.170 0.1610306 85 113 0.097 0.278 2 201 1.032 1.5510434 1 202 0.803 1.0631001 5 203 1.032 1.5510434 mu-apply(dat[,-1],2,mean) sigma-apply(dat[,-1],2,sd) len-5 n-20 s1-vector(list,len) set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=rnorm(n*i,mean=mu[1],sd=sigma[1]), y=rnorm(n*i,mean=mu[2],sd=sigma[2])) } Thanks for any help, Tom - S?? efter k??leken! [[alternative HTML version deleted]] -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 between 2 ecdfs
Please chk out the url below it might be of some help for plotting step function or *look like* of step function. On Thu, 27 Mar 2008 09:03:58 -0400 wrote: Thanks to David and Zaihra for their help. Besides plotting the difference between 2 ecdfs, I also would like it to *look like* a step function. Any suggestion? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Winsemius Sent: Friday, March 21, 2008 8:51 PM To: [EMAIL PROTECTED] Subject: Re: [R] difference between 2 ecdfs In article [EMAIL PROTECTED], wrote: hi, a) i have something like: ! ; ecdfgrp1-ecdf(subset(mydata,TMT_GRP==1)$Y); ecdfgrp2-ecdf(subset(mydata,TMT_GRP==2)$Y); how can i plot the difference between these 2 step functions? i could begin with ecdfrefl-function(x){ecdfgrp2(x)-ecdfgrp1(x);} ... what next? #not tested ...mydata not provided ecrange-range(mydata$Y) plot(ecdfrefl(seq(from=ecrange[1],to=ecrange[2],by=0.2)) b) if i have a vector with repeated numeric values how can i get the subset without repeated values .e.g (0,4,0,2,2) (0,4,2) ? ?unique ttt-c(1,3,5,5,5,7) unique(ttt) [1] 1 3 5 7 -- David Winsemius ! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding loops
Thanks for this. I was afraid someone was going to say this ... Does this mean the only way of getting this to run faster is by moving to C code? The cases I'm thinking of applying this in have dimensions of A that are much larger than the example, eg n by n by T where n has a max of 10 or so but T could be hundreds or even thousands. Best, Ingmar On Mar 27, 2008, at 12:11 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: If you have lots of memory there is an obvious strategy: d12 - prod(dim(A)[1:2]) A - A * array(rep(B, each = d12), dim = dim(A)) I don't really see much wrong with the obvious for() loop, though: for(b in 1:length(B)) A[,,b] - A[,,b] * B[b] Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] project.org] On Behalf Of Ingmar Visser Sent: Thursday, 27 March 2008 7:58 AM To: R-help@r-project.org Subject: [R] avoiding loops Hi, I need to compute an array from a matrix and an array: A - array(1:20,c(2,2,5)) B - matrix(1:10,5) And I would like the result to be an array consisting of the following: rbind(A[1,,1]*B[1,], A[2,,1]*B[1,]) rbind(A[1,,2]*B[2,], A[2,,2]*B[2,]) rbind(A[1,,3]*B[2,], A[2,,3]*B[2,]) etc. Hence the result should have the same dimension as A, ie a series of 2 by 2 matrices. Short of a for loop over the the last index of A I have struggled with versions of apply but to no avail ... Any insights much appreciated, Best, Ingmar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Slow code display in R console
It could be almost anything. You need to supply some information about what you are doing and your system It would be a good idea to supply the information that sessionInfo() gives. --- Huilin Chen [EMAIL PROTECTED] wrote: Hi When I copy a block of code to R console, the code would be displayed line by line very slowly. I am using R version 2.6.2(2008-2-8). Does anybody know what is the reason for the slow display? It was not like this when I used earlier versions. Huilin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
Yes, indeed. The help page says that @ extracts the contents of a slot in S4 objects. But you mention below that this 'works' for S3 objects because S4 slots are stored as attributes. Doesn't this mean that @ is currently implemented to access attributes of objects in general (attributes of S3 objects or slots of S4 objects that are implemented as attributes)? I realize that this might change in the future... -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Thursday, March 27, 2008 3:17 AM To: Christos Hatzis Cc: r-help@r-project.org Subject: Re: [R] Rule for accessing attributes? Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dynamic string as element name in a list
Dear all, I have a piece of code along the lines of f - function(x) { clipname - LK # but is in real determined based on info in data.frame x # other manipulations return( list(clipname=list())) } My intention is to do out - f(dat) and then (in this example) having/getting out$LK which is a list in itself. Of course, it doesn't work like this, but having tried all kinds of combinations of eval(), parse(), substitute(), and friends I was unable to get the contents of clipname as the element name of the list that I return in f(). Is this possible to do so at all and if so, what am I missing? Kind regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 subject to constraints
Hi all One suggestion, tranforme the x 0x11 Tranforme x1=exp(u1)/(exp(u1)+exp(u2)+exp(u3)+1) 0x21 Tranforme x2=exp(u2)/(exp(u1)+exp(u2)+exp(u3)+1) 0x31 Tranforme x3=exp(u3)/(exp(u1)+exp(u2)+exp(u3)+1) 0x41 Tranforme x4= 1/(exp(u1)+exp(u2)+exp(u3)+1) x1+x2+x3+x4=1 Now solve : Aexp(u1)+bexp(u2)+cexp(u3)+d=n(exp(u1)+exp(u2)+exp(u3)+1) (c-n)exp(u3)=(n-a)exp(u1)+(n-b)exp(u2)+n-d u3=ln((n-a)/(c-n)exp(u1)+(n-b)/(c-n)exp(u2)+(n-d)/(c-n)) (u3 expression) Generate u1 Generate u2 bounded so the ln term should be positive (n-a)/(c-n)exp(u1)+(n-b)/(c-n)exp(u2)+(n-d)/(c-n)0 u or ln() (u1 u2 are not independant) Compute u3 given the above formula Generate the x Hope this help Naji Le 26/03/08 22:41, « Ala' Jaouni » [EMAIL PROTECTED] a écrit : X1,X2,X3,X4 should have independent distributions. They should be between 0 and 1 and all add up to 1. Is this still possible with Robert's method? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Dynamic string as element name in a list
Try this: foo - function(x) { clipname - LK out - list() out[[clipname]] - rnorm(5) return(out) } On 27/03/2008, Paul Lemmens [EMAIL PROTECTED] wrote: Dear all, I have a piece of code along the lines of f - function(x) { clipname - LK # but is in real determined based on info in data.frame x # other manipulations return( list(clipname=list())) } My intention is to do out - f(dat) and then (in this example) having/getting out$LK which is a list in itself. Of course, it doesn't work like this, but having tried all kinds of combinations of eval(), parse(), substitute(), and friends I was unable to get the contents of clipname as the element name of the list that I return in f(). Is this possible to do so at all and if so, what am I missing? Kind regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] options in 'rnorm' to set the lower bound of normal dist
Brian Ripley's suggestions of truncated normal and log-normal are of course resources for ensuring that you get positive simulated results. However, I think youre real problem (having looked at the numbers you quote) is that you should not be thinking of using a normal distribution, or anything similar, at all. Your variables dat$x and dat$y have: mean(dat$x) ## [1] 0.3126667 sd(dat$x) ## [1] 0.3372137 mean(dat$y) ## [1] 0.4223137 sd(dat$y) ## [1] 0.5120841 so in both cases the SD is about the same as the mean, and getting negative values from simulated normal distributions with these means and SDs is inevitable. But now look at the two series of 15 numbers in dat$x and dat$y: The first 12 are of the order of 0.15 and 0.20 respectively, while the final 3 in each case are of the order of 1.0 and 1.5 respectively. And this is where your large SD is coming from. Neither series is from a simple normal distribution. mean(dat$x[1:12]) ## [1] 0.1519167 sd(dat$x[1:12]) ## [1] 0.02447432 and it is impossible for the last 3 ( 1.032 0.803 1.032) to have come from a normal distribution giving the first 12. mean(dat$y[1:12]) ## [1] 0.1807932 sd(dat$y[1:12]) ## [1] 0.03380083 with a similar conclusion; and likewise for the last three 1.551043 1.063100 1.551043 Note that, for the first 12 in each case, the SD less that 1/5 of the mean: mean(dat$x[1:12])/sd(dat$x[1:12]) ## [1] 6.207186 mean(dat$y[1:12])/sd(dat$y[1:12]) ## [1] 5.348779 so, where the first 12 of x and y are concerned, if you sampled from normal distributions with the same means and SDs you would get a negative number with probability less than pnorm(-5) ## [1] 2.866516e-07 What you in fact have here is that the numbers are in two groups, each with a small SD relative to its mean: dat$x dat$y Mean SD Mean SD +--- 1:120.152 0.024 | 0.181 0.034 | 13:150.956 0.132 | 1.390.282 Note that for dat$x Mean/SD approx = 6 for each sub-series, and for data$y Mean/SD approx = 5 for each subseries, so you could be looking at results which display a nearly constant coefficient of variation. Now, this is indeed a property of the log-normal distribution (as well as of others), so that could indeed be worth considering. However, you still have to account for the apparent split noted above into distinct groups. So you are really facing a modelling question: why did the numbers come out as they did, and what is a good way to represent that mechanism as a distribution? With best wishes, Ted. On 27-Mar-08 12:27:55, Tom Cohen wrote: Dear list, I have a dataset containing values obtained from two different instruments (x and y). I want to generate 5 samples from normal distribution for each instrument based on their means and standard deviations. The problem is values from both instruments are non-negative, so if using rnorm I would get some negative values. Is there any options to determine the lower bound of normal distribution to be 0 or can I simulate the samples in different ways to avoid the negative values? dat id x y 75 101 0.134 0.1911315 79 102 0.170 0.1610306 76 103 0.134 0.1911315 84 104 0.170 0.1610306 74 105 0.134 0.1911315 80 106 0.170 0.1610306 77 107 0.134 0.1911315 81 108 0.170 0.1610306 82 109 0.170 0.1610306 78 111 0.170 0.1610306 83 112 0.170 0.1610306 85 113 0.097 0.278 2 201 1.032 1.5510434 1 202 0.803 1.0631001 5 203 1.032 1.5510434 mu-apply(dat[,-1],2,mean) sigma-apply(dat[,-1],2,sd) len-5 n-20 s1-vector(list,len) set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=rnorm(n*i,mean=mu[1],sd=sigma[1]), y=rnorm(n*i,mean=mu[2],sd=sigma[2])) } Thanks for any help, Tom - Sök efter kärleken! [[alternative HTML version deleted]] E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 27-Mar-08 Time: 14:00:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] strptime and plot(),lines()
Hello, Im reading Data out of a Database. #v+ rs - dbGetQuery(con,SELECT * ... ) attach(rs) #v- There ist a colum I convert into Time. #v+ zeit-strptime(datum,format=%Y-%m-%d %H:%M:%S); class(zeit) [1] POSIXt POSIXlt #v- 1. A plot(zeit,money) plots the Data. All i see on the x-achis are the Days. I would like to see the hours also. 2. length(zeit) gives mit the length of one entry. But zeit exists of 500 entries. How can i get the amount of entries zeit got? 3. Im used to draw whith lines() into an existing plot. But something like lines(zeit,food) wouldnt work. All this works quit well, when Im using unixtime. But seconds since 1970 are not that nice on the x-achis:-) Regards Erkan Yanar -- über den grenzen muß die freiheit wohl wolkenlos sein __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] barplot as Trellis graphic
On 3/26/08, Agustin Lobo [EMAIL PROTECTED] wrote: Dear list, Is there any way of making barplots as a Trellis graphic? Yes, the function to use is 'barchart'. -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dynamic string as element name in a list
Hi Henrique, On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: Try this: foo - function(x) { clipname - LK out - list() out[[clipname]] - rnorm(5) return(out) } That easy ... Hadn't thought of it. But now I have a refinement in foo() foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } But this returns the/an empty list? Best regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rule for accessing attributes?
On Thu, 27 Mar 2008, Christos Hatzis wrote: Yes, indeed. The help page says that @ extracts the contents of a slot in S4 objects. But you mention below that this 'works' for S3 objects because S4 slots are stored as attributes. Doesn't this mean that @ is currently implemented to access attributes of objects in general (attributes of S3 objects or slots of S4 objects that are implemented as attributes)? I realize that this might change in the future... Yes, but it will change, quite possibly for 2.7.0. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Thursday, March 27, 2008 3:17 AM To: Christos Hatzis Cc: r-help@r-project.org Subject: Re: [R] Rule for accessing attributes? Oh please don't recommend misuse of @ to those already confused. @ is for accessing slots in S4 objects. This 'works' because they happen to be stored as attributes. See the help page (and the warning that it does no checking - we may change that). Similarly, plt$title - My Title works because the package maintainer (of ggplot2, unmentioned?) has chosen to set things up that way. R is very flexible, and there is plenty of scope for package authors to do confusing things. On Thu, 27 Mar 2008, Christos Hatzis wrote: You need to use the '@' operator to directly access attributes (not elements) of objects: [EMAIL PROTECTED] [1] x y z See ?'@' for more details. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tribo Laboy Sent: Thursday, March 27, 2008 12:16 AM To: r-help@r-project.org Subject: [R] Rule for accessing attributes? Hi ! I am a new user and quite confused by R-indexing. Make a list and get the attributes lst - list(x = 1:3, y = 4:6, z = 7:9) attributes(lst) This returns: $names [1] x y z I can easily do: nm -names(lst) or nm -attr(lst,names) which both return the assigned names of the named list 'lst', but why then this doesn't work: lst$names ? I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g. xydf - data.frame(x = 1:5, y = 11:15) plt - ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt) Now we can change the title: plt$title - My Title plt So is it some inconsistency or am I missing something important? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to apply bootstrap with a grouping variable?
Hello, my name is Alfonso. I'm trying to apply bootstrap to a database. This database present as variables: cohort, age, length, an group. The variable group is unique for each age*cohort, at this way, if we have 18 cohorts and we study individuals with an age between 2 and 10 years (9 diferent ages) then we will have 162 (9*18) diferent numbers in the variable named as group. I would like to apply bootstrap to this database but taken into account the variable group, at this way the resample would be carry out for each cohort*age. I've tried to do it with this sentence: boo - bootstrap(subset.cod,cod.bootstr,nboot=5, strata=subset.cod$Groups,sim=ordinary) and also at this way: boo - bootstrap(subset.cod,nboot=5,cod.bootstr,group=Groups) But I've obtained the beginning error message: Error in FUN(newX[, i], ...) : unused argument(s) (strata = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2... Please, if someone knows something about this question, please let me know. All sugestions will be wellcome, thank you in advance. Alfonso. _ La vida de los famosos al desnudo en MSN Entretenimiento [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dynamic string as element name in a list
HI, I don't understand why you're using lapply. Please provide a example of your 'x' data.frame str(x) On 27/03/2008, Paul Lemmens [EMAIL PROTECTED] wrote: Hi Henrique, On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: Try this: foo - function(x) { clipname - LK out - list() out[[clipname]] - rnorm(5) return(out) } That easy ... Hadn't thought of it. But now I have a refinement in foo() foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } But this returns the/an empty list? Best regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Execute R with *.RData argument
Not sure if this is sufficient but if you always open your RData file in the same directory this may be good enough: mkdir ~/tmp cd ~/tmp R x - 33 q() # answer y to save in .RData Now whenever you open R in ~/tmp it will load .RData containing x. You must be in ~/tmp and the file must be called .RData . If you subsequently quit again in a subsequent session press y to update .RData for the subsequent session or n if you want to keep the first .RData. On Thu, Mar 27, 2008 at 5:02 AM, Bio7 [EMAIL PROTECTED] wrote: Dear R developers, i would like to start R with a *.RData argument under Linux. Something like R -f /home/user/workspace.RData Is this possible? Thanks in advance for any answers. -- View this message in context: http://www.nabble.com/Execute-R-with-*.RData-argument-tp16323374p16323374.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strptime and plot(),lines()
You normally want to represent your times as POSIXct rather than POSIXlt so try xct - as.POSIXct(xlt) or you may want to use chron. Read read more about this in R News 4/1 which has info on dates and times. Use the axis or Axis command to create custom axes. ?axis ?Axis You may also want to look at the zoo package which has numerous examples of working with and plotting time series including three vignettes. On Thu, Mar 27, 2008 at 9:59 AM, erkan yanar [EMAIL PROTECTED] wrote: Hello, Im reading Data out of a Database. #v+ rs - dbGetQuery(con,SELECT * ... ) attach(rs) #v- There ist a colum I convert into Time. #v+ zeit-strptime(datum,format=%Y-%m-%d %H:%M:%S); class(zeit) [1] POSIXt POSIXlt #v- 1. A plot(zeit,money) plots the Data. All i see on the x-achis are the Days. I would like to see the hours also. 2. length(zeit) gives mit the length of one entry. But zeit exists of 500 entries. How can i get the amount of entries zeit got? 3. Im used to draw whith lines() into an existing plot. But something like lines(zeit,food) wouldnt work. All this works quit well, when Im using unixtime. But seconds since 1970 are not that nice on the x-achis:-) Regards Erkan Yanar -- über den grenzen muß die freiheit wohl wolkenlos sein __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dynamic string as element name in a list
Hi, Sorry yes, I forgot to give comment about the lapply(). foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } So x is a dataframe with the data from one subject that has viewed multiple clips in two variations. x contains both the responses as well as info about the clips in factors and responses in integers. So for each clip (using function(c) call in lapply() to be able to access/subset data from x), I extract the name and other info (using c), store that info in a list element named after the clip. Finally return the full list of clips with associated data. Mvg, Paul On Thu, Mar 27, 2008 at 3:23 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: HI, I don't understand why you're using lapply. Please provide a example of your 'x' data.frame str(x) On 27/03/2008, Paul Lemmens [EMAIL PROTECTED] wrote: Hi Henrique, On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: Try this: foo - function(x) { clipname - LK out - list() out[[clipname]] - rnorm(5) return(out) } That easy ... Hadn't thought of it. But now I have a refinement in foo() foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } But this returns the/an empty list? Best regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Want to draw 3D cylinder objects
Here is one approach to drawing simple cylinders at specified locations, the height, width, and angle should all be numbers between 0 and 1 and you may want to rewrite the ms.cylinder function below so that the arguments are more meaningful relative to the input data that you want to use: library(TeachingDemos) ms.cylinder - function(height, width, angle) { + theta - seq(2*pi, 0, length=200) + x1 - cos(theta) * width + y1 - sin(theta) * width * angle + + x - c(x1, x1[1:100], x1[100]) + y - c(y1 + height/2, y1[1:100]-height/2, y1[100]+height/2) + + return(cbind(x,y)) + } x - 0:8 %/% 3 y - 0:8 %% 3 h - runif(9) w - runif(9) a - runif(9) plot(x,y, xlim=c(-.5,2.5), ylim=c(-.5,2.5), type='n') my.symbols(x,y,ms.cylinder, height=h, width=w, angle=a) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans-Joachim Klemmt Sent: Wednesday, March 26, 2008 2:03 PM To: r-help@r-project.org Subject: [R] Want to draw 3D cylinder objects Hello, I want to draw 3D cylinder objects in R. Given is the length and the diameter of the cylinder. Has anybody an example? Thank you very much! Best regards -- -- Dr. Hans-Joachim Klemmt Forstoberrat Organisationsprogrammierer IHK Bayerische Landesanstalt für Wald und Forstwirtschaft zugewiesen an Lehrstuhl für Waldwachstumskunde Technische Universität München Am Hochanger 13 85354 Freising Tel.: 08161/ 7147-14 Fax : 08161/ 7147-21 eMail: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] options in 'rnorm' to set the lower bound of normal dist
On Thu, 27 Mar 2008, [EMAIL PROTECTED] wrote: Brian Ripley's suggestions of truncated normal and log-normal are of course resources for ensuring that you get positive simulated results. I was answering the question asked! Wanting to simulate from the fitted mean and sd does *not* mean you want to emulate the data -- indeed, it is often done to see if peculiar aspects of data have a noticeable effect on the rest of the analysis. I've done this with analytical chemist colleagues several times, although I did point out it was better to use robust summaries. However, I think youre real problem (having looked at the numbers you quote) is that you should not be thinking of using a normal distribution, or anything similar, at all. Your variables dat$x and dat$y have: mean(dat$x) ## [1] 0.3126667 sd(dat$x) ## [1] 0.3372137 mean(dat$y) ## [1] 0.4223137 sd(dat$y) ## [1] 0.5120841 so in both cases the SD is about the same as the mean, and getting negative values from simulated normal distributions with these means and SDs is inevitable. But now look at the two series of 15 numbers in dat$x and dat$y: The first 12 are of the order of 0.15 and 0.20 respectively, while the final 3 in each case are of the order of 1.0 and 1.5 respectively. And this is where your large SD is coming from. Neither series is from a simple normal distribution. mean(dat$x[1:12]) ## [1] 0.1519167 sd(dat$x[1:12]) ## [1] 0.02447432 and it is impossible for the last 3 ( 1.032 0.803 1.032) to have come from a normal distribution giving the first 12. mean(dat$y[1:12]) ## [1] 0.1807932 sd(dat$y[1:12]) ## [1] 0.03380083 with a similar conclusion; and likewise for the last three 1.551043 1.063100 1.551043 Note that, for the first 12 in each case, the SD less that 1/5 of the mean: mean(dat$x[1:12])/sd(dat$x[1:12]) ## [1] 6.207186 mean(dat$y[1:12])/sd(dat$y[1:12]) ## [1] 5.348779 so, where the first 12 of x and y are concerned, if you sampled from normal distributions with the same means and SDs you would get a negative number with probability less than pnorm(-5) ## [1] 2.866516e-07 What you in fact have here is that the numbers are in two groups, each with a small SD relative to its mean: dat$x dat$y Mean SD Mean SD +--- 1:120.152 0.024 | 0.181 0.034 | 13:150.956 0.132 | 1.390.282 Note that for dat$x Mean/SD approx = 6 for each sub-series, and for data$y Mean/SD approx = 5 for each subseries, so you could be looking at results which display a nearly constant coefficient of variation. Now, this is indeed a property of the log-normal distribution (as well as of others), so that could indeed be worth considering. However, you still have to account for the apparent split noted above into distinct groups. So you are really facing a modelling question: why did the numbers come out as they did, and what is a good way to represent that mechanism as a distribution? With best wishes, Ted. On 27-Mar-08 12:27:55, Tom Cohen wrote: Dear list, I have a dataset containing values obtained from two different instruments (x and y). I want to generate 5 samples from normal distribution for each instrument based on their means and standard deviations. The problem is values from both instruments are non-negative, so if using rnorm I would get some negative values. Is there any options to determine the lower bound of normal distribution to be 0 or can I simulate the samples in different ways to avoid the negative values? dat id x y 75 101 0.134 0.1911315 79 102 0.170 0.1610306 76 103 0.134 0.1911315 84 104 0.170 0.1610306 74 105 0.134 0.1911315 80 106 0.170 0.1610306 77 107 0.134 0.1911315 81 108 0.170 0.1610306 82 109 0.170 0.1610306 78 111 0.170 0.1610306 83 112 0.170 0.1610306 85 113 0.097 0.278 2 201 1.032 1.5510434 1 202 0.803 1.0631001 5 203 1.032 1.5510434 mu-apply(dat[,-1],2,mean) sigma-apply(dat[,-1],2,sd) len-5 n-20 s1-vector(list,len) set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=rnorm(n*i,mean=mu[1],sd=sigma[1]), y=rnorm(n*i,mean=mu[2],sd=sigma[2])) } Thanks for any help, Tom - Sök efter kärleken! [[alternative HTML version deleted]] E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 27-Mar-08 Time: 14:00:44 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of
Re: [R] generate random numbers subject to constraints
On Thu, 27 Mar 2008, Robert A LaBudde wrote: At 05:06 PM 3/26/2008, Ted Harding wrote: On 26-Mar-08 21:26:59, Ala' Jaouni wrote: X1,X2,X3,X4 should have independent distributions. They should be between 0 and 1 and all add up to 1. Is this still possible with Robert's method? Thanks I don't think so. A whileago you wrote The numbers should be uniformly distributed (but in the context of an example where you had 5 variable; now you are back to 4 variables). Let's take the 4-case first. The two linear constraints confine the point (X1,X2,X3,X4) to a triangular region within the 4-dimensional unit cube. Say it has vertices A, B, C. You could then start by generating points uniformly distributed over a specific triangle in 2 dimentions, say the one with vertices at A0=(0,0), B0=(0,1), C0=(1,0). This is easy. Then you need to find a linear transformation which will map this triangle (A0,B0,C0) onto the triangle (A,B,C). Then the points you have sampled in (A0,B0,C0) will map into points which are uniformly distributed over the triangle (A,B,C). More generally, you will be seeking to generate points uniformly distributed over a simplex. For example, the case (your earlier post) of 5 points with 2 linear constraints requires a tetrahedron with vertices (A,B,C,D) in 5 dimensions whose coordinates you will have to find. Then take an easy tetrahedron with vertices (A0,B0,C0,D0) and sample uniformly within this. Then find a linear mapping from (A0,B0,C0,D0) to (A,B,C,D) and apply this to the sampled points. This raises a general question: Does anyone know of an R function to sample uniformly in the interior of a general (k-r)-dimensional simplex embedded in k dimensions, with (k+1) given vertices? snip The method of rejection: 1. Generate numbers randomly in the hypercube. 2. Test to see if the point falls within the prescribed area. 3. Accept the point if it does. 4. Repeat if it doesn't. Efficiency depends upon the ratio of volumes involved. The ratio is zero. The subspace of the solution has lower dimension than the space you are sampling from. So you will repeat '4' forever. (Up to machine accuracy, of course.) And as I pointed out in my response to Ala' Jaouni, the 'solution' may lie in the null space. When it does not it will be a point, a line segment, a piece of a plane, or a 3 dimensional simplex. Chuck Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [EMAIL PROTECTED] Least Cost Formulations, Ltd.URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239Fax: 757-467-2947 Vere scire est per causas scire __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strptime and plot(),lines()
As Gabor said, your zeit should be a POSIXct object, not a POSIXlt object. Then, for example: zeit - Sys.time() + 150*runif(10) val - rnorm(10) plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d %H:%M') Or better (perhaps) yet: plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d\n%H:%M', mgp=c(3,2,0)) However, depending on the overall time range, this example might make more sense: zeit - Sys.time() + 15000*runif(10) plot(zeit,val,xaxt='n') axis.POSIXct(1,zeit, format='%Y-%m-%d\n%H:%M', mgp=c(3,2,0)) class(zeit) [1] POSIXt POSIXct -Don At 2:59 PM +0100 3/27/08, erkan yanar wrote: Hello, Im reading Data out of a Database. #v+ rs - dbGetQuery(con,SELECT * ... ) attach(rs) #v- There ist a colum I convert into Time. #v+ zeit-strptime(datum,format=%Y-%m-%d %H:%M:%S); class(zeit) [1] POSIXt POSIXlt #v- 1. A plot(zeit,money) plots the Data. All i see on the x-achis are the Days. I would like to see the hours also. 2. length(zeit) gives mit the length of one entry. But zeit exists of 500 entries. How can i get the amount of entries zeit got? 3. Im used to draw whith lines() into an existing plot. But something like lines(zeit,food) wouldnt work. All this works quit well, when Im using unixtime. But seconds since 1970 are not that nice on the x-achis:-) Regards Erkan Yanar -- über den grenzen muß die freiheit wohl wolkenlos sein __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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! - spectral analysis - spec.pgram
Can someone explain me this spec.pgram effect? Code: period.6-c(0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10 ,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10) period.5-c(0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10 ,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0) par(mfrow=c(2,1)) spec.pgram(period.6, log=no) spec.pgram(period.5, log=no) The first series has period 6 and shows its periodicity in 1/6 and harmonics. In the second series I was expecting to see a signal occurring at frequency 1/5 but it does not. Can anybody explain me why? Thanks in advance, Nuno __ Centro de Oceanografia - IO-FCUL, Portugal Center for Quantitative Fisheries Ecology - ODU, USA email: [EMAIL PROTECTED] ; [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] snow, stopping cluster
Not at present. The next release should include something along these lines. luke On Thu, 27 Mar 2008, Markus Schmidberger wrote: Hello, is there any function in the package snow to check for a really running cluster? The function checkCluster only checks the variable cl. And the variable is still available after stopping the cluster! ( a simple solution would be deleting the cluster variable cl in the function stopCluster) library(snow) cl - makeCluster(5) 5 slaves are spawned successfully. 0 failed. clusterApply(cl, 1:2, get(+), 3) [[1]] [1] 4 [[2]] [1] 5 stopCluster(c1) [1] 1 clusterApply(cl, 1:2, get(+), 3) Fehler in mpi.probe(source, tag, comm, status) : MPI_Error_string: invalid communicator sessionInfo() R version 2.6.0 (2007-10-03) x86_64-unknown-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] affyPara_0.99.2 affy_1.16.0 preprocessCore_1.0.0 [4] affyio_1.6.1 Biobase_1.16.1 Rmpi_0.5-5 [7] snow_0.2-9 loaded via a namespace (and not attached): [1] rcompgen_0.1-15 Best Markus -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: [EMAIL PROTECTED] Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading in multiple files in a loop
Hi, I'm new to R and want to use it to analyse a number of data files (e.g. 100). I want to read in multiple files in a loop in a specific order (e.g. 1 to 100) and was hoping to do something like: for (r in 1:100) { d1 -read.table(r.anl) for (r2 in 1:100) { d2 -read.table(r2.anl) cc -cor(d2,d1) } From my basic understanding of R, it requires in read.table and so, r and r2 would not be substituted. Is there a better way to read in multiple files in an order that preserves numerical order (e.g. 1.anl, 2.anl, 3.anl, 4.anl etc)? Thanks! ZT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help! - spectral analysis - spec.pgram
On Thu, 27 Mar 2008, Nuno Prista wrote: Can someone explain me this spec.pgram effect? Code: period.6-c(0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10 ,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10,0,0,0,0,0,10) period.5-c(0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10 ,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,0,0,10,0,0,0,0,10,0) par(mfrow=c(2,1)) spec.pgram(period.6, log=no) spec.pgram(period.5, log=no) The first series has period 6 and shows its periodicity in 1/6 and harmonics. In the second series I was expecting to see a signal occurring at frequency 1/5 but it does not. Can anybody explain me why? Because it does not have period 5 but 12 With such short series tapering has some effect. Try x - rep(c(0,0,0,0,0,10,0,0,0,0,10,0), 100) spec.pgram(x, log=no) Thanks in advance, Nuno __ Centro de Oceanografia - IO-FCUL, Portugal Center for Quantitative Fisheries Ecology - ODU, USA email: [EMAIL PROTECTED] ; [EMAIL PROTECTED] [[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. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] A faster way to compute finite-difference gradient of a scalar function of a large number of variables
Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are better, more efficient ways to approximate the gradient of a large scalar function in R. Here is an example. grad - function(x, fn=func, eps=1.e-07, ...){ npar - length(x) df - rep(NA, npar) f - fn(x, ...) for (i in 1:npar) { dx - x dx[i] - dx[i] + eps df[i] - (fn(dx, ...) - f)/eps } df } myfunc - function(x){ nvec - 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g - function(x){ nvec - 1: length(x) nvec * (exp(x) - 1) / 10 } p0 - rexp(1000) system.time(g.1 - grad(x=p0, fn=myfunc))[1] system.time(g.2 - myfunc.g(x=p0))[1] max(abs(g.2 - g.1)) Thanks in advance for any help or hints. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading in multiple files in a loop
On Thu, Mar 27, 2008 at 4:40 PM, Zu Thur Yew [EMAIL PROTECTED] wrote: for (r in 1:100) { d1 -read.table(r.anl) read.table(paste(r,.anl, sep=)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] options in 'rnorm' to set the lower bound of normal distribution to 0 ?
Thanks Prof Brian for your suggestion. I should know that for right-skewed data, one should generate the samples from a lognormal. My problem is that x and y are two instruments that were thought to be measured the same thing but somehow show a wide confidence interval of the difference between the two intruments.This may be true that these two measure differently but can also due to the small number of observations, so the idea is if I increases the sample size then I may get better precision between the two instrument by generating samples based on the means and standard deviations from x and y. I am using 'urlnorm' which allows sampling from truncated distribution since I want the samples to take values from 0 to the max(x) respectively max(y). I am unsure how to specify the means and standard deviations in 'urlnorm'. Based on x- and y-values I have standard deviations sd_x=0.3372137, sd_y=0.5120841 and the means mean_x=0.3126667 mean_y=0.4223137 which are not on log scale as required in urlnorm. To covert sd_x, sd_y and mean_x, mean_y on a log-scale I did sd_logx=sqrt(log(1.3372137))=0.54, sd_logy=sqrt(log(1.5120841))=0.64, mean_logx=-(0.54^2)/2 and mean_logy=-(0.64^2)/2. Can anyone tell if these are correctly calculated? Are these the values to be specified in urlnorm? Do the lower respectively upper bound have to be on the log-scale as well or which scale? set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=urlnorm(n*i,meanlog=mean_logx,sdlog=sd_logx, lb=0, ub=max(x)), y=urlnorm(n*i,meanlog=mean_logy,sdlog=sd_logy, lb=0, ub=max(y))) } Thanks again for any suggetions. Prof Brian Ripley [EMAIL PROTECTED] skrev: On Thu, 27 Mar 2008, Tom Cohen wrote: Dear list, I have a dataset containing values obtained from two different instruments (x and y). I want to generate 5 samples from normal distribution for each instrument based on their means and standard deviations. The problem is values from both instruments are non-negative, so if using rnorm I would get some negative values. Is there any options to determine the lower bound of normal distribution to be 0 or can I simulate the samples in different ways to avoid the negative values? Well, that would not be a normal distribution. If you want a _truncated_ normal distribution it is very easy by inversion. E.g. trunc_rnorm - function(n, mean = 0, sd = 1, lb = 0) { lb - pnorm(lb, mean, sd) qnorm(runif(n, lb, 1), mean, sd) } but I suggest you may rather want samples from a lognormal. dat id x y 75 101 0.134 0.1911315 79 102 0.170 0.1610306 76 103 0.134 0.1911315 84 104 0.170 0.1610306 74 105 0.134 0.1911315 80 106 0.170 0.1610306 77 107 0.134 0.1911315 81 108 0.170 0.1610306 82 109 0.170 0.1610306 78 111 0.170 0.1610306 83 112 0.170 0.1610306 85 113 0.097 0.278 2 201 1.032 1.5510434 1 202 0.803 1.0631001 5 203 1.032 1.5510434 mu-apply(dat[,-1],2,mean) sigma-apply(dat[,-1],2,sd) len-5 n-20 s1-vector(list,len) set.seed(7) for(i in 1:len){ s1[[i]]-cbind.data.frame(x=rnorm(n*i,mean=mu[1],sd=sigma[1]), y=rnorm(n*i,mean=mu[2],sd=sigma[2])) } Thanks for any help, Tom - S?? efter k??leken! [[alternative HTML version deleted]] -- 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, UK Fax: +44 1865 272595 - Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] inheritence in S4
[EMAIL PROTECTED] wrote: Sorry to come back on callNextMethod, I am still not very confident about it. Consideres the following (there is a lot of code, but very simple with almost only some cat) : -- setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) .Object - callNextMethod() return(.Object) }) setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object){ cat( Init B \n) .Object - callNextMethod() return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # * Valid A * #*** Valid B *** # An object of class B # Slot b: # [1] 2 # # Slot a: # [1] 3 new(B) will go trought - initialize B that will call the nextMethod that is : - initialize A that will call the nextMethod that is : - initialize ANY call validObject A. This would be perfect... But there is also a call to validObject B. Where does it come from ? You're creating a B object, so validObject is called on B. This probably makes you wonder why, then, validObject is being called on A. And the answer to this is that the validity method of 'B' is responsible only for the unique aspects of the object that relate to B. validObject A has to be called so that the parts of B that are inheritted from A can be checked. This is anoying because : In an object-oriented sense, initialize,B-method should really just deal with it's own slots; it shouldn't have to 'know' about either classes that it extends (A) or classes that extend it. I completly agree with that. But if the author of A change its code : - setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) [EMAIL PROTECTED] - 10 return(.Object) }) setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object){ cat( Init B \n) .Object - callNextMethod() return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # An object of class B # Slot b: # numeric(0) # # Slot a: # [1] 10 - Then validObject of B is no longer call, and B is no longueur correctly set... Yes this would be a bad thing for the author of A to do (in my opinion). So if A is changed by its author, the comportement of B is change as well... Anoying, isn't it ? Yes, but in any object oriented system you're relying on inherited methods to fulfill a contract. If they change the contract (e.g., no longer guaranteeing that slots will be populated and validity checked), then downstream classes have to change. But I agree with the initialize,B-method should really just deal with it's own slots; So may be something like : - setClass(A,representation(a=numeric)) setValidity(A,function(object){cat( * Valid A *\n);TRUE}) setMethod(initialize,A,function(.Object){ cat(** Init A **\n) #[EMAIL PROTECTED] - 10 .Object - callNextMethod() return(.Object) }) Here you're implementing part of the functionality of the default method (populating slots) so this code duplication is not very good practice (in my opinion). setClass(B,representation(b=numeric),contains=A) setValidity(B,function(object){cat( *** Valid B ***\n);TRUE}) setMethod(initialize,B,function(.Object,a,b){ cat( Init B \n) as(.Object,A) - new(A,a=a) [EMAIL PROTECTED] - b return(.Object) }) new(B,a=3,b=2) Result # Init B # ** Init A ** # An object of class B # Slot b: # [1] 2 # # Slot a: # [1] 10 - The call to validObject of B is no longer dependent of the A code. You're free to do what you like, of course. This replicates functionality of the default method (slot assignment) and does it in an inefficient way (making unnecessary copies of .Object; this matters when real-world objects are large). There is no validity checking, and to ensure that you'd have to add to your paradigm that all initialize methods call validObject. Because of the way validObject is implemented, you'll end up evaluating it multiple times for each construction of B. Lack of ... in the argument list means that derived classes must use your convention for object initialization, so you've replaced one (semi-established) convention with another. A close reading of initialize shows that the contract is more complicated than what we've talked about, with unnamed arguments used to
Re: [R] Dynamic string as element name in a list
But, your lapply is: lapply(x$clipno, function(c){ clipname - x$clipname out[[clipname]] - rnorm(5) }) So, you don't use 'c' argument. On 27/03/2008, Paul Lemmens [EMAIL PROTECTED] wrote: Hi, Sorry yes, I forgot to give comment about the lapply(). foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } So x is a dataframe with the data from one subject that has viewed multiple clips in two variations. x contains both the responses as well as info about the clips in factors and responses in integers. So for each clip (using function(c) call in lapply() to be able to access/subset data from x), I extract the name and other info (using c), store that info in a list element named after the clip. Finally return the full list of clips with associated data. Mvg, Paul On Thu, Mar 27, 2008 at 3:23 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: HI, I don't understand why you're using lapply. Please provide a example of your 'x' data.frame str(x) On 27/03/2008, Paul Lemmens [EMAIL PROTECTED] wrote: Hi Henrique, On Thu, Mar 27, 2008 at 2:52 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: Try this: foo - function(x) { clipname - LK out - list() out[[clipname]] - rnorm(5) return(out) } That easy ... Hadn't thought of it. But now I have a refinement in foo() foo - function(x) { out - list() lapply(x$clipno, function(c) { clipname - x$clipname # stuff out[[clipname]] - rnorm(5) }) return(out) } But this returns the/an empty list? Best regards, Paul Lemmens __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 faster way to compute finite-difference gradient of a scalarfunction of a large number of variables
Here is as solution that calculates derivatives using central differences by appropriately embedding the vectors: grad.1 function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) y.e - apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) cbind(x=x.e[, 1], grad=y.e) } myfunc.1 function(x){ (exp(x) - x) / 10 } system.time(g.3 - grad.1(p0, myfunc.1)) user system elapsed 0.060.000.07 CAVEAT: this assumes that the x-values are equally spaced, i.e. same h throughout, but this part can be easily modified to accommodate h1, h2 on either side of x. Also, your myfunc takes a vector input and returns a scalar. If this is what was intended, you will need to find a way to vectorize it. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan Sent: Thursday, March 27, 2008 12:00 PM To: [EMAIL PROTECTED] Subject: [R] A faster way to compute finite-difference gradient of a scalarfunction of a large number of variables Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are better, more efficient ways to approximate the gradient of a large scalar function in R. Here is an example. grad - function(x, fn=func, eps=1.e-07, ...){ npar - length(x) df - rep(NA, npar) f - fn(x, ...) for (i in 1:npar) { dx - x dx[i] - dx[i] + eps df[i] - (fn(dx, ...) - f)/eps } df } myfunc - function(x){ nvec - 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g - function(x){ nvec - 1: length(x) nvec * (exp(x) - 1) / 10 } p0 - rexp(1000) system.time(g.1 - grad(x=p0, fn=myfunc))[1] system.time(g.2 - myfunc.g(x=p0))[1] max(abs(g.2 - g.1)) Thanks in advance for any help or hints. Ravi. -- -- --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -- -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Code and the Pygments Python SyntaxHighlighter
Dear R Help, is someone going to write a R/S language lexer for the Pygments Python syntax highlighter http://pygments.org/? As it is used now by Trac, Django, or the Python documentation tool Sphinx, the R community can apply it in Python-based Wikis like Moinmoin and others. Hans Werner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 faster way to compute finite-difference gradient of ascalarfunction of a large number of variables
If 'myfunc' is a vector function and can be vectorized in R, then it is even faster to use the following: grad.vec - function(x, fn, ..., eps = sqrt(.Machine$double.neg.eps)){ x1 - x + eps * pmax(abs(x), 1) x2 - x - eps * pmax(abs(x), 1) (fn(x1, ...) - fn(x2, ...)) / (x1 - x2) } grad.1 - function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) } myfunc.1 - function(x){ (exp(x) - x) / 10 } p0 - rexp(1000) system.time(for(i in 1:500) out1 - grad.1(p0, myfunc.1)) system.time(for(i in 1:500) out2 - grad.vec(p0, myfunc.1)) but for scalar functions I don't think that there is any other way than the one Ravi already has used (maybe doing the whole computation in C??). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Christos Hatzis [EMAIL PROTECTED] To: 'Ravi Varadhan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 27, 2008 5:36 PM Subject: Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables Here is as solution that calculates derivatives using central differences by appropriately embedding the vectors: grad.1 function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) y.e - apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) cbind(x=x.e[, 1], grad=y.e) } myfunc.1 function(x){ (exp(x) - x) / 10 } system.time(g.3 - grad.1(p0, myfunc.1)) user system elapsed 0.060.000.07 CAVEAT: this assumes that the x-values are equally spaced, i.e. same h throughout, but this part can be easily modified to accommodate h1, h2 on either side of x. Also, your myfunc takes a vector input and returns a scalar. If this is what was intended, you will need to find a way to vectorize it. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan Sent: Thursday, March 27, 2008 12:00 PM To: [EMAIL PROTECTED] Subject: [R] A faster way to compute finite-difference gradient of a scalarfunction of a large number of variables Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are better, more efficient ways to approximate the gradient of a large scalar function in R. Here is an example. grad - function(x, fn=func, eps=1.e-07, ...){ npar - length(x) df - rep(NA, npar) f - fn(x, ...) for (i in 1:npar) { dx - x dx[i] - dx[i] + eps df[i] - (fn(dx, ...) - f)/eps } df } myfunc - function(x){ nvec - 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g - function(x){ nvec - 1: length(x) nvec * (exp(x) - 1) / 10 } p0 - rexp(1000) system.time(g.1 - grad(x=p0, fn=myfunc))[1] system.time(g.2 - myfunc.g(x=p0))[1] max(abs(g.2 - g.1)) Thanks in advance for any help or hints. Ravi. -- -- --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -- -- [[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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide
[R] Dendrogram orientation
I am using the two functions hclust and plot to draw a dendrogram. The result is a vertical dendrogram , but I prefer a horizontal one. Need help. This is my script: dd1=hclust(d1, method=ward) plot(dd1) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables
Thank you, Dimitris Christos. Yes, myfunc is a scalar function that needs to be minimized over a high-dimensional parameter space. I was afraid that there might be no better way, apart from coding in C. Thanks, Dimitris, for confirming my fear! Best regards, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: Dimitris Rizopoulos [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 12:55 PM To: [EMAIL PROTECTED]; 'Ravi Varadhan' Cc: [EMAIL PROTECTED] Subject: Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables If 'myfunc' is a vector function and can be vectorized in R, then it is even faster to use the following: grad.vec - function(x, fn, ..., eps = sqrt(.Machine$double.neg.eps)){ x1 - x + eps * pmax(abs(x), 1) x2 - x - eps * pmax(abs(x), 1) (fn(x1, ...) - fn(x2, ...)) / (x1 - x2) } grad.1 - function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) } myfunc.1 - function(x){ (exp(x) - x) / 10 } p0 - rexp(1000) system.time(for(i in 1:500) out1 - grad.1(p0, myfunc.1)) system.time(for(i in 1:500) out2 - grad.vec(p0, myfunc.1)) but for scalar functions I don't think that there is any other way than the one Ravi already has used (maybe doing the whole computation in C??). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Christos Hatzis [EMAIL PROTECTED] To: 'Ravi Varadhan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 27, 2008 5:36 PM Subject: Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables Here is as solution that calculates derivatives using central differences by appropriately embedding the vectors: grad.1 function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) y.e - apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) cbind(x=x.e[, 1], grad=y.e) } myfunc.1 function(x){ (exp(x) - x) / 10 } system.time(g.3 - grad.1(p0, myfunc.1)) user system elapsed 0.060.000.07 CAVEAT: this assumes that the x-values are equally spaced, i.e. same h throughout, but this part can be easily modified to accommodate h1, h2 on either side of x. Also, your myfunc takes a vector input and returns a scalar. If this is what was intended, you will need to find a way to vectorize it. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan Sent: Thursday, March 27, 2008 12:00 PM To: [EMAIL PROTECTED] Subject: [R] A faster way to compute finite-difference gradient of a scalarfunction of a large number of variables Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are better, more efficient ways to approximate the gradient of a large scalar function in R. Here is an example. grad - function(x, fn=func, eps=1.e-07, ...){ npar - length(x) df - rep(NA, npar) f - fn(x, ...) for (i in 1:npar) { dx - x dx[i] - dx[i] + eps df[i] - (fn(dx, ...) - f)/eps } df } myfunc - function(x){ nvec - 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g - function(x){ nvec - 1: length(x) nvec * (exp(x) - 1) / 10 } p0 - rexp(1000) system.time(g.1 - grad(x=p0, fn=myfunc))[1] system.time(g.2 - myfunc.g(x=p0))[1] max(abs(g.2 - g.1)) Thanks in advance for any help or hints. Ravi. -- -- --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage:
Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables
On Thu, 27 Mar 2008, Ravi Varadhan wrote: Thank you, Dimitris Christos. Yes, myfunc is a scalar function that needs to be minimized over a high-dimensional parameter space. I was afraid that there might be no better way, apart from coding in C. Thanks, Dimitris, for confirming my fear! But there is C code available to do it: no one has remembered what is in 'Writing R Extensions' where it crops up in several places. See numericDeriv in stats, for one piece of C code with an R interface. Best regards, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: Dimitris Rizopoulos [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 12:55 PM To: [EMAIL PROTECTED]; 'Ravi Varadhan' Cc: [EMAIL PROTECTED] Subject: Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables If 'myfunc' is a vector function and can be vectorized in R, then it is even faster to use the following: grad.vec - function(x, fn, ..., eps = sqrt(.Machine$double.neg.eps)){ x1 - x + eps * pmax(abs(x), 1) x2 - x - eps * pmax(abs(x), 1) (fn(x1, ...) - fn(x2, ...)) / (x1 - x2) } grad.1 - function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) } myfunc.1 - function(x){ (exp(x) - x) / 10 } p0 - rexp(1000) system.time(for(i in 1:500) out1 - grad.1(p0, myfunc.1)) system.time(for(i in 1:500) out2 - grad.vec(p0, myfunc.1)) but for scalar functions I don't think that there is any other way than the one Ravi already has used (maybe doing the whole computation in C??). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Christos Hatzis [EMAIL PROTECTED] To: 'Ravi Varadhan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, March 27, 2008 5:36 PM Subject: Re: [R] A faster way to compute finite-difference gradient of ascalarfunction of a large number of variables Here is as solution that calculates derivatives using central differences by appropriately embedding the vectors: grad.1 function(x, fn) { x - sort(x) x.e - head(embed(x, 2), -1) y.e - embed(fn(x), 3) hh - abs(diff(x.e[1, ])) y.e - apply(y.e, 1, function(z) (z[1] - z[3])/(2 * hh)) cbind(x=x.e[, 1], grad=y.e) } myfunc.1 function(x){ (exp(x) - x) / 10 } system.time(g.3 - grad.1(p0, myfunc.1)) user system elapsed 0.060.000.07 CAVEAT: this assumes that the x-values are equally spaced, i.e. same h throughout, but this part can be easily modified to accommodate h1, h2 on either side of x. Also, your myfunc takes a vector input and returns a scalar. If this is what was intended, you will need to find a way to vectorize it. -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan Sent: Thursday, March 27, 2008 12:00 PM To: [EMAIL PROTECTED] Subject: [R] A faster way to compute finite-difference gradient of a scalarfunction of a large number of variables Hi All, I would like to compute the simple finite-difference approximation to the gradient of a scalar function of a large number of variables (on the order of 1000). Although a one-time computation using the following function grad() is fast and simple enough, the overhead for repeated evaluation of gradient in iterative schemes is quite significant. I was wondering whether there are better, more efficient ways to approximate the gradient of a large scalar function in R. Here is an example. grad - function(x, fn=func, eps=1.e-07, ...){ npar - length(x) df - rep(NA, npar) f - fn(x, ...) for (i in 1:npar) { dx - x dx[i] - dx[i] + eps df[i] - (fn(dx, ...) - f)/eps } df } myfunc - function(x){ nvec - 1: length(x) sum(nvec * (exp(x) - x)) / 10 } myfunc.g - function(x){ nvec - 1: length(x) nvec * (exp(x) - 1) / 10 } p0 - rexp(1000) system.time(g.1 - grad(x=p0, fn=myfunc))[1] system.time(g.2 - myfunc.g(x=p0))[1] max(abs(g.2 - g.1)) Thanks in advance for any help or hints. Ravi.
Re: [R] Thinking about using two y-scales on your plot?
Hello all, I know I'm not making friends with this, but: I absolutely see the point in dual-(or more!)-y-axis plots! I find them quite informative, and I see them often. In Earth-Sciences (and I very generously include atmospheric sciences here, as Johannes has given an example of a meteorological plot...) very often time-series plots of some values are given rather to show the temporal correlation of these, than to show the actual numerical values! The same applies for plots of some sample values over distance (eg. element concentration over a sample or investigation area). In this case one is more interested in whether some values change simultaneously, than what the actual values at every point are. In the mentioned plot (see link below), the temporal evolution of the mean temperature and of the precipitation over a year is the important information. No-one would get confused or yield wrong conclusions, if the curves would intersect somewhere else, only because of a shift of one y-axis relative to the other!? (which was proposed to be one of the great dangers of dual-scaled axes in the article Hadley posted) On the other hand, you would never express temperature in terms of a percentage of some arbitrary start value, if you could give it just in plain °C!? (as was proposed as a workaround in the article mentioned) An awkward scale like this makes the actual graph much harder to read, not easier, as proposed. Furthermore, since the observed values in Earth Sciences often show a cyclic behavior, the graphs would still cross each other over and over again, no matter what the scale was. So my conclusion for now: I'd answer the Question are dual-scaled axes in graphs ever the best solution? with a definitive YES. Maybe only in some specialized applications, but - yes. I strongly expect this discussion to go on (as I've read frequently here that these kind of graphs are considered very inappropriate..) and I am happy to learn to do better graphs, if you can show me to be wrong... Greetings, Martin Johannes Hüsing wrote: I wonder how long it will take until metereologists will see the light. http://www.zoolex.org/walter.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Recode factors
I know this comes up, but I didn't see my exact issue in the archives. I have variables in a dataframe that need to be recoded. Here is what I'm dealing with I have a factor called aa class(aa) [1] factor table(aa) aa *0123ABCDLNT 00 1908 725 208900 6700216 I need to recode everything that is not a numeric value into a 0. So, for example mm - ifelse(aa == 'B', 0, aa) table(mm) mm 0345 11 12 13 67 1908 725 2089216 The recoding works, but the values are no longer what they were previously. For example, what was a '1' is now a '4' etc. Is there a way to recode factors and also keep the values the same as they were before? That is, a '1' would remain a '1' after the recode? After the recoding, I need to convert to a numeric variable. I can do this as mm - as.numeric(as.character(aa)) Harold sessionInfo() R version 2.6.2 (2008-02-08) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gdata_2.4.0 loaded via a namespace (and not attached): [1] gtools_2.4.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recode factors
If I understand, you can try this: levels(x)[is.na(as.numeric(levels(x)))] - 0 On 27/03/2008, Doran, Harold [EMAIL PROTECTED] wrote: I know this comes up, but I didn't see my exact issue in the archives. I have variables in a dataframe that need to be recoded. Here is what I'm dealing with I have a factor called aa class(aa) [1] factor table(aa) aa *0123ABCDLNT 00 1908 725 208900 6700216 I need to recode everything that is not a numeric value into a 0. So, for example mm - ifelse(aa == 'B', 0, aa) table(mm) mm 0345 11 12 13 67 1908 725 2089216 The recoding works, but the values are no longer what they were previously. For example, what was a '1' is now a '4' etc. Is there a way to recode factors and also keep the values the same as they were before? That is, a '1' would remain a '1' after the recode? After the recoding, I need to convert to a numeric variable. I can do this as mm - as.numeric(as.character(aa)) Harold sessionInfo() R version 2.6.2 (2008-02-08) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gdata_2.4.0 loaded via a namespace (and not attached): [1] gtools_2.4.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Recode factors
Perfect. My headache is gone. Thanks. -Original Message- From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 12:50 PM To: Doran, Harold Cc: r-help@r-project.org Subject: Re: [R] Recode factors If I understand, you can try this: levels(x)[is.na(as.numeric(levels(x)))] - 0 On 27/03/2008, Doran, Harold [EMAIL PROTECTED] wrote: I know this comes up, but I didn't see my exact issue in the archives. I have variables in a dataframe that need to be recoded. Here is what I'm dealing with I have a factor called aa class(aa) [1] factor table(aa) aa *0123ABCDLNT 00 1908 725 208900 6700216 I need to recode everything that is not a numeric value into a 0. So, for example mm - ifelse(aa == 'B', 0, aa) table(mm) mm 0345 11 12 13 67 1908 725 2089216 The recoding works, but the values are no longer what they were previously. For example, what was a '1' is now a '4' etc. Is there a way to recode factors and also keep the values the same as they were before? That is, a '1' would remain a '1' after the recode? After the recoding, I need to convert to a numeric variable. I can do this as mm - as.numeric(as.character(aa)) Harold sessionInfo() R version 2.6.2 (2008-02-08) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gdata_2.4.0 loaded via a namespace (and not attached): [1] gtools_2.4.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] barplot as Trellis graphic
Thanks, it was a matter of reshaping the data matrix as I usually have it, ie: datos - data.frame(x=abs(round(rnorm(100,10,5))),y=abs(round(rnorm(100,2,1))),f=factor(round(runif(100,1,3 to become: datos2 - data.frame(V1=c(datos[,1],datos[,2]),VAR=c(rep(x,100),rep(y,100)),f=factor(c(datos[,3],datos[,3]))) and then require(lattice) barchart(V1~VAR|f,data=datos2) I get horizontal lines in the bars that I do not understand, though. Agus Deepayan Sarkar escribió: On 3/26/08, Agustin Lobo [EMAIL PROTECTED] wrote: Dear list, Is there any way of making barplots as a Trellis graphic? Yes, the function to use is 'barchart'. -Deepayan -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: [EMAIL PROTECTED] http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] barplot as Trellis graphic
On Mar 27, 2008, at 1:47 PM, Agustin Lobo wrote: Thanks, it was a matter of reshaping the data matrix as I usually have it, ie: datos - data.frame(x=abs(round(rnorm(100,10,5))),y=abs(round(rnorm (100,2,1))),f=factor(round(runif(100,1,3 to become: datos2 - data.frame(V1=c(datos[,1],datos[,2]),VAR=c(rep(x,100),rep(y, 100)),f=factor(c(datos[,3],datos[,3]))) and then require(lattice) barchart(V1~VAR|f,data=datos2) I get horizontal lines in the bars that I do not understand, though. In order to understand the lines , you should ask: What does the height of each bar correspond to? As you have set things up, the x bar in panel 1 should somehow correspond to the all values: datos2$V1[datos2$VAR==x datos2$f==1] [1] 15 13 14 1 18 14 8 12 7 19 10 1 5 14 7 9 14 7 5 10 6 12 10 11 11 7 15 [28] 9 4 12 17 10 4 5 So you should ask yourself, how you expect R to produce a single column, which in some sense corresponds to just one single number, its height, from these different values. My guess is that you want R to show you just the mean on each group. For me this is not a barplot, but anyway. What happens in the barplot you have now, I think, is this that R will start by constructing a bar with height 15, then put on it a bar of height 13, then on it a bar of height 14 and so on. So the lines you see account for the boxes that survive: x-datos2$V1[datos2$VAR==x datos2$f==1] unique(cummax(rev(x))) [1] 5 10 17 19 I would recommend using boxplots instead of barplots only showing the means. If you really want barplots of the means, I think you can do the following: datos3 - with(datos2, aggregate(x=V1, by=list(VAR=VAR,f=f), mean)) barchart(x~VAR|f, datos3) Another option would be ggplot2 I think, but I'll let someone knowledgeable with that package speak up. Agus Haris Skiadas Department of Mathematics and Computer Science Hanover College __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assistance with RDAtest beta version application
Pierre Legendre has developed a beta version of a new redundancy analysis package called RdaTest that is available on his web page at the Universit® de Montréal. The test example that is included with the package is based on the example provided in his book (Numerical Ecology, Chapter 11 (Legendre Legendre 1998)) I have downloaded the package and am attempting to run it so that I might learn how to match the outputs from the RDA test to the outputs in the book. this is a first step towards me eventually using this technique to analyze my own data with this methodology. However, I keep hitting road blocks trying to get the package to work and so am looking for someone who has used this test package and could help me troubleshoot. Any takers? Les [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Execute R with *.RData argument
Thanks for the nice tip. I also consider to use the clipboard to transfer a command with the file path which then can be pasted easily in the shell and executed. Gabor Grothendieck wrote: Not sure if this is sufficient but if you always open your RData file in the same directory this may be good enough: mkdir ~/tmp cd ~/tmp R x - 33 q() # answer y to save in .RData Now whenever you open R in ~/tmp it will load .RData containing x. You must be in ~/tmp and the file must be called .RData . If you subsequently quit again in a subsequent session press y to update .RData for the subsequent session or n if you want to keep the first .RData. On Thu, Mar 27, 2008 at 5:02 AM, Bio7 [EMAIL PROTECTED] wrote: Dear R developers, i would like to start R with a *.RData argument under Linux. Something like R -f /home/user/workspace.RData Is this possible? Thanks in advance for any answers. -- View this message in context: http://www.nabble.com/Execute-R-with-*.RData-argument-tp16323374p16323374.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Execute-R-with-*.RData-argument-tp16323374p16331147.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recode factors
Another suggestion is: blah = as.character(aa) blah=gsub('[a-z]','0',blah,ignore.case=T) aa = as.factor(blah) I've found changing factors to characters rather than numeric is generally safer. Abhijit Doran, Harold wrote: Perfect. My headache is gone. Thanks. -Original Message- From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 12:50 PM To: Doran, Harold Cc: r-help@r-project.org Subject: Re: [R] Recode factors If I understand, you can try this: levels(x)[is.na(as.numeric(levels(x)))] - 0 On 27/03/2008, Doran, Harold [EMAIL PROTECTED] wrote: I know this comes up, but I didn't see my exact issue in the archives. I have variables in a dataframe that need to be recoded. Here is what I'm dealing with I have a factor called aa class(aa) [1] factor table(aa) aa *0123ABCDLNT 00 1908 725 208900 6700216 I need to recode everything that is not a numeric value into a 0. So, for example mm - ifelse(aa == 'B', 0, aa) table(mm) mm 0345 11 12 13 67 1908 725 2089216 The recoding works, but the values are no longer what they were previously. For example, what was a '1' is now a '4' etc. Is there a way to recode factors and also keep the values the same as they were before? That is, a '1' would remain a '1' after the recode? After the recoding, I need to convert to a numeric variable. I can do this as mm - as.numeric(as.character(aa)) Harold sessionInfo() R version 2.6.2 (2008-02-08) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] gdata_2.4.0 loaded via a namespace (and not attached): [1] gtools_2.4.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] histogram for integer data
hi, library(lattice) x-c(-1,-1,-1,0,0,0,0,1,1,2) rng-range(x) histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x))) instead of contiguous bins, i'd like spaces between them to indicate that the data is discrete, or even better, line segments positioned at integer values. i know how to do this with plot, but i need it with histogram, so that in more complicated contexts i can use histogram(~x| f1 * f2) thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assistance with RDAtest beta version application
Hi ! I am familiar with the rdaTest package. It works perfectly find for me. Can you give me more details on the problems you have so I can be of greater help ! Have a nice day ! Guillaume Blanchet PhD student Stanfield, Les (MNR) a écrit : Pierre Legendre has developed a beta version of a new redundancy analysis package called RdaTest that is available on his web page at the Universit® de Montréal. The test example that is included with the package is based on the example provided in his book (Numerical Ecology, Chapter 11 (Legendre Legendre 1998)) I have downloaded the package and am attempting to run it so that I might learn how to match the outputs from the RDA test to the outputs in the book. this is a first step towards me eventually using this technique to analyze my own data with this methodology. However, I keep hitting road blocks trying to get the package to work and so am looking for someone who has used this test package and could help me troubleshoot. Any takers? Les [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dreaded p-val for d^2 of a glm / gam
OK, I really dread to ask that much more that I know some discussion about p-values and if they are relevant for regressions were already on the list. I know to get p-val of regression coefficients - this is not a problem. But unfortunately one editor of a journal where i would like to publish some results insists in giving p-values for the squared deviance i get out from different glm and gam models. I came up with this solution, but sincerely i would like to get yours'all opinion on the matter. p1.glm - glm(count ~be+ch+crr+home, family = 'poisson') # count - is count of species (vegetation) # be, ch, crr, home - different lidar metrics # calculating d^2 d2.p1 - round((p1.glm[[12]]-p1.glm[[10]])/p1.glm[[12]],4) d2.p1 0.6705 # calculating f statistics with N = 148 and n=4; f = (N-n-1)/(N-1)(1-d^2) f - (148-4-1)/(147*(1-0.6705)) f [1] 2.952319 #calculating p-value pval.glm - 1-pf(f, 147,143) pval.glm [1] 1.135693e-10 So, what do you think? Is this acceptable if i really have to give a p-value for the deviance squared? If it is i think i will transform everything in a fuction Thanks, Monica _ Windows Live Hotmail is giving away Zunes. M_Mobile_Zune_V3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] generating a paired t-test with multiple levels of a factor
James == James Root [EMAIL PROTECTED] writes: Is there a way to run all paired t-tests where a paired t-test is run for every possible combination? Sounds like pairwise.t.test is the sort of thing you are looking for... Mike __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] colMeans in a data.frame with numeric and character data
Hi all, I would like to know if it is posible by, someway, to get colMeans from a data.frame with numeric as well as character data, dispersed all over the object. Note that I would like to get colMeans neglecting character data. I am really in need of some function proceeding in that way All the best Diogo André Alagador [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram for integer data
You might consider something based on the concept of: y - table( x) plot( as.numeric(names(y)) , y, type='h') -Don At 2:59 PM -0400 3/27/08, [EMAIL PROTECTED] wrote: hi, library(lattice) x-c(-1,-1,-1,0,0,0,0,1,1,2) rng-range(x) histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x))) instead of contiguous bins, i'd like spaces between them to indicate that the data is discrete, or even better, line segments positioned at integer values. i know how to do this with plot, but i need it with histogram, so that in more complicated contexts i can use histogram(~x| f1 * f2) thanks! [[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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 for integer data
Thanks! Yes, but I also want to be able to condition easily hence histogram(...), not plot -Original Message- From: Don MacQueen [mailto:[EMAIL PROTECTED] Sent: Thursday, March 27, 2008 3:55 PM To: Rogard, Erwann RD/US/EXT; r-help@r-project.org Subject: Re: [R] histogram for integer data You might consider something based on the concept of: y - table( x) plot( as.numeric(names(y)) , y, type='h') -Don At 2:59 PM -0400 3/27/08, [EMAIL PROTECTED] wrote: hi, library(lattice) x-c(-1,-1,-1,0,0,0,0,1,1,2) rng-range(x) histogram(x,endpoints=c(rng[1]-0.5,rng[2]+0.5),nint=length(unique(x))) instead of contiguous bins, i'd like spaces between them to indicate that the data is discrete, or even better, line segments positioned at integer values. i know how to do this with plot, but i need it with histogram, so that in more complicated contexts i can use histogram(~x| f1 * f2) thanks! [[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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] generating a paired t-test with multiple levels of a factor
On 28/03/2008, at 8:42 AM, Michael A. Miller wrote: James == James Root [EMAIL PROTECTED] writes: Is there a way to run all paired t-tests where a paired t-test is run for every possible combination? Sounds like pairwise.t.test is the sort of thing you are looking for... Mike Don't forget to pass along the argument ``paired=TRUE'' (in the ``...'' arguments)!!! cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] colMeans in a data.frame with numeric and character data
try this: dat - data.frame(x = rnorm(10), y = rexp(10), z = letters[1:10]) colMeans(data.matrix(dat[sapply(dat, is.numeric)])) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Diogo André Alagador [EMAIL PROTECTED]: Hi all, I would like to know if it is posible by, someway, to get colMeans from a data.frame with numeric as well as character data, dispersed all over the object. Note that I would like to get colMeans neglecting character data. I am really in need of some function proceeding in that way All the best Diogo André Alagador [[alternative HTML version deleted]] Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assistance with RDAtest beta version application
Hi !! Stanfield, Les (MNR) a écrit : Thank you so much for coming to my rescue!: OK I have been able to open it (but only in the R editor. I assumed that we had to generate our own files of XX.txt and YY.txt and bring them into R before the program could run Is this right? Yon do not have to, but you can. I personally like to import the whole file I'm working (here Table_11-3.txt) and go from there. If you feel more comfortable to do it another way there is no problem there ! So I created two as tab delimited text files (Here they are). I am able to bring them into R and when I edit them, they look fine. OK This is the code to this stage: rdaTest - function(YY.mat, XX.mat, WW.mat=NULL, scale.Y=FALSE, testF=NULL, nperm=NULL, print.results=TRUE, print.cum=FALSE) { library(MASS) # Read the data tables. Transform them into matrices Y, X, and W YY.mat = -read.table(YY.txt) XX.mat = -read.table(XX.txt) Y.mat=as.matrix(YY.mat) X.mat=as.matrix(XX.mat) bb-edit(y.mat) bb-edit(x.mat) But when I try to then convert these two files to mat files, nothing happens? I'm assuming it has something to do with this step, but I can't figure it out. Note: I tried creating base yy.mat and xx.mat files, by just changing the file names, but that didn't work. So is this the problem, When I look at the y.mat and x.mat they look no different than the original txt files Here I get a bit confused Here is what I propose: ### Load the whole file tab11.3-read.table(Table_11-3.txt,header=TRUE,row.names=1) ### Extract the species (Y) and the environmental variables (X) from tab11.3 Y-tab11.3[,1:6] X-tab11.3[,7:10] ### Calculate the RDA coco-rdaTest(Y,X,testF=TRUE,nperm=999) coco ### Draw the triplot graph.rdaTest(coco,plot.type=F) With these couple of lines you should get the same results as the ones presented in Legendre and Legendre (1998). Les Stanfield Have a nice day !! Guillaume Blanchet __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] colMeans in a data.frame with numeric and character data
On Thu, Mar 27, 2008 at 3:05 PM, Dimitris Rizopoulos [EMAIL PROTECTED] wrote: try this: dat - data.frame(x = rnorm(10), y = rexp(10), z = letters[1:10]) colMeans(data.matrix(dat[sapply(dat, is.numeric)])) Alternatively sapply(dat, mean) x y z -0.5260131 1.0523121 NA Warning message: In mean.default(X[[3L]], ...) : argument is not numeric or logical: returning NA If you don't like the warning message showing up you can wrap the expression in suppressWarnings(). Quoting Diogo André Alagador [EMAIL PROTECTED]: Hi all, I would like to know if it is posible by, someway, to get colMeans from a data.frame with numeric as well as character data, dispersed all over the object. Note that I would like to get colMeans neglecting character data. I am really in need of some function proceeding in that way… All the best Diogo André Alagador [[alternative HTML version deleted]] Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extracting single output data into a vector or matrix
I've been struggling to do the following: After a lengthy computation, I receive an output along the lines of the list below. This list has 41 values and is not the end of my computations. I have another computation to do on the list below, but in this final computation the list is supposed to be a vector. I've tried to assign the list below to a data frame and then extract it, but not luck! Cleary, this is because each of the outputs in the list represents an individual data point that is not regarded as part of a matrix. Any help? I desperately need to be able to extract all the output data into a Vector so I can perform the final step of my computation. Thanks in advance. [1] 1.573233e-10 [1] 2.939187e-10 [1] 5.491124e-10 [1] 1.025877e-09 [1] 1.916591e-09 [1] 3.580663e-09 [1] 6.689559e-09 [1] 1.249774e-08 [1] 2.334885e-08 [1] 4.36214e-08 [1] 8.149551e-08 [1] 1.522537e-07 [1] 2.844473e-07 [1] 5.314175e-07 [1] 9.928186e-07 [1] 1.854829e-06 [1] 3.465277e-06 [1] 6.47399e-06 [1] 1.209501e-05 [1] 2.259645e-05 [1] 4.221572e-05 [1] 7.886935e-05 [1] 0.0001473473 [1] 0.0002752811 [1] 0.0005142927 [1] 0.0009608253 [1] 0.001795058 [1] 0.00335361 [1] 0.006265368 [1] 0.01171493 [1] 0.02188637 [1] 0.04088913 [1] 0.07639071 [1] 0.1427168 [1] 0.2666308 [1] 0.4981322 [1] 0.9306848 [1] 1.738748 [1] 3.248409 [1] 6.068827 [1] 11.33806 - [[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] functions
I wrote some functions for multiway CANDECOMP, i.e. for least squares fitting of a_{i_1\cdots i_m}\approx\sum_{s=1}^p x^1_{i_1s}x^1_{i_1s}\cdots x^m_{i_ms} with arrays of arbitrary dimension. Reminded me of the good old APL days. I could not find this in the archives, but if it's already there, I would appreciate if someone let me know. == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225, 661-245-1725 .mac: jdeleeuw ++ aim: deleeuwjan ++ skype: j_deleeuw homepages: http://www.cuddyvalley.org and http://gifi.stat.ucla.edu == The Good -- and this is surely true -- is just the Bad that we don't do ! (Wilhelm Busch) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] colMeans in a data.frame with numeric and character data
summaryBy in the doBy package can do that. The builtin iris data set has 4 numeric columns and one factor column: library(doBy) summaryBy(.~1, iris, fun = mean, keep = TRUE) Sepal.Length Sepal.Width Petal.Length Petal.Width 1 5.843.0573333.7581.199333 On Thu, Mar 27, 2008 at 3:22 PM, Diogo André Alagador [EMAIL PROTECTED] wrote: Hi all, I would like to know if it is posible by, someway, to get colMeans from a data.frame with numeric as well as character data, dispersed all over the object. Note that I would like to get colMeans neglecting character data. I am really in need of some function proceeding in that way… All the best Diogo André Alagador [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] functions
Sorry. I mean a_{i_1i_2\cdots i_m}\approx\sum_{s=1}^p x^1_{i_1s}x^2_{i_2s}\cdots x^m_{i_ms} -- J. On Mar 27, 2008, at 12:57 , Jan de Leeuw wrote: I wrote some functions for multiway CANDECOMP, i.e. for least squares fitting of a_{i_1\cdots i_m}\approx\sum_{s=1}^p x^1_{i_1s}x^1_{i_1s}\cdots x^m_{i_ms} with arrays of arbitrary dimension. Reminded me of the good old APL days. I could not find this in the archives, but if it's already there, I would appreciate if someone let me know. == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 home 661-245-1725 skype 661-347-0667 global 254-381-4905 .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw == Many nights on the road and not dead yet --- the end of autumn. (Basho 1644-1694) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Covariates in LME?
On Thu, Mar 27, 2008 at 7:01 AM, Aberg Carl [EMAIL PROTECTED] wrote: Hi, Im using lme to calculate a mixed factors ANOVA according to: px_anova = anova(lme(dep~music*time*group, random = ~1|id, data = px_data)) where dep is a threshold, time is a repeated measures variable (2 levels) group is a between subjects variable (2 levels) id is a random factor (subject id) music is a between subjects variable (2 levels) indicating if a person has a musical experience, or not Musical experience is now decided by categorizing depending on the number of years practicing playing an instrument. I would like to use the years of playing an instrument as a covariate instead of creating categories. Hmm. Your question can be answered on the level of tactics (i.e. an immediate response to the question that was asked) or on the level of strategy (considering why are you asking the question in the first place). The tactics answer is just to use the numeric variable, say 'years', instead of the factor 'music'. The formula language for linear models in R is very flexible and is described in many of the books that are listed on the Books link at www.r-project.org The strategy answer would address the question of why you are writing the model as dep ~ music*time*group and why you don't save the fitted model but instead immediately pass it to the anova function. It seems that you are approaching the problem as a special type of ANOVA problem so the only items of interest are the F statistics and p-values in an ANOVA table. The more common approach in R is to model your data, first by plotting the data so you can formulate an initial model, then fitting that model, examining residual plots and other diagnostics, and modifying the model if indicated. Only after that process has converged on a model that seems reasonable does one calculate inferential statistics such as p-values. The inferential statistics are always based on mathematical models of the data and will be misleading unless the model is appropriate. The model is never correct. As George Box famously said, All models are wrong; however, some models are useful. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Extracting single output data into a vector or matrix
Ayman, It is difficult to say without seeing some code, but your output seems to be not a list in the R sense but a collection of vectors, each of length 1. The best way to put the values into a vector probably is to assign them to the elements of the vector during your computations. Mike Prager Ayman Oweida [EMAIL PROTECTED] wrote: I've been struggling to do the following: After a lengthy computation, I receive an output along the lines of the list below. This list has 41 values and is not the end of my computations. I have another computation to do on the list below, but in this final computation the list is supposed to be a vector. I've tried to assign the list below to a data frame and then extract it, but not luck! Cleary, this is because each of the outputs in the list represents an individual data point that is not regarded as part of a matrix. Any help? I desperately need to be able to extract all the output data into a Vector so I can perform the final step of my computation. Thanks in advance. [1] 1.573233e-10 [1] 2.939187e-10 [1] 5.491124e-10 [1] 1.025877e-09 [1] 1.916591e-09 [1] 3.580663e-09 [1] 6.689559e-09 [1] 1.249774e-08 [1] 2.334885e-08 [1] 4.36214e-08 [1] 8.149551e-08 [1] 1.522537e-07 [1] 2.844473e-07 [1] 5.314175e-07 [1] 9.928186e-07 [1] 1.854829e-06 [1] 3.465277e-06 [1] 6.47399e-06 [1] 1.209501e-05 [1] 2.259645e-05 [1] 4.221572e-05 [1] 7.886935e-05 [1] 0.0001473473 [1] 0.0002752811 [1] 0.0005142927 [1] 0.0009608253 [1] 0.001795058 [1] 0.00335361 [1] 0.006265368 [1] 0.01171493 [1] 0.02188637 [1] 0.04088913 [1] 0.07639071 [1] 0.1427168 [1] 0.2666308 [1] 0.4981322 [1] 0.9306848 [1] 1.738748 [1] 3.248409 [1] 6.068827 [1] 11.33806 - [[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. -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] list as object in dataframe
Hi All, I need to place lists or vectors within dataframes as single elements. However when I try this: df=data.frame(y=1, x=I(list(c(a,b), c(f,c), c(a df df[1,'x']=I(c(a,d)) I get this error, even though I am using I(): Error in `[-.data.frame`(`*tmp*`, 1, x, value = c(a, d)) : replacement has 2 rows, data has 1 Note that this behavior does not match that described here http:// finzi.psych.upenn.edu/R/Rhelp02a/archive/37297.html in this post from 2004. Can someone please point me towards the right way to do this? Thanks!! Dan $platform [1] i386-apple-darwin8.10.1 $arch [1] i386 $os [1] darwin8.10.1 $system [1] i386, darwin8.10.1 $status [1] $major [1] 2 $minor [1] 6.2 $year [1] 2008 $month [1] 02 $day [1] 08 $`svn rev` [1] 44383 $language [1] R $version.string [1] R version 2.6.2 (2008-02-08) [[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] panel function question
I have two data sets with locations, X, Y of houses (df.house) and habitats(df.habitat), respectively. In each dataset, there are 3 replicates (Repeat). Because each replicate has different locations of houses and habitats, I would like to plot them in panels. I wrote something like this: mypanel-function(x,y,subscripts,...){ panel.xyplot(x,y,pch=20) panel.xyplot( df.habitat$X[subscripts], df.habitat$Y[subscripts], pch=3) } with(df.house, xyplot(X~Y|Repeat, panel=mypanel, subscripts=T)) But the problem is that all habitats from 3 replicates are ended in one panel. Any help would be appreciated. Weidong Gu Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 [[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.