Re: [R] How to detect and exclude outliers in R?
Hi V.S., Did you search first on r-repositories about this issue prior to ask? May be not. RSiteSearch(outliers) bests milton On Tue, Jan 19, 2010 at 1:08 AM, vikrant vikrant.shi...@tcs.com wrote: Suppose I am reading data from a file and the data contains some outliers. I want to know if it is possible in R to automatically detect outliers in a dataset and remove them -- View this message in context: http://n4.nabble.com/How-to-detect-and-exclude-outliers-in-R-tp1017285p1017285.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to open excel 2007 (.xlsx) file in R
Dear V.K., 1. http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html 2. it is - in general - good someone that write to the list identify your self. It is a polite way of participate of the list. bests milton On Tue, Jan 19, 2010 at 12:15 AM, vikrant vikrant.shi...@tcs.com wrote: i am unable to open a file which is saved as .xlsx format in R . The file contains approximately 1,50,000 rows. So I m not able to save it as csv file.Please suggest ways to open this file -- View this message in context: http://n4.nabble.com/how-to-open-excel-2007-xlsx-file-in-R-tp1017273p1017273.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data import export zipped files from URLs
Velappan Periasamy wrote: I am not able to import zipped files from the following link. How to get thw same in to R?. mydata - read.csv(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) As Brian Ripley noted in http://markmail.org/message/7dsauipzagq5y36o you will have to download it first and then to unzip. Dieter -- View this message in context: http://n4.nabble.com/Data-import-export-zipped-files-from-URLs-tp1017287p1017326.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to open excel 2007 (.xlsx) file in R
vikrant wrote: i am unable to open a file which is saved as .xlsx format in R . The file contains approximately 1,50,000 rows. Use odbcConnectExcel2007 in package RODBC to read these data. So I m not able to save it as csv file. I do not understand why you want to use R to convert an xlsx file to csv. Even if you are a command line aficionado, I recommend to use the features of Excel to do this. Dieter -- View this message in context: http://n4.nabble.com/how-to-open-excel-2007-xlsx-file-in-R-tp1017273p1017327.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] Predict polynomial problem
On Tue, Jan 19, 2010 at 1:36 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: Its the environment thing. I think you want something like this: models[[i]]=lm( bquote( y ~ poly(x,.(i)) ), data=d) Use terms( mmn[[3]] ) both with and without this change and ls( env = environment( formula( mmn[[3]] ) ) ) get(i,env=environment(formula(mmn[[3]]))) sapply(mmn,function(x) environment( formula( x ) ) ) to see what gives. Think I see it now. predict involves evaluating poly, and poly here needs 'i' for the order. If the right 'i' isn't gotten when predict is called then I get the error. Your fix sticks the right 'i' into the environment when predict is called. I haven't quite got my head round _how_ it does it, and I have no idea how I could have figured this out for myself. Oh well... The following lines are also illustrative: d = data.frame(x=1:10,y=runif(10)) i=3 #1 naive model: m1 = lm(y~poly(x,i),data=d) #2,3 bquote, without or with i-wrapping: m2 = lm(bquote(y~poly(x,i)),data=d) m3 = lm(bquote(y~poly(x,.(i))),data=d) #1 works, gets 'i' from global i=3 above: predict(m1,newdata=data.frame(x=9:11)) #2 fails - why? predict(m2,newdata=data.frame(x=9:11)) #3 works, gets 'i' from within: predict(m3,newdata=data.frame(x=9:11)) rm(i) #1 now fails because we removed 'i' from top level: predict(m1,newdata=data.frame(x=9:11)) #2 still fails: predict(m2,newdata=data.frame(x=9:11)) #3 still works: predict(m3,newdata=data.frame(x=9:11)) Thanks -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] read.table with special chars
Hi all, I am just starting with R and I have come across a problem which I guess it is easy to solve. I am reading a table with read.table function. This table contains chars which seem to be problematic when reading them such as ' and #, if I remove these characters fromt the table by hand the problem disappears. Otherwise, the whole table is not read, since reading stops at the problematic tuple. I have been looking in the ?read.table manual but have not found anything. Is there any option to make R not interpret these characters? Thanks in advance Marc -- - Marc Noguera i Julian, PhD Genomics unit / Bioinformatics Institut de Medicina Preventiva i Personalitzada del Càncer (IMPPC) B-10 Office Carretera de Can Ruti Camí de les Escoles s/n 08916 Badalona, Barcelona __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] column selection for aggregate()
Hi If I really wanted aggregate all numerics by all non numerics this is how I would do it my.numerics - which(sapply(zeta, is.numeric)) my.factor - which(sapply(zeta, is.factor)) aggregate(zeta[, my.numerics], zeta[, my.factor], mean) Regards Petr r-help-boun...@r-project.org napsal dne 18.01.2010 16:33:17: I didn't understand from the help what really does the function rowMeans but it looks like it doesn't take into account the categorical variables (I want to calculate the means when the values of all categorical variables are the same, second part of aggregate). Moreover, ssfa_num contains only numeric variables, meaning that the categories will not be associated with it. I'm kind of confused with this approach. You think it would work for me? Thanks Ivan b k a écrit : On Mon, Jan 18, 2010 at 10:17 AM, Ivan Calandra ivan.calan...@uni-hamburg.de mailto:ivan.calan...@uni-hamburg.de wrote: Thanks for your answer, but it doesn't work... Here is what I get: ssfamean - aggregate(ssfa[[10:24]],ssfa[c(SPECSHOR, BONE, TO_POS, FACETTE, SHEARFAC, ENA_BA)],mean) Error in .subset2(x, i, exact = exact) : recursive indexing failed at level 2 Wouldn't you be better off with rowMeans() ? Split your dataframe into numeric matrix: ssfa_num - ssfa[10:24] ssfameans - rowMeans(ssfa_num) Also col_index - match(Asfc, ssfa) doesn't really work since col_index is composed of 1227 NAs... Yes, it should be: col_index - match(Asfc, names(ssfa)) Ben [[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] Help using Cast (Text) Version
Hi Hadley Thanks I have downloaded the intro and the material and will work through it once get a chance Thanks for your interest Regards Steve - Original Message - From: hadley wickham h.wick...@gmail.com To: David Winsemius dwinsem...@comcast.net Cc: Steve Sidney sbsid...@mweb.co.za; r-help@r-project.org Sent: Monday, January 18, 2010 9:43 PM Subject: Re: [R] Help using Cast (Text) Version If you can point me towards a doc that explains this in simple terms I would be obliged. Don't expect you to have to provide the answer. Any of the introductory texts should explain the various forms of indexing and the use of the apply family of functions. They are both central to effective R programming. See also the plyr package, http://had.co.nz/plyr, which tries to provide a more uniform interface to the apply family of functions. I've also tried to document everything in one place, so hopefully it's a bit easier to learn and to see how all the different functions fit together. 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] read.table with special chars
On 01/19/2010 07:41 PM, Marc Noguera wrote: Hi all, I am just starting with R and I have come across a problem which I guess it is easy to solve. I am reading a table with read.table function. This table contains chars which seem to be problematic when reading them such as ' and #, if I remove these characters fromt the table by hand the problem disappears. Otherwise, the whole table is not read, since reading stops at the problematic tuple. I have been looking in the ?read.table manual but have not found anything. Is there any option to make R not interpret these characters? Hi Marc, Try changing the quote argument to \ and the comment.char argument to . 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] read.table with special chars
Thanks Jim, I've tried that but still no luck. Some other suggestions? Thanks again Marc Jim Lemon wrote: On 01/19/2010 07:41 PM, Marc Noguera wrote: Hi all, I am just starting with R and I have come across a problem which I guess it is easy to solve. I am reading a table with read.table function. This table contains chars which seem to be problematic when reading them such as ' and #, if I remove these characters fromt the table by hand the problem disappears. Otherwise, the whole table is not read, since reading stops at the problematic tuple. I have been looking in the ?read.table manual but have not found anything. Is there any option to make R not interpret these characters? Hi Marc, Try changing the quote argument to \ and the comment.char argument to . Jim . -- - Marc Noguera i Julian, PhD Genomics unit / Bioinformatics Institut de Medicina Preventiva i Personalitzada del Càncer (IMPPC) B-10 Office Carretera de Can Ruti Camí de les Escoles s/n 08916 Badalona, Barcelona __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Odp: For loops in R
Hi r-help-boun...@r-project.org napsal dne 19.01.2010 02:32:45: Hello Petr. For the random values, I wanted to generate a different random number for each element of my velocity matrix. So will this do it? rmat - matrix(runif(1000), 500,2) rmat2 - matrix(runif(1000), 500,2) rindex - sample(1:500, replace=TRUE) #with repetition velocity-0.4 * velocity + rmat * (pbestsVar - popVar) + rmat2 * (archiveVar[rindex,] - popVar) AFAICS it seems to do what you want. Basically your rmat and rmat2 will have different numbers from uniform distribution. If you wanted different distribution of random numbers you need to use differend random number generator. See ?rnorm. And repetition means that in your index you can have some rows more times and some rows never. Again only you know if this is desired behaviour. If not use replace=FALSE. Also, do the apply methods perform better than for loops given the same function? sample: apply(x, fun) and for (i in 1:length(x)) fun(x[i]) In some quite recent R-News (I believe 2009 or 2008) there is an article about loops. And also R-Inferno by P.Burns is worth reading. My opinion is that simple cycles and apply functions are more or less similar. When I want to scan a file and make same plots for each column I use for cycle and in most other cases I use *apply family. If you have nested cycles which work correctly in reasonable time why not use them. But usually vectorised approach can be far quicker and, when you get used to it, clearer. Regards Petr cheers cjmr -- View this message in context: http://n4.nabble.com/For-loops-in-R-tp1015933p1017196.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] exporting text output to pdf
The modified snippet (with the long paragraph truncated) does not produce anything like the requested document. -- View this message in context: http://n4.nabble.com/exporting-text-output-to-pdf-tp837699p1017332.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] exporting text output to pdf
Thanks a lot! -- View this message in context: http://n4.nabble.com/exporting-text-output-to-pdf-tp837699p1017331.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] column selection for aggregate()
Not really, I tried without select = - c(MEASUREM, SEL_FACET, SEL_MEAS) and indeed the mean was not computed, but it still appeared in the data, which I didn't want. Thanks a lot for your help Ivan Gabor Grothendieck a écrit : It looks ok except you have both specified the wanted factors and removed the undesired factors from the data frame. You only need to do one of these as in the example I gave, not both, so the solution could be simpler. On Mon, Jan 18, 2010 at 11:19 AM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Hi! It looks like it works perfectly. However, since I cannot check whether I get the good result or not, can you please let me know if you see any mistakes? Here is the code: ssfamean - summaryBy(.~SPECSHOR+BONE+TO_POS+FACETTE+SHEARFAC+ENA_BA, data = subset(ssfa, select = - c(MEASUREM, SEL_FACET, SEL_MEAS)), FUN=mean) That should give me the mean for all numerical variables grouped by SPECSHOR+BONE+TO_POS+FACETTE+SHEARFAC+ENA_BA (i.e. the mean of the rows with equal values for all these variables) on the data file ssfa without the columns for MEASUREM, SEL_FACET, SEL_MEAS, right? Sorry to ask such stupid question, but this line will give me the data I have to analyze, I cannot afford to make any mistake here (nowhere of course, but here I cannot really check). Thanks in advance Ivan Gabor Grothendieck a écrit : Try summaryBy in the doBy package. e.g. using the built-in CO2 summarize each numeric variable by each factor except for the factors Plant and Type: library(doBy) summaryBy(. ~ ., data = subset(CO2, select = - c(Plant, Type))) On Mon, Jan 18, 2010 at 9:53 AM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Hi everybody! I'm working on R today so I have a lot of questions (you may have noticed that it's the 3rd email today). I'm new on R, so please excuse the spam! I have a dataset ssfa with many rows and the column names are: names(ssfa) [1] SPECSHOR BONE TO_POSMEASUREM FACETTE SHEARFAC [7] ENA_BASEL_FACET SEL_MEAS Asfc Smc epLsar [13] HAsfc4HAsfc9HAsfc16 HAsfc25 HAsfc36 HAsfc49 [19] HAsfc64 HAsfc81 HAsfc100 HAsfc121 Tfv Ftfv I want to aggregate that way: ssfamean - aggregate(ssfa[c(Asfc, Smc, epLsar, HAsfc4, HAsfc9, HAsfc16, HAsfc25, HAsfc36, HAsfc49, HAsfc64, HAsfc81, HAsfc100, HAsfc121, Tfv, Ftfv)], ssfa[c(SPECSHOR, BONE, TO_POS, FACETTE, SHEARFAC, ENA_BA)], mean). As you can see, it is very long since I have many variables. Basically I want to select all numerical variables (10 to 24), and all categorical variables except MEASUREM, SEL_FACET and SEL_MEAS without having to write each of them. I would also like to avoid writing the names, the indexes would be nice. I tried with: ssfamean - aggregate(ssfa[c(ssfa[[10]]:ssfa[[24]])], ssfa[c(SPECSHOR, BONE, TO_POS, FACETTE, SHEARFAC, ENA_BA)], mean) but it obviously doesn't work (well obviously...) Could anyone help me on this? Thanks in advance Ivan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read.table with special chars
On 01/19/2010 08:26 PM, Marc Noguera wrote: Thanks Jim, I've tried that but still no luck. Some other suggestions? The comment.char change should have worked, as others have reported that it did. The single quote problem came up a few weeks ago and the answer then was to remove the single quotes. Perhaps these are more difficult to ignore than comment characters. It is probably a good idea to try globally removing or substituting these, as they will probably cause trouble later even if they can be read in. 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] Rotating pca scores
Hello On 1/18/10, francesca.ior...@googlemail.com francesca.ior...@googlemail.com wrote: Does anybody know how I can obtain/calculate rotated PC scores with R? You might want to try principal() in package psych, and see if it does what you need. With this function you can use all the rotations provided by GPArotation. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] exporting text output to pdf
Hi, You could play with the splitTextGrob() function from the RGraphics package, string - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo ipsum, ultricies scelerisque volutpat non, volutpat et nulla. Curabitur consequat ullamcorper tellus id imperdiet. Duis semper malesuada nulla, blandit lobortis diam fringilla at. Vestibulum nec tellus orci, eu sollicitudin quam. Phasellus sit amet enim diam. Phasellus mattis hendrerit varius. Curabitur ut tristique enim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed convallis, tortor id vehicula facilisis, nunc justo facilisis tellus, sed eleifend nisi lacus id purus. Maecenas tempus sollicitudin libero, molestie laoreet metus dapibus eu. Mauris justo ante, mattis et pulvinar a, varius pretium eros. Curabitur fringilla dui ac dui rutrum pretium. Donec sed magna adipiscing nisi accumsan congue sed ac est. Vivamus lorem urna, tristique quis accumsan quis, ullamcorper aliquet velit. library(RGraphics) g - splitTextGrob(string) grid.draw(g) See also this ggplot2 thread for mixing this kind of basic text with tables and graphics using only Grid functions, http://groups.google.com/group/ggplot2/browse_frm/thread/808af3b15d54ef38/822d8c2296ef3447 I haven't seen mention here of asciidoc or brew, these two packages might give you other options. HTH, baptiste 2010/1/18 Dimitri Shvorob dimitri.shvo...@gmail.com: ... You can modify this (dysfunctional) snippet. pdf() plot.new() mtext(Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque leo ipsum, ultricies scelerisque volutpat non, volutpat et nulla. Curabitur consequat ullamcorper tellus id imperdiet. Duis semper malesuada nulla, blandit lobortis diam fringilla at. Vestibulum nec tellus orci, eu sollicitudin quam. Phasellus sit amet enim diam. Phasellus mattis hendrerit varius. Curabitur ut tristique enim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed convallis, tortor id vehicula facilisis, nunc justo facilisis tellus, sed eleifend nisi lacus id purus. Maecenas tempus sollicitudin libero, molestie laoreet metus dapibus eu. Mauris justo ante, mattis et pulvinar a, varius pretium eros. Curabitur fringilla dui ac dui rutrum pretium. Donec sed magna adipiscing nisi accumsan congue sed ac est. Vivamus lorem urna, tristique quis accumsan quis, ullamcorper aliquet velit.) mtext(A nice-looking paragraph! Now this is what I call good advice!) dev.off() -- View this message in context: http://n4.nabble.com/exporting-text-output-to-pdf-tp837699p1017087.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] call R with un expression (String)?
Hi, ?eval seems like a good candidate HTH, baptiste 2010/1/15 Jiiindo jiin...@yahoo.com: Hello all, I want to call R from java. And I have a expression in Java as a String, example : (variable 1 + variable 2)* variable 3 and i want R calculate this expression. How can I do? ex: Java -int x1,x2; -float x3; -String s=( x1.toString()+x2.toString() ) * x3.toString(); R: calculate expression s and return in to Java? Thanks Jin -- View this message in context: http://n4.nabble.com/call-R-with-un-expression-String-tp1014832p1014832.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on using WinBUGS on Mac
On 19.01.2010 03:23, Wayne (Yanwei) Zhang wrote: Dear all, I had trouble in setting up WinBUGS on my Mac, and I'm seeking for some help here. I followed the instruction by Tom Palmer here: http://www.ruudwetzels.com/MacBUGS/winbugsonmacosx.pdf I installed Darwine 1.1.21, and downloaded WinBUGS14. However, when I double-clicked the WinBUGS14.exe file, a black-box dialog window poped up, and I got error message in the Wine log as follows: fixme:keyboard:RegisterHotKey (0x10032,13,0x0002,3): stub err:ole:CoGetClassObject class {0003000a---c000-0046} not registered err:ole:CoGetClassObject class {0003000a---c000-0046} not registered err:ole:CoGetClassObject no class object {0003000a---c000- 0046} could be created for context 0x3 So this is a WinBUGS on Darwine question that needs to be solved at first - pelase ask on a bugs/Darwine/Mac related mailing list. This is unrelated to R (and errors with R2WinBUGS on the ancient R version reported below are coming from this first problem). Best, Uwe Ligges I googled this and saw some other people having the same problem, but I did not find any useful answer to this. Then I tried to run the schools example in the R2WinBUGS package as follows: schools- read.table (schools.txt, header=TRUE) J- nrow(schools) y- schools$estimate sigma.y- schools$sd data- list (J, y, sigma.y) inits- function() {list (theta=rnorm(J,0,100), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100))} parameters- c(theta, mu.theta, sigma.theta) schools.sim- bugs (data, inits, parameters, model.file=schoolsmodel.bug, n.chains=3, n.iter=1000, bugs.directory=/Applications/WinBUGS14, WINE=/Applications/Darwine/Wine.bundle/Contents/bin/wine, WINEPATH=/Applications/Darwine/Wine.bundle/Contents/bin/winepath, useWINE=TRUE,clearWD=FALSE) It still did not work, and the same error message occurred, plus some error message from R: fixme:keyboard:RegisterHotKey (0x10058,13,0x0002,3): stub err:ole:CoGetClassObject class {0003000a---c000-0046} not registered err:ole:CoGetClassObject class {0003000a---c000-0046} not registered err:ole:CoGetClassObject no class object {0003000a---c000- 0046} could be created for context 0x3 Error in bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE, : Look at the log file and try again with 'debug=TRUE' to figure out what went wrong within Bugs. The information returned from sessionInfo() is the following: sessionInfo() R version 2.8.1 (2008-12-22) i386-apple-darwin8.11.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] foreign_0.8-29 arm_1.2-8 R2WinBUGS_2.1-13 coda_0.13-4 lme4_0.999375-28 Matrix_0.999375-23 lattice_0.17-17 [8] MASS_7.2-45 loaded via a namespace (and not attached): [1] grid_2.8.1 Would someone please help on this ? What did I miss? Thanks, Wayne __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] apply command
Can you please help on the issue? I using the apply command on a matrix below the example: Create a vector x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5) create a matrix of 2 rows by 6 columns b=matrix(x, 2,6) print(b) [,1] [,2] [,3] [,4] [,5] [,6] [1,]524791 [2,]33 NA325 using the command apply print(apply(b, 1, function(y) sort(y, na.last=F))) the output is a matrix of 6 rows by 2 columns. [,1] [,2] [1,]1 NA [2,]22 [3,]43 [4,]53 [5,]73 [6,]95 As you can see in the example I start with a matrix of (2 by 6) and the output of apply is a mtraxi of (6 by 2). This is very strange because I was expecting as output a matrix of the same dim (2 by 6) of the input matrix. I can solve this issues using an if statment on the dim of the matrix but if I am using a square matrix I am not able to control if the result of the apply is correct. Do anyone find a solution to this issue? thanks Marco [[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] apply command
Hello Marco What I would do, is use t to transpose the matrix. Why it is that apply switches the matrix, is beyond my knowledge - and I would love to read more informed replies. Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com/ (English) -- On Tue, Jan 19, 2010 at 12:27 PM, marco salvini marco.salv...@gmail.comwrote: Can you please help on the issue? I using the apply command on a matrix below the example: Create a vector x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5) create a matrix of 2 rows by 6 columns b=matrix(x, 2,6) print(b) [,1] [,2] [,3] [,4] [,5] [,6] [1,]524791 [2,]33 NA325 using the command apply print(apply(b, 1, function(y) sort(y, na.last=F))) the output is a matrix of 6 rows by 2 columns. [,1] [,2] [1,]1 NA [2,]22 [3,]43 [4,]53 [5,]73 [6,]95 As you can see in the example I start with a matrix of (2 by 6) and the output of apply is a mtraxi of (6 by 2). This is very strange because I was expecting as output a matrix of the same dim (2 by 6) of the input matrix. I can solve this issues using an if statment on the dim of the matrix but if I am using a square matrix I am not able to control if the result of the apply is correct. Do anyone find a solution to this issue? thanks Marco [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help ~
-- View this message in context: http://n4.nabble.com/Help-tp1017274p1017414.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] Macaulay Duration for Group
Dear R helpers I have following csv file which is an input id par_value coupon_rate frequency_coupon tenure ytm 1 1000 10 1 5 12 # Here frequency_coupon is coded s.t. 0 means Daily compounding, 1 means monthly compouding, 2 means Quarterly, 3 means Half yearly and 4 means only once. Thus in the case the frequency_coupon = 1 means, total number of times compounding is done = 12. My R Code for calcualting Macaulay Duration is as follows - ## INPUT ONS = read.csv('instrument details..csv') par_value = ONS$par_value coupon = ONS$coupon_rate*par_value/100 freq_coupon = ONS$frequency_copoun tenure = ONS$tenure ytm = ONS$ytm # _ ## COMPUTATIONS macaulay_duration = NULL modified_duration = NULL freq_coupon_new = NULL if(freq_coupon = 0) { freq_coupon_new = 365 } if(freq_coupon 0 freq_coupon = 1) { freq_coupon_new = 12 } if(freq_coupon 1 freq_coupon = 2) { freq_coupon_new = 4 } if(freq_coupon 2 freq_coupon = 3) { freq_coupon_new = 2 } if(freq_coupon 3 freq_coupon = 4) { freq_coupon_new = 1 } ## COMPUTATIONS terms_coupon_payment = (seq(1/freq_coupon_new, tenure, by = 1/freq_coupon_new))*freq_coupon_new coupon_amount = coupon/(freq_coupon_new) cash_flow1 = rep(c(coupon_amount), (tenure*freq_coupon_new - 1)) cash_flow2 = par_value + coupon_amount cash_flow = c(cash_flow1, cash_flow2) ytm_effective = ((1+ytm/100)^(1/freq_coupon_new))-1 pv = NULL for (i in 1:(tenure*freq_coupon_new)) { pv[i] = cash_flow[i] / ((1+ytm_effective)^terms_coupon_payment[i]) } macaulay_duration = sum(pv*terms_coupon_payment)/sum(pv) modified_duration = macaulay_duration / (1+(ytm_effective)/freq_coupon_new) macaulay_duration modified_duration ## _ # My PROBLEM Here I am dealing with only one id i.e. only one record. However, if Instead of one record, ahve say 20 records, how do I calculate the Macaulay Duration for each of these 20 records. One option is to run this code 20 times *which I guess will be foolish thing to do. Other method is to define above code as some function and tehn run this function for each of these records, but I don't underatnd how to write a function and thord option is to treat the input of these 20 records in a matrix form, which I had tried unsuccessfully. Please guide me as to how do I modify the R-code to calculate Mac duration for each of tehse records and store tehm. Regards Madhavi Bhave The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[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] restricted permutations in permtest()?
Hallo List, I'm trying to implemement a restricted permutation scheme in permutest(). More precisely I have dependence in my data that should be allowed for in the permutation - I simulated the problem in the example of the vegan documentation p.24: library(vegan) data(varespec) ## Bray-Curtis distances between samples dis - vegdist(varespec) ## First 16 sites grazed, remaining 8 sites ungrazed groups - factor(c(rep(1,16), rep(2,8)), labels = c(grazed,ungrazed)) ## Calculate multivariate dispersions mod - betadisper(dis, groups) ## Perform test anova(mod) ##simulation of dependence; blocks blocks-factor(c(rep(1,4),rep(2,4),rep(3,4),rep(4,4))) ##the unrestricted Permutation test for F is permutest(mod, pairwise = TRUE) ..I wasn't able to find out the right syntax for implementation of blocks, I tried with argument strata, which would be blocks, in permutest(mod, pairwise = TRUE, blocks) but this doesn't work. By the way, what is 'pairwise = TRUE' for? Thanks for any help, Kay - Mag. Kay Cichini Institute of Botany Sternwartestr. 15 A-6020 Innsbruck Tel.: +43 (0)512 507 5938 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 ~
Fan Dan wrote: Generate a clustered pattern in [0; 1]2 as follows: (a) Generate n, say 20, independent cluster centers (which can be called parents) that are distributed i.i.d. uniformly in the unit square; (b) then m,say 100, daughters are assigned i.i.d. uniformly to these parents and such that each daughter is located i.i.d. uniformly in a disk of radius r = 0:1 centred at her parent, under the periodic boundary conditions, i.e. the square is converted into a torus. I tried some but can not figure out the whole thing. Thank you very much for your time. Yours Wolfgang Amadeus Dear Wolfgang Amadeus, next time you post homework here, please make sure that you modify the language of the task a bit so that the discrepancy between the task and your helplessness is less evident. You really are the greatest composer on earth. Better stick with that. Josef Haydn / currently London -- View this message in context: http://n4.nabble.com/Help-tp1017274p1017423.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] PCA scores and loadings
Dear R users group I have performed PCA using the function rda in vegan and then used plot(pcaobject). I have a couple of questions: 1) The default plot shows the individual sites (black) and the variables (red). What I want however is a plot showing the mean of site groups with bidirectional error bars displaying the standard deviation for those groups (with the variables still plotted in the background)... 2) ...I know how to do this by export the scores and loadings to excel and then using excel or Sigmaplot to do the graphs; however then I have an issue with the scaling of the loadings (i.e. the values are so small that they are bunched up at the origin) so here is my second question: Can I multiply the loadings by a constant to display them in my plot and if yes what is the convention for doing this. Many thanks Paul _ Tell us your greatest, weirdest and funniest Hotmail stories [[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] How to detect and exclude outliers in R?
fortune(outlier) vikrant schrieb: Suppose I am reading data from a file and the data contains some outliers. I want to know if it is possible in R to automatically detect outliers in a dataset and remove them -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] apply command
Hi, I think you could use iapply (search the archives) or the plyr package to save you from transposing the result. HTH, baptiste 2010/1/19 marco salvini marco.salv...@gmail.com: Can you please help on the issue? I using the apply command on a matrix below the example: Create a vector x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5) create a matrix of 2 rows by 6 columns b=matrix(x, 2,6) print(b) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 5 2 4 7 9 1 [2,] 3 3 NA 3 2 5 using the command apply print(apply(b, 1, function(y) sort(y, na.last=F))) the output is a matrix of 6 rows by 2 columns. [,1] [,2] [1,] 1 NA [2,] 2 2 [3,] 4 3 [4,] 5 3 [5,] 7 3 [6,] 9 5 As you can see in the example I start with a matrix of (2 by 6) and the output of apply is a mtraxi of (6 by 2). This is very strange because I was expecting as output a matrix of the same dim (2 by 6) of the input matrix. I can solve this issues using an if statment on the dim of the matrix but if I am using a square matrix I am not able to control if the result of the apply is correct. Do anyone find a solution to this issue? thanks Marco [[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] how to install spatstat
On 19.01.2010 03:42, Rolf Turner wrote: On 19/01/2010, at 11:24 AM, Senlin Liang wrote: Hi, I tried to install spatstat using: install.packages(spatstat, dependencies = TRUE, lib = ./R/i486-pc-linux-gnu-library/2.8) but got the following msg: --- Please select a CRAN mirror for use in this session --- here i selected one mirror, and tried several mirrors) Loading Tcl/Tk interface ... done Warning message: In install.packages(spatstat, dependencies = TRUE, lib = ./R/i486-pc-linux-gnu-library/2.8) : package ‘spatstat’ is not available any idea why i am getting this error? The error message is puzzling; spatstat is certainly available. Perhaps the PAKAGES file was rewritten in the second you tried to install - or you are using a corrupted mirror. Hence please tell us which mirror you are using in which OS with which version of R. Best, Uwe Ligges However you should be getting a ***warning*** message about being unable to ``rename'' stuff/spatstat. The somewhat mysterious cause of such warnings is that it is necessary to supply an *absolute* pathname for ``lib'' rather than a relative pathname as you have done. I was flummoxed by this for decades; very recently Simon Urbanek (thank you again Simon) pointed out to me the error of my ways. Try something like: xlib - paste(getwd(),/R/i486-pc-linux-gnu-library/2.8,sep=/) install.packages(spatstat,dependencies=TRUE,lib=xlib) and see how you go. cheers, Rolf Turner ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.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] ggplot2 histogramm
Hi Dennis, the BaseTheme() are some settings scale the text and title etc. , the plot should work without that. At present i'm experiment with the huge amount of possibilities and try to understand and maybe doing beginner mistakes. Thanks for the hint with scale_fill_gradient and specialized mailing list. Regards , Christian Hi: I have to admit, there are several things about your call I don't understand. First of all, you're really constructing bar charts by group, not histograms. Secondly, you don't want legend.text, but legend.title; unfortunately, that doesn't work (for reasons I don't understand), so I put in a workaround with scale_fill_gradient(). Thirdly, I couldn't find a function called BaseTheme() in ggplot2; is this in package ggExtra? I got some errors when running your code. The first one had to do with BaseTheme (not found). When I got rid of that, there was the following (in my modified code): p + geom_bar(aes(y= ..count.. / sum(..count..),fill=..count../sum(..count..)*100)) + + scale_y_continuous(Anteil in %, formatter = percent) + + facet_wrap(~ group) + xlab(Attribute) + + opts(title=Title) last_plot() + opts(legend.title = Antiel in Prozent) Error in el(...) : unused argument(s) (x = 0, y = 0.5) (It happened in yours, too.) I got the following to work; I think it's what you want, but let me know if I'm off. p + geom_bar(aes(y= ..count.. / sum(..count..),fill=..count../sum(..count..)*100)) + scale_y_continuous(Anteil in %, formatter = percent) + scale_fill_gradient(Antiel in Prozent, limits = c(0, 50)) + facet_wrap(~ group) + xlab(Attribute) + opts(title=Title) HTH, Dennis PS: Questions about ggplot2 are better directed to its mailing list: ggpl...@googlegroups.com mailto:ggpl...@googlegroups.com On Mon, Jan 18, 2010 at 4:34 AM, Christian Schulz chsch...@email.de mailto:chsch...@email.de wrote: Hi, i get no success change the title of the fill (colour) legend and the defintion of levels. Have anybody a hint how i can do this. df - data.frame(variable=sample(c(A,B,C),1000,replace=T,prob=c(0.22,0.28,0.5)),group=gl(2,500)) p - ggplot(df, aes(x = variable)) p + geom_histogram(aes(y= ..count.. / sum(..count..),fill=..count../sum(..count..)*100)) + scale_y_continuous(formatter = percent) + facet_wrap(~group) + ylab(Anteil in %) + xlab(Attribute) + opts(title=Title,legend.text=Anteil in Prozent) + BaseTheme(base_size=12) many thanks, Christian __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: help with time Series regression please
Dear all, I am having difficulty to built a model of quarter sales of spirits data, and deciding which is the best model. The yfit2, yfit3, and yfit4 lines was not appeared right at the end. The data and script is enclosed with this email. I am using the harmonic regression model to exam the periodogram of the residuals. I am not sure this step is right or not? Which is the best formula to analysis the trend and seasonality for this data set? AR, MA or ARMA and how to decide? Please help!! many thanks and regard, Cathy Wong _ Got a cool Hotmail story? Tell us now 'SPIRITS SALES' : 40 : 82 59 107 221 102 75 122 278 140 103 163 335 166 113 175 354 172 113 179 417 229 127 157 462 225 156 271 592 290 196 334 617 339 219 343 724 383 255 409 703 : options(windowsBuffered=FALSE) y=scan('F:/Math355/SPIRITS.txt',skip=2,nline=4) yts=ts(log(y)) plot(yts,main=Log Quarterly Sales of Alcoholic Spirits,type='b',col=2) n=length(y) time=seq(1:n) quarter=c(rep(seq(1:4),10)) quarter fquarter=as.factor(quarter) ymod1=lm(yts~time+fquarter) summary(ymod1) yfit1=ymod1$fitted lines(yfit1,col=3) yres1=ymod1$res plot(yres1) ymod2=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)) summary(ymod2) yfit2=ymod2$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/2)+sin(2*pi*time/2)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/1)+sin(2*pi*time/1)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) yspec=spec.pgram(yts,pad=4,detrend=TRUE) plot(yspec$freq,yspec$spec,type='l',col=5) resspec=spec.pgram(ymod3$res,pad=4,detrend=FALSE) plot(resspec$freq,resspec$spec,type='l',col=5) acf(ymod3$res,lag.max=20,col=6) pacf(ymod3$res,lag.max=20,col=6) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with time Series regression please
Dear all, I am having difficulty to built a model of quarter sales of spirits data, and deciding which is the best model. The yfit2, yfit3, and yfit4 lines was not appeared right at the end. The data and script is enclosed with this email. I am using the harmonic regression model to exam the periodogram of the residuals. I am not sure this step is right or not? Which is the best formula to analysis the trend and seasonality for this data set? AR, MA or ARMA and how to decide? Please help!! many thanks and regard, Cathy Wong Got a cool Hotmail story? Tell us now _ Got a cool Hotmail story? Tell us now 'SPIRITS SALES' : 40 : 82 59 107 221 102 75 122 278 140 103 163 335 166 113 175 354 172 113 179 417 229 127 157 462 225 156 271 592 290 196 334 617 339 219 343 724 383 255 409 703 : options(windowsBuffered=FALSE) y=scan('F:/Math355/SPIRITS.txt',skip=2,nline=4) yts=ts(log(y)) plot(yts,main=Log Quarterly Sales of Alcoholic Spirits,type='b',col=2) n=length(y) time=seq(1:n) quarter=c(rep(seq(1:4),10)) quarter fquarter=as.factor(quarter) ymod1=lm(yts~time+fquarter) summary(ymod1) yfit1=ymod1$fitted lines(yfit1,col=3) yres1=ymod1$res plot(yres1) ymod2=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)) summary(ymod2) yfit2=ymod2$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/2)+sin(2*pi*time/2)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) ymod3=lm(y~time+cos(2*pi*time/4)+sin(2*pi*time/4)+cos(2*pi*time/1)+sin(2*pi*time/1)) summary(ymod3) yfit3=ymod3$fitted plot(yts,main=Quarterly Sales of Alcoholic Spirits in Log Transcations,type='p',col=2) lines(yfit2,col=4) yspec=spec.pgram(yts,pad=4,detrend=TRUE) plot(yspec$freq,yspec$spec,type='l',col=5) resspec=spec.pgram(ymod3$res,pad=4,detrend=FALSE) plot(resspec$freq,resspec$spec,type='l',col=5) acf(ymod3$res,lag.max=20,col=6) pacf(ymod3$res,lag.max=20,col=6) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply command
I guess that the matrix dimension changed because matrix in R are filled by columns. Since you try: apply(b, 1, function(y) sort(y, na.last=F)) The second parameter make it scan matrix b row by row but store result by columns, which make the result be a matrix transposed. If you try: apply(b, 2, function(y) sort(y, na.last=F)) The second parameter means scan column by column, and the result matrix will have the same dimension with origin. On Tue, Jan 19, 2010 at 6:31 PM, Tal Galili tal.gal...@gmail.com wrote: Hello Marco What I would do, is use t to transpose the matrix. Why it is that apply switches the matrix, is beyond my knowledge - and I would love to read more informed replies. Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com/ (English) -- On Tue, Jan 19, 2010 at 12:27 PM, marco salvini marco.salv...@gmail.comwrote: Can you please help on the issue? I using the apply command on a matrix below the example: Create a vector x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5) create a matrix of 2 rows by 6 columns b=matrix(x, 2,6) print(b) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 5 2 4 7 9 1 [2,] 3 3 NA 3 2 5 using the command apply print(apply(b, 1, function(y) sort(y, na.last=F))) the output is a matrix of 6 rows by 2 columns. [,1] [,2] [1,] 1 NA [2,] 2 2 [3,] 4 3 [4,] 5 3 [5,] 7 3 [6,] 9 5 As you can see in the example I start with a matrix of (2 by 6) and the output of apply is a mtraxi of (6 by 2). This is very strange because I was expecting as output a matrix of the same dim (2 by 6) of the input matrix. I can solve this issues using an if statment on the dim of the matrix but if I am using a square matrix I am not able to control if the result of the apply is correct. Do anyone find a solution to this issue? thanks Marco [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Working with text data/text operators
Hello, Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? For example, if the column names are Bond1.Creditclass,Bond1.Price,Bond2.Creditclass,Bond2.Price, how do I select only the columns corresponding to Bond1? Thanks a lot, Mihai [[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] Working with text data/text operators
On 01/19/2010 01:22 PM, mihai.mira...@bafin.de wrote: Hello, Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? For example, if the column names are Bond1.Creditclass,Bond1.Price,Bond2.Creditclass,Bond2.Price, how do I select only the columns corresponding to Bond1? Thanks a lot, Mihai You can do things like : dataset[ , grepl( ^Bond1, names( dataset ) ) ] dataset[ , substr( names( dataset ), 1, 5 ) == Bond1 ] Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/KfKn : Rcpp 0.7.2 |- http://tr.im/JOlc : External pointers with Rcpp `- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] restricted permutations in permtest()?
On Tue, 2010-01-19 at 11:39 +0100, Kay Cecil Cichini wrote: Hallo List, I'm trying to implemement a restricted permutation scheme in permutest(). More precisely I have dependence in my data that should be allowed for in the permutation - I simulated the problem in the example of the vegan documentation p.24: snip / ##the unrestricted Permutation test for F is permutest(mod, pairwise = TRUE) ..I wasn't able to find out the right syntax for implementation of blocks, I tried with argument strata, which would be blocks, in permutest(mod, pairwise = TRUE, blocks) but this doesn't work. By the way, what is 'pairwise = TRUE' for? This looks like you haven't really read or understood the help for permutest.betadisper? If you had, you'd have noticed that this method doesn't (currently) support the 'strata' argument and because you didn't name the argument you supplied 'blocks' to, this would have gone to argument 'control' and that should have resulted in an error. You can't implement a restricted permutation for any model in vegan at the moment, unless you fancy hacking the code. Work is in progress to implement for vegan the type of dependence structures available in Canoco. I produced a new package 'permute' that is available on r-forge: http://r-forge.r-project.org/R/?group_id=68 (within the vegan stable) to do those kinds of restricted permutations, but this is very much at alpha status at the moment as some aspects of the code just don't work. There is enough there to generate a restricted permutation of a dataset, but not the extra checking code. If you can explain what kind of dependence structure you have in your data perhaps I can help with a bespoke version of permutest.betadisper until permute is ready for release, but if you do so, please move this to a thread on the r-forge vegan help forum: http://r-forge.r-project.org/forum/forum.php?forum_id=194 'pairwise = TRUE' indicates that you also want pairwise comparisons of group variances. I.e. if you have 3 groups, pairwise = FALSE would only give an overall analysis (one p-value) for differences in variances across all groups, where as pairwise = TRUE conducts tests of the difference between group 1 and 2, between group 1 and 3, and between 2 and 3, as well as the overall analysis. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] apply command
Thank you for the answer Linlin, I am wondering, is there a way to change it so that R will fill matrix's by rows ? Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com/ (English) -- On Tue, Jan 19, 2010 at 2:07 PM, Linlin Yan yanlinli...@gmail.com wrote: I guess that the matrix dimension changed because matrix in R are filled by columns. Since you try: apply(b, 1, function(y) sort(y, na.last=F)) The second parameter make it scan matrix b row by row but store result by columns, which make the result be a matrix transposed. If you try: apply(b, 2, function(y) sort(y, na.last=F)) The second parameter means scan column by column, and the result matrix will have the same dimension with origin. On Tue, Jan 19, 2010 at 6:31 PM, Tal Galili tal.gal...@gmail.com wrote: Hello Marco What I would do, is use t to transpose the matrix. Why it is that apply switches the matrix, is beyond my knowledge - and I would love to read more informed replies. Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com/ (English) -- On Tue, Jan 19, 2010 at 12:27 PM, marco salvini marco.salv...@gmail.com wrote: Can you please help on the issue? I using the apply command on a matrix below the example: Create a vector x =c(5, 3, 2:4, NA, 7, 3, 9, 2, 1, 5) create a matrix of 2 rows by 6 columns b=matrix(x, 2,6) print(b) [,1] [,2] [,3] [,4] [,5] [,6] [1,]524791 [2,]33 NA325 using the command apply print(apply(b, 1, function(y) sort(y, na.last=F))) the output is a matrix of 6 rows by 2 columns. [,1] [,2] [1,]1 NA [2,]22 [3,]43 [4,]53 [5,]73 [6,]95 As you can see in the example I start with a matrix of (2 by 6) and the output of apply is a mtraxi of (6 by 2). This is very strange because I was expecting as output a matrix of the same dim (2 by 6) of the input matrix. I can solve this issues using an if statment on the dim of the matrix but if I am using a square matrix I am not able to control if the result of the apply is correct. Do anyone find a solution to this issue? thanks Marco [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Data import export zipped files from URLs
Dieter Menne wrote: Velappan Periasamy wrote: I am not able to import zipped files from the following link. How to get thw same in to R?. mydata - read.csv(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) As Brian Ripley noted in http://markmail.org/message/7dsauipzagq5y36o you will have to download it first and then to unzip. Well if downloading to disk first does need to be avoided, you can use the RCurl and Rcompression packages to do the computations in memory: library(RCurl) ctnt = getURLContent(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) library(Rcompression) zz = zipArchive(ctnt) names(zz) txt = zz[[1]] read.csv(textConnection(txt)) D. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Data import export zipped files from URLs
If you need an example of this look at the yacasInstall function in this file: http://ryacas.googlecode.com/svn/trunk/R/yacasInstall.R from the Ryacas package. It downloads, unzips and installs yacas and associated files for Windows users. On Tue, Jan 19, 2010 at 3:10 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: Velappan Periasamy wrote: I am not able to import zipped files from the following link. How to get thw same in to R?. mydata - read.csv(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) As Brian Ripley noted in http://markmail.org/message/7dsauipzagq5y36o you will have to download it first and then to unzip. Dieter -- View this message in context: http://n4.nabble.com/Data-import-export-zipped-files-from-URLs-tp1017287p1017326.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] how to open excel 2007 (.xlsx) file in R
See http://wiki.r-project.org/rwiki/doku.php?id=tips:data-io:ms_windows Most of the methods there work with xls files only but a few work with xlsx. On Tue, Jan 19, 2010 at 12:15 AM, vikrant vikrant.shi...@tcs.com wrote: i am unable to open a file which is saved as .xlsx format in R . The file contains approximately 1,50,000 rows. So I m not able to save it as csv file.Please suggest ways to open this file -- View this message in context: http://n4.nabble.com/how-to-open-excel-2007-xlsx-file-in-R-tp1017273p1017273.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Macualay Duration code in a Functional Form - Please Help
# I have written this code in Notepad++ and copied here. ## ONS - PPA Duration = function(par_value, coupon_rate, freq_coupon, tenure, ytm) { macaulay_duration = NULL modified_duration = NULL freq_coupon_new = NULL if(freq_coupon = 0) { freq_coupon_new = 365 } if(freq_coupon 0 freq_coupon = 1) { freq_coupon_new = 12 } if(freq_coupon 1 freq_coupon = 2) { freq_coupon_new = 4 } if(freq_coupon 2 freq_coupon = 3) { freq_coupon_new = 2 } if(freq_coupon 3 freq_coupon = 4) { freq_coupon_new = 1 } ## COMPUTATIONS terms_coupon_payment = (seq(1/freq_coupon_new, tenure, by = 1/freq_coupon_new))*freq_coupon_new coupon = coupon_rate*par_value/100 coupon_amount = coupon/(freq_coupon_new) cash_flow1 = rep(c(coupon_amount), (tenure*freq_coupon_new - 1)) cash_flow2 = par_value + coupon_amount cash_flow = c(cash_flow1, cash_flow2) ytm_effective = ((1+ytm/100)^(1/freq_coupon_new))-1 pv = NULL for (i in 1:(tenure*freq_coupon_new)) { pv[i] = cash_flow[i] / ((1+ytm_effective)^terms_coupon_payment[i]) } macaulay_duration = sum(pv*terms_coupon_payment)/sum(pv) modified_duration = macaulay_duration / (1+(ytm_effective)/freq_coupon_new) return(data.frame(macaulay_duration, modified_duration)) } result = Duration(par_value = 1000, coupon_rate = 10, freq_coupon = 0, tenure = 5, ytm = 12) ## ___ When I run this function, I get the values of Macaulay Duration and Modified Duration result macaulay_duration modified_duration 1 1423.797 1423.795 ### MY PROBLEM I have arrived at a result using only one set of observations i.e. for the following data - Duration(par_value = 1000, coupon_rate = 10, freq_coupon = 0, tenure = 5, ytm = 12) However, if I need to obtain these results for multiple records, how do I calculate and obtain the result in a tabular form? e.g. suppose my input data file is 'instrument details.csv' given as id par_value coupon_rate frequency_coupon tenure ytm 1 1000 10 0 5 12 2 100 7 1 8 11 ### frequency_coupon is coded s.t. if frequency_coupon = 0, no of compoundings in a year = 365 and if it is 1, then no of compoundings = 12 Then how do modify the above code? I have tried to convert in a matrix form as follows I have added following code after the function is defined i.e. after #return(data.frame(macaulay_duration, modified_duration)) #} # Added code ONS = read.csv('instrument details.csv') n = length(ONS$par_value) par_value = matrix(data = ONS$par_value, nrow = n, ncol = 1, byrow = TRUE) coupon_rate = matrix(data = ONS$coupon_rate, nrow = n, ncol = 1, byrow = TRUE) freq_coupon = matrix(data = ONS$frequency_copoun, nrow = n, ncol = 1, byrow = TRUE) tenure = matrix(data = ONS$tenure, nrow = n, ncol = 1, byrow = TRUE) ytm = matrix(data = ONS$ytm, nrow = n, ncol = 1, byrow = TRUE) result = matrix(data = NA, nrow = n, ncol = 2, byrow = TRUE) result = Duration(par_value, coupon_rate, freq_coupon, tenure, ytm) ## When I run result, besides getting 50 warnings, I get following result macaulay_duration modified_duration 1 826.9026 826.9019 2 826.9026 826.9019 which is I know wrong. Is there any other way I can use the function defined above to process multiple recrds. Thanking you and sincerely apologize for writing such a long mail as I wanted to be clear in my communication. Regards Madhavi Bhave ONS = read.csv('instrument details.csv') n = length(ONS$par_value) par_value = matrix(data = ONS$par_value, nrow = n, ncol = 1, byrow = TRUE) coupon_rate = matrix(data = ONS$coupon_rate, nrow = n, ncol = 1, byrow = TRUE) freq_coupon = matrix(data = ONS$frequency_copoun, nrow = n, ncol = 1, byrow = TRUE) tenure = matrix(data = ONS$tenure, nrow = n, ncol = 1, byrow = TRUE) ytm = matrix(data = ONS$ytm, nrow = n, ncol = 1, byrow = TRUE) result = matrix(data = ONS$par_value, nrow = n, ncol = 2, byrow = TRUE) result = Duration(par_value, coupon_rate, freq_coupon, tenure, ytm) The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[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] how to open excel 2007 (.xlsx) file in R
RExcel mention in the link below can transfer data from Excel 2007 to R. But you have to be on Windows, and you probably have to have Excel 2007. it might work if you have Excel 2003 with the (free) compatibility package installed. On Jan 19, 2010, at 2:09 PM, Gabor Grothendieck wrote: See http://wiki.r-project.org/rwiki/doku.php?id=tips:data-io:ms_windows Most of the methods there work with xls files only but a few work with xlsx. On Tue, Jan 19, 2010 at 12:15 AM, vikrant vikrant.shi...@tcs.com wrote: i am unable to open a file which is saved as .xlsx format in R . The file contains approximately 1,50,000 rows. So I m not able to save it as csv file.Please suggest ways to open this file -- View this message in context: http://n4.nabble.com/how-to-open-excel-2007-xlsx-file-in-R-tp1017273p1017273.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] restricted permutations in permutest()?
hello gavin, you are right, i didn't get into the documentation to deep and i'm also a beginner, that's why i'm just about to get into the logical part of the syntax. now, the output from perm.disp() says: #No. of permutations: 999 #Permutation type: free #Permutations are unstratified #Mirrored permutations?: No #Use same permutation within strata?: No from this i concluded that you can restrict the permutation scheme.. with permcontrol() i did the following #with the simulated blocks from blocks-factor(c(rep(1,4),rep(2,4),rep(3,4),rep(4,4),rep(5,4),rep(6,4))) #i did this, which should permute strata as a whole, as i understood the documentation permutest(mod, permControl(strata = blocks, type = free, permute.strata = TRUE), pairwise=TRUE) and the output said.. Permutations: 199 Permutation type: free Permutations stratified between 'blocks' Mirrored permutations?: No Use same permutation within strata?: No so, i stratified the permutation, but i have the feeling that#s not what it should be - to my understanding it is necessary to permute the group-alignment of each block concordantly and i don't know if that's what happend.. the last line of the presented output shoul be yes, i guess. the documentation quotes that the argument for this is permute.strata=TRUE, which i did... thanks a lot for your help, kay -- View this message in context: http://n4.nabble.com/restricted-permutations-in-permtest-tp1017422p1017572.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] bootstrapping
Thanks all for your help! Aaron Date: Sat, 16 Jan 2010 00:04:59 +0100 From: stephan.kola...@gmx.de To: aaron.fo...@students.tamuk.edu CC: r-help@r-project.org Subject: Re: [R] bootstrapping Hi Aaron, try the argument statistic=mean. Then boot() will give you the mean turn angle in your actual data (which appears to be 6 degrees, judging from what you write), as well as the means of the bootstrapped data. Then you can get (nonparametric) bootstrap CIs by quantile(boot$t,probs=c(.025,.975)). As far as I can see, there is really no need to look at sd(). A more interesting question would be how to deal with the fact that -180=+180, there may be something to think about here... HTH, Stephan aaron.fo...@students.tamuk.edu schrieb: Hi All, I'm new to R so please bear with me. I have a dataset with 337 turn angles ranging from -180 to 180 degrees. I need to bootstrap (sample with replacement) 1,000 times to create expected average turn angle with 95% CIs. The code is pretty straightforward (-boot(data =, statistic = ,R =)) but I am unsure how to input my observed mean (6 degrees) and standard deviation (66 degrees) into the statistic component. I realize there is a 'function' code but I can't seem to carry the results over to the 'boot' code. Thanks, Aaron M. Foley PhD Candidate Caesar Kleberg Wildlife Research Institute Texas AM University - Kingsville Cousins Hall, Room 201 Kingsville, TX 78363 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Predict polynomial problem
On Tue, 2010-01-19 at 08:27 +, Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 1:36 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: Its the environment thing. I think you want something like this: models[[i]]=lm( bquote( y ~ poly(x,.(i)) ), data=d) Use terms( mmn[[3]] ) both with and without this change and ls( env = environment( formula( mmn[[3]] ) ) ) get(i,env=environment(formula(mmn[[3]]))) sapply(mmn,function(x) environment( formula( x ) ) ) to see what gives. Think I see it now. predict involves evaluating poly, and poly here needs 'i' for the order. If the right 'i' isn't gotten when predict is called then I get the error. Your fix sticks the right 'i' into the environment when predict is called. I haven't quite got my head round _how_ it does it, and I have no idea how I could have figured this out for myself. Oh well... Perhaps this Programmer's Niche article by Bill Venables might also be useful as it discuss how to manipulate formulas to automate model fitting...? Bill Venables. Programmer's Niche. R News, 2(2):24-26, June 2002. http://cran.r-project.org/doc/Rnews/Rnews_2002-2.pdf HTH G The following lines are also illustrative: d = data.frame(x=1:10,y=runif(10)) i=3 #1 naive model: m1 = lm(y~poly(x,i),data=d) #2,3 bquote, without or with i-wrapping: m2 = lm(bquote(y~poly(x,i)),data=d) m3 = lm(bquote(y~poly(x,.(i))),data=d) #1 works, gets 'i' from global i=3 above: predict(m1,newdata=data.frame(x=9:11)) #2 fails - why? predict(m2,newdata=data.frame(x=9:11)) #3 works, gets 'i' from within: predict(m3,newdata=data.frame(x=9:11)) rm(i) #1 now fails because we removed 'i' from top level: predict(m1,newdata=data.frame(x=9:11)) #2 still fails: predict(m2,newdata=data.frame(x=9:11)) #3 still works: predict(m3,newdata=data.frame(x=9:11)) Thanks -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Memory usage in read.csv()
I'm sure this has gotten some attention before, but I have two CSV files generated from vmstat and free that are roughly 6-8 Mb (about 80,000 lines) each. When I try to use read.csv(), R allocates all available memory (about 4.9 Gb) when loading the files, which is over 300 times the size of the raw data. Here are the scripts used to generate the CSV files as well as the R code: Scripts (run for roughly a 24-hour period): vmstat -ant 1 | awk '$0 !~ /(proc|free)/ {FS= ; OFS=,; print strftime(%F %T %Z),$6,$7,$12,$13,$14,$15,$16,$17;}' ~/vmstat_20100118_133845.o; free -ms 1 | awk '$0 ~ /Mem\:/ {FS= ; OFS=,; print strftime(%F %T %Z),$2,$3,$4,$5,$6,$7}' ~/memfree_20100118_140845.o; R code: infile.vms - ~/vmstat_20100118_133845.o; infile.mem - ~/memfree_20100118_140845.o; vms.colnames - c(time,r,b,swpd,free,inact,active,si,so,bi,bo,in,cs,us,sy,id,wa,st); vms.colclass - c(character,rep(integer,length(vms.colnames)-1)); mem.colnames - c(time,total,used,free,shared,buffers,cached); mem.colclass - c(character,rep(integer,length(mem.colnames)-1)); vmsdf - (read.csv(infile.vms,header=FALSE,colClasses=vms.colclass,col.names=vms.colnames)); memdf - (read.csv(infile.mem,header=FALSE,colClasses=mem.colclass,col.names=mem.colnames)); I am running R v2.10.0 on a 64-bit machine with Fedora 10 (Linux version 2.6.27.41-170.2.117.fc10.x86_64 ) with 6Gb of memory. There are no other significant programs running and `rm()` followed by ` gc()` successfully frees the memory (followed by swapins after other programs seek to used previously cached information swapped to disk). I've incorporated the memory-saving suggestions in the `read.csv()` manual page, excluding the limit on the lines read (which shouldn't really be necessary here since we're only talking about 20 Mb of raw data. Any suggestions, or is the read.csv() code known to have memory leak/ overcommit issues? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cannot load RInterpreter (SJava)
Jiiindo wrote: Hello, I write a test for call R function from Java by Eclipse. When i run it, raise a error: Loading RInterpreter library Exception in thread main java.lang.UnsatisfiedLinkError: no RInterpreter in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1028) at org.omegahat.R.Java.ROmegahatInterpreter.clinit(ROmegahatInterpreter.java:34) at RTest.JavaR2.main(JavaR2.java:10) ok, i have set variable PATH = directory contain file .so (i use UBUNTU) correct..and i install R with option --enable-R-shlib. When i create script for call this class file, it runresult: Loading RInterpreter library R version 2.10.1 (2009-12-14) - In this script, I use command java - Djava.library.path=${SJAVA_PATH}:/usr/local/R/lib/R/library/SJava/libs -cp $CLASSPATH:${SJAVA_PATH}/rsjava.jar:${SJAVA_PATH}/antlr.jar:${SJAVA_PATH}/Environment.jar:${SJAVA_PATH}/jas.jar:${SJAVA_PATH}/jhall.jar $* i set variable PATH = $PATH:/usr/local/R/lib/R/library/SJava/libs:/usr/local/R/lib/R/library/SJava/org/omegahat/Jars? CLASSPATH= correctly. Why i have error when i use Eclipe to run it? (It not load RInterpreter library) In the eclipse Run configuration for this project, on the Arguments tab, add -Djava.library.path=${SJAVA_PATH}:/usr/local/R/lib/R/library/SJava/libs as a VM argument. Martin Who can help me? Thanks -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Server hanging despite efforts to correct memory limits
My group is working with datasets between 100 Mb and 1 GB in size, using multiple log ins. From the documentation, it appears that vsize is limited to 2^30-1, which tends to prove too restrictive for our use. When we drop that restriction (set vsize = NA) we end up hanging the server, which requires a restart. Is there any way to increase the memory limits on R while keeping our jobs from hanging? Having to restart the server is a major inconvenience, second only to memory limitations in R. mem.limits() nsize vsize 1NA mem.limits(vsize=2^30) nsize vsize 1 1073741824 mem.limits(vsize=2^31) nsize vsize 1 1073741824 Warning message: In structure(.Internal(mem. limits(as.integer(nsize), as.integer(vsize))), : NAs introduced by coercion [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] question on plot in R with mac
-- Hello all My computer is MacBook and I want to draw a plot in R, for example for x - c(1,3,6,9,12) y - c(1.5,2,7,8,15) I use this command plot(x,y). but it dosn't work. Could you please help me? thank you khazaei __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Symmetric Matrix classes
Scanning for 'Matrix' in old R-help e-mail, I found GA == Gad Abraham gabra...@csse.unimelb.edu.au on Fri, 27 Nov 2009 13:45:00 +1100 writes: GA Hi, GA I'd like to store large covariance matrices using Matrix classes. GA dsyMatrix seems like the right one, but I want to specify just the GA upper/lower triangle and diagonal and not have to instantiate a huge GA n^2 vector just for the sake of having half of it ignored: GA Dumb example: GA M - new(dsyMatrix, uplo=U, x=rnorm(1e4), Dim=as.integer(c(100, 100))) GA diag(M) - 1 GA This doesn't work: GA M - new(dsyMatrix, uplo=U, x=0, Dim=as.integer(c(100, 100))) GA Error in validObject(.Object) : GA invalid class dsyMatrix object: length of x slot != prod(Dim) GA Is there an easier way of doing this? I think you want a dspMatrix (sp == symmetric packed) instead. Before going into details: Is this topic still interesting to those involved almost two months ago? Regards, Martin GA -- GA Gad Abraham GA PhD Student, Dept. CSSE and NICTA GA The University of Melbourne GA Parkville 3010, Victoria, Australia GA email: gabra...@csse.unimelb.edu.au GA web: http://www.csse.unimelb.edu.au/~gabraham __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Server hanging despite efforts to correct memory limits
I am running into a separate, but related issue. On Linux, one may impose memory limits via the --max-vsize, --max-nsize, and --max-ppsize arguments upon starting R. I do not know if similar arguments are available on Windows. HTH -- View this message in context: http://n4.nabble.com/Server-hanging-despite-efforts-to-correct-memory-limits-tp1017618p1017654.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] restricted permutations in permutest()?
On Tue, 2010-01-19 at 06:19 -0800, Kay Cichini wrote: hello gavin, you are right, i didn't get into the documentation to deep and i'm also a beginner, that's why i'm just about to get into the logical part of the syntax. now, the output from perm.disp() says: As I said, you *can't* do this in vegan yet. I interfaced permutest.betadisper with an earlier version of the code now in the 'permute' package as an example of how we might go ahead and implement these fancier permutation tests within vegan. I'd be very surprised if manipulating the control object would work. You (still) haven't said what you are trying to do and what the dependence structure is relative to the groups in your data that permutest is trying to test. #No. of permutations: 999 #Permutation type: free #Permutations are unstratified #Mirrored permutations?: No #Use same permutation within strata?: No from this i concluded that you can restrict the permutation scheme.. I should probably add a note to the docs to mention not to do this at this stage in vegan... with permcontrol() i did the following #with the simulated blocks from blocks-factor(c(rep(1,4),rep(2,4),rep(3,4),rep(4,4),rep(5,4),rep(6,4))) #i did this, which should permute strata as a whole, as i understood the documentation permutest(mod, permControl(strata = blocks, type = free, permute.strata = TRUE), pairwise=TRUE) If everything was working, yes, that was the intention at the time, that the strata (the chunks of 4 samples) would be permuted as a block but the sample ordering within the strata would remain unchanged. and the output said.. Permutations: 199 Permutation type: free Permutations stratified between 'blocks' Mirrored permutations?: No Use same permutation within strata?: No so, i stratified the permutation, but i have the feeling that#s not what it should be - to my understanding it is necessary to permute the group-alignment of each block concordantly and i don't know if that's what happend.. the last line of the presented output shoul be yes, i guess. the documentation quotes that the argument for this is permute.strata=TRUE, which i did... No, that would only be 'Yes' if you wanted to permute the observations *within* the strata, but you are permuting the strata themselves. What you have understood from the docs is not what they say nor the intention. I accept that the documentation could be clearer in this regard. Again, can you show me your code that fitted the betadisper model in the first place and how you defined the groups for that analysis. Do these differ from blocks above? The whole point of betadisper is that you have groups and you want to know if the dispersion of the sample scores differs between groups. Whether it makes sense to condition the permutation tests on some other structure is not yet clear to me from your postings. In summary, I would caution against do this unless you take a very close look at the code and examples in permuted.index2 to confirm for yourself that the permutation design you are specifying is being permuted correctly. The code in package 'permute' *does* work correctly and is capable of more complex designs but in situations where you have only a small number of permutations, sanity checking code kicks in and it is this code that currently doesn't work within 'permute'. Again, if you would like some help with a specific permutation design, please start a new thread in the r-forge vegan help forum and post the exact code you used to fit the betadisper model, define your groups etc. Then I can provide further assistance. HTH G thanks a lot for your help, kay -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] (2nd part) variable name substitution
Hi again! I feel like I cannot do anything by myself but I would now like to plot for all numeric variables I have (14 of them). I wanted to add a loop then. The code is: -- #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } #run the function on ssfa with TO_POS as x and ssfa[[i]] as y, the numerical variables are from column 7 to 21 for (i in 7:21) { with(ssfa, twoplots(TO_POS, ssfa[[i]])) } -- I have therefore two questions: - The code above works fine, but in the titles I get Histogram of ssfa[[i]] instead of Histogram of 'variable name' - What if I don't want to loop on all variables, but for example, variables (=columns) 7 to 10 and 12 to 17? How do I give such breaks and ranges? I admit I'm thinking about it since yesterday and I don't have a clue... I hope you will be able to help me. Thanks in advance, Ivan. Duncan Murdoch a écrit : On 18/01/2010 9:02 AM, Ivan Calandra wrote: Hi everybody! I'm trying to write a script to plot a histogram, a boxplot and a qq-plot (under Windows XP, R2.10 if it matters) What I want to do: define the variables (x and y) to be used at the very beginning, so that I don't have to change all occurrences in the script when I want to plot a different variable. The dataset is called ssfa. TO_POS is a categorical variable containing the tooth position for each sample. Asfc is a numerical variable. In my dataset, I have more variables but it wouldn't change; I want to plot one numeric vs one category. Do I need to supply some data? I don't think it's really necessary but let me know if you would like to. The code of what I do up to now: --- x - ssfa$TO_POS y - ssfa$Asfc hist(y, main=Histogram of Asfc, xlab=Asfc) boxplot(y~x, main=Boxplot of Asfc by TO_POS, xlab=TO_POS, ylab=Asfc) --- I would like something like: hist(y, main=Histogram of y, xlab=y) but that will add Asfc where I write y. And the same for boxplot(y~x, main=Boxplot of y by x, xlab=x, ylab=y) I thought about something like: --- cat - TO_POS num - Asfc x - paste(ssfa$, TO_POS, sep=) y - paste(ssfa$, Asfc, sep=) hist(y, main=paste(Histogram of , cat, sep=), xlab=num) --- but it doesn't work since y is a string. I don't know how to get the syntax correctly. I am on the right path at least?! I think you're on the wrong path. You want to write a function, and pass either x and y as arguments, or pass a formula containing both (the former is easier). For example, twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Then with(ssfa, twoplots(TO_POS, Asfc)) will give you your plots. Duncan Murdoch [[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] (2nd part) variable name substitution
Hello, You can loop in the subset you need by storing in a variable and looping on that variable with indexes: seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] with(ssfa, twoplots(TO_POS, ssfa[[j]])) } Regards, Carlos. On Tue, Jan 19, 2010 at 4:53 PM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Hi again! I feel like I cannot do anything by myself but I would now like to plot for all numeric variables I have (14 of them). I wanted to add a loop then. The code is: -- #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } #run the function on ssfa with TO_POS as x and ssfa[[i]] as y, the numerical variables are from column 7 to 21 for (i in 7:21) { with(ssfa, twoplots(TO_POS, ssfa[[i]])) } -- I have therefore two questions: - The code above works fine, but in the titles I get Histogram of ssfa[[i]] instead of Histogram of 'variable name' - What if I don't want to loop on all variables, but for example, variables (=columns) 7 to 10 and 12 to 17? How do I give such breaks and ranges? I admit I'm thinking about it since yesterday and I don't have a clue... I hope you will be able to help me. Thanks in advance, Ivan. Duncan Murdoch a écrit : On 18/01/2010 9:02 AM, Ivan Calandra wrote: Hi everybody! I'm trying to write a script to plot a histogram, a boxplot and a qq-plot (under Windows XP, R2.10 if it matters) What I want to do: define the variables (x and y) to be used at the very beginning, so that I don't have to change all occurrences in the script when I want to plot a different variable. The dataset is called ssfa. TO_POS is a categorical variable containing the tooth position for each sample. Asfc is a numerical variable. In my dataset, I have more variables but it wouldn't change; I want to plot one numeric vs one category. Do I need to supply some data? I don't think it's really necessary but let me know if you would like to. The code of what I do up to now: --- x - ssfa$TO_POS y - ssfa$Asfc hist(y, main=Histogram of Asfc, xlab=Asfc) boxplot(y~x, main=Boxplot of Asfc by TO_POS, xlab=TO_POS, ylab=Asfc) --- I would like something like: hist(y, main=Histogram of y, xlab=y) but that will add Asfc where I write y. And the same for boxplot(y~x, main=Boxplot of y by x, xlab=x, ylab=y) I thought about something like: --- cat - TO_POS num - Asfc x - paste(ssfa$, TO_POS, sep=) y - paste(ssfa$, Asfc, sep=) hist(y, main=paste(Histogram of , cat, sep=), xlab=num) --- but it doesn't work since y is a string. I don't know how to get the syntax correctly. I am on the right path at least?! I think you're on the wrong path. You want to write a function, and pass either x and y as arguments, or pass a formula containing both (the former is easier). For example, twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Then with(ssfa, twoplots(TO_POS, Asfc)) will give you your plots. Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Remove term from formula for predict.lm
Hi, probably just a quick question: can I somehow change the formula used with predict? E.g., the regression was run on y ~ u + v + w but for the prediction the term v should be removed from the formula contained in the regression object and only y ~ u + w be used. I could use model.matrix etc. to do the predictions but it would be very helpful to know a simpler way. Thanks so much, Werner __ verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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] Server hanging despite efforts to correct memory limits
You should be able to set limits on memory use for a process in the operating system, eg with limits or ulimits under Unix-alike shells. -thomas On Tue, 19 Jan 2010, Nathan Stephens wrote: My group is working with datasets between 100 Mb and 1 GB in size, using multiple log ins. From the documentation, it appears that vsize is limited to 2^30-1, which tends to prove too restrictive for our use. When we drop that restriction (set vsize = NA) we end up hanging the server, which requires a restart. Is there any way to increase the memory limits on R while keeping our jobs from hanging? Having to restart the server is a major inconvenience, second only to memory limitations in R. mem.limits() nsize vsize 1NA mem.limits(vsize=2^30) nsize vsize 1 1073741824 mem.limits(vsize=2^31) nsize vsize 1 1073741824 Warning message: In structure(.Internal(mem. limits(as.integer(nsize), as.integer(vsize))), : NAs introduced by coercion [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Remove term from formula for predict.lm
Try this; mod1 - lm(y ~ u + v + w, data = d) update(mod1, . ~ . -v) On Tue, Jan 19, 2010 at 2:10 PM, Werner W. pensterfuz...@yahoo.de wrote: Hi, probably just a quick question: can I somehow change the formula used with predict? E.g., the regression was run on y ~ u + v + w but for the prediction the term v should be removed from the formula contained in the regression object and only y ~ u + w be used. I could use model.matrix etc. to do the predictions but it would be very helpful to know a simpler way. Thanks so much, Werner __ verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] (2nd part) variable name substitution
Thank you for your answer, I got the second part! Ivan Le 1/19/2010 17:03, Carlos Ortega a écrit : Hello, You can loop in the subset you need by storing in a variable and looping on that variable with indexes: seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] with(ssfa, twoplots(TO_POS, ssfa[[j]])) } Regards, Carlos. On Tue, Jan 19, 2010 at 4:53 PM, Ivan Calandra ivan.calan...@uni-hamburg.de mailto:ivan.calan...@uni-hamburg.de wrote: Hi again! I feel like I cannot do anything by myself but I would now like to plot for all numeric variables I have (14 of them). I wanted to add a loop then. The code is: -- #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } #run the function on ssfa with TO_POS as x and ssfa[[i]] as y, the numerical variables are from column 7 to 21 for (i in 7:21) { with(ssfa, twoplots(TO_POS, ssfa[[i]])) } -- I have therefore two questions: - The code above works fine, but in the titles I get Histogram of ssfa[[i]] instead of Histogram of 'variable name' - What if I don't want to loop on all variables, but for example, variables (=columns) 7 to 10 and 12 to 17? How do I give such breaks and ranges? I admit I'm thinking about it since yesterday and I don't have a clue... I hope you will be able to help me. Thanks in advance, Ivan. Duncan Murdoch a écrit : On 18/01/2010 9:02 AM, Ivan Calandra wrote: Hi everybody! I'm trying to write a script to plot a histogram, a boxplot and a qq-plot (under Windows XP, R2.10 if it matters) What I want to do: define the variables (x and y) to be used at the very beginning, so that I don't have to change all occurrences in the script when I want to plot a different variable. The dataset is called ssfa. TO_POS is a categorical variable containing the tooth position for each sample. Asfc is a numerical variable. In my dataset, I have more variables but it wouldn't change; I want to plot one numeric vs one category. Do I need to supply some data? I don't think it's really necessary but let me know if you would like to. The code of what I do up to now: --- x - ssfa$TO_POS y - ssfa$Asfc hist(y, main=Histogram of Asfc, xlab=Asfc) boxplot(y~x, main=Boxplot of Asfc by TO_POS, xlab=TO_POS, ylab=Asfc) --- I would like something like: hist(y, main=Histogram of y, xlab=y) but that will add Asfc where I write y. And the same for boxplot(y~x, main=Boxplot of y by x, xlab=x, ylab=y) I thought about something like: --- cat - TO_POS num - Asfc x - paste(ssfa$, TO_POS, sep=) y - paste(ssfa$, Asfc, sep=) hist(y, main=paste(Histogram of , cat, sep=), xlab=num) --- but it doesn't work since y is a string. I don't know how to get the syntax correctly. I am on the right path at least?! I think you're on the wrong path. You want to write a function, and pass either x and y as arguments, or pass a formula containing both (the former is easier). For example, twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Then with(ssfa, twoplots(TO_POS, Asfc)) will give you your plots. Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Institut und Museum Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] Remove term from formula for predict.lm
This recomputes the lm but if that is ok then: mod - lm(y1 ~ x1 + x2 + x3 + x4, anscombe) mod$call$formula - update(as.formula(mod$call$formula), ~ . - x1 - x2) predict(eval(mod$call), list(x3 = 1, x4 = 1)) On Tue, Jan 19, 2010 at 11:10 AM, Werner W. pensterfuz...@yahoo.de wrote: Hi, probably just a quick question: can I somehow change the formula used with predict? E.g., the regression was run on y ~ u + v + w but for the prediction the term v should be removed from the formula contained in the regression object and only y ~ u + w be used. I could use model.matrix etc. to do the predictions but it would be very helpful to know a simpler way. Thanks so much, Werner __ verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.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] question on plot in R with mac
On Jan 19, 2010, at 10:21 AM, khaz...@ceremade.dauphine.fr wrote: -- Hello all My computer is MacBook and I want to draw a plot in R, for example for x - c(1,3,6,9,12) y - c(1.5,2,7,8,15) I use this command plot(x,y). Yes?, And what happened? but it dosn't work. The phrase doesn't work should be banned from written discourse. Please provide the information requesting in the Posting Guide. sessionInfo() generally provides what you need. (My guess, if you are using the R- Mac GUI, is that you have not yet figured out that you need to use the Window menu to bring the default Quartz window forward. It probably has your requested plot with 5 points despite the 6 element y.) Could you please help me? thank you khazaei PLEASE do read the posting guide http://www.R-project.org/posting-guide.html ^^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] OT: Software for specific visualisation of data...ideas?
Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Model
Hello, I have a barchart. The y-axis represents counts and thex-axis is divided into 10 equal intervals ranging fronm 0 to 0.1, 0.1 to 0.2, ..0.9 to 1.0. Is there a way to model the counts in R? thanks, Jim [[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] (2nd part) variable name substitution
OK. For the names of the variables you can include this code in the loop (variable nv): seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] nv-names(ssfa)[j] with( ssfa, twoplots(TO_POS, ssfa[[j]], nv) ) } And this modification in the function (nm): #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y,nm) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , nm), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Regards, Carlos. On Tue, Jan 19, 2010 at 5:21 PM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Thank you for your answer, I got the second part! Ivan Le 1/19/2010 17:03, Carlos Ortega a écrit : Hello, You can loop in the subset you need by storing in a variable and looping on that variable with indexes: seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] with(ssfa, twoplots(TO_POS, ssfa[[j]])) } Regards, Carlos. On Tue, Jan 19, 2010 at 4:53 PM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Hi again! I feel like I cannot do anything by myself but I would now like to plot for all numeric variables I have (14 of them). I wanted to add a loop then. The code is: -- #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } #run the function on ssfa with TO_POS as x and ssfa[[i]] as y, the numerical variables are from column 7 to 21 for (i in 7:21) { with(ssfa, twoplots(TO_POS, ssfa[[i]])) } -- I have therefore two questions: - The code above works fine, but in the titles I get Histogram of ssfa[[i]] instead of Histogram of 'variable name' - What if I don't want to loop on all variables, but for example, variables (=columns) 7 to 10 and 12 to 17? How do I give such breaks and ranges? I admit I'm thinking about it since yesterday and I don't have a clue... I hope you will be able to help me. Thanks in advance, Ivan. Duncan Murdoch a écrit : On 18/01/2010 9:02 AM, Ivan Calandra wrote: Hi everybody! I'm trying to write a script to plot a histogram, a boxplot and a qq-plot (under Windows XP, R2.10 if it matters) What I want to do: define the variables (x and y) to be used at the very beginning, so that I don't have to change all occurrences in the script when I want to plot a different variable. The dataset is called ssfa. TO_POS is a categorical variable containing the tooth position for each sample. Asfc is a numerical variable. In my dataset, I have more variables but it wouldn't change; I want to plot one numeric vs one category. Do I need to supply some data? I don't think it's really necessary but let me know if you would like to. The code of what I do up to now: --- x - ssfa$TO_POS y - ssfa$Asfc hist(y, main=Histogram of Asfc, xlab=Asfc) boxplot(y~x, main=Boxplot of Asfc by TO_POS, xlab=TO_POS, ylab=Asfc) --- I would like something like: hist(y, main=Histogram of y, xlab=y) but that will add Asfc where I write y. And the same for boxplot(y~x, main=Boxplot of y by x, xlab=x, ylab=y) I thought about something like: --- cat - TO_POS num - Asfc x - paste(ssfa$, TO_POS, sep=) y - paste(ssfa$, Asfc, sep=) hist(y, main=paste(Histogram of , cat, sep=), xlab=num) --- but it doesn't work since y is a string. I don't know how to get the syntax correctly. I am on the right path at least?! I think you're on the wrong path. You want to write a function, and pass either x and y as arguments, or pass a formula containing both (the former is easier). For example, twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Then with(ssfa, twoplots(TO_POS, Asfc)) will give you your plots. Duncan Murdoch [[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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Institut und Museum Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231
Re: [R] Data import export zipped files from URLs
How to unzip this file?. mydata - unzip(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) Warning message: In unzip(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) : error 1 in extracting from zip file __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] OT: Software for specific visualisation of data...ideas?
You might be able to do that with Rgraphviz or another R package, but if I was doing it I would probably use PGF/tikZ. The homepage is here: http://pgf.sourceforge.net/ -Ista On Tue, Jan 19, 2010 at 4:27 PM, Gavin Simpson gavin.simp...@ucl.ac.uk wrote: Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] OT: Software for specific visualisation of data...ideas?
MS PowerPoint (version 2007 or beta 2010) although difficult for so dense graphic. Prefearable: MindManager although is $$. Use the Trial. Regards, Carlos. On Tue, Jan 19, 2010 at 5:27 PM, Gavin Simpson gavin.simp...@ucl.ac.ukwrote: Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/http://www.ucl.ac.uk/%7Eucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splitting a factor in an analysis of deviance table (negative binomial model)
Dears useRs, I have 2 factors, (for the sake of explanation - A and B), with 4 levels each. I've already fitted a negative binomial generalized linear model to my data, and now I need to split the factors in two distinct analysis of deviance table: - A within B1, A within B2, A within B3 and A within B4 - B within A1, B within A2, B within A3 and B within A4 Here is a code that illustrates my problem: # inputing my data require(MASS) my.data - data.frame(A=rep(c(rep(Alevel1,4),rep(Alevel2,4),rep(Alevel3,4),rep(Alevel4,4)),4), B=c(rep(Blevel1,16),rep(Blevel2,16),rep(Blevel3,16),rep(Blevel4,16)), value=rnegbin(64, 10, 10)) # fitting the model with interaction (a + b + a:b) model - glm.nb(value ~ A*B, data=my.data) anova(model, test=F) Df Deviance Resid. Df Resid. Dev F Pr(F) NULL 63 80.639 A 3 1.374 60 79.265 0.4581 0.7115 B 3 2.285 57 76.980 0.7616 0.5155 A:B 9 9.700 48 67.280 1.0778 0.3753 #until here it's ok, now I need to redistribute the 12 degrees of freedom (B+A:B - 3+9) into 4 splitted factors (A within B1, A within B2...) model2 - glm.nb(value ~ A/((B==Blevel1)+(B==Blevel2)+(B==Blevel3)+(B==Blevel4)), data=my.data) anova(model2, test=F) Df Deviance Resid. Df Resid. Dev F Pr(F) NULL 63 80.639 A 3 1.374 60 79.265 0.4581 0.7115 A:B == Blevel1 4 3.871 56 75.394 0.9676 0.4238 A:B == Blevel2 4 5.236 52 70.158 1.3090 0.2639 A:B == Blevel3 4 2.878 48 67.280 0.7195 0.5784 A:B == Blevel4 0 0.000 48 67.280 However, the 12 degrees of freedom are distributed as 4,4,4,0 and not 3,3,3,3, as I expected. Is there a way of obtaining the split I need? Thanks in advance, all the best! Rafael. [[elided Yahoo spam]] [[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] (2nd part) variable name substitution
Super, thanks a lot!! I didn't think about using names() Ivan Le 1/19/2010 17:35, Carlos Ortega a écrit : OK. For the names of the variables you can include this code in the loop (variable nv): seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] nv-names(ssfa)[j] with( ssfa, twoplots(TO_POS, ssfa[[j]], nv) ) } And this modification in the function (nm): #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y,nm) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , nm), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } Regards, Carlos. On Tue, Jan 19, 2010 at 5:21 PM, Ivan Calandra ivan.calan...@uni-hamburg.de mailto:ivan.calan...@uni-hamburg.de wrote: Thank you for your answer, I got the second part! Ivan Le 1/19/2010 17:03, Carlos Ortega a écrit : Hello, You can loop in the subset you need by storing in a variable and looping on that variable with indexes: seq.dat-c(seq(7,10,1), seq(12,17,1)) for( i in 1:length(seq.dat) ) { j-seq.dat[i] with(ssfa, twoplots(TO_POS, ssfa[[j]])) } Regards, Carlos. On Tue, Jan 19, 2010 at 4:53 PM, Ivan Calandra ivan.calan...@uni-hamburg.de mailto:ivan.calan...@uni-hamburg.de wrote: Hi again! I feel like I cannot do anything by myself but I would now like to plot for all numeric variables I have (14 of them). I wanted to add a loop then. The code is: -- #defines the function for the plots (as written by Duncan Murdoch) twoplots - function(x, y) { ylab - deparse(substitute(y)) # get the expression passed as y xlab - deparse(substitute(x)) # get the expression passed as x hist(y, main=paste(Histogram of , ylab), xlab=ylab) boxplot(y ~ x, main=paste(Boxplot of, ylab, by, xlab), xlab=xlab, ylab=ylab) } #run the function on ssfa with TO_POS as x and ssfa[[i]] as y, the numerical variables are from column 7 to 21 for (i in 7:21) { with(ssfa, twoplots(TO_POS, ssfa[[i]])) } -- I have therefore two questions: - The code above works fine, but in the titles I get Histogram of ssfa[[i]] instead of Histogram of 'variable name' - What if I don't want to loop on all variables, but for example, variables (=columns) 7 to 10 and 12 to 17? How do I give such breaks and ranges? I admit I'm thinking about it since yesterday and I don't have a clue... I hope you will be able to help me. Thanks in advance, Ivan. Duncan Murdoch a écrit : On 18/01/2010 9:02 AM, Ivan Calandra wrote: Hi everybody! I'm trying to write a script to plot a histogram, a boxplot and a qq-plot (under Windows XP, R2.10 if it matters) What I want to do: define the variables (x and y) to be used at the very beginning, so that I don't have to change all occurrences in the script when I want to plot a different variable. The dataset is called ssfa. TO_POS is a categorical variable containing the tooth position for each sample. Asfc is a numerical variable. In my dataset, I have more variables but it wouldn't change; I want to plot one numeric vs one category. Do I need to supply some data? I don't think it's really necessary but let me know if you would like to. The code of what I do up to now: --- x - ssfa$TO_POS y - ssfa$Asfc hist(y, main=Histogram of Asfc, xlab=Asfc) boxplot(y~x, main=Boxplot of Asfc by TO_POS, xlab=TO_POS, ylab=Asfc) --- I would like something like: hist(y, main=Histogram of y, xlab=y) but that will add Asfc where I write y. And the same for boxplot(y~x, main=Boxplot of y by x, xlab=x, ylab=y) I thought about something like: --- cat - TO_POS num - Asfc x - paste(ssfa$, TO_POS, sep=) y - paste(ssfa$, Asfc, sep=) hist(y, main=paste(Histogram of , cat, sep=), xlab=num) --- but it doesn't work since y is a string. I don't know how to get the syntax correctly. I am on the right path at least?! I think you're on the wrong path. You want to write a function, and pass either x and y as arguments, or pass
[R] problem with the precision of numbers
Hi All, I was wodering if it is possible to increase the precision using R. I ran the script below in R and MAPLE and I got different results when k is large. Any idea how to fix this problem? thanks for your help for (k in 0:2000){ s=0 for(i in 0:k){ s=s+((-1)^i)*3456*(1+i*1/2000)^3000 } } -- View this message in context: http://n4.nabble.com/problem-with-the-precision-of-numbers-tp1017727p1017727.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] Remove term from formula for predict.lm
Werner, You could set 0 to that regressors you don't want to consider for prediction. da - expand.grid(A=1:20, B=rnorm(20, 4, 0.2), C=10^seq(1,2,l=20)) da$y - rnorm(da$A, 0, 0.3) m0 - lm(y~A+B+C, data=da) new - da new$C - 0 predict(m0)[1:5] predict(m0, newdata=new)[1:5] At your disposal. Walmes. - ..oooO .. ..()... 0ooo... Walmes Zeviani ...\..(.(.)... Master in Statistics and Agricultural Experimentation \_). )../ walmeszevi...@hotmail.com, Lavras - MG, Brasil (_/ -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017759.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] Remove term from formula for predict.lm
Thanks Gabor and Henrique! Sorry for the imprecise question. I want predict() to use the coefficients estimated by the original regression but to exclude terms from the prediction formula. If I originally estimated y ~ x1 + x2 and got coefficients b0, b1, b2, I would like to remove x2 and predict y = b0 + b1*x1 using the the originally estimated coefficients b0 and b1. @Gabor: I tried your suggestion but it seems although predict now accepts a list with fewer variables, the new function is not used so that the coefficient does not change. mod - lm(y1 ~ x1 + x2 + x3 + x4, anscombe) predict(eval(mod$call), list(x1=1,x2=1,x3=1, x4=1)) 1 4.684909 Warning message: In predict.lm(eval(mod$call), list(x1 = 1, x2 = 1, x3 = 1, x4 = 1)) : prediction from a rank-deficient fit may be misleading mod$call$formula - update(as.formula(mod$call$formula), ~ . - x1 - x2) predict(eval(mod$call), list(x3=1, x4=1)) 1 4.684909 Many thanks, Werner -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017749.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] Remove term from formula for predict.lm
On Jan 19, 2010, at 12:05 PM, werner w wrote: Thanks Gabor and Henrique! Sorry for the imprecise question. I want predict() to use the coefficients estimated by the original regression but to exclude terms from the prediction formula. If I originally estimated y ~ x1 + x2 and got coefficients b0, b1, b2, I would like to remove x2 and predict y = b0 + b1*x1 using the the originally estimated coefficients b0 and b1. So just set x2 = 0 in your newdata argument. @Gabor: I tried your suggestion but it seems although predict now accepts a list with fewer variables, the new function is not used so that the coefficient does not change. mod - lm(y1 ~ x1 + x2 + x3 + x4, anscombe) predict(eval(mod$call), list(x1=1,x2=1,x3=1, x4=1)) 1 4.684909 Warning message: In predict.lm(eval(mod$call), list(x1 = 1, x2 = 1, x3 = 1, x4 = 1)) : prediction from a rank-deficient fit may be misleading mod$call$formula - update(as.formula(mod$call$formula), ~ . - x1 - x2) predict(eval(mod$call), list(x3=1, x4=1)) 1 4.684909 Many thanks, Werner -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017749.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data import export zipped files from URLs
Try this: f - tempfile() download.file(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;, f) myData - read.csv(unzip(f)) On Tue, Jan 19, 2010 at 2:56 PM, Velappan Periasamy veepsi...@gmail.com wrote: How to unzip this file?. mydata - unzip(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) Warning message: In unzip(http://nseindia.com/content/historical/EQUITIES/2010/JAN/cm15JAN2010bhav.csv.zip;) : error 1 in extracting from zip file __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Model
Jim, Did you read the posting guide? Did you do a google search, for example, with terms like [R] generalized linear models, [R] count models, [R] poisson regression? I think you should do. Walmes. - ..oooO .. ..()... 0ooo... Walmes Zeviani ...\..(.(.)... Master in Statistics and Agricultural Experimentation \_). )../ walmeszevi...@hotmail.com, Lavras - MG, Brasil (_/ -- View this message in context: http://n4.nabble.com/Re-Model-tp1017712p1017772.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] Predict polynomial problem
On Tue, 19 Jan 2010, Charles C. Berry wrote: and the values in those places are different: On Tue, 19 Jan 2010, Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 1:36 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: Its the environment thing. I think you want something like this: ? ? ? ? ? ? ? ?models[[i]]=lm( bquote( y ~ poly(x,.(i)) ), data=d) Use ? ? ? ? ? ? ? ?terms( mmn[[3]] ) both with and without this change and ? ? ? ? ? ? ? ?ls( env = environment( formula( mmn[[3]] ) ) ) ? ? ? ? ? ? ? ?get(i,env=environment(formula(mmn[[3]]))) ? ? ? ? ? ? ? ?sapply(mmn,function(x) environment( formula( x ) ) ) to see what gives. Think I see it now. predict involves evaluating poly, and poly here needs 'i' for the order. If the right 'i' isn't gotten when predict is called then I get the error. Your fix sticks the right 'i' into the environment when predict is called. I haven't quite got my head round _how_ it does it, and I have no idea how I could have figured this out for myself. Oh well... Per ?bquote, bquote quotes its argument except that terms wrapped in '.()' are evaluated in the specified 'where' environment. (which by default is the parent.frame) Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) So, now 'i' is irrelevant as the expression returned by bquote has '20' as the 'degree' arg. The following lines are also illustrative: d = data.frame(x=1:10,y=runif(10)) i=3 #1 naive model: m1 = lm(y~poly(x,i),data=d) #2,3 bquote, without or with i-wrapping: m2 = lm(bquote(y~poly(x,i)),data=d) m3 = lm(bquote(y~poly(x,.(i))),data=d) #1 works, gets 'i' from global i=3 above: predict(m1,newdata=data.frame(x=9:11)) #2 fails - why? predict(m2,newdata=data.frame(x=9:11)) Well, the terms() objects are the same: all.equal(terms(m1),terms(m2)) [1] TRUE but they will look in different places for 'i': environment(terms(m2)) environment: 0x01b7c178 environment(terms(m1)) environment: R_GlobalEnv and the values in those places are different: environment(terms(m2))$i [1] 2 environment(terms(m1))$i [1] 3 And I should have mentioned that environment(terms(m2)) happens to have an object 'i' in it regardless of whether poly() is used. Chuck #3 works, gets 'i' from within: predict(m3,newdata=data.frame(x=9:11)) It doesn't need 'i', because the i was evaluated and substituted by bquote. That is, it doesn't get(i) as the expression returned by bquote has no 'i' in it. HTH, Chuck rm(i) #1 now fails because we removed 'i' from top level: predict(m1,newdata=data.frame(x=9:11)) #2 still fails: predict(m2,newdata=data.frame(x=9:11)) #3 still works: predict(m3,newdata=data.frame(x=9:11)) Thanks -- blog: http://geospaced.blogspot.com/ web: http: //www.maths.lancs.ac.uk/~rowlings web: http: //www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu 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] Predict polynomial problem
and the values in those places are different: On Tue, 19 Jan 2010, Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 1:36 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: Its the environment thing. I think you want something like this: models[[i]]=lm( bquote( y ~ poly(x,.(i)) ), data=d) Use terms( mmn[[3]] ) both with and without this change and ls( env = environment( formula( mmn[[3]] ) ) ) get(i,env=environment(formula(mmn[[3]]))) sapply(mmn,function(x) environment( formula( x ) ) ) to see what gives. Think I see it now. predict involves evaluating poly, and poly here needs 'i' for the order. If the right 'i' isn't gotten when predict is called then I get the error. Your fix sticks the right 'i' into the environment when predict is called. I haven't quite got my head round _how_ it does it, and I have no idea how I could have figured this out for myself. Oh well... Per ?bquote, bquote quotes its argument except that terms wrapped in '.()' are evaluated in the specified 'where' environment. (which by default is the parent.frame) Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) So, now 'i' is irrelevant as the expression returned by bquote has '20' as the 'degree' arg. The following lines are also illustrative: d = data.frame(x=1:10,y=runif(10)) i=3 #1 naive model: m1 = lm(y~poly(x,i),data=d) #2,3 bquote, without or with i-wrapping: m2 = lm(bquote(y~poly(x,i)),data=d) m3 = lm(bquote(y~poly(x,.(i))),data=d) #1 works, gets 'i' from global i=3 above: predict(m1,newdata=data.frame(x=9:11)) #2 fails - why? predict(m2,newdata=data.frame(x=9:11)) Well, the terms() objects are the same: all.equal(terms(m1),terms(m2)) [1] TRUE but they will look in different places for 'i': environment(terms(m2)) environment: 0x01b7c178 environment(terms(m1)) environment: R_GlobalEnv and the values in those places are different: environment(terms(m2))$i [1] 2 environment(terms(m1))$i [1] 3 #3 works, gets 'i' from within: predict(m3,newdata=data.frame(x=9:11)) It doesn't need 'i', because the i was evaluated and substituted by bquote. That is, it doesn't get(i) as the expression returned by bquote has no 'i' in it. HTH, Chuck rm(i) #1 now fails because we removed 'i' from top level: predict(m1,newdata=data.frame(x=9:11)) #2 still fails: predict(m2,newdata=data.frame(x=9:11)) #3 still works: predict(m3,newdata=data.frame(x=9:11)) Thanks -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu 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] OT: Software for specific visualisation of data...ideas?
See the Rgraphviz package in bioconductor. On Tue, Jan 19, 2010 at 11:27 AM, Gavin Simpson gavin.simp...@ucl.ac.uk wrote: Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Predict polynomial problem
On Tue, Jan 19, 2010 at 5:37 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote: Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) I see it now. bquote(y~poly(x,.(i))) gets it's 'i' there and then, sticks it in the returned expression as the value '20', so any further evaluations get poly(x,20). This is reminiscent of the way macro languages work... Thanks, Barry -- blog: http://geospaced.blogspot.com/ web: http://www.maths.lancs.ac.uk/~rowlings web: http://www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman [[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 model-building strategy in mixed-effects modelling
Stats Wolf stats.wolf at gmail.com writes: Dear all, Consider a completely randomized block design (let's use data(Oats) irrespoctive of the split-plot design it was arranged in). Look: library(nlme) fit - lme(yield ~ nitro, Oats, random = ~1|Block, method=ML) fit2 - lm(yield ~ nitro + Block, Oats) anova(fit, fit2) gives this: Model df AIC BIClogLik Test L.Ratio p-value fit 1 4 624.3245 633.4312 -308.1623 fit2 2 8 611.9309 630.1442 -297.9654 1 vs 2 20.39366 4e-04 Clearly, considering block a random term is worse than considering it a fixed term. I have technical concerns with this step (and larger philosophical concerns with the whole approach -- see below). It's not at all clear that anova() applied to these two models makes sense -- in fact I think it doesn't, because the two models aren't nested. (I guess technically I could take the limit as the random effects variance goes to infinity, or 1/variance - 0, to get from the random to the fixed specification. Then the LRT would be suspect on the grounds that the null hypothesis (1/variance=0) is on the boundary of the allowable region, but that will typically only bias the p-value by a factor of 2 ...) Furthermore, I'm not 100% convinced that the likelihoods computed by lm() and lme() are comparable, constant terms are often left out. But let's suppose this comparison is OK ... Let's see if blocking should be included in the model at all: fit3 - lm(yield ~nitro, Oats) anova(fit2,fit3) which gives a very small P value in favor of fit2, which suggests the block term should be included. So, I go for the second model, with block considered fixed. Is this indeed how I should generally proceed when choosing the optimum model for a situation that calls for mixed effects? Of course, the example above is overly simplistic, yet such situations can occur I think in general that you should decide on random vs fixed on philosophical and practical grounds, _a priori_ ... if you're going to be Bayesian (see various discussions by Andrew Gelman on the subject) then you don't have any philosophical problems at all, because fixed and pooled are just two ends of a spectrum (variance of the priors of the effects fixed at infinity and zero, respectively), and it's just a practical question of estimation. Doing a lot of hypothesis testing to decide on the best model starts down the road of data-dredging ... In general, questions like this might get more attention on r-sig-mixed-mod...@lists.r-project.org cheers Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sampling theory
Hi there, are there any R-packages for computations required in sampling theury (such as confidence intervals under random, stratified, cluster sampling; I'd be partoculary interested in confidence intervals for the population variance, which is difficult enough to find even in books)? Thanks, Christian *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with the precision of numbers
kayj kjaja27 at yahoo.com writes: Hi All, I was wodering if it is possible to increase the precision using R. I ran the script below in R and MAPLE and I got different results when k is large. Any idea how to fix this problem? thanks for your help for (k in 0:2000){ s=0 for(i in 0:k){ s=s+((-1)^i)*3456*(1+i*1/2000)^3000 } } (1) see http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:high_precision_arithmetic (2) consider whether there is more accurate algorithm you could use. I don't recognize the series, but perhaps it has a closed form solution, maybe as a special function? How much accuracy do you really need in the solution? Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Remove term from formula for predict.lm
If you want to keep the same coefficients but ignore certain ones just use 0 for the ones you don't want: mod - lm(Sepal.Length ~ Petal.Length + Petal.Width, iris) predict(mod, list(Petal.Length = 3, Petal.Width = 0)) Regarding the problem with the example, the example data was not the best for showing this because there are co-linear columns in the anscombe data set. Using iris we see that it does produce different answers: mod - lm(Sepal.Length ~ Petal.Length + Petal.Width, iris) predict(eval(mod$call), list(Petal.Length = 3, Petal.Width = 3)) 1 4.857262 mod$call$formula - update(as.formula(mod$call$formula), ~ . - Petal.Width) predict(eval(mod$call), list(Petal.Length = 3)) 1 5.53337 On Tue, Jan 19, 2010 at 12:05 PM, werner w pensterfuz...@yahoo.de wrote: Thanks Gabor and Henrique! Sorry for the imprecise question. I want predict() to use the coefficients estimated by the original regression but to exclude terms from the prediction formula. If I originally estimated y ~ x1 + x2 and got coefficients b0, b1, b2, I would like to remove x2 and predict y = b0 + b1*x1 using the the originally estimated coefficients b0 and b1. @Gabor: I tried your suggestion but it seems although predict now accepts a list with fewer variables, the new function is not used so that the coefficient does not change. mod - lm(y1 ~ x1 + x2 + x3 + x4, anscombe) predict(eval(mod$call), list(x1=1,x2=1,x3=1, x4=1)) 1 4.684909 Warning message: In predict.lm(eval(mod$call), list(x1 = 1, x2 = 1, x3 = 1, x4 = 1)) : prediction from a rank-deficient fit may be misleading mod$call$formula - update(as.formula(mod$call$formula), ~ . - x1 - x2) predict(eval(mod$call), list(x3=1, x4=1)) 1 4.684909 Many thanks, Werner -- View this message in context: http://n4.nabble.com/Remove-term-from-formula-for-predict-lm-tp1017686p1017749.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] Predict polynomial problem
On Tue, 19 Jan 2010, Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 5:37 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote: Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) I see it now. bquote(y~poly(x,.(i))) gets it's 'i' there and then, sticks it in the returned expression as the value '20', so any further evaluations get poly(x,20). This is reminiscent of the way macro languages work... Yes, bquote() was written to mimic the backquote macro in Lisp, hence its name. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] OT: Software for specific visualisation of data...ideas?
On Tue, Jan 19, 2010 at 6:56 PM, Ista Zahn istaz...@gmail.com wrote: You might be able to do that with Rgraphviz or another R package, but if I was doing it I would probably use PGF/tikZ. The homepage is here: http://pgf.sourceforge.net/ I second that - gives you really good results. Cheers, Rainer -Ista On Tue, Jan 19, 2010 at 4:27 PM, Gavin Simpson gavin.simp...@ucl.ac.uk wrote: Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- NEW GERMAN FAX NUMBER!!! Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Cell: +27 - (0)83 9479 042 Fax:+27 - (0)86 516 2782 Fax:+49 - (0)321 2125 2244 email: rai...@krugs.de Skype: RMkrug Google: r.m.k...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] OT: Software for specific visualisation of data...ideas?
Whats wrong with Power Point or anyone of its equivalents? Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 Gavin Simpson gavin.simp...@uc l.ac.uk To Sent by: R-help r-h...@stat.math.ethz.ch r-help-boun...@r- cc project.org Subject [R] OT: Software for specific 01/19/2010 11:27 visualisation of data...ideas? AM Please respond to gavin.simp...@ucl .ac.uk Dear List, A student in the Department where I work would like to produce a graphic similar to this one: http://image.guardian.co.uk/sys-files/Guardian/documents/2009/09/16/Public_spending_160909.pdf Does anyone know if the figure in the pdf can be generated in a specific software application for example? Any suggestions would be most gratefully received by the student concerned. Many thanks, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Predict polynomial problem
Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 5:37 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote: Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) I see it now. bquote(y~poly(x,.(i))) gets it's 'i' there and then, sticks it in the returned expression as the value '20', so any further evaluations get poly(x,20). This is reminiscent of the way macro languages work... And that might be why ?bquote says: An analogue of the LISP backquote macro. :) Cheers, Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sampling theory
On Tue, 19 Jan 2010, Christian Hennig wrote: are there any R-packages for computations required in sampling theury (such as confidence intervals under random, stratified, cluster sampling; I'd be partoculary interested in confidence intervals for the population variance, which is difficult enough to find even in books)? Yes, these are in the survey package, for fairly general designs, using linearization or replicate weights. I don't know how good the confidence intervals for the variance are. One of the disadvantages of implementing survey estimators in a general way is that you lose the opportunity to use bias corrections that are only available for simple cases. The forthcoming version 3.19 (later this week) has nicer output for the population variance, but the computations are still the same. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Working with text data/text operators
Mihai.Mirauta wrote: Could someone tell me, how can I select from a dataframe only those columns whose names contain a certain text? For example, if the column names are Bond1.Creditclass,Bond1.Price,Bond2.Creditclass,Bond2.Price, how do I select only the columns corresponding to Bond1? See Wacek's https://stat.ethz.ch/pipermail/r-help/2009-February/187462.html Dieter -- View this message in context: http://n4.nabble.com/Working-with-text-data-text-operators-tp1017490p1017837.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] problem with the precision of numbers
On 19-Jan-10 17:55:43, Ben Bolker wrote: kayj kjaja27 at yahoo.com writes: Hi All, I was wodering if it is possible to increase the precision using R. I ran the script below in R and MAPLE and I got different results when k is large. Any idea how to fix this problem? thanks for your help for (k in 0:2000){ s=0 for(i in 0:k){ s=s+((-1)^i)*3456*(1+i*1/2000)^3000 } } (1) see http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:high_precisi on_arithmetic (2) consider whether there is more accurate algorithm you could use. I don't recognize the series, but perhaps it has a closed form solution, maybe as a special function? How much accuracy do you really need in the solution? Ben Bolker I suspect this is an invented computation -- the 3456 strikes me as unlikely (it reminds me of my habitual illustrative use of set.seed(54321)). There is a definite problem with the development given by kayj. When k=2000 and i=k, the formula requires evaluation of 3456*(2^3000) on a log10 scale this is log10(3456) + 3000*log10(2) = 906.6286 Since R gives up at 10^308.25471 = 1.79767e+308 (10^308.25472 = Inf), this algorithm is going to be tricky to evaluate! I don't know how well Rmpfr copes with very large numbers (the available documentation seems cryptic). However, I can go along with the recommendation in the URL the Ben gives, to use 'bc' (Berkeley Calculator), available on unix[oid] systems since a long time ago. That is an old friend of mine, and works well (it can cope with exponents up to X^2147483647 in the version I have). It can eat for breakfast the task of checking whether Kate Bush can accurately sing pi to 117 significant figures: http://www.absolutelyrics.com/lyrics/view/kate_bush/pi (Try it in R). Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 19-Jan-10 Time: 18:41:27 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with the precision of numbers
On Tue, Jan 19, 2010 at 1:41 PM, Ted Harding ted.hard...@manchester.ac.uk wrote: On 19-Jan-10 17:55:43, Ben Bolker wrote: kayj kjaja27 at yahoo.com writes: Hi All, I was wodering if it is possible to increase the precision using R. I ran the script below in R and MAPLE and I got different results when k is large. Any idea how to fix this problem? thanks for your help for (k in 0:2000){ s=0 for(i in 0:k){ s=s+((-1)^i)*3456*(1+i*1/2000)^3000 } } (1) see http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:high_precisi on_arithmetic (2) consider whether there is more accurate algorithm you could use. I don't recognize the series, but perhaps it has a closed form solution, maybe as a special function? How much accuracy do you really need in the solution? Ben Bolker I suspect this is an invented computation -- the 3456 strikes me as unlikely (it reminds me of my habitual illustrative use of set.seed(54321)). There is a definite problem with the development given by kayj. When k=2000 and i=k, the formula requires evaluation of 3456*(2^3000) on a log10 scale this is log10(3456) + 3000*log10(2) = 906.6286 Since R gives up at 10^308.25471 = 1.79767e+308 (10^308.25472 = Inf), this algorithm is going to be tricky to evaluate! I don't know how well Rmpfr copes with very large numbers (the available documentation seems cryptic). However, I can go along with the recommendation in the URL the Ben gives, to use 'bc' (Berkeley Calculator), available on unix[oid] systems since a long time ago. That is an old friend of mine, and works well (it can cope with exponents up to X^2147483647 in the version I have). It can eat for breakfast the task of checking whether Kate Bush can accurately sing pi to 117 significant figures: http://www.absolutelyrics.com/lyrics/view/kate_bush/pi (Try it in R). There is an R interface to bc here at http://r-bc.googlecode.com . Trying it for k up to 10: source(http://r-bc.googlecode.com/svn/trunk/R/bc.R;) bc(for (k = 0; k = 10; k = k + 1) { + s=0 + for (i = 0; i = k; i = i + 1) { + s=s+((-1)^i)*3456*(1+i*1/2000)^3000 + } + } + s + ) [1] 8886117368.3070119572856212990071196502030186189331701144530548672570992204603757660023189324468582740298425344 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 ~
On 19/01/2010, at 11:40 PM, Dieter Menne wrote: SNIP next time you post homework here, please make sure that you modify the language of the task a bit so that the discrepancy between the task and your helplessness is less evident. This sounds like a fortune to me! How about it Prof. Zeileis? 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] Memory usage in read.csv()
I read vmstat data in just fine without any problems. Here is an example of how I do it: VMstat - read.table('vmstat.txt', header=TRUE, as.is=TRUE) vmstat.txt looks like this: date time r b w swap free re mf pi po fr de sr intr syscalls cs user sys id 07/27/05 00:13:06 0 0 0 27755440 13051648 20 86 0 0 0 0 0 456 2918 1323 0 1 99 07/27/05 00:13:36 0 0 0 27755280 13051480 11 53 0 0 0 0 0 399 1722 1411 0 1 99 07/27/05 00:14:06 0 0 0 27753952 13051248 18 88 0 0 0 0 0 424 1259 1254 0 1 99 07/27/05 00:14:36 0 0 0 27755304 13051496 17 85 0 0 0 0 0 430 1029 1246 0 1 99 07/27/05 00:15:06 0 0 0 27755064 13051232 41 278 0 1 1 0 0 452 2047 1386 0 1 99 07/27/05 00:15:36 0 0 0 27753824 13040720 125 1039 0 0 0 0 0 664 4097 1901 3 2 95 07/27/05 00:16:06 0 0 0 27754472 13027000 15 91 0 0 0 0 0 432 1160 1273 0 1 99 07/27/05 00:16:36 0 0 0 27754568 13027104 17 85 0 0 0 0 0 416 1058 1271 0 1 99 Have you tried a smaller portion of data? Here is what it took to read in a file with 85K lines: system.time(vmstat - read.table('c:/vmstat.txt', header=TRUE)) user system elapsed 2.010.012.03 str(vmstat) 'data.frame': 85680 obs. of 20 variables: $ date: Factor w/ 2 levels 07/27/05,07/28/05: 1 1 1 1 1 1 1 1 1 1 ... $ time: Factor w/ 2856 levels 00:00:26,00:00:56,..: 27 29 31 33 35 37 39 41 43 45 ... $ r : int 0 0 0 0 0 0 0 0 0 0 ... $ b : int 0 0 0 0 0 0 0 0 0 0 ... $ w : int 0 0 0 0 0 0 0 0 0 0 ... $ swap: int 27755440 27755280 27753952 27755304 27755064 27753824 27754472 27754568 27754560 27754704 ... $ free: int 13051648 13051480 13051248 13051496 13051232 13040720 13027000 13027104 13027096 13027240 ... $ re : int 20 11 18 17 41 125 15 17 13 12 ... $ mf : int 86 53 88 85 278 1039 91 85 69 51 ... $ pi : int 0 0 0 0 0 0 0 0 0 0 ... $ po : int 0 0 0 0 1 0 0 0 0 1 ... $ fr : int 0 0 0 0 1 0 0 0 0 1 ... $ de : int 0 0 0 0 0 0 0 0 0 0 ... $ sr : int 0 0 0 0 0 0 0 0 0 0 ... $ intr: int 456 399 424 430 452 664 432 416 425 432 ... $ syscalls: int 2918 1722 1259 1029 2047 4097 1160 1058 1198 1727 ... $ cs : int 1323 1411 1254 1246 1386 1901 1273 1271 1268 1477 ... $ user: int 0 0 0 0 0 3 0 0 0 0 ... $ sys : int 1 1 1 1 1 2 1 1 1 1 ... $ id : int 99 99 99 99 99 95 99 99 99 99 ... On Tue, Jan 19, 2010 at 9:25 AM, nabble.30.miller_2...@spamgourmet.com wrote: I'm sure this has gotten some attention before, but I have two CSV files generated from vmstat and free that are roughly 6-8 Mb (about 80,000 lines) each. When I try to use read.csv(), R allocates all available memory (about 4.9 Gb) when loading the files, which is over 300 times the size of the raw data. Here are the scripts used to generate the CSV files as well as the R code: Scripts (run for roughly a 24-hour period): vmstat -ant 1 | awk '$0 !~ /(proc|free)/ {FS= ; OFS=,; print strftime(%F %T %Z),$6,$7,$12,$13,$14,$15,$16,$17;}' ~/vmstat_20100118_133845.o; free -ms 1 | awk '$0 ~ /Mem\:/ {FS= ; OFS=,; print strftime(%F %T %Z),$2,$3,$4,$5,$6,$7}' ~/memfree_20100118_140845.o; R code: infile.vms - ~/vmstat_20100118_133845.o; infile.mem - ~/memfree_20100118_140845.o; vms.colnames - c(time,r,b,swpd,free,inact,active,si,so,bi,bo,in,cs,us,sy,id,wa,st); vms.colclass - c(character,rep(integer,length(vms.colnames)-1)); mem.colnames - c(time,total,used,free,shared,buffers,cached); mem.colclass - c(character,rep(integer,length(mem.colnames)-1)); vmsdf - (read.csv(infile.vms,header=FALSE,colClasses=vms.colclass,col.names=vms.colnames)); memdf - (read.csv(infile.mem,header=FALSE,colClasses=mem.colclass,col.names=mem.colnames)); I am running R v2.10.0 on a 64-bit machine with Fedora 10 (Linux version 2.6.27.41-170.2.117.fc10.x86_64 ) with 6Gb of memory. There are no other significant programs running and `rm()` followed by ` gc()` successfully frees the memory (followed by swapins after other programs seek to used previously cached information swapped to disk). I've incorporated the memory-saving suggestions in the `read.csv()` manual page, excluding the limit on the lines read (which shouldn't really be necessary here since we're only talking about 20 Mb of raw data. Any suggestions, or is the read.csv() code known to have memory leak/ overcommit issues? 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal,
Re: [R] Predict polynomial problem
Charles C. Berry wrote: On Tue, 19 Jan 2010, Charles C. Berry wrote: and the values in those places are different: On Tue, 19 Jan 2010, Barry Rowlingson wrote: On Tue, Jan 19, 2010 at 1:36 AM, Charles C. Berry cbe...@tajo.ucsd.edu wrote: Its the environment thing. I think you want something like this: � � � � � � � �models[[i]]=lm( bquote( y ~ poly(x,.(i)) ), data=d) Use � � � � � � � �terms( mmn[[3]] ) both with and without this change and � � � � � � � �ls( env = environment( formula( mmn[[3]] ) ) ) � � � � � � � �get(i,env=environment(formula(mmn[[3]]))) � � � � � � � �sapply(mmn,function(x) environment( formula( x ) ) ) to see what gives. Think I see it now. predict involves evaluating poly, and poly here needs 'i' for the order. If the right 'i' isn't gotten when predict is called then I get the error. Your fix sticks the right 'i' into the environment when predict is called. I haven't quite got my head round _how_ it does it, and I have no idea how I could have figured this out for myself. Oh well... Per ?bquote, bquote quotes its argument except that terms wrapped in '.()' are evaluated in the specified 'where' environment. (which by default is the parent.frame) Note: i - 20 bquote(y ~ poly(x,.(i))) y ~ poly(x, 20) So, now 'i' is irrelevant as the expression returned by bquote has '20' as the 'degree' arg. The following lines are also illustrative: d = data.frame(x=1:10,y=runif(10)) i=3 #1 naive model: m1 = lm(y~poly(x,i),data=d) #2,3 bquote, without or with i-wrapping: m2 = lm(bquote(y~poly(x,i)),data=d) m3 = lm(bquote(y~poly(x,.(i))),data=d) #1 works, gets 'i' from global i=3 above: predict(m1,newdata=data.frame(x=9:11)) #2 fails - why? predict(m2,newdata=data.frame(x=9:11)) Well, the terms() objects are the same: all.equal(terms(m1),terms(m2)) [1] TRUE but they will look in different places for 'i': environment(terms(m2)) environment: 0x01b7c178 environment(terms(m1)) environment: R_GlobalEnv and the values in those places are different: environment(terms(m2))$i [1] 2 environment(terms(m1))$i [1] 3 And I should have mentioned that environment(terms(m2)) happens to have an object 'i' in it regardless of whether poly() is used. Right. It might be worth pointing out that the 'i' in environment(terms(m2)) or in environment(terms(m3)), which also has an 'i', is there even if you use poly(x,j). It is (if I'm not mistaken) the number of 'variables' in the formula: response plus predictor terms. Thus j - 5 m4 - lm(bquote(y ~ sqrt(x) + poly(x, .(j))), data=d) environment(terms(m4))$i [1] 3 -Peter Ehlers Chuck #3 works, gets 'i' from within: predict(m3,newdata=data.frame(x=9:11)) It doesn't need 'i', because the i was evaluated and substituted by bquote. That is, it doesn't get(i) as the expression returned by bquote has no 'i' in it. HTH, Chuck rm(i) #1 now fails because we removed 'i' from top level: predict(m1,newdata=data.frame(x=9:11)) #2 still fails: predict(m2,newdata=data.frame(x=9:11)) #3 still works: predict(m3,newdata=data.frame(x=9:11)) Thanks -- blog: http://geospaced.blogspot.com/ web: http: //www.maths.lancs.ac.uk/~rowlings web: http: //www.rowlingson.com/ twitter: http://twitter.com/geospacedman pics: http://www.flickr.com/photos/spacedman Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.eduUC 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. -- Peter Ehlers University of Calgary 403.202.3921 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error compiling R 2.10.1 on AIX
I'm trying to compile R 2.10.1 on AIX 5.3, and am getting the following error: Error in read.dcf(file = descfile) : Line starting 'Package: tools ...' is malformed! Calls: makeLazyLoading ... code2LazyLoadDB - loadNamespace - parseNamespaceFile - read.dcf Execution halted make[3]: *** [all] Error 1 make[3]: Leaving directory `/afs/.isis.unc.edu/pkg/r-2.10.1/.build/rs_aix53/R-patched/src/library/tools ' My environment and configure settings are as follows: export PATH=/usr/local/bin:/opt/freeware/bin:$PATH export OBJECT_MODE=64 export LIBICONV=/opt/freeware export CC=xlc_r -q64 export CFLAGS=-O -qstrict export CXX=xlC_r -q64 export CXXFLAGS=-O -qstrict export AR=ar -X64 export F77=xlf_r -q64 export CPPFLAGS=-I/afs/isis/pkg/libpng/include -I/usr/local/include -I$LIBICONV/include -I/usr/lpp/X11/include/X11 export LDFLAGS=-L/usr/local/lib -L$LIBICONV/lib -L/usr/lib -L/usr/X11R6/lib export CAIRO_CFLAGS=-I/opt/freeware/include/cairo -I/opt/freeware/include/freetype2 export CAIRO_LIBS=-L/opt/freeware/lib -lcairo export JAVA_HOME=/usr/java14_64 export JAVA_CPPFLAGS=-I/usr/java14_64/include export LDR_CNTRL=USERREGS ./configure --prefix=/afs/.isis/pkg/r-2.10.1 --with-tcltk=/usr/local/lib --with-tcl-config=/usr/local/lib/tclConfig.sh --with-tk-config=/usr/local/lib/tkConfig.sh Mike Waldron __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] restricted permutations in permutest()?
i'll post in r-forge vegan help forum and appreciate your help very much. greetings, kay -- View this message in context: http://n4.nabble.com/restricted-permutations-in-permtest-tp1017422p1017865.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] Using the output of strsplit
This suggestion does not work. x seems to have twice the number of entries as spl. x - do.call(rbind, spl) names(x) - c('Date', 'quarter') x$Date - as.Date(x$Date) Error in x$Date : $ operator is invalid for atomic vectors x$quarter - as.numeric(x$quarter) Error in x$quarter : $ operator is invalid for atomic vectors names(x) [1] Datequarter NANANANA NA [8] NANANANANANA NA [15] NANANANANANA NA [22] NANANANANANA NA [29] NANANANANANANA # and on for 13000 entries! Making it a data.frame dod not work either. I also tried qt=c(length(spl)) dt=c(length(spl)) ### for(j in 1:length(spl)) { dt[j]=spl[[j]][1] qt[j]=spl[[j]][2] } qt=as.numeric(qt) dt=as.POSIXlt(dt) rate=as.vector(ar) ratedata=data.frame(c(rate=rate,date=dt,quarter=qt)) ### but then ratedata was totally wrong. Thanks, Jim On 1/18/10 4:59 PM, Dennis Murphy wrote: Hi James: To slurp your list into a matrix, run x - do.call(rbind, yourlistname) Date - as.Date(x[, 1]) quarter - as.numeric(x[, 2]) You could also convert x to a data frame with as.data.frame(x) : x - as.data.frame(x) names(x) - c('Date', 'quarter') x$Date - as.Date(x$Date) x$quarter - as.numeric(x$quarter) do.call() takes a function as its first argument and a list as its second argument. HTH, Dennis On Mon, Jan 18, 2010 at 1:48 PM, James Rome jamesr...@gmail.com mailto:jamesr...@gmail.com wrote: I successfully combined my data frames, and am now on my next hurdle. I had combined the data and quarter, and used tapply to count the entries for each unique date/quarter pair. ar= tapply(ewrgnd$gw, list(ewrgnd$dq), sum) #for each date/quarter combination sums the gw (which are all 1) dq=row.names(ar) spl=strsplit(dq) But I need to split them back into the separate date and quarter. So I used strsplit(), and get spl [[1]] [1] 2009-01-01 60 [[2]] [1] 2009-01-01 61 [[3]] [1] 2009-01-01 62 [[4]] [1] 2009-01-01 63 [[5]] [1] 2009-01-01 68 . . . But lists throw me. I want to get separate vectors of the date and quarter out of my list. All the things I have seen extract rows from the list. I need to extract columns. Thanks list, Jim Rome __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Using the output of strsplit
'x' is a matrix and not a dataframe. You should be doing colnames(x) - c(Date, quarter) x[,Date] - as.Date(x[,Date]) It would help if you took a look at the structure you were using to understand how to access. 'names' applied to a vector would give you the output for 13000 more entries. Think about it. On Tue, Jan 19, 2010 at 2:07 PM, James Rome jamesr...@gmail.com wrote: This suggestion does not work. x seems to have twice the number of entries as spl. x - do.call(rbind, spl) names(x) - c('Date', 'quarter') x$Date - as.Date(x$Date) Error in x$Date : $ operator is invalid for atomic vectors x$quarter - as.numeric(x$quarter) Error in x$quarter : $ operator is invalid for atomic vectors names(x) [1] Date quarter NA NA NA NA NA [8] NA NA NA NA NA NA NA [15] NA NA NA NA NA NA NA [22] NA NA NA NA NA NA NA [29] NA NA NA NA NA NA NA # and on for 13000 entries! Making it a data.frame dod not work either. I also tried qt=c(length(spl)) dt=c(length(spl)) ### for(j in 1:length(spl)) { dt[j]=spl[[j]][1] qt[j]=spl[[j]][2] } qt=as.numeric(qt) dt=as.POSIXlt(dt) rate=as.vector(ar) ratedata=data.frame(c(rate=rate,date=dt,quarter=qt)) ### but then ratedata was totally wrong. Thanks, Jim On 1/18/10 4:59 PM, Dennis Murphy wrote: Hi James: To slurp your list into a matrix, run x - do.call(rbind, yourlistname) Date - as.Date(x[, 1]) quarter - as.numeric(x[, 2]) You could also convert x to a data frame with as.data.frame(x) : x - as.data.frame(x) names(x) - c('Date', 'quarter') x$Date - as.Date(x$Date) x$quarter - as.numeric(x$quarter) do.call() takes a function as its first argument and a list as its second argument. HTH, Dennis On Mon, Jan 18, 2010 at 1:48 PM, James Rome jamesr...@gmail.com mailto:jamesr...@gmail.com wrote: I successfully combined my data frames, and am now on my next hurdle. I had combined the data and quarter, and used tapply to count the entries for each unique date/quarter pair. ar= tapply(ewrgnd$gw, list(ewrgnd$dq), sum) #for each date/quarter combination sums the gw (which are all 1) dq=row.names(ar) spl=strsplit(dq) But I need to split them back into the separate date and quarter. So I used strsplit(), and get spl [[1]] [1] 2009-01-01 60 [[2]] [1] 2009-01-01 61 [[3]] [1] 2009-01-01 62 [[4]] [1] 2009-01-01 63 [[5]] [1] 2009-01-01 68 . . . But lists throw me. I want to get separate vectors of the date and quarter out of my list. All the things I have seen extract rows from the list. I need to extract columns. Thanks list, Jim Rome __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem with the precision of numbers
On 19-Jan-10 18:48:47, Gabor Grothendieck wrote: On Tue, Jan 19, 2010 at 1:41 PM, Ted Harding ted.hard...@manchester.ac.uk wrote: On 19-Jan-10 17:55:43, Ben Bolker wrote: kayj kjaja27 at yahoo.com writes: Hi All, I was wodering if it is possible to increase the precision using R. I ran the script below in R and MAPLE and I got different results when k is large. Any idea how to fix this problem? thanks for your help for (k in 0:2000){ _s=0 _for(i in 0:k){ _s=s+((-1)^i)*3456*(1+i*1/2000)^3000 _} } (1) see http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:high_preci si on_arithmetic (2) consider whether there is more accurate algorithm you could use. I don't recognize the series, but perhaps it has a closed form solution, maybe as a special function? How much accuracy do you really need in the solution? _ Ben Bolker I suspect this is an invented computation -- the 3456 strikes me as unlikely (it reminds me of my habitual illustrative use of set.seed(54321)). There is a definite problem with the development given by kayj. When k=2000 and i=k, the formula requires evaluation of _3456*(2^3000) on a log10 scale this is _log10(3456) + 3000*log10(2) = 906.6286 Since R gives up at 10^308.25471 = 1.79767e+308 (10^308.25472 = Inf), this algorithm is going to be tricky to evaluate! I don't know how well Rmpfr copes with very large numbers (the available documentation seems cryptic). However, I can go along with the recommendation in the URL the Ben gives, to use 'bc' (Berkeley Calculator), available on unix[oid] systems since a long time ago. That is an old friend of mine, and works well (it can cope with exponents up to X^2147483647 in the version I have). It can eat for breakfast the task of checking whether Kate Bush can accurately sing pi to 117 significant figures: _http://www.absolutelyrics.com/lyrics/view/kate_bush/pi (Try it in R). There is an R interface to bc here at http://r-bc.googlecode.com . Trying it for k up to 10: source(http://r-bc.googlecode.com/svn/trunk/R/bc.R;) bc(for (k = 0; k = 10; k = k + 1) { + s=0 + for (i = 0; i = k; i = i + 1) { + s=s+((-1)^i)*3456*(1+i*1/2000)^3000 + } + } + s + ) [1] 8886117368.307011957285621299007119650203018618933170114453054867257099 2204603757660023189324468582740298425344 Excellent reource! Thanks for pointing it out, Gabor. Now for Kate Bush. First, KB: == Sweet and gentle sensitive man With an obsessive nature and deep fascination For numbers And a complete infatuation with the calculation Of PI Oh he love, he love, he love He does love his numbers And they run, they run, they run him In a great big circle In a circle of infinity 3.1415926535 897932 3846 264 338 3279 Oh he love, he love, he love He does love his numbers And they run, they run, they run him In a great big circle In a circle of infinity But he must, he must, he must Put a number to it 50288419 716939937510 582319749 44 59230781 6406286208 821 4808651 32 Oh he love, he love, he love He does love his numbers And they run, they run, they run him In a great big circle In a circle of infinity 82306647 0938446095 505 8223? KB she say: 3. 14159 26535 89793 2384620 26433 83279 50288 4197140 69399 37510 582*31* 97494 60 45923 07816 40628 6208||8 80 21480 86513 28230 66470 100 93844 60955 05822 3 116+1 = 117 Next, bc: source(http://r-bc.googlecode.com/svn/trunk/R/bc.R;) bc(scale=200 + 4*a(1) + ) [1] 3. 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 582*0*9 74944 59230 78164 06286 208|99 86280 34825 34211 70679 |82148 08651 32823 06647 09384 46095 50582 23 172 53594 08128 48111 74502 84102 70193 85211 05559 64462 29489 54930 38196 [edited for layout and indicators] So KB replaces a 0 at decimal place 54 by 31, and omits 99 86280 34825 34211 70679. Maybe there were overwhelming poetic reasons for this. Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 19-Jan-10 Time: 19:25:20 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Memory usage in read.csv()
You could also try read.csv.sql in sqldf. See examples on sqldf home page: http://code.google.com/p/sqldf/#Example_13._read.csv.sql_and_read.csv2.sql On Tue, Jan 19, 2010 at 9:25 AM, nabble.30.miller_2...@spamgourmet.com wrote: I'm sure this has gotten some attention before, but I have two CSV files generated from vmstat and free that are roughly 6-8 Mb (about 80,000 lines) each. When I try to use read.csv(), R allocates all available memory (about 4.9 Gb) when loading the files, which is over 300 times the size of the raw data. Here are the scripts used to generate the CSV files as well as the R code: Scripts (run for roughly a 24-hour period): vmstat -ant 1 | awk '$0 !~ /(proc|free)/ {FS= ; OFS=,; print strftime(%F %T %Z),$6,$7,$12,$13,$14,$15,$16,$17;}' ~/vmstat_20100118_133845.o; free -ms 1 | awk '$0 ~ /Mem\:/ {FS= ; OFS=,; print strftime(%F %T %Z),$2,$3,$4,$5,$6,$7}' ~/memfree_20100118_140845.o; R code: infile.vms - ~/vmstat_20100118_133845.o; infile.mem - ~/memfree_20100118_140845.o; vms.colnames - c(time,r,b,swpd,free,inact,active,si,so,bi,bo,in,cs,us,sy,id,wa,st); vms.colclass - c(character,rep(integer,length(vms.colnames)-1)); mem.colnames - c(time,total,used,free,shared,buffers,cached); mem.colclass - c(character,rep(integer,length(mem.colnames)-1)); vmsdf - (read.csv(infile.vms,header=FALSE,colClasses=vms.colclass,col.names=vms.colnames)); memdf - (read.csv(infile.mem,header=FALSE,colClasses=mem.colclass,col.names=mem.colnames)); I am running R v2.10.0 on a 64-bit machine with Fedora 10 (Linux version 2.6.27.41-170.2.117.fc10.x86_64 ) with 6Gb of memory. There are no other significant programs running and `rm()` followed by ` gc()` successfully frees the memory (followed by swapins after other programs seek to used previously cached information swapped to disk). I've incorporated the memory-saving suggestions in the `read.csv()` manual page, excluding the limit on the lines read (which shouldn't really be necessary here since we're only talking about 20 Mb of raw data. Any suggestions, or is the read.csv() code known to have memory leak/ overcommit issues? 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.
[R] Number of download.
Hi the list Is there a way to know how many times an R package (on CRAN) has been download ? Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.