Re: [R] baseline fitters
I am not surprised at slowness of runquantile, since it is trying to perform n=4500 partial sorts of k=225 elements. Here are some thoughts at speeding it up: 1) playing with different endrule settings can save some time, but usually results with undesirable effects at first and last 112 values. All rum* functions in caTools use low level C code for inner elements between k/2 and n-k/2. However the elements at the edge are calculated using R functions. In case of runquantile with endrule=func that means k calls of R quantile function. One option for endrule not available at present would be to pad both sides of the array with k/2 numbers and than use endrule=trim. The trick would be to pick good value for the padding number. 2) you mentioned that you jimmied something together with runmin and runmedian. I would try something like runmean with window of size 5, 15, 25 and than runmin with window size k. The first one should get rid of your 'reverse-spikes' and second would take running min of your smoothed function. Best, Jarek Tuszynski -Original Message- From: Thaden, John J [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 20, 2007 1:23 PM To: r-help@stat.math.ethz.ch Cc: Tuszynski, Jaroslaw W. Subject: baseline fitters I am pretty pleased with baselines I fit to chromatograms using the runquantile() function in caTools(v1.6) when its probs parameter is set to 0.2 and its k parameter to ~1/20th of n (e.g., k ~ 225 for n ~ 4500, where n is time series length). This ignores occasional low- side outliers, and, after baseline subtraction, I can re-adjust any negative values to zero. But runquantile's computation time proves exceedingly long for my large datasets, particularly if I set the endrule parameter to 'func'. Here is what caTools author Jarek Tuszynski says about relative speeds of various running-window functions: - runmin, runmax, runmean run at O(n) - runmean(..., alg=exact) can have worst case speed of O(n^2) for some small data vectors, but average case is still close to O(n). - runquantile and runmad run at O(n*k) - runmed - related R function runs at O(n*log(k)) The obvious alternative runmin() performs poorly due to dropout (zero- and low-value 'reverse-spikes') in the data. And runmed fits a baseline that, upon subtraction, obviously will send half the values into the negative, not suitable for my application. I jimmied something together with runmin and runmedian that is considerably faster; unfortunately, the fit seems less good, at least by eye, due still to the bad runmin behavior. I'd be interested in other baseline fitting suggestions implemented or implementable in R (I'm using v. 2.4.1pat under WinXP). Why, for instance, can I not find a running trimmean function? Because it offers no computational savings over runquantile? Also, the 'func' setting for the caTools endrule parameter--which adjusts the value of k as ends are approached--is said not to be optimized (using this option does add further time to computations). Is there an alter- native that would be speedier, e.g., setting endrule = keep and then subsequently treating ends with R's smoothEnds() function? -John Thaden Little Rock, Arkansas USA Confidentiality Notice: This e-mail message, including any a...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 can you buy R?
On 5/19/06, J Dougherty [EMAIL PROTECTED] wrote: While there is no charge for R, it IS properly licensed properly licensed under the GPL. At one company I was working for, I had to run all the licenses of all the software I had on my machine, through the legal department. When they read GNU Public License (GPL) their only comment was: We have no idea what that license means. Do not touch any software using it. Jarek On 5/19/06, J Dougherty [EMAIL PROTECTED] wrote: On Thursday 18 May 2006 14:51, Damien Joly wrote: Hi all, This may seem like a dumb question, but I work for an entity that is soon converting to XP across the board, and I will lose the ability to install software on my own. The entity has a policy of only using software that has been purchased and properly licensed (whatever that means). This means I will soon lose the ability to use R at work - something I can't do without at this point. HOWEVER, I might be able to work around this policy if I can find a licensed software vendor, preferably in Canada, that sells R. I tried googling R vendors but was unsuccessful. Any ideas? Well, first, have you pointed out to whatever limited neurons came up with that specification, that this will mean that part of your job can no longer be done because their specifications appear to rule out a key tool? Second, R is available for windows and works quite well. While there is no charge for R, it IS properly licensed properly licensed under the GPL. Theoretically, is system security is the actual issue, then the individual in charge of software acquisition can download and install it for you. All of that should be clear and above board and shouldn't compromise anything unless the entity you work for has become contractually constrained to avoid using OS ware for some obscure and irrational reason. What do they actually expect to gain from this policy? The _expensive_ alternative is to have them purchase S-Plus for you. If you present them with an estimated cost and l imagine they might think having the BOFH download R for windows for you might be the cost-effective way to go. JD __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Package docs for CRAN
See Function promptPackage() and http://cran.r-project.org/doc/manuals/R-exts.html#Rd-format section 2.1.4 fpr writing Rd files for packages. I just did it first time for my package caMassClass, so you can see the results in its pdf file. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of William Asquith Sent: Sunday, April 30, 2006 10:00 AM To: R-Help Subject: [R] Package docs for CRAN CRAN et al., I would like to add an extented introduction or other arbitrary sections to my package lmomco. I have been shipping inst/doc/Introduction.Rd. I would like to have this content inserted to the front of the PDF build for the CRAN. The R-exts.pdf seems to be a little silent on this subject? For my purposes, I have been doing this R CMD Rd2dvi --pdf --title=lmomco---version X inst/doc/ Introduction.Rd man/*.Rd but I don't get the correct header (description) or the index built as seen in the lmomco.pdf from the CRAN. Further, is there any point in shipping a complete PDF build of the docs as in inst/doc/lmomco.pdf? Please advise on best practices for building the best docs that I can. . . William __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R icon image file
http://cran.r-project.org/Rlogo.jpg In the future all you have to do (on PC) is to right click on image you want and press properties to get the exact link. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Erin Hodgess Sent: Wednesday, March 15, 2006 2:39 PM To: r-help@stat.math.ethz.ch Subject: [R] R icon image file Dear R People: I would like to include a link to the R home page on a web page for students. I would like to have the R icon as part of the link. Where is the image file please? (for the icon) Thanks, Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to compare areas under ROC curves calculated with ROC R package
I might be missing something but I thought that AUC was a measure for comparing ROC curves, so there is nothing else needed to compare them. The larger AUC is the higher correlation of 2 variables compared. No other measures or calculations are needed. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Laurent Fanchon Sent: Wednesday, March 15, 2006 11:57 AM To: r-help@stat.math.ethz.ch Subject: [R] How to compare areas under ROC curves calculated with ROCR package Dear all, I try to compare the performances of several parameters to diagnose lameness in dogs. I have several ROC curves from the same dataset. I plotted the ROC curves and calculated AUC with the ROCR package. I would like to compare the AUC. I used the following program I found on R-help archives : From: Bernardo Rangel Tura Date: Thu 16 Dec 2004 - 07:30:37 EST seROC-function(AUC,na,nn){ a-AUC q1-a/(2-a) q2-(2*a^2)/(1+a) se-sqrt((a*(1-a)+(na-1)*(q1-a^2)+(nn-1)*(q2-a^2))/(nn*na)) se } cROC-function(AUC1,na1,nn1,AUC2,na2,nn2,r){ se1-seROC(AUC1,na1,nn1) se2-seROC(AUC2,na2,nn2) sed-sqrt(se1^2+se2^2-2*r*se1*se2) zad-(AUC1-AUC2)/sed p-dnorm(zad) a-list(zad,p) a } The author of this script says: The first function (seROC) calculate the standard error of ROC curve, the second function (cROC) compare ROC curves. What do you think of this script? Is there any function to do it better in ROCR? Any help would be greatly appreciated. Laurent Fanchon DVM, MS Ecole Nationale Vétérinaire d'Alfort FRANCE __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] need help in tune.nnet
You use tune function to find optimal parameters needed for particular classification algorithm. I had more experience with tune.svm but, I would try first to put parameters covering the whole possible range of each variable (in which algorithm do not crash), for example c(4^-2, 4^-1, 4^0, 4^1, 4^2) look at the results and than narrow down the search in the best ranges. For allowed ranges of parameters you will need to experiment or study documentation of your chosen classifier (nnet). Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of madhurima bhattacharjee Sent: Friday, March 10, 2006 5:38 AM To: r-help@stat.math.ethz.ch; Bioconductor Subject: [R] need help in tune.nnet Dear R people, I want to use the tune.nnet function of e1071 package to tune nnet . I am unable to understand the parameters of tune.nnet from the e1071 pdf document. I have performed nnet on a traindata and want to test it for class prediction with a testdata. I want to know the values of size,decay,range etc. parameters for which the prediction of testdata is best. Can anyone please tell me how to do this with the tune.nnet function. Anticipating quick response. Thanks and Regards, Madhurima. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] C-Code in R (running Windows)
The simplest way to add C (C++) code in R, that I know is by creating a package ( even if you are not planning on distributing it). See 'Writing R Extensions' manual (http://cran.r-project.org/manuals.html) for details. Download source codes of packages for more examples, many of them will have .c files. See also FAQ http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Building-from-Sou rce . Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of K.A. Sent: Wednesday, March 01, 2006 7:14 AM To: r-help@stat.math.ethz.ch Subject: [R] C-Code in R (running Windows) Hello, I need to include C (or C++)-Code in R. I'm searching for a tutorial, how to do this. It is only a very small algorith (one function). Using google, I read somethig about including dll-Files and so on (on windows). Is there no possibility to include a C-File directly?!? -- View this message in context: http://www.nabble.com/C-Code-in-R-%28running-Windows%29-t1205196.html#a3 182004 Sent from the R help forum at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] need palette of topographic colors similar to topo.colors ()
I will second Roger's suggestion, colorRampPalette is a great function for creating your own palettes. For example, Matlab's jet palette (also available in fields package under peculiar name 'tim.colors') can be defined by: jet.colors = colorRampPalette(c(#7F, blue, #007FFF, cyan, #7FFF7F, yellow, #FF7F00, red, #7F)) Other predefined functions for creating and managing color palettes that I know of, are: * R provides functions for creating palettes of continuous colors: rainbow, topo.colors, heat.colors, terrain.colors.colors, gray * tim.colors in package fields contains palette similar to Matlab's jet palette (see examples for simpler implementation) * rich.colors in package gplots contains two palettes of continuous colors. * Functions brewer.pal from RColorBrewer package and colorbrewer.palette from epitools package contain tools for generating palettes * rgb and hsv creates palette from RGB or HSV 3-vectors. Maybe one of those will work for you. Jarek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, January 07, 2006 3:10 PM To: bogdan romocea Cc: r-help Subject: Re: [R] need palette of topographic colors similar to topo.colors() On Sat, 7 Jan 2006, bogdan romocea wrote: Dear useRs, I got stuck trying to generate a palette of topographic colors that would satisfy these two requirements: - the pallete must be 'anchored' at 0 (just like on a map), with light blue/lawn green corresponding to data values close to 0 (dark blue to light blue for negative values, green-yellow-brown for positive values) - the brown must get darker for higher positive values. topo.colors() fails both requirements and AFAICS lacks any options to control its behavior. #---unsatisfactory topo.colors() behavior topoclr - function(tgt) { clr - topo.colors(length(tgt)) clr - clr[round(rank(tgt),0)] plot(tgt,pch=15,col=clr) } par(mfrow=c(2,1)) ; topoclr(-50:50) ; topoclr(-20:80) An acceptable solution would be something like this grayclr - function(tgt) { tgt - sort(tgt) ; neg - which(tgt 0) clrneg - gray(0:length(tgt[neg])/length(tgt[neg])) clrpos - gray(length(tgt[-neg]):0/length(tgt[-neg])) clr - c(clrneg,clrpos) plot(tgt,pch=15,col=clr) } par(mfrow=c(2,1)) ; grayclr(-50:50) ; grayclr(-20:80) if only I could make gray() use blue/brown instead of black (I tried a couple of things but got stuck again). Any suggestions? Use colorRampPalette() to roll your own, or something better tuned, perhaps catenating two ramps together. Thank you, b. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Looking for packages to do Feature Selection and Classifi cation
Hi, You should also check my msc.features.select from caMassClass package. It has feature selection algorithm that I found useful in case of mass-spectra data. It performs individual feature selection and/or removes highly correlated neighbor features. Jarek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, January 06, 2006 3:12 PM To: Weiwei Shi Cc: Diaz.Ramon; r-help Subject: Re: [R] Looking for packages to do Feature Selection and Classification Thanks. It's indeed an interesting paper. Besides RF (using Ramon's varSelRF package), I am also testing Guyon et al's (2002) Recursive Feature Elimination for my feature-selection part. On 1/5/06, Weiwei Shi [EMAIL PROTECTED] wrote: FYI: check the following paper on svm (using libsvm) as well as random forest in the context of feature selection. http://www.csie.ntu.edu.tw/~cjlin/papers/features.pdf HTH On 1/4/06, Diaz.Ramon [EMAIL PROTECTED] wrote: Dear Frank, I expect you'll get many different answers since a wide variety of approaches have been suggested. So I'll stick to self-advertisment: I've written an R package, varSelRF (available from R), that uses random forest together with a simple variable selection approach, and provides also bootstrap estimates of the error rate of the procedure. Andy Liaw and collaborators previously developed and published a somewhat similar procedure. You probably also want to take a look at several packages available from BioConductor. Best, R. -Original Message- From: [EMAIL PROTECTED] on behalf of Frank Duan Sent: Wed 1/4/2006 4:23 AM To: r-help Cc: Subject:[R] Looking for packages to do Feature Selection and Classification Hi All, Sorry if this is a repost (a quick browse didn't give me the answer). I wonder if there are packages that can do the feature selection and classification at the same time. For instance, I am using SVM to classify my samples, but it's easy to get overfitted if using all of the features. Thus, it is necessary to select good features to build an optimum hyperplane (?). Here is a simple example: Suppose I have 100 useful features and 100 useless features (or noise features), I want the SVM to give me the same results when 1) using only 100 useful features or 2) using all 200 features. Any suggestions or point me to a reference? Thanks in advance! Frank [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Ramón Díaz-Uriarte Bioinformatics Unit Centro Nacional de Investigaciones Oncológicas (CNIO) (Spanish National Cancer Center) Melchor Fernández Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electrónico, y en s...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Weiwei Shi, Ph.D Did you always know? No, I did not. But I believed... ---Matrix III [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Wilcoxon Mann-Whitney Rank Sum Test
Does anybody know what is relation between 'T' value calculated by 'wilcox_test' function (coin package) and more common 'W' value? Jarek Tuszynski library(coin) ### Tritiated Water Diffusion Across Human Chorioamnion ### Hollander Wolfe (1999), Table 4.1, page 110 water_transfer - data.frame( + pd = c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46, +1.15, 0.88, 0.90, 0.74, 1.21), + age = factor(c(rep(At term, 10), rep(12-26 Weeks, 5 ### Wilcoxon-Mann-Whitney test, cf. Hollander Wolfe (1999), page 111 ### exact p-value and confidence interval for the difference in location ### (At term - 12-26 Weeks) wt - wilcox_test(pd ~ age, data = water_transfer, distribution = exact, conf.int = TRUE) print(wt) Exact Wilcoxon Mann-Whitney Rank Sum Test data: pd by groups 12-26 Weeks, At term T = -1.2247, p-value = 0.2544 alternative hypothesis: true mu is not equal to 0 95 percent confidence interval: -0.76 0.15 sample estimates: difference in location -0.305 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Name conflict between Epi and ROC packages
The name conflicts in Epi and ROC packages (2 'ROC' functions are the problem) cause the following code to work once, but not twice: library(MASS); data(cats); x = cats[,2] y = ifelse(cats[,1]=='F',0,1) library(Epi); ROC(x,y,grid=0)$AUC library(ROC); AUC(rocdemo.sca(y, x, dxrule.sca)) What is the standard way of resolving name conflicts? Ask maintainers to resolve it or rename the younger function, use namespaces somehow, or something else? My machine is WinXP, R-2.2.0, ROC and Epi packages are the latest versions. Jarek Tuszynski [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Finding all possible partitions of N units into k classe
See Also http://finzi.psych.upenn.edu/R/library/caTools/html/combs.html Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 08, 2005 11:19 AM To: Ales Ziberna Cc: R-help Subject: Re: [R] Finding all possible partitions of N units into k classe On 08-Dec-05 Ales Ziberna wrote: Dear useRs! I would like to generate a list of all possible (unique) partitions of N units into k classes. For example, all possible partitions of 4 units into 2 classes are (I hope I have not missed anyone): 1,1,1,2 (this can be read as {1,2,3},{4}) 1,1,2,1 1,2,1,1 2,1,1,1 1,1,2,2 1,2,1,2 1,2,2,1 The partitions 1,1,2,2 and 2,2,1,1 are the same and are therefore not two unique partitions. ... which seems to imply that 2,1,1,1 and 1,2,2,2 are the same, so I would write your list above as 1,1,1,2 (this can be read as {1,2,3},{4}) 1,1,2,1 1,2,1,1 1,2,2,2 1,1,2,2 1,2,1,2 1,2,2,1 which should be a clue! Fix the class to which unit 1 belongs as Class 1. This leaves the partitioning of units 2:N, of which there are 2^(N-1) except that you want to exclude the case where they all go into Class 1. So 2^(N-1) -1. So let K = 1:(2^(N-1)-1), and for each k in K make the binary representation of k. Say this gives N-1 binary digits i1 i2 ... i[N-1] (note that none of these will have all binary digits = 0). Then assign unit j+1 to Class 1 if ij = 0, otherwise to Class 2. However, that is if you want to do it with your bare hands! The package combinat contains also the function 'hcube' which can be readily adapted to do just that (since it initially generates all the 2^N combinations of the above). library(combinat) ?hcube x-rep(2,4) # for partitions of 4 units into classes {1,2} hcube(x,scale=1,transl=0) # [,1] [,2] [,3] [,4] # [1,]1111 # [2,]2111 # [3,]1211 # [4,]2211 # [5,]1121 # [6,]2121 # [7,]1221 # [8,]2221 # [9,]1112 # [10,]2112 # [11,]1212 # [12,]2212 # [13,]1122 # [14,]2122 # [15,]1222 # [16,]2222 ### Note, by following the 2s, that this is counting in binary ### from 0 to 2^N - 1, with 1 for 0 and 2 for 1 and least ### significant bit on the left, so it does what is described ### above. But we need to manipulate this, so assign it to K: K-hcube(x,scale=1,transl=0) ### Now select only thos which assign unit 1 to Class 1: K[K[,1]==1,] # [,1] [,2] [,3] [,4] # [1,]1111 # [2,]1211 # [3,]1121 # [4,]1221 # [5,]1112 # [6,]1212 # [7,]1122 # [8,]1222 of which you need to leave off the first, so, finally: N-4 ### Or general N at this point x-rep(2,N) K-hcube(x,scale=1,transl=0) K[K[,1]==1,][-1,] # [,1] [,2] [,3] [,4] # [1,]1211 # [2,]1121 # [3,]1221 # [4,]1112 # [5,]1212 # [6,]1122 # [7,]1222 That looks like it! Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 08-Dec-05 Time: 16:19:24 -- XFMail -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] sign and sign rank tests
See Wilcox.test and Wilcox_test functions. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Sorkin Sent: Friday, December 02, 2005 7:13 AM To: r-help@stat.math.ethz.ch Subject: [R] sign and sign rank tests R 2.1.1 on Windows 2K I hope one and all will allow both an R question and a general stats question: (1) Is there any function that will perform non-parametric tests such as a sign test or a signed rank test? I know I could program both but I would prefer not re-inventing the wheel. (2) When performing a sign test, the usual practice is to drop zero values. Is there any theoretical reason for doing this? I know it makes life a little easier (i.e. one need not decide how to handle zero values, how to split them between successes and failures) but is there more theory behind this theory? John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School of Medicine Claude Pepper OAIC University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 410-605-7119 -- NOTE NEW EMAIL ADDRESS: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] cant get colAUC to plot
It is a bug, I will have to fix. I assumed that data will have column names I can use for legend. So temporary fix is to provide column names: library(caTools) a-matrix(rnorm(100), 100,1) b-rbinom(100,1,0.7) colnames(a) = test; colAUC(a,b,plotROC=TRUE) Thanks for reporting it. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of tom wright Sent: Wednesday, November 30, 2005 8:34 AM To: R-help@stat.math.ethz.ch Subject: [R] cant get colAUC to plot Can someone please explain why this wont plot. The cats example given for the colAUC function will plot. Many thanks again tom # library(caTools) a-rnorm(100) b-rbinom(100,1,0.7) colAUC(a,b,plotROC=TRUE) colAUC(a,b,plotROC=TRUE) Error in strwidth(legend, units = user, cex = cex) : argument legend is missing, with no default R.Version() $platform [1] x86_64-pc-linux-gnu $arch [1] x86_64 $os [1] linux-gnu $system [1] x86_64, linux-gnu $status [1] $major [1] 2 $minor [1] 1.0 $year [1] 2005 $month [1] 04 $day [1] 18 $language [1] R __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] finding peaks in a simple dataset with R
Try, # work directly with data from the input files directory = system.file(Test, package = caMassClass) X = msc.rawMS.read.csv(directory, IMAC_normal_.*csv) Peaks = msc.peaks.find(X) # Find Peaks cat(nrow(Peaks), peaks were found in, Peaks[nrow(Peaks),2], files.\n) stopifnot( nrow(Peaks)==424 ) On my data to see that every thing works OK. Than I would convert your input.dat to CSV format: 2.00, 233 2.04, 220 ... 11.60, 540 12.00, 600 -- a peak! 12.04, 450 ... On Windows machine, you can do it by opening your file in excel, and saving it as CSV. Or possibly using test editor to replace ' ' with ', '. Than the script X = msc.rawMS.read.csv('.', Input.csv) Peaks = msc.peaks.find(X) cat(nrow(Peaks), peaks were found in, Peaks [nrow(Peaks),2], files.\n) should work. Other way, is to try: X = read.table(input.dat, header=TRUE) Y = X[,2] rownames(Y) = signif(X[,1], 6) Peaks = msc.peaks.find(Y) Which casts your data in correct format, described in documentation as: Spectrum data either in matrix format [nFeatures x nSamples] or in 3D array format [nFeatures x nSamples x nCopies]. Row names (rownames(X)) store M/Z mass of each row. I hope one of those solutions works for you. Good Luck. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 23, 2005 5:47 PM To: r-help@stat.math.ethz.ch Cc: Tuszynski, Jaroslaw W. Subject: Re: [R] finding peaks in a simple dataset with R On Wednesday 23 November 2005 10:15 am, Tuszynski, Jaroslaw W. wrote: I am looking for some way to locate peaks in a simple x,y data set. See my 'msc.peaks.find' function in 'caMassClass', it has a simple peak finding algorithm. Jarek Tuszynski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Jarek, Thanks for the tip. I was able to install the caMassClass package and all of its dependancies. In addition, I was able to run the examples on the manual pages. However, The format of the input data to the 'msc.peaks.find' function is not apparent to me. In its simplest form, my data looks something like this: 2.00 233 2.04 220 ... 11.60 540 12.00 600 -- a peak! 12.04 450 ... Here is an example R session, trying out the function you suggested: #importing my data like this: X - read.table(input.dat, header=TRUE) #from the example: Peaks = msc.peaks.find(X) #errors with: Error in sort(x, partial = unique(c(lo, hi))) : 'x' must be atomic Also: I have tried one of the functions ( 'getPeaks' ) listed on the 'msc.peaks.find' manual page, however I am still having a problem with the format of my data vs. what the function is expecting. #importing my data like this: X - read.table(input.dat, header=TRUE) #setup an output file for peak information peakfile - paste(peakinfo.csv, sep=/) #run the analysis: getPeaks(X,peakfile) #errors with: Error in area/max(area) : non-numeric argument to binary operator In addition: Warning message: no finite arguments to max; returning -Inf any ideas would be greatly appreciated! -- Dylan Beaudette Soils and Biogeochemistry Graduate Group University of California at Davis 530.754.7341 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] obtaining a ROC curve
See, my old post at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/61879.html to see a list of ROC related packages and functions. One of them should work well for your application. All of them take data in the form: - x - real number value returned by the classifier - y - true labels / classes (only 2 levels allowed) In Case of classification trees it might be hard to get your hands on the x since your function might only return binary labels (classes), what gives you only 3 points on your ROC ( (0,0), (1,1) and one point calculated from returned labels). But you might find function that can return probabilities of each sample. For example if you use 'rpart' than: model = rpart( ytrain~., data = data.frame(cbind(ytrain,xtrain)), ...) Prob = predict(model, newdata=xtest, type=prob) x = Prob[,1] y = ytest will give you needed probabilities instead of classes. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, November 25, 2005 4:23 PM To: r-help@stat.math.ethz.ch Subject: [R] obtaining a ROC curve Hello, I have a classification tree. I want to obtain a ROC curve for this test. What is the easiest way to obtain one? -Anjali - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] PNG-import into R
I was looking once for all supported image formats, here is what I found: Format | read file to matrix | write matrix to file | write plot to file ---|-|--|--- PNG| | | png, bitmap, GDD JPEG | read.jpeg | | jpeg, bitmap, GDD GIF| read.gif| write.gif| GDD TIFF | read.picture| write.picture| savetiff, bitmap PDF| | | pdf, bitmap ENVI | read.ENVI | write.ENVI | ? | read.pnm| write.pnm| I have not played with every one of those functions and I think that every read/write returns matrix in some other internal format. Also, last 2 formats are rather exotic and of limited use. Use CRAN search to look up package of each function. So I think that in your case your best bet would be to convert your file to GIF (if you can live with only 256 colors) or TIFF. Also does anybody know how hard would it be to tap into C code needed for 'read.jpeg', 'png' and 'jpeg' functions to write 'read.png' , 'write.png', and 'write.jpeg' functions? Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sydler, Dominik Sent: Monday, November 21, 2005 5:36 AM To: r-help@stat.math.ethz.ch Subject: [R] PNG-import into R Hi there I'm looking for a function to read PNG-bitmap-images from a file into R. I only found: - the pixmap-package which cannot import png or similar formats - the rimage-package which can only import lossy jpeg-images (the convertion from png to jpeg modifies the data!) Is there any possibility to read PNG-files? Thanks for any help Dominic Sydler __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Warning message: package '...' was built under R version 2.3.0
Hi, While installing precompiled packages I often get warnings like the one in the subject. I usually ignore them, but I still do not understand why windows packages are build with unreleased versions of R. Is there some way to get packages build under R-2.2.0? What are potential problems that can result from that version mismatch? My system: winXP R version: 2.2.0 Jarek Tuszynski [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Warning message: package '...' was built under R version 2.3.0
Uwe, I think I used following repositories: PA1, PA2 and NC, which are the closest to me and I think I got the same results in all. The package I downloaded was coin which downloaded other packages. The consol printout follows: chooseCRANmirror() utils:::menuInstallPkgs() trying URL 'http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.2/coin_0. 3-3.zip' Content type 'application/zip' length 793299 bytes opened URL downloaded 774Kb package 'coin' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\tuszynskij\Local Settings\Temp\Rtmp7594\downloaded_packages updating HTML package descriptions library(coin) Loading required package: survival Loading required package: splines Loading required package: mvtnorm Loading required package: modeltools Error in load(dataFile, ns) : ReadItem: unknown type 241 In addition: Warning messages: 1: package 'mvtnorm' was built under R version 2.3.0 2: package 'modeltools' was built under R version 2.3.0 Error: unable to load R code in package 'modeltools' Error: package 'modeltools' could not be loaded Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 16, 2005 11:27 AM To: Tuszynski, Jaroslaw W. Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Warning message: package '...' was built under R version 2.3.0 Tuszynski, Jaroslaw W. wrote: Hi, While installing precompiled packages I often get warnings like the one in the subject. I usually ignore them, but I still do not understand why windows packages are build with unreleased versions of R. Is there some way to get packages build under R-2.2.0? Well, those in the corresponding 2.2 repository on CRAN should all be build with R-2.2.0. If not, please tell me which one is wrong. Where did you get the packages for R-devel from? Uwe Ligges What are potential problems that can result from that version mismatch? My system: winXP R version: 2.2.0 Jarek Tuszynski [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Warning message: package '...' was built under R version 2.3.0
I do have single version of R (2.2.0) and all packages I have were installed by downloading precompiled packages from PA or NC repositories within last month. I also just managed to download 'modeltools' from PA2 and its DESCRIPTION says: Built: R 2.3.0; ; 2005-11-04 20:47:47; windows R console: utils:::menuInstallPkgs() --- Please select a CRAN mirror for use in this session --- trying URL 'http://lib.stat.cmu.edu/R/CRAN/bin/windows/contrib/2.2/modeltools_0.2-0.zip ' Content type 'application/zip' length 64426 bytes opened URL downloaded 62Kb package 'modeltools' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\tuszynskij\Local Settings\Temp\Rtmp4458\downloaded_packages updating HTML package descriptions library(modeltools) Error in load(dataFile, ns) : ReadItem: unknown type 241 In addition: Warning message: package 'modeltools' was built under R version 2.3.0 Error: unable to load R code in package 'modeltools' Error: package/namespace load failed for 'modeltools' The same package downloaded from PA1 does not give me any warnings or errors. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 16, 2005 1:04 PM To: Tuszynski, Jaroslaw W. Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Warning message: package '...' was built under R version 2.3.0 Tuszynski, Jaroslaw W. wrote: Uwe, I think I used following repositories: PA1, PA2 and NC, which are the closest to me and I think I got the same results in all. The package I downloaded was coin which downloaded other packages. The consol printout follows: chooseCRANmirror() utils:::menuInstallPkgs() trying URL 'http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.2/c oin_0. 3-3.zip' Content type 'application/zip' length 793299 bytes opened URL downloaded 774Kb package 'coin' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\tuszynskij\Local Settings\Temp\Rtmp7594\downloaded_packages updating HTML package descriptions library(coin) Loading required package: survival Loading required package: splines Loading required package: mvtnorm Loading required package: modeltools Error in load(dataFile, ns) : ReadItem: unknown type 241 In addition: Warning messages: 1: package 'mvtnorm' was built under R version 2.3.0 I have just downloaded http://www.ibiblio.org/pub/languages/R/CRAN/bin/windows/contrib/2.2/mvtnorm_ 0.7-2.zip and its DESCRIPTION file correctly has: Built: R 2.2.0; i386-pc-mingw32; 2005-10-14 14:44:12; windows My guess is that you are using one library for two different R versions and you have installed some R-devel package into the library you are now using with R-2.2.0 ... You cannot mix binary packages for R 2.3.0 with those for R-devel due to changes in environment handling. Uwe Ligges __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Warning message: package '...' was built under R version 2.3.0
Yes. The Statlib mirror (which I suppose is what you call PA2) appears to be badly messed up. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 Peter, Thanks for checking on this problem. My names for CRAN mirror sites (PA 1, PA 2, NC, etc.) came from that is shown in windows RGui when you choose Packages/Set CRAN mirror menu. All mirrors are represented by Country (city) for most of the world except US which is shown as USA (state abbreviation + number). So what I call PA 1 means USA/Pennsylvania #1, etc. Names you are using (Statlib mirror) are not visible in GUI. Just a clarification. Jarek Tuszynski __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Search within a file
Thanks for a great suggestions. I guess the code you suggested would look something like this: fregexpr = function(pattern, filename) { # same as gregexpr but operating on files not strings # Only single string 'pattern's allowed buf.size=1024 n = file.info(filename)$size pos = NULL fp = file(filename, rb) for (d in seq(1,n,by=buf.size)) { m = if (n-dbuf.size) buf.size else n-d p = gregexpr(pattern, readChar(fp, m))[[1]] if(p[1]0) pos=c(pos, p+d-1) } close(fp) if (is.null(pos)) pos=-1 return (pos) } fname = file.path(R.home(),COPYING) fregexpr(right, fname) [1]73 1347 1422 1460 1727 1879 1908 1939 3106 3350 4240 5530 [13] 6637 6661 6740 9460 9534 10503 11756 12528 12566 13805 15907 16056 [25] 17053 17681 17813 gregexpr(right, readChar(fname,file.info(fname)$size))[[1]] [1]73 1347 1422 1460 1727 1879 1908 1939 3106 3350 4240 5530 [13] 6637 6661 6740 9460 9534 10503 11756 12528 12566 13805 15907 16056 [25] 17053 17681 17813 attr(,match.length) [1] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 The function above does what I need, if someone needs a function that parallels gregexpr but operates on files not strings, than most of the work would be in modifying line if(p[1]0) pos=c(pos, p+d-1) to do concatination and addition on lists. Thanks Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Seth Falcon Sent: Friday, November 04, 2005 1:44 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] Search within a file On 3 Nov 2005, [EMAIL PROTECTED] wrote: I am looking for a way to search a file for position of some expression, from within R. My current code: sha1Pos = gregexpr(sha1, readChar(filename, file.info(filename)$size))[[1]] Works fine for small files, but text files I will be working with might get up to Gb range, so I was trying to accomplish the same without loading the whole file into R. I would think you could use readLines to read in a batch of lines, run (g)regexpr, and keep track of matches and position. Create a connection to the file using file() first, and then subsequent calls to readLines will start where you left off. But you will need to adjust the position indices returned by gregexpr by how far into the file you are. Seems very doable. + seth __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Real FFT
How about 'fft' function. It is a little higher level than Fortran function you mention, since array can be any length and you do not need to pack complex numbers into a vector of floats. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Glenn Meyers Sent: Wednesday, November 02, 2005 9:50 PM To: r-help@stat.math.ethz.ch Subject: [R] Real FFT The book Numerical Recipes in Fortran77 by Press, Teukolsky, Vetterling and Flannery describes a way to pack the even and odd coordinates of a real vector R into a complex vector C of half the length. Then using various FFT symmetries, they extract the FFT of R from the FFT of C which is half the length of R, There is also an inverse process. Is there an R function that does this? Glenn Meyers [EMAIL PROTECTED] [EMAIL PROTECTED] [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Search within a file
Hi, I am looking for a way to search a file for position of some expression, from within R. My current code: sha1Pos = gregexpr(sha1, readChar(filename, file.info(filename)$size))[[1]] Works fine for small files, but text files I will be working with might get up to Gb range, so I was trying to accomplish the same without loading the whole file into R. I realize this is not what R is designed to do, but maybe there is some way I am missing. Jarek Tuszynski [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Sum of logical vector
Hi, Recently I was told by users of some of the function I wrote that they experience crashes in places where logical vector was passed to sum function. However on my computer those functions work just fine. After closer look at documentation of function 'sum', I realized that it is defined only for complex and numeric vectors, so I guess I was using undocumented feature. What I am trying to understand is why it works on some systems (my - Win XP, from R-1.9.? to R-2.2.0) and does not work on other (unknown platform, R-2.2.0): - Is it that they have more methods of function sum defined and some other function (maybe some package has logical.sum defined) is being used? - Different operating systems will have different behavior for supporting undocumented features? Is there any way to automatically test your code for presence of unsupported functions it uses? Should function 'sum' produced warning/error, or convert logical to integer? An Example code: repeats = function(x) return (sum(duplicated(x)) ) # how many numbers repeat themselves in vector x? repeats( c(1:10, 3:14) ) Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Still a bug with NA in sd() or var()?
Try: sd (x,na.rm=TRUE) [1] 1.707825 Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roger Dungan Sent: Monday, October 31, 2005 4:24 PM To: r-help@stat.math.ethz.ch Subject: [R] Still a bug with NA in sd() or var()? Dear R-users, Running R 2.1.1 in WindowsXP, there seems to be a 'bug' in sd() If x-c(1,2,3,NA,5) mean(x) [1] NA But sd(x) Or var(x) give Error in var(x, na.rm = na.rm) : missing observations in cov/cor There are obvious work-rounds, like sd(x, is.na(x)==F) which gives the result (with error message) [1] 1.707825 Warning message: the condition has length 1 and only the first element will be used in: if (na.rm) complete.obs else all.obs or y-subset(x, is.na(x)==F) sd(y) [1] 1.707825 Am I missing something, or is this a problem with sd()? Why does mean(x) give a simple NA, but var(x) requires some additional work? There was some previous discussion in r-help about this for R v 1.6.0, with mention of a fix for 1.6.1. Dr Roger Dungan School of Biological Sciences University of Cantebury Christchurch, New Zealand ph +64 3 366 7001 ext. 4848 fax +64 3 364 2590 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Efficient ways of finding functions and Breslow-Day test for homogeneity of the odds ratio
Try Breslow OR Breslowday filetype:R -robol search in Google. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of MJ Price, Social Medicine Sent: Tuesday, October 18, 2005 9:28 AM To: r-help@stat.math.ethz.ch Subject: [R] Efficient ways of finding functions and Breslow-Day test for homogeneity of the odds ratio Dear all, I have been trying to find a function to calculate the Breslow-Day test for homogeneity of the odds ratio in R. I know the test can be preformed in SAS but i was wondering if anyone could help me to perform this in r. In addition i have the fullrefman file to search for functions in the basic R packages, does anyone have any suggestions of an efficient way of searching for functions in the other add-on packages on the website? Thanks in advance Malcolm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Animated lissajous
Pretty neat. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, October 15, 2005 11:34 PM To: r-help@stat.math.ethz.ch Subject: [R] Animated lissajous Here's some code to make lissajous dance. I've attached a small sample GIF. Cheers, Rob Steele robsteele at yahoo dot com plot.lissajous = function(omega.x, omega.y, delta = 0, num.thetas = 200) { thetas = seq(0, 2 * pi, length = num.thetas) xs = sin(omega.x * thetas + delta) ys = cos(omega.y * thetas) plot(xs, ys, type = 'l', lwd = 3, ann = FALSE, axes = FALSE) } ## Show one. par(mar = c(2, 2, 2, 2)) plot.lissajous(4, 3) ## Animate it. while (TRUE) { for (delta in seq(0, 2 * pi, length = 120)) { plot.lissajous(4, 3, delta) Sys.sleep(1 / 30) } } ## Show a bunch. par(mar = c(1, 1, 1, 1)) par(mfrow = c(length(omega.xs), length(omega.ys))) for (omega.x in 1:5) { for (omega.y in 1:5) { plot.lissajous(omega.x, omega.y, deltas[i]) } } ## Animate them. (Requires ImageMagick.) num.frames = 120 image.dir = 'images' if (! file.exists(image.dir)) { dir.create(image.dir) } deltas = seq(0, 2 * pi, length = num.frames) for (i in 1 : length(deltas)) { png(file = file.path(image.dir, sprintf('img-%03d.png', i))) par(mar = c(1, 1, 1, 1)) par(mfrow = c(length(omega.xs), length(omega.ys))) for (omega.x in 1:5) { for (omega.y in 1:5) { plot.lissajous(omega.x, omega.y, deltas[i]) } } dev.off() } ## This ImageMagick command combines the image files into a GIF animation: # convert -delay 3 images/*.png images/animation.gif __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Questions about readBin function (Was: dec2bin?)
Hi, The latest version of R had some changes to functions readbin() and writeBin() [which] now support raw vectors as well as filenames and connections.. As a result I am working on retiring raw2bin and bin2raw functions from caTools package which do exactly the same. Thanks to Prof. Ripley for bringing this change to my attention. Which brings me to my question: how to use readBin function to read the whole file or vector con and not just requested number of elements (n) from it? In other words what to do if I do not know what to set argument n to (The (maximal) number of records to be read), and want to read all records? So far the simplest solution I found is to measure vector length (or file size) of con and set n to length()%/%size. Which gets quite messy if size is not provided and have to be deduced from what (see code below). Am I missing something? Is there an easier way to read the whole file or vector? Shouldn't that be the default? readBin(con, what, n = 1, size = NA, signed = TRUE, endian = .Platform$endian) bin2raw = function(x, ...) writeBin(x, raw(), ...) # old bin2raw can be easily written using curent writeBin raw2bin = function(r, what, size=NA, ...) { TypeList = c(logical, integer, double, complex, character, raw, numeric, int) if (!is.character(what) || length(what) != 1 || !(what %in% TypeList)) what - typeof(what) if (!is.vector(r) || mode(r) == list) stop(raw2bin: 'r' has to be vector of type 'raw') if (what==raw) return(r) if (!is.na(size)) nBits=size else nBits = switch(match(typeof(x), TypeList), 4, 4, 8, 16, 2, 1, 8, 4) n = length(r) if (n%%nBits) stop(raw2bin: number of elements in 'r' is not multiple of 'size') x = readBin(r, what, n = n%/%nBits, size=size, ...) return (x) } Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R data import
A few suggestions: - read.fwf function sounds like what you need, but I have never used it so I am not sure - use readLines and manually extract needed positions and convert them to numbers Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 11, 2005 7:52 PM To: r-help@stat.math.ethz.ch Subject: [R] R data import Hello, I hope all is well. I've gone through and searched just about all the manuals, faqs, contribs available on the data import/export process and have not found any answer to a specific question. Hopefully, I will be able to fall back upon the valuable expertise in mailing list. Here goes: How can I import SPECIFIC columns of data in a fixed width file? E.g. I have a fwf with 40 variables ranging from 1 to 10 characters and at any given time, need only a few to analyze, like so: age: 2 char sex: 1 charmorning: 1 charlocation: 3 char..family: 9 chartagged: date...weight at capture: 4 charlength at capture: 7 charetc. which looks something like: 02M1LOS...xxcanidae011289.10001291412 In essence I am looking for functionality similar to the SAS pointer/informat method. I would appreciate any help anyone would be able to give! Thanks so much for your help. best, Ratnendra Sharma U Minn __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] matrix operation
There a re a few ways to do it without loop. Here is one: dat = matrix(runif(100), 50,2) dat[,1] = dat[,1] = dat[,2] Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, October 07, 2005 6:02 PM To: r-help@stat.math.ethz.ch Subject: [R] matrix operation Hello: I have a matrix 'dat' with 2 columns. I have the following code: for (i in 1:nrows(dat)) { if (dat[i,1] dat[i,2]) { dat[i,2]-0 } else { dat[i,2]-1 } Is there a way to accomplish this without the for loop? Thank you. -Dhiren __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] The R Graph Gallery {was boxplot statistics}
I agree with Martin R Graph Gallery has a lot of neat stuff. I also think there should be a on CRAN website a list of R websites. And in a perfect world one of the search engines scope would get extended to search them all. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, October 07, 2005 3:22 AM To: [EMAIL PROTECTED] Cc: R-help@stat.math.ethz.ch; [EMAIL PROTECTED]; bogdan romocea Subject: [R] The R Graph Gallery {was boxplot statistics} Romain == Romain Francois [EMAIL PROTECTED] on Thu, 06 Oct 2005 23:23:12 +0200 writes: Romain Selon bogdan romocea [EMAIL PROTECTED]: A related comment - don't rely (too much) on boxplots. They show only a few things, which may be limiting in many cases and completely misleading in others. Here are a couple of suggestions for plots which you may find more useful than the standard box plots: - figure 3.27 from http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter3.html - violin plots (see package vioplot) - density plots - histograms - box-percentile plots (bpplot from Hmisc) - quantile plots - if comparing 2 distributions, qq plots, quantile-difference plots, mean-difference plots etc. Romain Hi, Romain HDR (highest density regions) boxplots are interresting. Romain See http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=102 Let me take the opportunity to thank Romain for setting up and maintaining the R Graph Gallery. This is really a cool website for R users. He'd get my number one vote for R website of the year! Martin Maechler, ETH Zurich __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Applying a function to each element of an array
I suspect that loop would be the fastest since it would have the least memory overhead. You do not want to have too many internal copies of 7000x7000 matrices. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Smith Sent: Friday, October 07, 2005 2:48 PM To: r-help@stat.math.ethz.ch Subject: [R] Applying a function to each element of an array Hi, I have a 7000x7000 matrix, and each element is an integer. For each element, I want to apply the function : wt - 0 for(q in 1:count){ wt - wt + 0.5^(q-1) } I get the value of 'count' from the elements in the matrix , and want to store the corresponding 'wt' value for that element. I suppose I could loop through the matrix, and apply the function to each element but this would take a really really long time. Are there any quicker ways to get the same result? many thanks, Tim - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] playing with R: make a animated GIF file...
See write.gif function in caTools. Jarek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of klebyn Sent: Wednesday, October 05, 2005 8:05 PM To: r-help@stat.math.ethz.ch Subject: [R] playing with R: make a animated GIF file... Hello all I am playing with R for to make a animated GIF. any suggestions, improvements are welcome :-) case somebody could help me, i thanks! Cleber N. Borges ( klebyn ) my objective: (steps TODO) --- 1) to save PNG files; - i don't know the best way to make this; 2) transform the PNG files into GIF files (easy! no problem! ... i think ...) 3) reload the GiF files in R and use the caTools package to make a animated GIF. -- the code reverse the STRING strReverse - function(x) sapply(lapply(strsplit(x, NULL), rev), paste, collapse=) logotype to animate yourLogo =Is Nice to play with R-package logoWidth = 1.5 logoHeight = 2.5 L = nchar(yourLogo) TrigSplit = 360 / L yourLogo = strReverse(yourLogo) posx = numeric(L) posy = numeric(L) for( i in 0:L){ posx[i] = logoHeight * sin(i * TrigSplit * pi / 180) posy[i] = logoWidth * cos(i * TrigSplit * pi / 180) } max_x = max(posx)*1.1 max_y = max(posy)*3 min_x = min(posx)*1.1 min_y = min(posy)*3 cex = 2/(posy + 2) idx = 1:L for(j in 1:L-1) { ###file = paste(CQM_,j,.png,sep=) ###png(filename=file, bg=transparent) plot(0,t='n', xlim=c(min_x,max_x), ylim=c(min_y,max_y), axes=FALSE, ann=FALSE, font=3 ) for( i in 1:L){text(x=posx[i], y=posy[i], labels=substr(yourLogo,idx[i],idx[i]), col='blue', cex=cex[i] ) } idx = (append(idx[L],idx))[1:L] Sys.sleep(0.2) ###dev.off() } ## final code __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Animation of Mandelbrot Set
http://cran.r-project.org/src/contrib/Descriptions/caTools.html has current versions (1.4) of both source and binary. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 06, 2005 8:19 AM To: roger bos; Tuszynski, Jaroslaw W. Cc: ([EMAIL PROTECTED]) Subject: Re: [R] Animation of Mandelbrot Set The binary version of caTools on CRAN (1.0) does not have the write.gif function but the source version (1.4) does ... hth, ingmar From: roger bos [EMAIL PROTECTED] Reply-To: roger bos [EMAIL PROTECTED] Date: Thu, 6 Oct 2005 08:14:42 -0400 To: Tuszynski, Jaroslaw W. [EMAIL PROTECTED] Cc: \([EMAIL PROTECTED]) r-help@stat.math.ethz.ch Subject: Re: [R] Animation of Mandelbrot Set Anyone know why I would get an Error: couldn't find function write.gif despite loading library(caTools) with no errors in R 2.1.1 under XP? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Animation of Mandelbrot Set
Hi, I was playing with Mandelbrot sets and come up with the following code, I thought I would share: library(fields) # for tim.colors library(caTools) # for write.gif m = 400 # grid size C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) ) C = matrix(C,m,m) Z = 0 X = array(0, c(m,m,20)) for (k in 1:20) { Z = Z^2+C X[,,k] = exp(-abs(Z)) } image(X[,,k], col=tim.colors(256)) # show final image in R write.gif(X, Mandelbrot.gif, col=tim.colors(256), delay=100) # drop Mandelbrot.gif file from current directory on any web brouser to see the animation Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dec2bin?
It is unclear what you are trying to do, but check bin2raw in caTools package: print(x - (1:5)*pi) [1] 3.141593 6.283185 9.424778 12.566371 [5] 15.707963 print(y - bin2raw(x)) [1] 18 2d 44 54 fb 21 09 40 18 2d 44 54 fb 21 19 [16] 40 d2 21 33 7f 7c d9 22 40 18 2d 44 54 fb 21 [31] 29 40 5e 38 55 29 7a 6a 2f 40 print(z - raw2bin(y,double)) [1] 3.141593 6.283185 9.424778 12.566371 [5] 15.707963 May be that is what you need. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Haiyong Xu Sent: Saturday, October 01, 2005 4:22 PM To: Help R Subject: [R] dec2bin? Hello, I just want to ask if there is any function that can convert decimal number to binary vector. Thanks a lot. Haiyong __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dec2bin?
Function bin2raw was written in order to convert vectors of any type into vectors containing binary form (little or big endian) of those values (stored in hex format as 'raw' since it is the only 1-byte type in R). It was needed in order to convert R vectors to Base64 format commonly used by XML files. It is a great news that next version of R (2.2.0) will extend capabilities of writeBin function to do the same. If it is more efficient (most likely) than bin2raw and raw2bin will be retired. In the current version of R the best solution I could find was too inefficient: print(x - (1:5)*pi) writeBin(x, temp.dat) y = readBin(temp.dat, raw, n = length(x)*8) y Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, October 03, 2005 11:49 AM To: Tuszynski, Jaroslaw W. Cc: Haiyong Xu; Help R Subject: Re: [R] dec2bin? On Mon, 3 Oct 2005, Tuszynski, Jaroslaw W. wrote: It is unclear what you are trying to do, but check bin2raw in caTools package: print(x - (1:5)*pi) [1] 3.141593 6.283185 9.424778 12.566371 [5] 15.707963 print(y - bin2raw(x)) [1] 18 2d 44 54 fb 21 09 40 18 2d 44 54 fb 21 19 [16] 40 d2 21 33 7f 7c d9 22 40 18 2d 44 54 fb 21 [31] 29 40 5e 38 55 29 7a 6a 2f 40 print(z - raw2bin(y,double)) [1] 3.141593 6.283185 9.424778 12.566371 [5] 15.707963 May be that is what you need. I fail to see what that has to do with the question (there are no `binary vectors' in the answer - raw vectors are no more or less binary than numeric ones), but in any case it can be done in base R 2.2.0 more efficiently by options(width=50) (y - writeBin(x, raw())) [1] 18 2d 44 54 fb 21 09 40 18 2d 44 54 fb 21 19 [16] 40 d2 21 33 7f 7c d9 22 40 18 2d 44 54 fb 21 [31] 29 40 5e 38 55 29 7a 6a 2f 40 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Haiyong Xu Sent: Saturday, October 01, 2005 4:22 PM To: Help R Subject: [R] dec2bin? Hello, I just want to ask if there is any function that can convert decimal number to binary vector. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Library error when using R CMD check
Maybe you forgot to list the name of dependent package in 'Depends' section of 'DESCRIPTION' file. I think that would have effect you describe. See http://cran.r-project.org/doc/manuals/R-exts.html#The-DESCRIPTION-file for details. Jarek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, October 03, 2005 2:05 PM To: r-help@stat.math.ethz.ch Subject: [R] Library error when using R CMD check Hi, I've got a library I'm trying to build, and am having an error on R CMD check... The source is fine, and the script runs OK, but during the script test execution it downloads a library from an online repository, which goes fine and it says that installation was successful... However, after it installs the library OK, it then cannot find it (despite it being installed properly in the R installation even before I ran R CMD check)...it is looking in the working directory's .Rcheck folder, and halts because it cannot find it there... I'm not sure at all what I'm sup'd to do...?? Is there a way for me to tell R CMD check to only look for installed libraries in another place? I'm sorry if this is vague, but I'm pretty thoroughly confused here... This is Mac OS X 10.3...but I am trying to build a source library that will be cross-platform (there is only R code / no C code or anything fancy...sourcing my scripts from this library works on mac and win2k pro)... Thanks in advance, Ken __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] .C help
See http://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/ and R Installation and Administration manual for details that will have to be followed very precisely. My own 2 cents below should be taken as fuzzy recollections, compared to detailed directions in 2 sources above. I do not know if they are the easiest or even correct, but they work. There are 2 ways to compile that I tried (both use MinGW compiler): - compile C into dll. Copy dll to the same directory as R functions. I was compiling on WIN XT machine by double clicking on any-name.bat text file containing: cl /MT /Ox /D WIN32 /c runfunc.c link /dll /EXPORT:runquantile /EXPORT:runmean /EXPORT:runmad /out:runfunc.dll *.obj pause My code was in runfunc.c. C Functions I was planning on calling were: runquantile runmean runmad. DLL name was runfunc.dll - follow the steps as if you were building a package (even if you are not planing on releasing it). This way was much easier, but only after I installed many other tools needed for package instalation/compilation. After everything was correctly set up the actual package compilation is done by double-clicking on C:\programs\R\rw2011\src\gnuwin32\install_caTools.bat text file containing: RCMD install C:/programs/R/rw2011/src/library/caTools pause Both of those approaches (I think) required R beeing installed in a path with no spaces (for example R can not be installed in default spot c:\Program Files\R since program files have space between two words. Also I remember having a lot of trouble ordering directories on my PATH (envirinmental variable - see my computer/properties/advanced/Environment Variables). Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Elizabeth Lawson Sent: Friday, September 30, 2005 2:46 PM To: r-help@stat.math.ethz.ch Subject: [R] .C help Hi, I am hoping some one can help me. I am learning to use C and would like to learn how to call c code in R. I have look at Writing R Extensions and I tried to copy the example on page 38 void convolve(double *a, int *na, double *b, int *nb, double *ab) { int i, j, nab = *na + *nb - 1; for(i = 0; i nab; i++) ab[i] = 0.0; for(i = 0; i *na; i++) for(j = 0; j *nb; j++) ab[i + j] += a[i] * b[j]; } called from R by conv - function(a, b) .C(convolve, as.double(a), as.integer(length(a)), as.double(b), as.integer(length(b)), ab = double(length(a) + length(b) - 1))$ab and I got the error C function name not in load table. Do I need to compile the C code first? Do I need a c copmiler at all? Any suggestions for a begginner? Thanks, Elizabeth Lawson I - Click here to donate to the Hurricane Katrina relief effort. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Fast AUC computation
See colAUC in caTools (there is a problem with 1.3 version, 1.4 is on the way). See examples for other functions calculating AUC. An alternative approach is: x1 = x[y==1]; n1 = length(x1); x2 = x[y==0]; n2 = length(x2); r = rank(c(x1,x2)) auc = (sum(r[1:n1]) - n1*(n1+1)/2) / (n1*n2) Which is very fast. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nina Paynter Sent: Wednesday, September 28, 2005 4:43 PM To: r-help@stat.math.ethz.ch Subject: [R] Fast AUC computation I am doing a simulation with a relatively large data set (20,000 observations) for which I want to calculate the area under the Receiver Operator Curve (AUC) for many parameter combinations. I am using the ROC library and the following commands to generate each AUC: rocobj=rocdemo.sca(truth = ymis, data = model$fitted.values, rule = dxrule.sca) #generation of observed ROC object aucobj=AUC(rocobj) #pulling out just the observed AUC - trapezoidal not integrated but they are pretty slow. Does anyone know of a faster way to get the AUC? Thanks, Nina [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to keep very small or large number?
R can hold very small numbers. It is the round-off error during addition (and other basic operations) that causes the problem. For example: x=1e-300 x [1] 1e-300 (x+1)-1 [1] 0 If you need a code that can be immune to round-off problems - you need to write it yourself (please correct me if I am wrong). At some point I needed 'sum' and 'cumsum' that would not have that problem and I end up writing my own versions of those functions. See examples of 'sum.exact' and 'cumsum.exact' in 'caTools' package. Jarek Tuszynski -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, September 22, 2005 12:53 PM To: r-help@stat.math.ethz.ch Subject: [R] how to keep very small or large number? When I was computing some joint probabilities, I found that R reported most of the results to to -Inf and thus didn't record the value. I guess it is b/c the joint log(probability) can be extremely small. Is there a way in R to keep the values even if they are small? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Survey of ROC AUC / wilcoxon test functions
Hi, I was lately debugging parts of my 'colAUC' function in caTools package, and in a process looked into other packages for calculating Areas Under ROC Curves (AUC). To my surprise I found at least 6 other functions: * wilcox.test * AUC from ROC package, * performance from ROCR package, * auROC from limma package, * ROC from Epi package, * roc.area from verification package And I belive I found problems with 3 of them: 'ROC', 'auROC' 'roc.area' I wrote short code to compare them all: # Compare calAUC with other functions designed for similar purpose library(caTools) library(verification) library(ROC) library(ROCR) library(Epi) library(limma) library(MASS) data(cats) colAUC(cats[,2:3], cats[,1], plotROC=TRUE) auc = matrix(NA,9,3) pval = matrix(NA,4,3) rownames(auc) = c(colAUC(alg='ROC'), colAUC(alg='Wilcox'), wilcox.test, rank, roc.area, AUC, performance, ROC, auROC) colnames(auc ) = c(AUC(x), AUC(-x), AUC(x+noise)) rownames(pval) = c(wilcox.test(exact=1),wilcox.test(exact=0), roc.area()$p.adj,roc.area()$p) colnames(pval) = c(p(x), p(-x), p(x+noise)) X = cbind(cats[,2], -cats[,2], cats[,2]+rnorm(nrow(cats))/10 ) y = ifelse(cats[,1]=='F',0,1) for (i in 1:3) { x = X[,i] x1 = x[y==1]; n1 = length(x1);# prepare input data ... x2 = x[y==0]; n2 = length(x2);# ... into required format r = rank(c(x1,x2)) auc[1,i] = colAUC(x, y, alg=ROC) auc[2,i] = colAUC(x, y, alg=Wilcox) auc[3,i] = wilcox.test(x1, x2, exact=0)$statistic / (n1*n2) auc[4,i] = (sum(r[1:n1]) - n1*(n1+1)/2) / (n1*n2) auc[5,i] = roc.area(y, x)$A.tilda auc[6,i] = AUC(rocdemo.sca(y, x, dxrule.sca)) auc[7,i] = performance(prediction( x, y),auc)@y.values[[1]] auc[8,i] = ROC(x,y,grid=0)$AUC # get AUC by 'ROC' auc[9,i] = auROC(y, x) # get AUC by 'auROC' pval[1,i] = wilcox.test(x1, x2, exact=0)$p.value pval[2,i] = wilcox.test(x1, x2, exact=1)$p.value pval[3,i] = roc.area(y, x)$p.adj pval[4,i] = roc.area(y, x)$p } print(auc) print(pval) Which gave the following results: print(auc) AUC(x) AUC(-x)AUC(x+noise) colAUC(alg='ROC')0.8338451 0.8338451 0.8225488 colAUC(alg='Wilcox') 0.8338451 0.8338451 0.8225488 wilcox.test 0.8338451 0.1661549 0.8225488 rank 0.8338451 0.1661549 0.8225488 roc.area 0.8338451 0.1661549 0.8225488 AUC 0.8338451 0.1661549 0.8225488 performance 0.8338451 0.1661549 0.8225488 ROC 0.8338451 0.1654968 0.8225488 auROC0.8131169 0.1454266 0.8225488 print(pval) p(x) p(-x) p(x+noise) wilcox.test(exact=1) 8.200e-11 8.200e-11 3.774e-10 wilcox.test(exact=0) 8.200e-11 8.200e-11 3.817e-11 roc.area()$p.adj 4.042e-11 1.000e+00 1.861e-10 roc.area()$p 4.446e-11 1.000e+00 1.861e-10 Some thoughts about those results: - Data used for the testing: column 1 (x) - has ties, column 2 (-x) - negative of the same data column 3 (x+noise) - similar data but with no ties - All AUC functions gave the same results for data with no ties - 'ROC' and 'auROC' gave different results for data with ties - 'colAUC' (my function) returns 'max(auc, 1-auc)' that's why AUC(x) and AUC(-x) are the same - I assume that roc.area()$p.adj and wilcox.test p.values suppose to return the same results, but they are different. - At least 'roc.area(x)$p.adj' and 'roc.area(-x)$p.adj' should be the same. Comments? Corrections? Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED]` \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Survey of ROC AUC / wilcoxon test functions
ROC package can be found in BioConductor repository. Jarek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, September 22, 2005 3:28 PM To: Tuszynski, Jaroslaw W. Cc: ([EMAIL PROTECTED]); [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Survey of ROC AUC / wilcoxon test functions Hi Jarek, I am getting read to leave on a trip till next week, so I can't address your observation today. I also can't seem to find the ROC library on CRAN and the moment. Do you know where I would locate it? Thanks for pointing out the discrepancy. I'll talk to you later. Matt ( verification package) Matt Pocernich NCAR - Research Applications Program 303-497-8312 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Splitting the string at the last sub-string
Hi, I need to split a string into 2 strings, with the split point defined by the last occurrence of some substring. I come up with some convoluted code to do so: str = Chance favors the prepared mind sub = e y = unlist(strsplit(str,sub)) z = cbind(paste(y[-length(y)], sub, sep=, collapse = ), y[length(y)]); y z z[1] z[2] Is there a simpler way to do so? I think ~8 function calls to do such a simple operation is an overkill. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED]`\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Splitting the string at the last sub-string
Thanks for suggestions. I suspect the regexpr version will be better than my version, since I use it to find an string towards the end of a large (up to ~30Mb) test/XML file. Thanks again. Jarek \ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] ` \ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Thursday, September 15, 2005 10:43 AM To: Barry Rowlingson Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Splitting the string at the last sub-string On Thu, 15 Sep 2005, Barry Rowlingson wrote: Prof Brian Ripley wrote: substring(str, c(1, 26), c(25,length(str))) nchar(str) surely? Yes, or anything larger: I actually tested 1. regexps can be rather slow though. Here's two functions: But that's not the way to do this repeatedly for the same pattern. (It is normally compiling regexps that is slow, and regexpr is vectorized.) Not that I would call 300us `slow'. byRipley = function(str,sub){ lp=attr(regexpr(paste(.*,sub,sep=),str),'match.length') return(substring(str, c(1, lp+1), c(lp,nchar(str } byJarek = function(str,sub){ y = unlist(strsplit(str,sub)) return(cbind(paste(y[-length(y)], sub, sep=, collapse = ), y[length(y)])) } and a quick test: system.time(for(i in 1:10){byJarek(str,sub)}) [1] 15.55 0.10 16.06 0.00 0.00 system.time(for(i in 1:10){byRipley(str,sub)}) [1] 30.28 0.07 31.86 0.00 0.00 Baz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] VB and R
I belive R, which is platform independent, does not work with any platform specific software or languages, like Visual Basic. Can you write your code by passing information through input/output files (CSV HML might be good formats)? Jarek Tuszynski SAIC -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 13, 2005 7:28 AM To: r-help@stat.math.ethz.ch Subject: [R] VB and R Dear Listers, Is there any good paper about how to use R together with VB? Thank you so much! -- WenSui Liu (http://statcompute.blogspot.com) Senior Decision Support Analyst Cincinnati Children Hospital Medical Center [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to use the function from another package
See Writing R Extensions / Creating R package / Description file / depends field (section 1.1.1). Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Yang Sent: Tuesday, August 09, 2005 1:56 PM To: R-help@stat.math.ethz.ch Subject: [R] how to use the function from another package Hi, I am trying to write a package(A) for myself and need to use a function from another package(B) which is in R already(need to install it before use). Could anyone tell me how to implement that? Also I hope that my package gives an ERROR message(something like STOP, please install package B first) if the package B is not installed yet. It is my first time to write a package. Thanks very much for your help. Peter __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to use the function from another package
Thanks very much for your help. Do I still have to write library( ) to load the library in my code after I add a depends field in the DESCRIPTION file? No, First when user of your package downloads it (at least on Windows machines) all required packages are also downloaded (this mechanism sometimes needs manual help, but that is another story). Then when he loads your package (by calling library(YourPackage)) all required packages are loaded into R. One good way to research this kind of questions (other than documentation and R-Help) is to study source code of other people packages. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 09, 2005 2:57 PM To: Tuszynski, Jaroslaw W. Subject: Re: [R] how to use the function from another package Thanks very much for your help. Do I still have to write library( ) to load the library in my code after I add a depends field in the DESCRIPTION file? Thanks. Peter On 8/9/05, Tuszynski, Jaroslaw W. [EMAIL PROTECTED] wrote: See Writing R Extensions / Creating R package / Description file / depends field (section 1.1.1). Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Yang Sent: Tuesday, August 09, 2005 1:56 PM To: R-help@stat.math.ethz.ch Subject: [R] how to use the function from another package Hi, I am trying to write a package(A) for myself and need to use a function from another package(B) which is in R already(need to install it before use). Could anyone tell me how to implement that? Also I hope that my package gives an ERROR message(something like STOP, please install package B first) if the package B is not installed yet. It is my first time to write a package. Thanks very much for your help. Peter __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] FW: color palette
Try: n = 100; x = matrix(seq(-10, 30, length.out=500), ncol=1) col = colorRampPalette( c(green, white, red), space=rgb)(n) breaks = c(seq(-10, 0, length.out=n/2)-0.5, 0, seq(0, 30, length.out=n/2)+0.5) image(x, col=col, breaks=breaks) See also today's discussion on R-Help about red-black-green color palette, since most of the code above came from Earl Glyn post. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of array chip Sent: Thursday, August 04, 2005 12:31 PM To: Thomas Lumley Cc: r-help@stat.math.ethz.ch Subject: Re: [R] color palette Thanks for the suggestion. I still could not figure out how to use the function to do my job. What's important in my job is that I have to map white color to value 0, and then form a bue gradient for negative values, and red gradient for positive values. The data matrix I have is not symmetric aound 0, say 0 is at the 18 percentile, and values range from -10 to 30. How exactly I could do my job? Bear with me, I am new to color, I don't quite understand how the image function map the number is the data matrix to the colors defined in the col argument. Thanks --- Thomas Lumley [EMAIL PROTECTED] wrote: On Wed, 3 Aug 2005, array chip wrote: Hi, I have a matrix with both positive and negative numbers, I would like to use image() to draw a heatmap. How can I can design a palette (or is there a function already available) that treat negative numbers in a blue gradient and positive numbers in a red gradient and treat 0 as white? ?colorRampPalette -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] can we manage memory usage to increase speed?
If you have a code that takes 2 weeks to run, than it might be a case of inefficient algorithm design. I was able to go from overnight runs (SELDI data analysis) to 20 minute runs by identifying single inefficient function that took most of the time, and writing it in C. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Zhilin Liu Sent: Monday, August 01, 2005 8:28 PM To: r-help@stat.math.ethz.ch Subject: [R] can we manage memory usage to increase speed? Hi, Thanks for reading. I am running a process in R for microarray data analysis. RedHat Enterprise Linux 4, dual AMD CPU, 6G memory. However, the R process use only a total of 200M memory. And the CPU usage is total to ~110% for two. The program takes at least 2 weeks to run at the current speed. Is there some way we can increase the usage of CPUs and memories and speed up? Any suggestion is appreciated. Thanks again. Zhilin [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] question on graphs and finding area under a curve
How about: trapz = function(x, y) { # computes the integral of y with respect to x using trapezoidal integration. idx = 2:length(x) return (as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1])) / 2) } Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Renuka Sane Sent: Tuesday, August 02, 2005 8:51 AM To: r-help@stat.math.ethz.ch Subject: [R] question on graphs and finding area under a curve Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? Thanks, Renuka -- Renuka Sane http://www.nyx.net/~rsane [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to hiding code for a package
I always thought that ability to see and study the code of every package, was a great thing about R and other open source environments. So I hope there are no good ways of hiding the code of packages. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gary Wong Sent: Saturday, July 30, 2005 4:21 AM To: r-help@stat.math.ethz.ch Subject: [R] How to hiding code for a package Hey everyone, I have made a package and wish to release it but before then I have a problem. I have a few functions in this package written in R that I wish to hide such that after installation, someone can use say the function foo(parameters = ) but cannot do foo. Typing foo should not show the source code or at least not all of it. Is there a way to do this ? I have searched the mailing list and used google, and have found something like [R] Hiding internal package functions for the doc. pkg-internal.Rd but this seems different since it seems that the keyword internal just hides the function from showing in the index and hides documentation, not the function itself. Can someone help? Thanks Gary __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] New functions supporting GIF file format in R
Sorry about late response but I was traveling and did not follow R-Help for 2 weeks. I think, I prefer to leave read/write.GIF functions in my package where I have a full control of IO formats. I like to store images as integer or real matrices, and movies as 3D arrays. I believe that 'pixmap' package (as well as 'rimage' package and possibly others) use specialized classes for images , and do not handle movies at all (correct me if I am wrong). If you would like to add capability reading and writing GIF files (or ENVI files - another multi-frame file format - see read/write.ENVI) to the 'pixmap' class, feel free to write a shell around my function. With input in correct range (0:255) and option scale='never', no processing will be done to your data on the way in or out. Also, I am not planning on making any changes to that function, unless bugs are found. Regards, Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Martin Maechler Sent: Tuesday, July 19, 2005 2:53 AM To: Tuszynski, Jaroslaw W. Cc: ([EMAIL PROTECTED]) Subject: Re: [R] New functions supporting GIF file format in R JarekT == Tuszynski, Jaroslaw W [EMAIL PROTECTED] on Mon, 18 Jul 2005 16:00:43 -0400 writes: JarekT Hi, A minor announcement. I just added two functions JarekT for reading and writing GIF files to my caTools JarekT package. Input and output is in the form of standard JarekT R matrices or arrays, and standard R color-maps JarekT (palettes). The functions can read and write both JarekT regular GIF images, as well as, multi-frame animated JarekT GIFs. Most of the work is done in C level code JarekT (included), so functions do not use any external JarekT libraries. JarekT For more info and examples go to JarekT http://cran.r-project.org/doc/packages/caTools.pdf JarekT http://cran.r-project.org/doc/packages/caTools.pdf JarekT and click GIF. Wouldn't it make sense to donate these to the 'pixmap' package which is dedicated to such objects and has been in place for a very long time? Regards, Martin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] New functions supporting GIF file format in R
Hi, A minor announcement. I just added two functions for reading and writing GIF files to my caTools package. Input and output is in the form of standard R matrices or arrays, and standard R color-maps (palettes). The functions can read and write both regular GIF images, as well as, multi-frame animated GIFs. Most of the work is done in C level code (included), so functions do not use any external libraries. For more info and examples go to http://cran.r-project.org/doc/packages/caTools.pdf http://cran.r-project.org/doc/packages/caTools.pdf and click GIF. Jarek Tuszynski [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Passing character strings from C code to R
Hi, I have a C code which produces array of integers and potentially a string, and I have problems passing the string out. Here is the relevant part of the code: 1 PROTECT(Ret = allocVector(INTSXP, n)); 2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */ 3 for(i=0; in; i++) ret[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n = strlen(comment); 8 if(n0) {// and it actually have some length 9Rprintf( '%s' %i\n, comment, n); 10 PROTECT(Str = allocString(n+1)); 11 str = CHAR(STRING_ELT(Str, 0)); 12 strcpy(str, comment); 13 Rprintf( '%s' %i\n, str, n); 14 setAttrib(Ret, install(comm), Str); 15 i=2; 16 } 17 Free(comment); 18 } 20 UNPROTECT(i); Print statement in line 9 gives right results, but program crashes before print statement in line 13. Any ideas to what am I doing wrong? Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Is there a working XML parser for the windows R Version 2 .0.1
I do not know if current XML package suppose to work for windows R Version 2.0.1; however, current version of XML works fine for current version of R (2.1.1). Also, version of XML available when R Version 2.0.1 was current, worked just fine as well. So the answer might be to update your R version. My System is: - R version: R 2.1.1 - Operating System: Win XP - Compiler: mingw32-gcc-3.4.2 Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Soren Wilkening Sent: Wednesday, July 13, 2005 9:16 AM To: r-help@stat.math.ethz.ch Subject: [R] Is there a working XML parser for the windows R Version 2.0.1 Dear all the regular XML package does not work correctly with the R 2.0.1 windows version. Can anybody indicate a suitable alternative ? I need to dynamically read, parse and process a HTML table in R that is available at a certain url. Regards Soren Wilkening -- CENSIX Consulting [EMAIL PROTECTED] http://www.censix.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] about image() function in R and colors
I do not know the solution to your problem, but I had the similar problems with image() function and most of derived functions. It seems that 'image' function was really not meant for displaying image data, instead it was designed to display matrices in the image format. Matlab had the same problem and ended up creating 2 functions: 'image' (similar to R's 'image') and 'imshow' (designed for displaying image data). There are three major processing steps in the 'image' that are hard to control or reverse: 1) scaling of the data intensities ( problem explained by Javier). Scaling is not much of a problem if continuous palette of colors is used , or to quote ?image when 'col' is a list of colors such as that generated by 'rainbow', 'heat.colors', 'topo.colors', 'terrain.colors' or similar functions. However scaling causes problems in case of discontinuous color-maps (palettes). 2) scaling of the data dimensions so it fits in default size window instead of scaling of the window to fit the data. This results in image with non-square pixels. There might be a way to force 'image' not to scale dimensions, I just did not spend much time looking for it yet. 3) Flipping of the image. As ?image shows one needs to transpose and flip matrix horizontally or perform image(t(volcano)[ncol(volcano):1,]) for the image data to be visualized in proper orientation. All those steps make sense in case of visualizing 2D data, but they are a hindrance in case of visualizing images. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of javier garcia Sent: Thursday, July 07, 2005 7:23 AM To: R-Help Cc: [EMAIL PROTECTED] Subject: [R] about image() function in R and colors Hi! I've got a map in R imported from a GIS (GRASS) as a vector of factors. So I've got 20 different levels in the map and I've created a vector of custom colors of exactly 20 colors in lenght. I'm trying to use image() (really plot.grassmeta() that call image()) to plot the map with those colors but it doesnt work and the colors are changed. I would like that all points belonging to level1 are color 1 , and so on... Please could you tell me if this procedure is not correct? Best regards, Javier -- A. Javier Garcia Water and Soil conservation department CEBAS-CSIC Campus Universitario Espinardo PO BOX 164 30100 Murcia (SPAIN) Phone: +34 968 39 62 57 Fax: +34 968 39 62 13 email: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Is.integer and testing for integers
Hi, I was trying to figure out if there is a function in R that tests if R object contains only integers. I though is.integer would be it, but this function only checks whether its argument is of integer type or not. As a result x = (1:5)^2 is.integer(x) Returns false. Of course I can write my own function like !any(x!=as.integer(x)) but I am just trying to make sure I am not reinventing the wheel. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] x*x*x*... vs x^n
I tried your code and got different results: system.time(ignore - f1(a)) [1] 0.83 0.09 1.08 NA NA system.time(ignore - f2(a)) [1] 0.38 0.01 0.41 NA NA system.time(ignore - f3(a)) [1] 0.32 0.04 0.43 NA NA So I tried it again but with a loop and got: for(i in 1:10) cat(system.time(ignore - f2(a)), \n) 0.36 0.04 0.44 NA NA 0.32 0.01 0.34 NA NA 0.28 0.03 0.32 NA NA 0.29 0.03 0.35 NA NA 0.3 0.02 0.32 NA NA 0.28 0.03 0.32 NA NA 0.3 0.02 0.32 NA NA 0.29 0.02 0.34 NA NA 0.23 0.03 0.32 NA NA 0.42 0 0.45 NA NA for(i in 1:10) cat(system.time(ignore - f3(a)), \n) 0.19 0.04 0.25 NA NA 0.17 0.04 0.25 NA NA 0.21 0.02 0.25 NA NA 0.21 0.02 0.23 NA NA 0.18 0.04 0.23 NA NA 0.18 0.05 0.23 NA NA 0.18 0.04 0.25 NA NA 0.17 0.06 0.23 NA NA 0.2 0.02 0.23 NA NA 0.14 0.06 0.25 NA NA It seems to me that f3 is 50% slower than f2 not 300%. My System is: - R version: R 2.1.1 - Operating System: Win XP - Compiler: mingw32-gcc-3.4.2 Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin Sent: Wednesday, June 29, 2005 7:32 AM To: r-help Subject: [R] x*x*x*... vs x^n Hi I have been wondering if there one can speed up calculating small powers of numbers such as x^8 using multiplication. In addition, one can be a bit clever and calculate x^8 using only 3 multiplies. look at this: f1 - function(x){x*x*x*x*x*x*x*x} f2 - function(x){x^8} f3 - function(x){x2 - x*x;x4 - x2*x2;return(x4*x4)} [so f1() and f2() and f3() are algebraically identical] a - rnorm(100) system.time(ignore - f1(a)) [1] 0.50 0.17 2.88 0.00 0.00 system.time(ignore - f2(a)) [1] 0.31 0.03 1.40 0.00 0.00 system.time(ignore - f3(a)) [1] 0.10 0.07 0.18 0.00 0.00 [these figures show little variance from trial to trial] I was expecting f2() and f3() to be about the same. I was not expecting a factor of 3 there! anyone got any comments? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] all connections are in use error during lazyload stage of packa ge installation
Hi, I suddenly started getting strange errors while working on my caTools package: RCMD install C:/programs/R/rw2011/src/library/caTools .. preparing package caTools for lazy loading Error in file(file, r, encoding = encoding) : all connections are in use Execution halted make: *** [lazyload] Error 1 *** Installation of caTools failed *** I searched through R website and mailing lists but did not found many clues. I am not running R environment so showConnections and CloseAllConnections functions are not helpful. Did I run into some OS specific limit on number of files allowed? I closed all other programs and rebooted my machine but it did not help. Any hints would be appreciated. My System is: - R version: R 2.1.1 - Operating System: Win XP - Compiler: mingw32-gcc-3.4.2 Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] all connections are in use error during lazyload stage of packa ge installation
I found the problem, by doing comparison of directories and files of working and not working versions, and applying changes one by one until one caused install to fail. It was a case of having a call to a source function somewhere in my code, that I forgot about. I was definitely doing something silly , but it was not a meaningful error message. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 29, 2005 10:07 AM To: Tuszynski, Jaroslaw W. Cc: r help Subject: Re: [R] all connections are in use error during lazyload stage of packa ge installation On 6/29/05, Tuszynski, Jaroslaw W. [EMAIL PROTECTED] wrote: Hi, I suddenly started getting strange errors while working on my caTools package: RCMD install C:/programs/R/rw2011/src/library/caTools .. preparing package caTools for lazy loading Error in file(file, r, encoding = encoding) : all connections are in use Execution halted make: *** [lazyload] Error 1 *** Installation of caTools failed *** I searched through R website and mailing lists but did not found many clues. I am not running R environment so showConnections and CloseAllConnections functions are not helpful. Did I run into some OS specific limit on number of files allowed? I closed all other programs and rebooted my machine but it did not help. I don't know what the problem is but you could see if adding LazyLoad: no to the DESCRIPTION file causes it to go away. Even if it does it would probably be best to track down what the cause is and in the past when I have had problems running R CMD on a package of mine I repeatedly removed half my package and reran R CMD until I found the offending portion. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Numerical accuracy
I do not know about details of numerical accuracy of R, it is probable related to numerical accuracy of C compiler that was used to compile it (gcc ?). However I would like to mention that I run into some problems with accuracy of sum and cumsum functions. See: x = c(1, 1e20, 1e40, -1e40, -1e20, -1) sum(x) [1] -1e+20 cumsum(x) [1] 1e+00 1e+20 1e+40 0e+00 -1e+20 -1e+20 And wrote functions (with help of R-Help list) to address the problem. See sum.exact and cumsum.exact in caTools package: sum.exact(x) [1] 0 cumsum.exact(x) [1] 1e+00 1e+20 1e+40 1e+20 1e+00 0e+00 Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Talita Perciano Costa Leite Sent: Monday, June 27, 2005 10:57 AM To: r-help@stat.math.ethz.ch Subject: [R] Numerical accuracy Hi people, I need to prove the good quality of numerical accuracy of R. Anyone knows a paper or anything else comparing R to other statistical softwares in terms of numerical accuracy. I've made a long search about that but I found nothing. Please help me!! Thanx, Talita Leite - Este e-mail foi enviado pelo Webmail da UFAL IMP: http://horde.org/imp/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] r programming help III
I am not sure if you can make this code shorter through R specific programming, but You can through simple programming technique of using functions: pFunc = function (S, d, N, p01, p11) { c1-N+1/2-abs(2*S-N-1/2+d); c-1:c1; a-ceiling((c-1+d)/2); b-ceiling((c-d)/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1+d),(b-1+d))*choose((N-S-d),a-d)*(((1 -p11)/(1-p01))^a)*((p01/p11)^b)) } # Transition Probabilities observed for 19 years p01-0.4052863; p11-0.7309942 # Now we try to find expected probabilities # for number of wet days in a week # as defined by Gabriel, Neumann (1962) N-7 p01=0.4052863 p11=0.7309942 pDry - function(S) pFunc(S,0,N,p01, p11) pWet - function(S) pFunc(S,1,N,p01, p11) # we obtain probabilities for dry case pN0-c(p11^N, pDry(1), pDry(2), pDry(3), pDry(4), pDry(5), pDry(6), pDry(7) ) # we obtain probabilities for wet case pN1-c(pWet(0), pWet(1), pWet(2), pWet(3), pWet(4), pWet(5), pWet(6), p11^N) # Use of transition probabilities to get expected probabilities d-p11-p01 P-p01/(1-d) pN-(1-P)*pN0+P*pN1 It is possible that you can find some ways of simplifying the pFunc. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mohammad Ehsanul Karim Sent: Friday, June 24, 2005 5:16 AM To: r help Subject: [R] r programming help III Dear List, Is there any way we can make the following formula any shorter by means of R programming: # Transition Probabilities observed for 19 years p01-0.4052863; p11-0.7309942 # Now we try to find expected probabilities # for number of wet days in a week # as defined by Gabriel, Neumann (1962) N-7 S-1; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p1N0 S-2; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p2N0 S-3; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p3N0 S-4; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p4N0 S-5; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p5N0 S-6; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p6N0 S-7; c0-N+1/2-abs(2*S-N-1/2);c-1:c0; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose((S-1),(b-1))*choose((N-S),a)*(((1-p11)/(1 -p01))^a)*((p01/p11)^b))-p7N0 # we obtain probabilities for dry case pN0-c(p11^N,p1N0,p2N0,p3N0,p4N0,p5N0,p6N0,p7N0) S-0; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p0N1 S-1; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p1N1 S-2; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p2N1 S-3; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p3N1 S-4; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p4N1 S-5; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p5N1 S-6; c1-N+1/2-abs(2*S-N+1/2);c-1:c1; a-ceiling((c-1)/2); b-ceiling(c/2); (p11^S)*((1-p01)^(N-S))*sum(choose(S,a)*choose((N-S-1),(b-1))*(((1-p11)/(1-p 01))^b)*((p01/p11)^a))-p6N1 # we obtain probabilities for wet case pN1-c(p0N1,p1N1,p2N1,p3N1,p4N1,p5N1,p6N1, p11^N) # Use of transition probabilities to get expected probabilities d-p11-p01 P-p01/(1-d) pN-(1-P)*pN0+P*pN1 # Expected Probabilities for number of wet days in a week is pN pN # gives the following output: [1] 0.05164856 0.05126159 0.10424380 0.16317247 0.20470403 0.20621178 0.16104972 [8] 0.09170593 Any hint, help, support, references will be highly appreciated. Thank you for your time.
Re: [R] Stop Warnings for Invalid Factor Level, NAs generated?
Check suppressWarnings function. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, June 23, 2005 9:09 AM To: r-help@stat.math.ethz.ch Subject: [R] Stop Warnings for Invalid Factor Level, NAs generated? How can I stop the following warning from occuring? invalid factor level, NAs generated in: [-.factor(`*tmp*`, iseq, value = structure(1, .Label = 12, class = factor)) The Label messages are for 5, 8, 12 and 46. I want the NAs to be generated as needed. Is this causing R to slow down by generating the warning messages? There are over 50. I loop through up to 10 datasets and append one row from each to create a summary dataset. The full code and data is too long to post. The snippet below might explain what I'm doing somewhat. I'll work up some sample data and code if no solutions are found. ...snip # Get info on first and last pair sets and lab names in last pair nlabs - labdata[[LABNUMBER]] #e.g. 1, 2, 5, 6, ... nolabs - length(nlabs) #Total number of labs in last pair of labdata #dpdata - labdata[which(labdata[[LABNUMBER]] == 13),] #Dummy paired data row dpdata - rbind(labdata[0,], NA) pdata - dpdata # Loop through pairs of labdata to build pdata for pairs (last 10 years or less) k=0 for(j in nlabs){ + for(i in ifpair:ilpair){ + k - k + 1 #Counter for number of pairs. Start at 1. + setwd(dirs[i]); load(labdata.Rdata)#No trailing / in wd + setwd(cdir) #Go back to original ESN pair (last pair's folder in analysis) + tpdata - labdata[which(labdata[[LABNUMBER]] == j),] + if(NROW(tpdata) == 0){ + tpdata - dpdata + tpdata[which(names(labdata) == LABNUMBER)] - j + tpdata[which(names(labdata) == ESN)] - ESN-((ilpair-ifpair)+1-k)*2 + tpdata[which(names(labdata) == ESNm1)] - ESN-((ilpair-ifpair)+1-k)*2-1 + } + #pdata[nrow(pdata)+1,names(tpdata)] - NA + pdata[nrow(pdata)+1,names(tpdata)] - tpdata + } + } There were 50 or more warnings (use warnings() to see the first 50) ...snip mailto:[EMAIL PROTECTED] Kenneth Ray Hobson, P.E. Oklahoma DOT - QA IAS Manager 200 N.E. 21st Street Oklahoma City, OK 73105-3204 (405) 522-4985, (405) 522-0552 fax Visit our website at: http://www.okladot.state.ok.us/materials/materials.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] [R-pkgs] Release of new version of caMassClass package and new package caT ools
Hi, A new version of caMassClass package was released today. The package contain pipeline for processing and classification of protein mass spectra data. The main change is off-spinning from the library collection of generic functions into a new package caTools. This package, which might be useful to broader group, is much smaller than caMassClass and has fewer dependencies. Other changes include: - Adding to caMassClass support for reading and writing mzXML data - a standard for storing proteomics MS data. - Adding more error checking to 'runmean', 'runmin', 'runmax', 'runmad' 'runquantile' functions - Writing 3 new functions for round-off-error free sumation: 'sum.exact', 'cumsum.exact' and 'runsum.exact'. - Added option to runmean function to allow use of above round-off-error free computation Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Reading Excel files...Error
If you need work-around, than you can always save excel file in csv format and than read that. See 'read.csv' or 'read.csv2'. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vivek Subramanian Sent: Wednesday, June 15, 2005 5:28 AM To: rhelp Subject: [R] Reading Excel files...Error hi, i am using the RODBC package to read .xls files. now after i installed the package and loaded the library and tried to read a file this is the error i got. channel-odbcConnect(D:/rstuff/1.xls) Warning messages: 1: [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 2: ODBC connection failed in: odbcDriverConnect(st, case = case, believeNRows = believeNRows) please help me. regards, vivek __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] FYI: Problems while loading package class (VR)
Hi, Today, I performed automatic updates of packages and somehow lost class package. I loaded a library that depended on it and got: Error: package 'class' could not be loaded In addition: Warning message: there is no package called 'class' in: library(pkg, character.only = TRUE, logical = TRUE, lib.loc = lib.loc) I tried to load it by instal-package: class (VR) and got error: dependency 'class (VR)' is not available. I did succesfully loaded it by instal-package: VR. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] FYI: Problems while loading package class (VR)
What happens after you reinstalling it? After installing VR bundle everything works perfectly. All problems solved. Version of R? platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor1.0 year 2005 month04 day 18 language R Version of VR? packageDescription(class)$Version = 7.2-15 Operating Sytstem? Win xp PLEASE do read the posting guide! Sorry about incomplete posting. My email was to inform that there are some problems with instaling package class (VR) by itself. If I go to Menu Packages/Install-package(s)/class(VR) I am still getting: utils:::menuInstallPkgs() dependency 'class (VR)' is not available Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 31, 2005 9:49 AM To: Tuszynski, Jaroslaw W. Cc: ([EMAIL PROTECTED]); '[EMAIL PROTECTED]' Subject: Re: [R] FYI: Problems while loading package class (VR) Tuszynski, Jaroslaw W. wrote: Hi, Today, I performed automatic updates of packages and somehow lost class package. I loaded a library that depended on it and got: Error: package 'class' could not be loaded In addition: Warning message: there is no package called 'class' in: library(pkg, character.only = TRUE, logical = TRUE, lib.loc = lib.loc) I tried to load it by instal-package: class (VR) and got error: dependency 'class (VR)' is not available. I did succesfully loaded it by instal-package: VR. What happens after you reinstalling it? Version of R? Version of VR? Operating Sytstem? PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Uwe Ligges Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] xmlAttrs and problems with reading node attributes of XML file (b ug?)
Duncan, Thanks, that that make sense, I have never encountered namespaces so I did not recognized them. So in my example xmlns=a xmlns:xsi=b are namespace variables, and xsi:schemaLocation=c is a Schema-Related Markup attribute. This last one seemed to be handled strangely, since it is listed as attribute but its name got truncated from xsi:schemaLocation to schemaLocation. Jarek -Original Message- From: Duncan Temple Lang [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 31, 2005 11:38 AM To: Tuszynski, Jaroslaw W. Cc: ([EMAIL PROTECTED]); '[EMAIL PROTECTED]' Subject: Re: [R] xmlAttrs and problems with reading node attributes of XML file (b ug?) Hi Jarek. Is the problem you are referring to simply that the xmlns=a and xmlns:xsi=b are not appearing when your handler prints the attributes? If it is this the case, the explanation is quite simple - they are namespace definitions, not attributes. They are in the node object x$namespaceDefinitions names(unclass(x)) will help to see what is in the node. HTH, D. Tuszynski, Jaroslaw W. wrote: Hi, Consider the following code: require(XML) xmlFile = paste( ?xml version=\1.0\ encoding=\ISO-8859-1\?\n, mzXML xmlns=\a\ xmlns:xsi=\b\ xsi:schemaLocation=\c\\n, parentFile a=\a\ b=\b\ /\n, /mzXML\n) cat(xmlFile) a = function(x,...){ cat(Attributes of , xmlName(x), : ); print(xmlAttrs(x)); cat(\n); NULL } xmlTreeParse(file=xmlFile, asText=TRUE, handlers=list(startElement=a) ) And its output: ?xml version=1.0 encoding=ISO-8859-1? mzXML xmlns=a xmlns:xsi=b xsi:schemaLocation=c parentFile a=a b=b / /mzXML Attributes of parentFile : a b a b Attributes of mzXML : schemaLocation c It seems to me that XML parser was able to correctly list all the attributes of the parentFile node but it failed on mzXML node. Am I missusing the functions somehow or is it a bug? Attribute names in mzXML node are part of mzXML file format and can not be changed (removing all ':' would fix the problem) and I would like to store than so whan I write mzXML file I have the same header. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] xmlAttrs and problems with reading node attributes of XML file (b ug?)
Hi, Consider the following code: require(XML) xmlFile = paste( ?xml version=\1.0\ encoding=\ISO-8859-1\?\n, mzXML xmlns=\a\ xmlns:xsi=\b\ xsi:schemaLocation=\c\\n, parentFile a=\a\ b=\b\ /\n, /mzXML\n) cat(xmlFile) a = function(x,...){ cat(Attributes of , xmlName(x), : ); print(xmlAttrs(x)); cat(\n); NULL } xmlTreeParse(file=xmlFile, asText=TRUE, handlers=list(startElement=a) ) And its output: ?xml version=1.0 encoding=ISO-8859-1? mzXML xmlns=a xmlns:xsi=b xsi:schemaLocation=c parentFile a=a b=b / /mzXML Attributes of parentFile : a b a b Attributes of mzXML : schemaLocation c It seems to me that XML parser was able to correctly list all the attributes of the parentFile node but it failed on mzXML node. Am I missusing the functions somehow or is it a bug? Attribute names in mzXML node are part of mzXML file format and can not be changed (removing all ':' would fix the problem) and I would like to store than so whan I write mzXML file I have the same header. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Useful tip: Use Google to find R scripts
Great tip. Thanks. One problem: a lot of hits are in REBOL language (whatever it is) that also uses R extension. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lapointe, Pierre Sent: Wednesday, May 25, 2005 9:29 PM To: 'r-help@stat.math.ethz.ch' Subject: [R] Useful tip: Use Google to find R scripts Hello, Ever wondered how people use a particular function in their programs? Use Google to find actual scripts: filetype:R boxplot will return real R scripts using the boxplot function. Regards, Pierre Lapointe Assistant Market Strategist *** AVIS DE NON-RESPONSABILITE:\ Ce document transmis par courri...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Reading text files and readLine
Hi, I am trying to write a function to read in a whole text file as a single string ( so I can calculate its sha1 hash function using package digest). I need a single string containing the whole file, and so far I was using paste(readLines(fileName), collapse = ). Unfortunately this function gives me warnings : incomplete final line found by readLines on 'test2.xml' due to lack of end-of-line character on the end of the file. Is there a way to suppress this warning? Or another function capable of reading whole text file into a string? Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] colors and palettes and things...
Colors predefined in R follow closely colors predefined in in HTML language. See: http://users.rcn.com/giant.interport/COLOR/1ColorSpecifier.html http://www.brobstsystems.com/colors1.htm http://www.geocities.com/html4kids/colors.htm And probably countless other websites defining them. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff D. Hamann Sent: Monday, May 23, 2005 11:35 AM To: r-help@stat.math.ethz.ch Subject: [R] colors and palettes and things... After trying to find if there was a color picker in the FAQs and the help, I thought I would send a post here. I was overwhelmed with all the wonderful color choices R has predefined (discovered after typing in colors()) but can't figure out what they all (by name) look like. Is there a color picker or some other method to display all those colors next to the name? I think I can put together palettes, but another question I have then regards the building of palettes (a list of variable length I can select or create myself other than the ones defined by Palette) so I can pass these colors into functions instead of having to predefine a bunch of colors myself or use the predefined colors like terrain.colors(n)? Are there groups of colors in the colors() that I can group together to make some nice palettes for drawing barplots, etc? Thanks, Jeff. -- Jeff D. Hamann Forest Informatics, Inc. PO Box 1421 Corvallis, Oregon 97339-1421 phone 541-754-1428 fax 541-752-0288 [EMAIL PROTECTED] www.forestinformatics.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Big-endian / Little-endian byte swap
Hi, Is there a way to perform Big-endian / Little-endian byte swap in R? An ugly way is by using readBin/writeBin: ByteSwap = function(X, size) { writeBin(X, tmp.dat) readBin(tmp.dat, typeof(X), n = length(x), size=size, endian=swap) } x = (1:5)*pi y = ByteSwap(x,8) z = ByteSwap(y,8) x [1] 3.141593 6.283185 9.424778 12.566371 15.707963 y [1] 3.207376e-192 3.207376e-192 -4.277269e+87 3.207376e-192 7.596046e+145 z [1] 3.141593 6.283185 9.424778 12.566371 15.707963 But, there has to be some way of doing that without use of temporaty files. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] R matrix sorting question
Try: A=matrix(c(1,3,4,5,7, -0.2, 0.8, 0.3, 0.2, 0.9 ),5,2) A [,1] [,2] [1,]1 -0.2 [2,]3 0.8 [3,]4 0.3 [4,]5 0.2 [5,]7 0.9 A[order(A[,2]), ] [,1] [,2] [1,]1 -0.2 [2,]5 0.2 [3,]4 0.3 [4,]3 0.8 [5,]7 0.9 Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, May 19, 2005 1:43 PM To: R-help@stat.math.ethz.ch Subject: [R] R matrix sorting question Dear there, I am trying to do the following stuff. Could you let me know how to do it efficiently? aaa [,1] [,2] [1,]1 -0.2 [2,]3 0.8 [3,]4 0.3 [4,]5 0.2 [5,]7 0.9 And I would like to sort the matrix by column 2 (and accordingly column 1 sorted as well). The desired matrix will be 1 -0.2 5 0.2 4 0.3 3 0.8 7 0.9 If using Excel or SAS, I can do this easily, but I couldn't figure out how to do it in R. Could you let me know the efficient way to do this ? I appreciate if the solution or reply comes as quickly as possible. Thank you very much. Insu __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Survey of moving window statistical functions - still l ooking for fast mad function
On 9 Oct 2004, Brian D. Ripley wrote: On Fri, 8 Oct 2004, Tuszynski, Jaroslaw W. wrote: Finally a question: I still need to get moving windows mad function faster my runmad function is not that much faster than apply/embed combo, and that I used before, and this is where my code spends most of its time. I need something like runmed but for a mad function. Any suggestions? Write your own C-level implementation, as runmed and most of the other fast functions you cite are. I did as suggested and just released runmean, runmax, runmin, runmad and runquantile functions as part of caMassClass package. Thanks for the suggestion, now my codes run 20 min. instead of overnight. Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Latex can not find Rd.sty
Hi, Lately my Latex engine used for checking packages stop working, and I can not figure out how to fix it. When creating my package (caMassClass) I get the * checking caMassClass-manual.tex ... ERROR LaTeX errors when creating DVI version. This typically indicates Rd problems. message. I look in caMassClass-manual.log file and find ! LaTeX Error: File `Rd.sty' not found. message. So I went to R Installation and Administration manual which recommended http://www.murdoch-sutherland.com/Rtools/miktex.html http://www.murdoch-sutherland.com/Rtools/miktex.html website to fix this exact problem. This page suggested findtexmf Rd.sty command to check whether it is finding Rd.sty in the right place. When I try that I get: C:\findtexmf Rd.sty C:\programs\R\rw2010\share\texmf\Rd.sty Which is the correct place where the file lives. I also tried workarounds 1 and 4, but it did not help. Any ideas of other thinks I can do? My setup is: - Windows XP - R 2.1.0 - Mitex 2.4.1461 The Mitex was working fine on my machine before but since I went from Windows 2K to XP and upgraded from R 2.0.1 to R 2.1.0. Thanks Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Error list and debugging R code
Hi, I am trying to debug my code and looking for any tool to help me out with it. My main problem is with the error messages I can not figure out where they come from (what function produced them) and what do they mean. Is there such a think as list of error messages produced by R and standard R packages, and what do they mean? Or any tool to extract information which function produced the run-time error (a call stack would be great)? I looked into debug and trace tools but you seem to have to know where the problem is to use them. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
FW: [R] Advice for calling a C function
I think it is a problem with matrices in R and C being stored in different row/column order void gowsim ( double *mat, int *OBJ, int *MATDESC) { double x [*MATDESC][*OBJ]; int i, j, nrow, ncol; nrow = *OBJ; ncol = *MATDESC; /* Rebuild Matrix */ for (j=0; j ncol; j++) { for (i=0; i nrow; i++) { x[i][j] = *mat; Swapping x[i][j] to x[j][i] should fix the problem. Sorry, I did not test it. Rprintf(row %d col %d value %f\n, i, j, x[i][j]); mat++; } } for (i=0; i nrow; i++) { Rprintf(%f %f %f %f\n, x[i][0], x[i][1], x[i][2], x[i][3]); } } Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Casting in R
Hi, I am looking for functions that would allow me to access raw binary data of R vectors. One way would be to use: x = (1:10)*pi writeBin(x, temp.bin) r = readBin(temp.bin, raw, n=length(x)*8) Other to write my own C code. Is there any other simpler way? I this message is a rewording of my yesterday message Looking for function for Double to raw to double conversions, to which I got no replies. I need this functionality to implement Base64 encoding for reading/writing XML files. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Casting in R
Yes, XML package does not seem to support Base64 encoding so I wrote my own encoder/decoder working with raw vectors. The only problem is casting R's vectors of doubles into vectors of type raw. Jarek -Original Message- From: Berton Gunter [mailto:[EMAIL PROTECTED] Sent: Friday, March 25, 2005 11:28 AM To: 'Tuszynski, Jaroslaw W.'; r-help@stat.math.ethz.ch Subject: RE: [R] Casting in R Have you looked at the XML package on CRAN? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tuszynski, Jaroslaw W. Sent: Friday, March 25, 2005 8:06 AM To: ([EMAIL PROTECTED]) Subject: [R] Casting in R Hi, I am looking for functions that would allow me to access raw binary data of R vectors. One way would be to use: x = (1:10)*pi writeBin(x, temp.bin) r = readBin(temp.bin, raw, n=length(x)*8) Other to write my own C code. Is there any other simpler way? I this message is a rewording of my yesterday message Looking for function for Double to raw to double conversions, to which I got no replies. I need this functionality to implement Base64 encoding for reading/writing XML files. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Unexpected error subset assignment (bug?)
Hi, I run into following problem. It seems to me that operation in the 3rd line should be valid. b = matrix(as.raw(0), 8,8) q = as.raw(1:8) b[1,] = q Error: incompatible types in subset assignment length(b[1,]) [1] 8 typeof(b[1,]) [1] raw length(q) [1] 8 typeof(q) [1] raw Is this a bug or a feature? Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Looking for function for Double to raw to double conversions
Hello, I am trying to implement function for reading/writing some XML file format. One feature of that XML format is that a lot of binary data is stored in Base64 format, and since R's XML package does not seem to support it, I just wrote my own converter from raw format to Base64, and back. However one place I have problems with is conversion from vector of doubles to vector of raws. I was expecting equivalent of C casting operation, like: double *doubleVec; unsigned char* rawVec; rawVec = (unsigned char*) doubleVec; Or if compiler complains: rawVec = (unsigned char*) ((void*) doubleVec); Unfortunately I can not find equivalent function in R. Simple minded: doubleVec = (1:4)*pi rawVec = as.raw(doubleVec) as.double(rawVec) Does not seem to work (output: 3 6 9 12, instead of: 3.141593 6.283185 9.424778 12.566371) . The only way I figured out how to do it is by using: raw2double = function(x) { writeBin(as.raw(x), temp.bin) return( readBin(temp.bin, double, n=length(x)%/%8) ) } double2raw = function(x) { writeBin(as.double(x), temp.bin) return( readBin(temp.bin, raw, n=length(x)*8) ) } Than: rawVec = double2raw(doubleVec) raw2double(rawVec) Gives correct results. Is there any other way that does not use temporary files to do this simple casting, that does not involve writing my own C code (which I am trying to avoid). Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with R CMD Rd2dvi: Rd.sty not found
Hi, I run into a problem with R CMD Rd2dvi command: it gives me File `Rd.sty' not found error (See the output message on the bottom). I get the same error when running RCMD check. My system is: Windows 2000, R version 2.0.1, MiKTeX version 2.4. I do have a Rd.sty file in R_HOME/share/texm directory. I looked through newsgroups for any related discussions and found Arnab Mukherji reporting the same problem on Dec 23 2003 (Subject: [R] Rd.sty not found -). In reply Prof. Brian Ripley suggested the following: It should be looking in TEXINPUTS, as is the point of the following in the check script $ENV{'TEXINPUTS'} = env_path(file_path($R::Vars::R_HOME, share, texmf), $ENV{'TEXINPUTS'}); So you could try adding to TEXINPUTS yourself, and you should certainly check the current setting of the environment variable (unset is fine). I am not sure if I understand it correctly but I created environmental variable TEXINPUTS with path to R_HOME/share/texm. It did not help. Any other suggestions? Should I use some other version of Latex? Do I have to configure it in any special way? Thanks for any suggestions, C:\programs\R\rw2001\src\library\caMassClass\manR CMD Rd2dvi BaselineSubstracton.Rd Converting Rd files to LaTeX ... BaselineSubstraction.Rd Creating dvi output from LaTeX ... This is pdfTeX, Version 3.141592-1.20a-rc7.2 (MiKTeX 2.4) output format initialized to PDF (Rd2.tex LaTeX2e 2003/12/01 Babel v3.8a and hyphenation patterns for english, french, german, ngerman, dumylang, nohyphenation, loaded. (C:\Program Files\latex\tex\latex\base\book.cls Document Class: book 2004/02/16 v1.4f Standard LaTeX document class (C:\Program Files\latex\tex\latex\base\bk10.clo)) ! LaTeX Error: File `Rd.sty' not found. Type X to quit or RETURN to proceed, or enter new name. (Default extension: sty) Enter file name: ! Emergency stop. read * l.4 \usepackage {makeidx} No pages of output. Transcript written on Rd2.log. Couldn't find input index file Rd2 nor Rd2.idx. Usage: c:\Program Files\latex\miktex\bin\makeindex.exe [-ilqrcg] [-s sty] [-o id] [-t log] [-p num] [idx0 idx1 ...] This is pdfTeX, Version 3.141592-1.20a-rc7.2 (MiKTeX 2.4) output format initialized to PDF (Rd2.tex LaTeX2e 2003/12/01 Babel v3.8a and hyphenation patterns for english, french, german, ngerman, dumylang, nohyphenation, loaded. (C:\Program Files\latex\tex\latex\base\book.cls Document Class: book 2004/02/16 v1.4f Standard LaTeX document class (C:\Program Files\latex\tex\latex\base\bk10.clo)) ! LaTeX Error: File `Rd.sty' not found. Type X to quit or RETURN to proceed, or enter new name. (Default extension: sty) Enter file name: ! Emergency stop. read * l.4 \usepackage {makeidx} No pages of output. Transcript written on Rd2.log. Saving output to 'BaselineSubstraction.dvi' ... cp: cannot stat `.Rd2dvi/Rd2.dvi': No such file or directory Done xdvi.bat: not found Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with as.array (bug?)
Hi, I run into the following problem: data(iris) as.array(iris[,-5]) Error in dimnames-.data.frame(`*tmp*`, value = list(c(Sepal.Length, : invalid dimnames given for data frame as.array(as.matrix(iris[,-5])) When trying to convert numeric data frame to an array. Conversion to matrix works just fine, but array crashes. Since documentation for as.array says its argument has to be an R object than it should work for data frames as well. Closer examination shows that as.array code with [150 x 4] data frame as input, does the following: # line of codeeffect 1if (is.array(x)) return(x)is.array is false 2 n - names(x)names return a vector of 4 column names 3 dim(x) - length(x)dim(x) before is [150 x 4]; length(x) is 4; dim(x) after is still [150 x 4] 4 if (length(n)) dimnames(x)-list(n)list(n) is a list containing 1 vector with 4 strings; attempt to set it as dimnames to [150x4] object fails 5 return(x) If this is a bug and not poorly documented feature, than changing line 2 to n - dimnames(x) seem to work for this example. Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Unexpected results from sort function when partial and index are used
Hi, Consider the following example: sort(10:1, partial=3) ## 1 2 3 7 6 5 4 8 9 10 sort(10:1, index=T) ## $x: 1 2 3 4 5 6 7 8 9 10 ## $ix: 10 9 8 7 6 5 4 3 2 1 sort(10:1, partial=3, index=T) ## 1 2 3 7 6 5 4 8 9 10 The first 2 calls gave expected returns; however, the third one did not returned an index as requested. I could not find anything about it in http://stat.ethz.ch/R-manual/R-patched/library/base/html/sort.html http://stat.ethz.ch/R-manual/R-patched/library/base/html/sort.html , so it seems to be an undocumented feature. Does any body know how to convince sort to return index of partially sorted array? Thanks Jarek =\ Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Survey of moving window statistical functions - still looking f or fast mad function
Hi, Lately I run into a problem that my code R code is spending hours performing simple moving window statistical operations. As a result I did searched archives for alternative (faster) ways of performing: mean, max, median and mad operation over moving window (size 81) on a vector with about 30K points. And performed some timing for several ways that were suggested, and few ways I come up with. The purpose of this email is to share some of my findings and ask for more suggestions (especially about moving mad function). Sum over moving window can be done using many different ways. Here are some sorted from the fastest to the slowest: 1. runmean = function(x, k) { n= length(x) y= x[ k:n ] - x[ c(1,1:(n-k)) ] # this is a difference from the previous cell y[1] = sum(x[1:k]); # find the first sum y= cumsum(y)# apply precomputed differences return(y/k) # return mean not sum } 2. filter(x, rep(1/k,k), sides=2, circular=T) - (stats package) 3. kernapply(x, kernel(daniell, m), circular=T) 4. apply(embed(x,k), 1, mean) 5. mywinfun - function(x, k, FUN=mean, ...) { # suggested in news group n - length(x) A - rep(x, length=k*(n+1)) dim(A) - c(n+1, k) sapply(split(A, row(A)), FUN, ...)[1:(n-k+1)] } 6. rollFun(x, k, FUN=mean) - (fSeries package) 7. rollMean(x, k) - (fSeries package) 8. SimpleMeanLoop = function(x, k) { n = length(x) # simple-minded loop used as a baseline y = rep(0, n) k = k%/%2; for (i in (1+k):(n-k)) y[i] = mean(x[(i-k):(i+k)]) } 9. running(x, fun=mean, width=k) - (gtools package) Some of above functions return results that are the same length as x and some return arrays with length n-k+1. The relative speeds (on Windows machine) were as follow: 0.01, 0.09, 1.2, 8.1, 11.2, 13.4, 27.3, 63, 345. As one can see there are about 5 orders of magnitude between the fastest and the slowest. Maximum over moving window can be done as follow, in order of speed 1. runmax = function(x, k) { n = length(x) y = rep(0, n) m = k%/%2; a = 0; for (i in (1+m):(n-m)) { if (a==y[i-1]) y[i] = max(x[(i-m):(i+m)]) # calculate max of the window else y[i] = max(y[i-1], x[i+m]); # max of the window is =y[i-1] a = x[i-m] # point that will be removed from the window } return(y) } 2. apply(embed(x,k), 1, max) 3. SimpleMaxLoop(x, k) - similar to SimpleMeanLoop above 4. mywinfun(x, k, FUN=max) - see above 5. rollFun(x, k, FUN=max) - fSeries package 6. rollMax(x, k) - fSeries package 7. running(x, fun=max, width=k) - gtools package The relative speeds were: 0.01, 3, 3.4, 5.3, 7.5, 7.7, 15.3 Median over moving window can be done as follows: 1. runmed(x, k) - from stats package 2. SimpleMedLoop(x, k) - similar to SimpleMeanLoop above 3. apply(embed(x,k), 1, median) 4. mywinfun(x, k, FUN=median) - see above 5. rollFun (x, k, FUN=median) - fSeries package 6. running(x, fun=max, width=k) - gtools package Speeds: 0.01, 3.4, 9, 15, 29, 165 Mad over moving window can be done as follows: 1. runmad = function(x, k) { n = length(x) A = embed(x,k) A = abs(A - rep(apply(A, 1, median), k)) dim(A) = c(n-k+1, k) apply(A, 1, median) } 2. apply(embed(x,k), 1, mad) 3. mywinfun(x, k, FUN=mad) - see above 4. SimpleMadLoop(x, k) - similar to SimpleMeanLoop above 5. rollFun(x, k, FUN=mad) - fSeries package 6. running(x, fun=mad, width=k) - gtools package Speeds: 11, 18, 25, 50, 50, 400 Some thoughts about those results: * All functions from Stats package (runmed, filter, kernapply) are fast and hard to improve on. * In case of Mean and Max a simple un-optimized R codes are much faster than specialized functions build for the same purpose. * apply(embed(x,k), 1, fun) - seem to be always faster than any functions from fSeries package or mywinfun * running function from gtools package is horribly slow compared to anything else * mywinfun proposed as a faster version of apply(embed(x,k), 1, fun) seems