[R] print median and sd...
Hii, Can anybody help me, I don't know how to print the median. Below is my code snipplet... x -read.table(file=D:/Uni/Diplom/Diplom/Grafiken/R/BATMAN/Kabel/Batman1hop/Standardabweichung__output_30_1_Kabel(30m)_b.txt) png(filename = D:/Grafiken/R/Standardabweichung/Kopie.png, width = 640, height = 480,pointsize = 12, bg = white, res = NA) median-with(x, tapply(V3, grup, median)) ??? dev.off() I will print, the median values with a simple line.. I tried many things but without success... I would be very appreciate, if anyone could help me... greetings, John -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22489185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to rotate the histogram
You may refer to the last example in ?layout Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086 Mobile: +86-15810805877 Homepage: http://www.yihui.name School of Statistics, Room 1037, Mingde Main Building, Renmin University of China, Beijing, 100872, China On Wed, Mar 11, 2009 at 5:33 PM, Abelian abelian1...@gmail.com wrote: Dear all I want to combine two figures on one plot. First figure display the data distribution. The x-axis of first figure is individual's ranking and the y-axis of first figure is probability. However, the second figure is a histogram about probability. In order to make the figure more clearly, i want to put those two figure together. But i have a problem that i can not rotate the histogram.Because i want put the x- axis of histogram on the left side of first figure. Can anyone provide some way to solve this problem. Sinerely __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fitting GUMBEL Distribution - CDF function ISSUE
Dear R helpers I am trying to fit the Gumbel distribution to a data. I am using lmom package. I am getting problem in Cumulative Distribution Function of Gumbel distribution as I am getting it as a series of 0's and 1's thereby affecting the P P Plot. My R code is as follows. library(quantreg) library(RODBC) library(MASS) library(actuar) library(lmom) x - c(986.78,1067.76,1046.47,1034.71,1004.53,1007.89,964.94, 1060.24, 1188.07, 1085.63,988.33,972.71, 1177.71,972.48,1203.20, 1047.27,1062.95, 1113.65, 995.97, 1093.98) #Estimating the parameters for GUMBEL distribution N- length(x) lmom - samlmu(x); lmom parameters_of_GUMBEL - pelgum(lmom); parameters_of_GUMBEL # Parameters are xi = 1019.4003 alpha = 59.5327 # _ P - P Plot e- c(1:N) f- c((e-.5)/N) Fx - cdfgum(x, para = parameters_of_GUMBEL) g- sort(Fx) png(filename = GUMBEL_P-P.png) a - par('bg'= #CC) plot (f,g,bg=a,fg= #804000,main =P-P Plot, ylab= Cumulative Distribution Function, xlab=i, font.main=2, cex.main=1,col=#66,bty = o,col.main=black,col.axis=black,col.lab =black) abline(rq(g ~ f, tau = .5),col=red) dev.off() # Fx RETURNS0 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 1 1 0 1 and Thus plot is not proper Please guide me as where I am going wrong. With regards Maithili __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] stats lm() function
Altough it depends on what crit you keep your variables, but maybe you should take a look at ?step. Bart Paul Hermes wrote: ok, i think i have to be more precise of what we are doing. first thing: this code is not from me, and Im new to R (and never touched anything like this) Im just the lucky guy who has to maintain this crap :) this call to the lm function is part of a code wich is used to predict the marketvalues from a bunch of our products. as 'target' function it gets the past marketvalues we have in our database.(this is what goes into the 'data' parameter into the lm function) then we have allot other prices and enviromental data (like similar products, stock sizes, seasonal informations, ) with this, the big formula is created (y ~ x1 + x2 + x3 + x4 + x5 ... + x300) all this goes into the lm call. then the result is somehow anaylsed to figure out wich input data-set had the least influence (or similaryti ) to the past marketvalues. this one gets eleminated and lm is called again wihout this data-set. this is done until we just have a small number of datasets left. could be that everything im writing here is totaly bullshit (cause im not shure if i got every thing right) but this thing is working an creates very nice predictions ;) i just fugured that the lm call's in this loop tooks the most time and i want to reduce this. any ideas? - Original Message - From: David Winsemius dwinsem...@comcast.net To: Paul Hermes paul.her...@analytic-company.com Cc: r-help@r-project.org Sent: Thursday, March 12, 2009 3:42 PM Subject: Re: [R] stats lm() function I think you will find that many readers of this list would rather try to dissuade you from this misguided strategy. You are unlikely to get to a sensible solution in using step-down procedures with this sort of situation (large number of predictors with modest size of data). -- David Winsemius On Mar 12, 2009, at 1:59 PM, Paul Hermes wrote: Hi, Im using the lm() function where the formula is quite big (300 arguments) and the data is a frame of 3000 values. This is running in a loop where in each step the formula is reduced by one argument, and the lm command is called again (to check which arguments are useful) . This takes 1-2 minutes. Is there a way to speed this up? i checked the code of the lm function and its seems that its preparing the data and then calls lm.Fit(). i thought about just doing this praparing stuff first and only call lm.fit() 300 times. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/stats-lm%28%29-function-tp22483608p22492199.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Invalid Type of Char Argument When Sum() is Used
Hi all, I have the following data AAA 1e+06 1222.312 AAC 100.2 0.33 However the following command dat - read.table(mydat.txt); print(dat) n1 - sum(as.matrix(dat$V1)); gives: Error in sum(as.matrix(dat$V1)) : invalid 'type' (character) of argument What's wrong with the data type so that it gives such error? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] regsubsets() [leaps package] - please share some good examples of use
On Fri, 13 Mar 2009, Tal Galili wrote: Thanks Thomas. Assuming I want to change the k factor (used in AIC type procedures), is there a way to do that ? There is no k factor in the leaps algorithm. It always reports the best model with one predictor, the best model with two predictors, the best model with three predictors, and so on. When comparing models with the same number of predictors the cost-complexity penalty cancels out and so only the residual sum of squares is needed. You can add any other penalty later. Also - is there a way to force the model to make only one step in the creation of the model ? For forward selection there is: set nvmax to 1, and only models with one variable will be considered. Then use force.in to force in the one variable you selected and set nvmax=2 to consider models with two variables. It might well be just as easy to program this yourself -- the leaps package doesn't seem to be a good fit for what you are trying to do. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] changing function argument
Hi, I wonder if the following is possible in R: Suppose a function takes an argument, and wants to modify this argument so that the change is visible _at the call side_. It would be what is for example known as pass-by-reference-to-non-const in C++. test - function(x) { x - 10 ... return (somethingElse) # I do NOT want having to return x } number = 5 test(number) stopifnot(number == 10) Is there some trick with scoping rules and maybe - to achieve this ? thanks, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] changing function argument
Thomas Mang thomas.mang at fiwi.at writes: I wonder if the following is possible in R: Suppose a function takes an argument, and wants to modify this argument so that the change is visible _at the call side_. It would be what is for example known as pass-by-reference-to-non-const in C++. test - function(x) { x - 10 ... return (somethingElse) # I do NOT want having to return x } number = 5 test(number) stopifnot(number == 10) Is there some trick with scoping rules and maybe - to achieve this ? Yes, it is possible. No, don't do it (coming from the c++ world, I understand your temptation). Try to look for assign to see the attached flames. http://r-project.markmail.org/search/?q=assign Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Windows binary version of DPpackage
The package does not install under Windows: see http://www.r-project.org/nosvn/R.check/r-release-windows-ix86/DPpackage-00check.html The maisntainer has been informed (probably many times via the automated notification system). With 1700 packages, the volunteers have no time to spend correcting packages for non-responsive maintainers (we do quite a lot for responsive ones). The posting guide suggested you contact him first: did you get a response? On Fri, 13 Mar 2009, Debabrata Midya wrote: Dear R users, Thanks in advance. I am Deb, Statistician at NSW Department of Commerce, Sydney. I am using R 2.8.1 on Windows XP. This has reference to the package ???DPpackage???. The binary version is available on Mac OS, but I am using Windows XP. May I request you to assist me in the followings: How can I prepare Windows binary of DPpackage from source? Follow the rw-FAQ, set yourself up to compile source packages, try this one, find the errors, correct them, use the package you compiled. 2. Is there any possibility to have a copy of Windows binary of DPpackage in the near future in the site http://www.cran.r-project.org/? Only if the maintainer submits a corrected version. Once again, thank you very much for the time you have given. I am looking forward for your reply. Regards, Debabrata Midya (Deb) NSW Department of Commerce Government Procurement Management Level 11 McKell Building 2-24 Rawson Place Sydney NSW 2000 Australia -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Windows binary version of DPpackage
Debabrata Midya Debabrata.Midya at commerce.nsw.gov.au writes: This has reference to the package âDPpackageâ. The binary version is available on Mac OS, but I am using Windows XP. May I request you to assist me in the followings: How can I prepare Windows binary of DPpackage from source? 2. Is there any possibility to have a copy of Windows binary of DPpackage in the near future in the site http://www.cran.r-project.org/? That package was available earlier and seems to work for me in the version from May 2007, but it currently does not build successfully. http://www.r-project.org/nosvn/R.check/r-devel-windows-ix86/DPpackage-00check.html Too bad, this is a great package. Looks like it no longer maintained? I will send a copy to alejandro.jaravalle...@med.kuleuven.be Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] changing function argument
On Fri, 13 Mar 2009, Thomas Mang wrote: Hi, I wonder if the following is possible in R: Suppose a function takes an argument, and wants to modify this argument so that the change is visible _at the call side_. It would be what is for example known as pass-by-reference-to-non-const in C++. test - function(x) { x - 10 ... return (somethingElse) # I do NOT want having to return x } number = 5 test(number) stopifnot(number == 10) It's possible in your example test-function(x){ eval(substitute(x-10),parent.frame()) return(42) } However, it is still likely to be a bad idea. What do you want to happen for test(5) test(x+y) test(test(y)) retest-function(z) {z-5; test(z); print(z)} retest(x) R really doesn't have pointer or reference types, and there's no way to ensure that the arguments to a function are lvalues. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] changing function argument
Dieter Menne wrote: Thomas Mang thomas.mang at fiwi.at writes: I wonder if the following is possible in R: Suppose a function takes an argument, and wants to modify this argument so that the change is visible _at the call side_. It would be what is for example known as pass-by-reference-to-non-const in C++. test - function(x) { x - 10 ... return (somethingElse) # I do NOT want having to return x } number = 5 test(number) stopifnot(number == 10) Is there some trick with scoping rules and maybe - to achieve this ? Yes, it is possible. No, don't do it (coming from the c++ world, I understand your temptation). Try to look for assign to see the attached flames. Hi, Well the point is I really really want to do it - and believe me, I know what I am doing ;) (for that matter, this is done solely in implementation code - of course I wouldn't do such a thing in a publicly used interface). I know assign, and I suppose the trick is something to pass the name of the variable at the call side, as well as the environment of the call side, as additional argument to my test-function, so it knows what to change where. Is that correct ? Is there some more short-hand / direct / elegant way of achieving my goal ? thanks, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Invalid Type of Char Argument When Sum() is Used
Do an 'str(dat)' and see what the structure is. When I read in your data I get: x V1V2 V3 1 AAA 100.0 1222.312 2 AAC 100.20.330 str(x) 'data.frame': 2 obs. of 3 variables: $ V1: Factor w/ 2 levels AAA,AAC: 1 2 $ V2: num 100 100 $ V3: num 1222.31 0.33 sum(x$V1) Error in Summary.factor(1:2, na.rm = FALSE) : sum not meaningful for factors sum(x$V2) [1] 1000100 So you 'V1 might be characters which is exactly what your error message is telling you. On Fri, Mar 13, 2009 at 4:37 AM, Gundala Viswanath gunda...@gmail.com wrote: Hi all, I have the following data AAA 1e+06 1222.312 AAC 100.2 0.33 However the following command dat - read.table(mydat.txt); print(dat) n1 - sum(as.matrix(dat$V1)); gives: Error in sum(as.matrix(dat$V1)) : invalid 'type' (character) of argument What's wrong with the data type so that it gives such error? - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time-Ordered Clustering
Dear Paul, Could you be more specific about what you mean here? I don't know the Runger paper so it's hard to tell what it is that you're looking for. Blatant plug: I developed a package for hidden Markov models called depmixS4 that in some sense does what you want: clustering taking dependencies over time into account by specifying a transition matrix. Similarly, there are other packages that fit similar models, searching for hidden markov model provides a number of them. hth, Ingmar Visser On 12 Mar 2009, at 23:39, Prew, Paul wrote: Hello All, Does anyone know of a package that performs constraint-based clusters? Ideally the package could perform Time-Ordered Clustering, a technique applied in a recent journal article by Runger, Nelson, Harnish (using MS Excel). Quote, in our specific implementation of constrained clustering, the clustering algorithm remains agglomerative and hierarchical, but observations or clusters are constrained to only join if they are adjacent in time. CRAN searches using variants of cluster and/or constraint and/or time etc. didn't yield anything I could recognize. Thank you, Paul Paul Prew Ecolab Eagan, MN paul.p...@ecolab.com CONFIDENTIALITY NOTICE: =\ \ This e-mail communication a...{{dropped: 12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Windows binary version of DPpackage
Prof Brian Ripley ripley at stats.ox.ac.uk writes: The maintainer has been informed (probably many times via the automated notification system). With 1700 packages, the volunteers have no time to spend correcting packages for non-responsive maintainers (we do quite a lot for responsive ones). The posting guide suggested you contact him first: did you get a response? The address in the package is dead. Dimitris gave me his new address, aja...@udec.cl, and I have sent a message to him. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ctree from Java via Rserve
Hi, I want to run the R-function ctree (package party) from Java over Rserve with the following Java-Code: try{ RConnection v = new RConnection(); v.voidEval(library(party)); v.voidEval(try(load(\C:\\Documents and Settings\\daten2.rda\))); v.voidEval(try(pdf(\C:\\Documents and Settings\\test4.pdf\))); v.voidEval(plot (ctree(ZF2~TKL_f+Regio_f+km1000+SF_f+Geschlecht_f+Alter_VN+Random, data=daten2, weights=daten2$Tage, controls=ctree_control(mincriterion=0.95,maxdepth=4,teststat=\quad\,testtype=\Bonferroni\)), type=\simple\)); //line 6 v.voidEval(dev.off()); }catch(RserveException e){e.printStackTrace();} I get the error-message voidEval failed for the line 6! What can I do? Although I know it`s a Java question I hope somebody can help me. Thanks, Max P.S. RServe is working at a simpler example. -- View this message in context: http://www.nabble.com/ctree-from-Java-via-Rserve-tp22492432p22492432.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mixed models fixed effects
Dear Emma, Have you tried a simpler model? False convergence can be due to an overcomplex model. Can you give a brief outline of your data? E.g. how many sites, how many data per site, ... Cross tabulations of all pairs of factor variables are usefull too. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: Emma Stone [mailto:emma.st...@bristol.ac.uk] Verzonden: vrijdag 13 maart 2009 10:50 Aan: ONKELINX, Thierry; Emma Stone; r-help@r-project.org Onderwerp: RE: [R] Mixed models fixed effects Hi Thierry, That's great thanks! I have done as you have said but I keep getting a warning message here is my code: G1Hvol-glmer(passes~hvolume+style+habitat(1|Site),family = poisson) And this is the message i get: Warning message: In mer_finalize(ans) : false convergence (8) any ideas?? Emma --On 11 March 2009 15:45 +0100 ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Hi Emma, Continuous predictors are no problem at all. You can mix both continuous and categorial predictors if needed. I suppose your response are counts (the number of bats that passes)? In that case a generalised linear mixed model is more appropriate. With the lme4 package you could try something like this: library(lme4) Model - glmer(BatPasses ~ Width + Height + (1|Site), family = poisson) HTH, Thierry PS There is a mailing list dedicated to mixed models: R-Sig-MixedModels ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Emma Stone Verzonden: woensdag 11 maart 2009 15:29 Aan: r-help@r-project.org Onderwerp: Re: [R] Mixed models fixed effects Dear All, This may sound like a dumb question but I am trying to use a mixed model to determine the predictors of bat activity along hedges within 8 sites. So my response is continuous (bat passes) my predictors fixed effects are continuous (height metres), width (metres) etc and the random effect is site - can you tell me if the fixed effects can be continuous as all the examples I have read show them as categorical, but this is not covered in any documents I can find. Help! Emma __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. -- Emma Stone Postgraduate Researcher Bat Ecology and Bioacoustics Lab Mammal Research Unit School of Biological Sciences, University of Bristol, Woodland Road, Bristol, BS8 1UG Email: emma.st...@bristol.ac.uk Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be
[R] cor.test(x,y)
Hi, I am not sure which test is applied to the data if you use cor.test(x, y) ? Is it an unpaired t-Test? Regards -- View this message in context: http://www.nabble.com/cor.test%28x%2Cy%29-tp22492993p22492993.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mixed models fixed effects
Hi Thierry, Thanks, my data are pasted in below: n = 48, with different numbers if site replicates. Site passes length width height ohwidth ohheight style shape nogap pgaps 1 1 32 38.21 7.18 2.600.00 0.00 1 1 0 0.00 2 1 7 154.38 2.55 2.430.00 0.00 2 1 0 0.00 3 2 24 130.00 2.73 4.965.83 2.27 1 2 0 1.92 4 2 43 130.00 2.73 4.963.45 2.45 1 2 0 1.91 5 2 32 130.00 3.30 4.343.67 2.63 3 2 0 0.00 6 2 9 130.00 3.30 4.342.13 1.53 2 2 0 0.00 7 2 25 214.00 1.65 6.232.80 2.53 3 2 0 0.00 8 2 1 214.00 2.20 1.050.00 0.00 2 1 0 0.00 9 2 57 188.00 5.87 4.973.23 2.13 2 2 0 0.00 102 32 211.00 2.63 6.094.37 2.50 2 2 0 0.00 112 14 211.00 2.63 6.093.50 2.53 2 2 0 0.00 123 78 192.00 2.30 2.400.33 0.88 2 2 0 2.19 133 11 192.00 2.50 2.500.13 0.55 2 2 0 2.19 143 9 444.00 2.10 1.930.00 0.00 2 1 2 6.19 154 40 44.00 1.83 2.050.00 0.00 1 1 1 31.81 164112 44.00 1.58 1.730.00 0.00 1 1 1 31.81 174 23 98.00 2.18 1.700.00 0.00 1 3 0 2.55 184 23 98.00 1.78 1.600.00 0.00 1 1 0 2.55 194 4 84.00 1.73 1.980.00 0.00 1 3 1 17.02 204 72 88.00 3.30 5.303.30 1.45 1 2 0 0.00 215207 116.00 3.08 3.383.65 3.68 1 2 0 0.00 225 2 116.00 2.85 2.183.18 3.53 1 2 0 0.00 235 81 104.00 2.68 2.781.00 0.75 2 1 0 0.00 245 3 104.00 2.68 2.380.00 0.00 2 1 0 0.00 255 21 59.00 2.78 4.032.23 1.75 2 2 0 6.78 265 1 59.00 2.78 3.331.38 1.35 2 2 0 6.78 276 82 165.56 2.50 4.001.00 1.33 1 2 0 0.00 286 1 165.56 2.60 3.630.50 1.40 1 2 0 0.00 296 46 69.35 3.23 10.674.73 4.67 1 2 0 0.00 306 7 165.56 3.50 10.172.67 1.67 1 2 0 0.00 316 45 136.00 3.33 3.670.00 0.00 1 2 0 2.20 326 3 136.00 3.33 2.750.00 0.00 1 2 0 3.30 336 34 82.00 2.83 12.003.33 3.83 1 2 0 0.00 347 0 228.00 2.57 2.700.30 1.00 2 2 0 0.50 357148 228.00 3.08 4.680.75 1.75 2 2 0 0.05 367 0 208.00 2.40 2.900.00 0.00 2 1 0 1.44 377 38 208.00 2.57 2.630.00 0.00 2 1 0 1.44 387 0 112.00 2.13 1.650.00 0.00 2 1 0 0.50 397 0 192.00 1.55 1.550.00 0.00 2 1 0 0.00 407 0 132.00 1.56 1.410.00 0.00 2 1 0 0.00 418 52 148.00 5.05 7.622.55 3.38 2 2 0 0.00 428 18 148.00 4.08 5.800.65 0.63 2 2 0 0.00 438 19 210.00 3.08 4.580.70 0.88 2 2 0 1.42 448 0 210.00 3.68 4.900.25 0.38 3 2 0 1.42 458 3 246.00 2.18 2.430.00 0.00 2 1 3 15.24 468 0 246.00 1.93 2.200.00 0.00 2 1 3 15.24 478 3 142.00 1.60 2.030.00 0.00 1 1 3 26.19 488 0 142.00 1.37 1.870.00 0.00 1 1 3 26.19 habitat side oharea hvolume 1120.00 713.30 2140.00 956.62 312 1720.43 1760.30 414 1098.83 1760.30 514 1254.77 1861.86 612 423.66 1861.86 711 1515.98 2199.81 8130.00 494.34 912 1293.42 5484.69 10 13 2305.18 3379.52 11 11 1868.41 3379.52 12 12 55.76 1059.84 13 14 13.73 1200.00 14 110.00 1799.53 15 110.00 165.07 16 130.00 120.27 17 120.00 363.19 18 140.00 279.10 19 140.00 287.73 20 12 421.08 1539.12 21 12 1558.11 1207.61 22 24 1302.15 720.71 23 22 78.00 774.84 24 140.00 663.35 25 12 230.25 661.00 26 14 109.92 546.19 27 13 220.19 1655.60 28 31 115.89 1562.56 29 11 1531.88 2390.09 30 13 738.22 5893.11 31 220.00 1662.07 32 440.00 1245.42 33 53 1045.82 2784.72 34 12 68.40 1582.09 35 14 299.25 3286.48 36 12
Re: [R] Map using projection
I think what you are missing is that the default map database is world. If you use: library(maps) require(mapproj) longlatLimit-c(-107,-93,40,52) par(plt=c(0,1,0,1),cex=1,cex.main=1) #Set plotting parameters map(regions=USA, projection=azequalarea, type=n,xlim=longlatLimit[1:2],ylim=longlatLimit[3:4]) bound-c(floor(longlatLimit[1]), ceiling(longlatLimit[2]), floor(longlatLimit[3]), ceiling(longlatLimit[4])) map.grid(lim=bound,col=light grey) I think you will get what you want (but what you want is not exactly clear). [I am not sure why this happens, but it seems to be an artifact of the projection code.] [All your examples have been very confusing, since you talk about plotting the states, but in fact your example code plots only a grid.] HTH Ray Brownrigg Dr. Alireza Zolfaghari wrote: Hi list, I have a real problem with plotting US state map. When I try to plot the northern state, there will be some blank space in the top of graph (see case 1 example), and when I plot southern states, there will be a blank space in the bottom of plot (see case 2). I spent almost 2 days to figure out a solution, but could not. Would you help me if you know what the problem is? Regards, Alireza # #case 1 library(maps) require(mapproj) longlatLimit-c(-107,-93,40,52) par(plt=c(0,1,0,1),cex=1,cex.main=1) #Set plotting parameters #map(projection=azequalarea, type=n,xlim=longlatLimit[1:2],ylim=longlatLimit[3:4]) map(projection=azequalarea, type=n,xlim=longlatLimit[1:2],ylim=longlatLimit[3:4]) bound-c(floor(longlatLimit[1]), ceiling(longlatLimit[2]), floor(longlatLimit[3]), ceiling(longlatLimit[4])) map.grid(lim=bound,col=light grey) # #case 2 library(maps) require(mapproj) longlatLimit-c(-107,-93,25,37) par(plt=c(0,1,0,1),cex=1,cex.main=1) #Set plotting parameters #map(projection=azequalarea, type=n,xlim=longlatLimit[1:2],ylim=longlatLimit[3:4]) map(projection=azequalarea, type=n,xlim=longlatLimit[1:2],ylim=longlatLimit[3:4]) bound-c(floor(longlatLimit[1]), ceiling(longlatLimit[2]), floor(longlatLimit[3]), ceiling(longlatLimit[4])) map.grid(lim=bound,col=light grey) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Selecting / creating unique colours for behavioural / transitional data
Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to combine xtable and minipage with Sweave ?
Hello, I'm trying to put a dynamic table and a dynamic graph side by side in a pdf document using Sweave. The data.frame used to generate the table is called rg (rg.txt): Date; Code; Data1; Data2 2009-03-10;1;1958;147 2009-03-10;2;302;144 2009-03-10;3;4;141 2009-03-10;4;4;144 2009-03-10;5;217;145 2009-03-10;6;133;147 2009-03-10;7;431;144 2009-03-10;8;177;142 2009-03-10;9;146;143 2009-03-10;10;123;142 2009-03-10;11;308;143 2009-03-10;12;115;144 2009-03-10;13;146;142 2009-03-10;14;124;143 2009-03-10;15;176;142 2009-03-10;16;177;143 The Sweave script to test, saved as test_minipage_sweave.rnw, is the following one (I'm a newbie in Latex and R so I pasted some commands I found here and there) : -- \documentclass[a4paper]{article} \usepackage[T1]{fontenc} \usepackage[frenchb]{babel} \usepackage{geometry} \usepackage{color, pdfcolmk} \usepackage[mediumqspace]{SIunits} \geometry{a4paper,left=1cm,right=1cm,top=1cm,bottom=1.5cm} \date{} \begin{document} \DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom = {\color[rgb]{0, 0, 0.56}}} \DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom = {\color[rgb]{0.56, 0, 0}}} \setkeys{Gin}{width=\textwidth} echo=FALSE, results=TEX= rg-read.table(file=d:/RWork/rg.txt, sep=;, dec=., header=T, as.is=T) @ \begin{figure}[ht] \begin{minipage}[b]{0.5\linewidth} \centering RsingleA,echo=F,fig=T,width=2.5,height=2.5= plot(1:10) @ \caption{First figure} \label{fig:figure1} \end{minipage} \end{figure} \hspace{0.5cm} \begin{minipage}{0.7\textwidth} echo=FALSE, results=TEX= library(xtable) print(xtable(kw), include.rownames=F) @ \end{minipage} \end{document} -- The following commands : Sweave(D:/RWork/test_minipage_sweave.rnw) shell(pdflatex D:/RWork/test_minipage_sweave.tex) give me a .pdf file containing the graph but instead of the table I have this text, below the graph : echo=FALSE, results=TEX = library(xtable) print(xtable(kw), include.rownames=F) @ It means that it doesn't recognize a R command but I don't kno why. And it is a problem with minipage because I managed to create a pdf file with only the table. Could someone give me a solution or at least a working example which I can modify ? Thanks in advance, Have a nice week-end, Ptit Bleu. -- View this message in context: http://www.nabble.com/How-to-combine-xtable-and-minipage-with-Sweave---tp22493636p22493636.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mixed models fixed effects
Dear Emma, First of all make shure that style and habitat are factors (assuming that they are categorical). glmer(passes~hvolume+style+habitat(1|Site),family = poisson) Style has 3 levels, habitat 5 levels. So your model needs to estimate 1 parameter for hvolume, 2 for style, 4 for habitat and 1 for site. In total 8 parameters. A rule of thumbs tells you that you need about 10 samples for each parameter. Hence you dataset (n = 48) is to small for this kind of model. Aditionally the variable habitat has some rare levels. Only one occures of levels 3 and 5, and just a few more for levels 2 and 4. This kind of data won't give you reliable estimates for habitat. So I would suggest to drop this from your model. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: Emma Stone [mailto:emma.st...@bristol.ac.uk] Verzonden: vrijdag 13 maart 2009 11:08 Aan: ONKELINX, Thierry; Emma Stone; r-help@r-project.org Onderwerp: RE: [R] Mixed models fixed effects Hi Thierry, Thanks, my data are pasted in below: n = 48, with different numbers if site replicates. Site passes length width height ohwidth ohheight style shape nogap pgaps 1 1 32 38.21 7.18 2.600.00 0.00 1 1 0 0.00 2 1 7 154.38 2.55 2.430.00 0.00 2 1 0 0.00 3 2 24 130.00 2.73 4.965.83 2.27 1 2 0 1.92 4 2 43 130.00 2.73 4.963.45 2.45 1 2 0 1.91 5 2 32 130.00 3.30 4.343.67 2.63 3 2 0 0.00 6 2 9 130.00 3.30 4.342.13 1.53 2 2 0 0.00 7 2 25 214.00 1.65 6.232.80 2.53 3 2 0 0.00 8 2 1 214.00 2.20 1.050.00 0.00 2 1 0 0.00 9 2 57 188.00 5.87 4.973.23 2.13 2 2 0 0.00 102 32 211.00 2.63 6.094.37 2.50 2 2 0 0.00 112 14 211.00 2.63 6.093.50 2.53 2 2 0 0.00 123 78 192.00 2.30 2.400.33 0.88 2 2 0 2.19 133 11 192.00 2.50 2.500.13 0.55 2 2 0 2.19 143 9 444.00 2.10 1.930.00 0.00 2 1 2 6.19 154 40 44.00 1.83 2.050.00 0.00 1 1 1 31.81 164112 44.00 1.58 1.730.00 0.00 1 1 1 31.81 174 23 98.00 2.18 1.700.00 0.00 1 3 0 2.55 184 23 98.00 1.78 1.600.00 0.00 1 1 0 2.55 194 4 84.00 1.73 1.980.00 0.00 1 3 1 17.02 204 72 88.00 3.30 5.303.30 1.45 1 2 0 0.00 215207 116.00 3.08 3.383.65 3.68 1 2 0 0.00 225 2 116.00 2.85 2.183.18 3.53 1 2 0 0.00 235 81 104.00 2.68 2.781.00 0.75 2 1 0 0.00 245 3 104.00 2.68 2.380.00 0.00 2 1 0 0.00 255 21 59.00 2.78 4.032.23 1.75 2 2 0 6.78 265 1 59.00 2.78 3.331.38 1.35 2 2 0 6.78 276 82 165.56 2.50 4.001.00 1.33 1 2 0 0.00 286 1 165.56 2.60 3.630.50 1.40 1 2 0 0.00 296 46 69.35 3.23 10.674.73 4.67 1 2 0 0.00 306 7 165.56 3.50 10.172.67 1.67 1 2 0 0.00 316 45 136.00 3.33 3.670.00 0.00 1 2 0 2.20 326 3 136.00 3.33 2.750.00 0.00 1 2 0 3.30 336 34 82.00 2.83 12.003.33 3.83 1 2 0 0.00 347 0 228.00 2.57 2.700.30 1.00 2 2 0 0.50 357148 228.00 3.08 4.680.75 1.75 2 2 0 0.05 367 0 208.00 2.40 2.900.00 0.00 2 1 0 1.44 377 38 208.00 2.57 2.630.00 0.00 2 1 0 1.44 387 0 112.00 2.13 1.650.00 0.00 2 1 0 0.50 397 0 192.00 1.55 1.550.00 0.00 2 1 0 0.00 407 0 132.00 1.56 1.410.00 0.00 2 1 0 0.00 418 52 148.00 5.05 7.622.55
[R] Taking diff of character vectors
Hello, everybody Say I have nm1 - c(rep(1,10), rep(0,10)) then I can do: diff(nm1) to see where I have shift in value but what if I have nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) how can I produce the same ouput as diff(nm1) does, that is zeros everywhere except for one place where SPZ8 changes to SPX9 (there should be 1 there)? What if I have a matrix of characters like that: nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) How can I efficiently create two more columns that contain zeros everywhere except for place where there is shift in character values? Thanks for help! Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any difference between - and =
Sean Zhang wrote: Dear Jens and Wacek: I appreciate your answers very much. I came up an example based on your comments. I feel the example helped me to understand...(I could be missing your points though :( ) If so, please let me know. Simon pointed out the following link: http://www.stat.auckland.ac.nz/mail/archive/r-downunder/2008-October/000300.html I am still trying to understand it... My question is how my conclusion (see at the end of the example below) drawn from lexical scope perspective is related to an understanding from an environment perspective (if an understanding from environment perspective validly exists). Thank you all again very much! -Sean Zhang #My little example is listed below f1-function(a=1,b=2) {print(a); print(b); print(a-b) } f1() #get 3, makes sense -1? f1(2,) #get 0, makes sense a - 10 b - 20 f1(a=a+1,b=a) a #get 10 a is not changed outside function scope b #get 20, b is not changed outside function scope a - 10 b - 20 f1(a - a+1, b - a) this is what you *really* shouldn't do unless you know what you're doing. here you have not only the issue of whether the assignment will actually be made, but also the issue of the order of evaluation of the argument expressions, which depends on the when the arguments are used within the function. f = function(a, b, c) if (c) a-b else b-a a=1; b=1; f(a - a+1, b - a, TRUE) # 0 a # 2 b # 2 a=1; b=1; f(a - a+1, b - a, FALSE) # -1 a # 2 b # 1 a #a is now 11, a is changed outside function b #b is now 11 b is changed outside function a - 10 b - 20 f1({a=a+1},{b = a}) a #a is changed into 11 b #b is changed into a(i.e., 11) a - 10 b - 20 f1((a=a+1),(b = a)) a #a is changed into 11 b #b is changed into a(i.e., 11) #my conclusion based on testing the example above is below #say argument is a, when used inside paraenthesis of whatever.fun-function() #a-something, (a=something) , and {a-something} #are the same. They all change the values outside the function's scope. #Typically, this breaks the desired lexical scope convention. so it is dangerous. i don't think you break lexical scoping here. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Taking diff of character vectors
2009/3/13 Sergey Goriatchev serg...@gmail.com: Say I have nm1 - c(rep(1,10), rep(0,10)) then I can do: diff(nm1) to see where I have shift in value but what if I have nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) how can I produce the same ouput as diff(nm1) does, that is zeros everywhere except for one place where SPZ8 changes to SPX9 (there should be 1 there)? What if I have a matrix of characters like that: nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) How can I efficiently create two more columns that contain zeros everywhere except for place where there is shift in character values? You could convert to factor and then to numeric: nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) diff(as.numeric(as.factor(nm2))) [1] 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 It might be that your character values should really be factors anyway - check out some R docs on what factors are and what they can do for you. That also means you might want your matrix to be a data frame, since a matrix can't contain your character values and numeric 0/1 values. Data frames can! If you try it with a matrix you end up getting character zeroes and minus ones: matr - cbind(nm2, nm3) matr = cbind(matr,c(0,diff(as.numeric(as.factor(matr[,1]) matr[8:12,] nm2nm3 [1,] SPZ8 GLF10 0 [2,] SPZ8 GLF10 0 [3,] SPZ8 GLF10 0 [4,] SPX9 GLF10 -1 [5,] SPX9 GLF10 0 Easier with factors in data frames: df=data.frame(nm2=as.factor(nm2),nm3=as.factor(nm3)) df$dnm2 = c(0,diff(as.numeric(df$nm2))) df[8:12,] nm2 nm3 dnm2 8 SPZ8 GLF100 9 SPZ8 GLF100 10 SPZ8 GLF100 11 SPX9 GLF10 -1 12 SPX9 GLF100 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mixed models fixed effects
Hi Thierry, Thanks again! You are a great help!! I have taken habitat out, and then run it with style but still the same problem exists, so I have taken both style and habitat out. The problem here is it leaves me with only 3 parameters and because they are all correlated I cant use them in the same models, so I just have 3 single models (one for each parameter) - which isnt ideal. G3Pgaps-glmer(passes~pgaps+(1|Site),family=poisson) C1Hvol-glmer(passes~hvolume+(1|Site)) C2OHArea-glmer(passes~oharea+(1|Site)) Also, when I run the C1 and C2 model, it wont work if I state family poisson. Is there anyway I can get rid of the correlations in the parameters so that I can use them in the same model? Or is there another option to boost n, ie bootsrapping?? Thanks again Emma --On 13 March 2009 11:21 +0100 ONKELINX, Thierry thierry.onkel...@inbo.be wrote: poisson -- Emma Stone Postgraduate Researcher Bat Ecology and Bioacoustics Lab Mammal Research Unit School of Biological Sciences, University of Bristol, Woodland Road, Bristol, BS8 1UG Email: emma.st...@bristol.ac.uk __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taking diff of character vectors
Hi: For A, you can use head and tail but you have to add a zero the front. For B, you can use the same function, but put it inside an sapply and run over the columns and then cbind it back with the original dataframe. A) nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) -1.0*c(0,as.numeric((head(nm2,-1) != tail(nm2,-1 B) nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) temp-as.data.frame(sapply(1:ncol(matr), function(.col) { -1.0*c(0,as.numeric((head(matr[,.col],-1) != tail(matr[,.col],-1 })) cbind(matr,temp) On Fri, Mar 13, 2009 at 5:24 AM, Sergey Goriatchev wrote: Hello, everybody Say I have nm1 - c(rep(1,10), rep(0,10)) then I can do: diff(nm1) to see where I have shift in value but what if I have nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) how can I produce the same ouput as diff(nm1) does, that is zeros everywhere except for one place where SPZ8 changes to SPX9 (there should be 1 there)? What if I have a matrix of characters like that: nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) How can I efficiently create two more columns that contain zeros everywhere except for place where there is shift in character values? Thanks for help! Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ r-h...@r-project.org mailto:R-help@r-project.org  mailing list https://stat.ethz.ch/mailman/listinfo/r-help https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] COURSE: R and S-PLUS 1 day introduction, UK, 29 April 2009
== Course: 1 day introduction to R and S-PLUS Location: Basingstoke, UK Date: Wednesday 29 April 2009 Cost: 500 GBP == Details: SP411: An introduction to R and TIBCO Spotfire S-PLUS This course will give an introduction to the S language, as implemented in both S-PLUS and R. Attendees will gain a basic understanding of the S language so that they can start to load, process, visualise and analyse their own data. The Graphical User Interfaces for S-PLUS and R will not be discussed. No prior knowledge of R or S-PLUS will be assumed. Duration: 1 day. For further details, and to register, go to: http://inter.viewcentral.com/reg/TIBCO/RandSPlusIntro - Andrew Jack Spotfire Division, TIBCO Software, Ltd aj...@tibco.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to combine xtable and minipage with Sweave ?
Ptit_Bleu ptit_bleu at yahoo.fr writes: I'm trying to put a dynamic table and a dynamic graph side by side in a pdf document using Sweave. The data.frame used to generate the table is called rg (rg.txt): Date; Code; Data1; Data2 2009-03-10;1;1958;147 2009-03-10;2;302;144 ... The Sweave script to test, saved as test_minipage_sweave.rnw, is the following one (I'm a newbie in Latex and R so I pasted some commands I found here and there) : 1) There were typos in your code. It should be print(xtable(rg), include.rownames=F) and it should be results=tex, not TEX 2) must start at column 0, this is the first error 3) Check about the rules of minipage and floats. See the sequence for the figure in the tex code; this gives the typical Not in outer mode error Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] pairs of numbers
Hi, I have two lists of numbers which are both 1,2,3,4. I would like to combine pairs so that I have: 1,2 1,3 1,4 2,3 2,4 3,4. I know that expand.grid() can give me all combinations of pairs. Any suggestions would be much appreciated. Emma -- View this message in context: http://www.nabble.com/pairs-of-numbers-tp22494116p22494116.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] pairs of numbers
I have solved my problem using: x-1:4 x [1] 1 2 3 4 combn(x,2) [,1] [,2] [,3] [,4] [,5] [,6] [1,]111223 [2,]234344 Thanks Emma emj83 wrote: Hi, I have two lists of numbers which are both 1,2,3,4. I would like to combine pairs so that I have: 1,2 1,3 1,4 2,3 2,4 3,4. I know that expand.grid() can give me all combinations of pairs. Any suggestions would be much appreciated. Emma -- View this message in context: http://www.nabble.com/pairs-of-numbers-tp22494116p22494346.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plots not loading
On Thu, Mar 12, 2009 at 01:25:40PM -0700, Atul Joshi wrote: When I run my .r script using source (myfilename) from console the plots appear. However, when I execute the same file via terminal command line using R CMD BATCH myfilename, the plots do not appear. I am working with Mac. Am I doing something wrong? In BATCH mode it does not make much sense to display plots on the screen because the script may be running on a system without screen (cluster). So R uses a different default device. On my LINUX system it's pdf, so all my plots go to Rplots.pdf unless I explicitly send them somewhere else. I don't know about the defaults on Macs but you should be able to find the file in the current directory easily. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Taking diff of character vectors
Fabulous, guys! Let me try your suggestions. Thanks a lot! Best, SErgey On Fri, Mar 13, 2009 at 11:53, markle...@verizon.net wrote: Hi: For A, you can use head and tail but you have to add a zero the front. For B, you can use the same function, but put it inside an sapply and run over the columns and then cbind it back with the original dataframe. A) nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) -1.0*c(0,as.numeric((head(nm2,-1) != tail(nm2,-1 B) nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) temp-as.data.frame(sapply(1:ncol(matr), function(.col) { -1.0*c(0,as.numeric((head(matr[,.col],-1) != tail(matr[,.col],-1 })) cbind(matr,temp) On Fri, Mar 13, 2009 at 5:24 AM, Sergey Goriatchev wrote: Hello, everybody Say I have nm1 - c(rep(1,10), rep(0,10)) then I can do: diff(nm1) to see where I have shift in value but what if I have nm2 - c(rep(SPZ8, 10), rep(SPX9, 10)) how can I produce the same ouput as diff(nm1) does, that is zeros everywhere except for one place where SPZ8 changes to SPX9 (there should be 1 there)? What if I have a matrix of characters like that: nm3 - c(rep(GLF9, 4), rep(GLF10, 16)) matr - cbind(nm2, nm3) How can I efficiently create two more columns that contain zeros everywhere except for place where there is shift in character values? Thanks for help! Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] print median and sd...
Where do you want to print it? Is it the console (if so, try 'print(median)') or if it is the plot, use 'text' with the appropriate parameters. It would help if you listed the I tried many things but without success... and what you were expecting vs. what you got. Reproducible code would be useful (and required). On Thu, Mar 12, 2009 at 10:42 PM, johnhj jhar...@web.de wrote: Hii, Can anybody help me, I don't know how to print the median. Below is my code snipplet... x -read.table(file=D:/Uni/Diplom/Diplom/Grafiken/R/BATMAN/Kabel/Batman1hop/Standardabweichung__output_30_1_Kabel(30m)_b.txt) png(filename = D:/Grafiken/R/Standardabweichung/Kopie.png, width = 640, height = 480,pointsize = 12, bg = white, res = NA) median-with(x, tapply(V3, grup, median)) ??? dev.off() I will print, the median values with a simple line.. I tried many things but without success... I would be very appreciate, if anyone could help me... greetings, John -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22489185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. Kingsford Jones wrote: Try #install.packages('RColorBrewer') example(brewer.pal, pack='RColorBrewer') hth, Kingsford Jones On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] code to find all distinct subsets of size r from a set of size n
I'm doing a permutation test and need to efficiently generate all distinct subsets of size r from a set of size n. P 138 of MASS (4th ed) notes that The code to generate this efficiently is in the scripts. I was unable to find this code on quick inspection of the \library\MASS\scripts file for Chapter 5 and 'subsets' is not a function in MASS. I did find this problem is discussed in RNews, Programmer's Niche 1(1):27 - 30 and RNews, 1(2):29-31. Is there function in 'base' R or other package to do this? Thanks. --Dale __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R multiline expression grief
Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? Thank you, Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Unable to run smoother in qplot() or ggplot() - complains about knots
From: Christopher David Desjardins cddesjard...@gmail.com To: r-help@r-project.org Date: Thu, 12 Mar 2009 17:37:26 -0500 Subject: [R] Unable to run smoother in qplot() or ggplot() - complains about knots I get the following error when I run qplot() qplot(grade, read,data = hhm.long.m, geom = c(point, smooth)) Error in smooth.construct.cr.smooth.spec(object, data, knots) : x has insufficient unique values to support 10 knots: reduce k. I am not sure how to tackle this problem. When I take a subsample ( 1000) than I am able to run that function but with my sample of ~ 40,000 qplot gives me that error. I have 6 grades. Please cc me on reply. Hi Chris, Have you read the documentation for stat_smooth? It's not clear to me what the problem is, because I'm not sure what the defaults are. But since the default's are not working, I would try it with different settings. See http://had.co.nz/ggplot2/stat_smooth.html. -Ista Thanks! Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting / creating unique colours for behavioural / transitional data
One option for creating your own palette is #install.packages('epitools') mycols - colors.plot(locator = TRUE) then left-click on 15 colors of your liking and then right-click 'Stop'. mycols will be a data.frame with the third column containing the color names. Kingsford On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. Kingsford Jones wrote: Try #install.packages('RColorBrewer') example(brewer.pal, pack='RColorBrewer') hth, Kingsford Jones On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
This is a perfectly legal expression: f - a + b + c; Type it in a the console, and it will assign a to f and then print out the values of b and c. In parsing 'f - a' that is a complete expression. You may be confused since you think that semicolons terminate an expression; that is not the case in R. If you write 'f - a +' and then continue on the next line, R recognizes that the parsing of the expression is not complete and will continue looking. So it is not a bug; just a misunderstanding of what the syntax is and how it works. There are similar questions when people type in the following type of statements: if (1 == 1) print (TRUE) else print (FALSE) At the console you get: if (1 == 1) print (TRUE) [1] TRUE else print (FALSE) Error: unexpected 'else' in else No suitable frames for recover() because the parsing of the 'if' is complete. Instead you should be doing: if (1 == 1) {print (TRUE) + } else {print (FALSE)} [1] TRUE so the parse knows that the initial 'if' is not complete on the single line. On Fri, Mar 13, 2009 at 8:55 AM, Paul Suckling paul.suckl...@gmail.com wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? Thank you, Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
On Fri, 13 Mar 2009, Paul Suckling wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. That is most unfortunate for you. Is this behaviour a bug? No. If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? No. R is not ignoring several lines of an expression. f - a + b + c; is three perfectly legitimate expressions over three lines. R evaluates f-a then evaluates +b then evaluates +c For people who like semicolons, it's the same as if you had f - a; +b; +c; The semicolons are just an alternative to a newline, so a semicolon at the end of a line is purely cosmetic. Modifying the parser to require a semicolon to terminate a statement would break essentially every piece of R code and documentation in existence, so it's probably easier to change your house style. You could fairly easily write a tool that parsed your scripts and checked that all your expressions were either assignments or function calls and that the top-level expressions did not include unary plus or minus. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cor.test(x,y)
Did you read the help for cor.test? Test statistics, references looks pretty complete to me. If the descriptions are too terse, then the references given would be the next step. Sarah Excerpted from ?cor.test If 'method' is 'pearson', the test statistic is based on Pearson's product moment correlation coefficient 'cor(x, y)' and follows a t distribution with 'length(x)-2' degrees of freedom if the samples follow independent normal distributions. If there are at least 4 complete pairs of observation, an asymptotic confidence interval is given based on Fisher's Z transform. If 'method' is 'kendall' or 'spearman', Kendall's tau or Spearman's rho statistic is used to estimate a rank-based measure of association. These tests may be used if the data do not necessarily come from a bivariate normal distribution. For Kendall's test, by default (if 'exact' is NULL), an exact p-value is computed if there are less than 50 paired samples containing finite values and there are no ties. Otherwise, the test statistic is the estimate scaled to zero mean and unit variance, and is approximately normally distributed. For Spearman's test, p-values are computed using algorithm AS 89. References: D. J. Best D. E. Roberts (1975), Algorithm AS 89: The Upper Tail Probabilities of Spearman's rho. _Applied Statistics_, *24*, 377-379. Myles Hollander Douglas A. Wolfe (1973), _Nonparametric Statistical Methods._ New York: John Wiley Sons. Pages 185-194 (Kendall and Spearman tests). On Fri, Mar 13, 2009 at 5:37 AM, mentor_ ment...@gmx.net wrote: Hi, I am not sure which test is applied to the data if you use cor.test(x, y) ? Is it an unpaired t-Test? Regards -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Many thanks yet again for your reply, thanks for that method, i gave it a go and i checked 'mycols' and sure enough it had selected the chosen colours and listed their names, but when i used it for making the graph warnigs informed me that the supplied colour in not numeric or character. Ross Kingsford Jones wrote: One option for creating your own palette is #install.packages('epitools') mycols - colors.plot(locator = TRUE) then left-click on 15 colors of your liking and then right-click 'Stop'. mycols will be a data.frame with the third column containing the color names. Kingsford On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. Kingsford Jones wrote: Try #install.packages('RColorBrewer') example(brewer.pal, pack='RColorBrewer') hth, Kingsford Jones On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496241.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
Paul Suckling wrote: ... # R-script... r_parse_error - function () { ... f - a + b + c; } ... f 1 As far as I am concerned f should have the value 3. as far as you intend, perhaps. note, the above snippet says: f - a; +b; +c not f - a + b + c This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? clearly not. and it's hardly idiosyncratic to r. you'd have the same behaviour in, e.g., python, though there you can explicitly demand that the lines form a single statement by ending the first two with a backslash. there have been similar discussions on mailing lists of a number of programming/scripting languages. If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, they're not ignored! you demand to compute +b and +c, and it's certainly done. (i don't think r is smart enough to optimize these away). perhaps by turning on a strict mode which requires the semi-colons? that's an idea, but the proposed solution would have to be optional to avoid annoying those who don't like semiquotes in r code. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting / creating unique colours for behavioural / transitional data
Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. I'll think you'll find it very challenging to create 15 distinguishable colours - there's a good reason the colorbrewer colours only go up to 12. Because you could describe your plot more fully - it might be possible to display your data in a way that doesn't require quite so many colours. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] code to find all distinct subsets of size r from a set of size n
For permutations a couple of options are 'permutations' in package gtools, and 'urnsamples' in package prob hth, Kingsford Jones On Fri, Mar 13, 2009 at 6:35 AM, Dale Steele dale.w.ste...@gmail.com wrote: I'm doing a permutation test and need to efficiently generate all distinct subsets of size r from a set of size n. P 138 of MASS (4th ed) notes that The code to generate this efficiently is in the scripts. I was unable to find this code on quick inspection of the \library\MASS\scripts file for Chapter 5 and 'subsets' is not a function in MASS. I did find this problem is discussed in RNews, Programmer's Niche 1(1):27 - 30 and RNews, 1(2):29-31. Is there function in 'base' R or other package to do this? Thanks. --Dale __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
I get it. Thanks everyone for the feedback. Now that I understand how it works, my comment would be that this system is dangerous since it makes it difficult to read the code and easy to make errors when typing it. I recognise that this is something so fundamental that it is unlikely to be changed so I'll have to adapt to it. My feeling is that such confusion could be avoided however, by introducing a line continuation character (or group of characters) into R that could be used to indicate to the parser (and reader of the code) that the expression continues onto the next line. Something like f - a ... + b ... + c Cheers, Paul 2009/3/13 Paul Suckling paul.suckl...@gmail.com: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? Thank you, Paul -- Nashi Power. http://nashi.podzone.org/ Registered address: 7 Trescoe Gardens, Harrow, Middx., U.K. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting / creating unique colours for behavioural / transitional data
Hi Oliver, Thanks very much for your reply. I have tried your script, but when the script for the graph runs it comes up with several error messages repeating that 'supplied colour is not numeric or character' Olivier Delaigue wrote: library(colorRamps) image(matrix(1:150, 10), col = blue2green2red(15)) Regards, Olivier Delaigue Ross Culloch wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496355.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
jim holtman wrote: if (1 == 1) {print (TRUE) + } else {print (FALSE)} [1] TRUE so the parse knows that the initial 'if' is not complete on the single line. ... and likewise the original code could be rewritten as f - { a + b + c } vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part: http://batchfiles.googlecode.com On Fri, Mar 13, 2009 at 8:55 AM, Paul Suckling paul.suckl...@gmail.com wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? Thank you, Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unable to run smoother in qplot() or ggplot() - complains about knots
On Thu, Mar 12, 2009 at 5:37 PM, Christopher David Desjardins cddesjard...@gmail.com wrote: I get the following error when I run qplot() qplot(grade, read,data = hhm.long.m, geom = c(point, smooth)) Error in smooth.construct.cr.smooth.spec(object, data, knots) : x has insufficient unique values to support 10 knots: reduce k. I am not sure how to tackle this problem. When I take a subsample ( 1000) than I am able to run that function but with my sample of ~ 40,000 qplot gives me that error. I have 6 grades. You have 6 values on the x-axis? Maybe you want to just calculate the mean at each grade. If so, see http://had.co.nz/ggplot2/stat_summary.html Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
On Fri, Mar 13, 2009 at 7:19 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Many thanks yet again for your reply, thanks for that method, i gave it a go and i checked 'mycols' and sure enough it had selected the chosen colours and listed their names, but when i used it for making the graph warnigs informed me that the supplied colour in not numeric or character. The data frame holds is storing the colors as class factor. You'll need to convert to character. Note mycols - colors.plot(T) str(mycols$color.names) Factor w/ 4 levels blue,green,..: 3 4 2 1 str(as.character(mycols$color.names)) chr [1:4] tomato1 yellow1 green blue hth, Kingsford Ross Kingsford Jones wrote: One option for creating your own palette is #install.packages('epitools') mycols - colors.plot(locator = TRUE) then left-click on 15 colors of your liking and then right-click 'Stop'. mycols will be a data.frame with the third column containing the color names. Kingsford On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. Kingsford Jones wrote: Try #install.packages('RColorBrewer') example(brewer.pal, pack='RColorBrewer') hth, Kingsford Jones On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496241.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
Re: [R] How to combine xtable and minipage with Sweave ?
Hello Dieter, And thank you for the corrections. Concerning the point 3, I'm a bit lost. Is it a problem of place to put the table and the graph side by side (my english is quite as low as my skills in Latex) ? I tried with \begin{minipage}{0.45\textwidth} instead of 0.7 and I put //tiny but no success. I tried to add some \begin{table} before \begin{minipage}[b]{0.45\linewidth} as I saw here : http://texblog.wordpress.com/2007/08/01/placing-figurestables-side-by-side-minipage/ http://texblog.wordpress.com/2007/08/01/placing-figurestables-side-by-side-minipage/ Again ! LaTeX Error: Not in outer par mode. Could you give me a last clue so that I can spend a nice week-end. Thanks in advance, Ptiti Bleu. last script : \documentclass[a4paper]{article} \usepackage[T1]{fontenc} \usepackage[frenchb]{babel} \usepackage{geometry} \usepackage{color, pdfcolmk} \usepackage[mediumqspace]{SIunits} \geometry{a4paper,left=1cm,right=1cm,top=1cm,bottom=1.5cm} \date{} \begin{document} \DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom = {\color[rgb]{0, 0, 0.56}}} \DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom = {\color[rgb]{0.56, 0, 0}}} \setkeys{Gin}{width=\textwidth} echo=FALSE, results=tex= rg-read.table(file=d:/RWork/rg.txt, sep=;, dec=., header=T, as.is=T) @ \begin{figure}[ht] \begin{minipage}[b]{0.45\linewidth} \centering RsingleA,echo=F,fig=T,width=2.5,height=2.5= plot(1:10) @ \caption{First figure} \label{fig:figure1} \end{minipage} \end{figure} \hspace{0.5cm} \begin{minipage}{0.45\textwidth} echo=FALSE, results=tex= library(xtable) print(xtable(rg), include.rownames=F, size=\\tiny) @ \end{minipage} \end{document} -- View this message in context: http://www.nabble.com/How-to-combine-xtable-and-minipage-with-Sweave---tp22493636p22496502.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Hi Hadley, Many thanks for your post. You're not wrong - i'm certainly finding it challenging, but i assumed it was because i was making some basic errors. My data are 15 types of behaviour, e.g. resting, alert, locomotion, etc. so i need to use 15 colours to tell each appart in a barplot which esentially colour codes the sequence of behaviours. Therefore i need all colours to be individually identifiable with no possible confusion between the 15. As you touched on colourbrewer and other packages typically use gradients for changes in terrain, etc, which is not what i need, and as yousay, they only go up to 12. But what is frustrating is that there are 657 colours, and i can see that i could pick out 15 colours that are all very different, but i can physically work out how i can do that. I that makes sense? hadley wrote: Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. I'll think you'll find it very challenging to create 15 distinguishable colours - there's a good reason the colorbrewer colours only go up to 12. Because you could describe your plot more fully - it might be possible to display your data in a way that doesn't require quite so many colours. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22496516.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Hi Kingsford, Thanks yet again for your help! I have tried this, and once again i have failed! I have put the code that i've used below (i'm sure you'll note some bad practice) if that is any use to help explain where i'm going wrong, it seems to run fine and feeds back just what you noted it would, but i still get the error message as before - if you have any more suggestions i'd be very greatful, i'm sure it is down to me missing something very simple! Thanks again, Ross mycols - colors.plot(T) str(mycols$color.names) Factor w/ 15 levels slategray2,snow3,..: 9 10 11 12 13 14 15 1 2 3 ... ##Factor w/ 4 levels blue,green,..: 3 4 2 1 str(as.character(mycols$color.names)) chr [1:15] tomato1 tomato4 turquoise1 violet violetred4 wheat3 ... ##chr [1:4] tomato1 yellow1 green blue attach(dd) seqiplot(data.seq[1:4,], withlegend=FALSE, ylab=Seal ID, + axes = F, title = 30-09-2008, cpal=mycols) There were 12 warnings (use warnings() to see them) y.lab.pos - c(0.7, 1.9, 3.1, 4.3) axis(2, at=y.lab.pos, labels=paste(ID[1:4], sep=), tick=FALSE) detach(dd) Kingsford Jones wrote: On Fri, Mar 13, 2009 at 7:19 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Many thanks yet again for your reply, thanks for that method, i gave it a go and i checked 'mycols' and sure enough it had selected the chosen colours and listed their names, but when i used it for making the graph warnigs informed me that the supplied colour in not numeric or character. The data frame holds is storing the colors as class factor. You'll need to convert to character. Note mycols - colors.plot(T) str(mycols$color.names) Factor w/ 4 levels blue,green,..: 3 4 2 1 str(as.character(mycols$color.names)) chr [1:4] tomato1 yellow1 green blue hth, Kingsford Ross Kingsford Jones wrote: One option for creating your own palette is #install.packages('epitools') mycols - colors.plot(locator = TRUE) then left-click on 15 colors of your liking and then right-click 'Stop'. mycols will be a data.frame with the third column containing the color names. Kingsford On Fri, Mar 13, 2009 at 6:38 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Hi Kingsford, Thanks for the reply - some of the sets/palettes in the RColorBrewer are ideal, but the problem with the problem i have is that they only go up to 12 colours, and i need 15 colours - so i assume the only thing i can do is create my own palette, but i'm having limited success in trying to work out how to do this. Kingsford Jones wrote: Try #install.packages('RColorBrewer') example(brewer.pal, pack='RColorBrewer') hth, Kingsford Jones On Fri, Mar 13, 2009 at 3:20 AM, Ross Culloch ross.cull...@dur.ac.uk wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22492438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495482.html Sent from the R help mailing list archive at Nabble.com. __
Re: [R] R multiline expression grief
Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part: http://batchfiles.googlecode.com for the puts each statement on one line based on the semicolons part, it's enough to pass the program through a simple sed script, *provided* that each line not ending in a semicolon is not a complete line: sed -n '/;\s*$/!{H}; /;\s*$/{H;g;s/\n//g;s/;\s*$//;p;s/.//g;h}' input output (i guess this can be simplified.) vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
On 13-Mar-09 12:55:35, Paul Suckling wrote: Dear all. After much grief I have finally found the source of some weird discrepancies in results generated using R. It turns out that this is due to the way R handles multi-line expressions. Here is an example with R version 2.8.1: # R-script... r_parse_error - function () { a - 1; b - 1; c - 1; d - a + b + c; e - a + b + c; f - a + b + c; cat('a',a,\n); cat('b',b,\n); cat('c',c,\n); cat('d',d,\n); cat('e',e,\n); cat('f',f,\n); } r_parse_error(); a 1 b 1 c 1 d 3 e 3 f 1 As far as I am concerned f should have the value 3. This is causing me endless problems since case f is our house style for breaking up expressions for readability. All our code will need to be rechecked as a result. Is this behaviour a bug? If not, is it possible to get R to generate a warning that several lines of an expression are potentially being ignored, perhaps by turning on a strict mode which requires the semi-colons? Thank you, Paul The lines are not being ignored! In e - a + b + c; each line (until the last) is syntactically incomplete, so the R parser continues on to the next line until the expression is complete; and the ; is irrelevant for this purpose. Unlike C, but like (say) 'awk', the ; in R serves to terminate an expression when this is followed on the same line by another one, so it is basically a separator. In f - a + b + c; however, f - a is complete, so the value of 'a' is assigned to f. The line + b would have sent the value of 'b' (the + being the unary operator + which does not change anything) to the console if it did not occur inside a function definition. As it is, although + b is evaluated, because it is inside the function no putput is produced. Similarly for + c; (and, once again, the ; is irrelevant since a ; at the end of a line does nothing -- unless the line was syntatically incomplete at that point, in which case ; as the expression terminator would trigger a syntax error since an incomplete expression was being terminated. So f - a + b + c; is not a multiline expression. It is three expressions on three separate lines. The only suggestion I can make is that you have to change your house style -- it is at odds with the way the R parser works, and is bound to cause much grief. Best wishes, and good luck! Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 13-Mar-09 Time: 14:16:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
On Fri, Mar 13, 2009 at 10:11 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part: http://batchfiles.googlecode.com for the puts each statement on one line based on the semicolons part, it's enough to pass the program through a simple sed script, *provided* that each line not ending in a semicolon is not a complete line: sed -n '/;\s*$/!{H}; /;\s*$/{H;g;s/\n//g;s/;\s*$//;p;s/.//g;h}' input output (i guess this can be simplified.) One would want to be sure that a comment is not continued onto a code line. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any difference between - and =
I would argue that this is a matter of preference and the arguments on principle for one side or another are not particularly compelling. When the = was introduced for assignment, an argument was made that name=value function arguments are also implicitly a kind of assignment. While Duncan has pointed out a typical example of how this could be ambiguous, - also has its problems. A syntactic confusion with - arises in expressions like x-3 which could be read either as an assignment or as a logical expression comparing x to -3. Perhaps obviously ambiguous when written naked like this but when buried in a larger expression, it's easy to write an expression like that and discover that you have overwritten x. Some might (and have, most emphatically) advise that we should routinely insert spaces in our typing in a way that disambiguates such expressions but I find an argument that relies on spaces, which are usually syntactically unmeaningful, not very compelling. Besides, I just find that clumsy two-character arrow ugly! This is an esthetic matter -- reminds me too much of an emoticon. :-( For over 10 years I used the alternative _ underscore for S assignment (nice as a single character with no competing syntactic meaning) but that has gone away, as far as I can tell primarily due to discomfort (disdain?) of developers who find it unattractive because of the use of _ as a connecting special category in OTHER contexts (C and shell programming). However, a mutually satisfactory solution is at hand!! If growth in the number of R programmers continues exponentially at its current rate, by the year 2097 the number of R programmers will exceed the population of the earth. At that point they will rise up and demand the restoration of the APL arrow key (remembered by some doddering guru who heard about it from her grandfather) to the standard keyboard, and our problem will be solved. (But there will be a minor irritation because in the New Zealand keyboard that key code will have been assigned to the locally popular sheep icon.) Alan Zaslavsky __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R multiline expression grief
Gabor Grothendieck wrote: On Fri, Mar 13, 2009 at 10:11 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Gabor Grothendieck wrote: If all your code has semicolons you could write a program that puts each statement on one line based on the semicolons and then passing it through R will reformat it in a standard way. See Rtidy.bat in the batchfiles distribution for the reformatting part: http://batchfiles.googlecode.com for the puts each statement on one line based on the semicolons part, it's enough to pass the program through a simple sed script, *provided* that each line not ending in a semicolon is not a complete line: sed -n '/;\s*$/!{H}; /;\s*$/{H;g;s/\n//g;s/;\s*$//;p;s/.//g;h}' input output (i guess this can be simplified.) One would want to be sure that a comment is not continued onto a code line. of course; you'd have to handle comments separately. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Time-Ordered Clustering
Dear Ingmar, Thank you for your reply, I hope I answer your question --- A couple specific applications I have in mind: * We work with customers to reduce energy consumption from use of hot water. Baseline data was gathered at several locations by attaching a temperature sensor downstream from a hot water valve and recording the temperature every two minutes, over 10 days. Example questions: how many times was hot water used? What was the average duration? What were the average temperatures of the hot water? * We have products that have a 3-stage lifecycle: 1) ramp-up = 2) steady-state = 3) end of life. Performance is different in each stage. Data is gathered by attaching sensors to the product, and continuously monitoring. Example questions for each stage:What was the average duration? What was the average performance? I'm not very familiar with markov processes, and don't know what detail is necessary to specify a transition matrix. The processes have not been regular/predictable/cyclical enough to consider time series analyses. Thanks, Paul = Message: 123 Date: Fri, 13 Mar 2009 10:45:45 +0100 From: Ingmar Visser i.vis...@uva.nl Subject: Re: [R] Time-Ordered Clustering To: Prew, Paul paul.p...@ecolab.com Cc: r-help@r-project.org Message-ID: 38589632-d0db-4466-8a69-887b9beef...@uva.nl Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Dear Paul, Could you be more specific about what you mean here? I don't know the Runger paper so it's hard to tell what it is that you're looking for. Blatant plug: I developed a package for hidden Markov models called depmixS4 that in some sense does what you want: clustering taking dependencies over time into account by specifying a transition matrix. Similarly, there are other packages that fit similar models, searching for hidden markov model provides a number of them. hth, Ingmar Visser On 12 Mar 2009, at 23:39, Prew, Paul wrote: Hello All, Does anyone know of a package that performs constraint-based clusters? Ideally the package could perform Time-Ordered Clustering, a technique applied in a recent journal article by Runger, Nelson, Harnish (using MS Excel). Quote, in our specific implementation of constrained clustering, the clustering algorithm remains agglomerative and hierarchical, but observations or clusters are constrained to only join if they are adjacent in time. CRAN searches using variants of cluster and/or constraint and/or time etc. didn't yield anything I could recognize. Thank you, Paul Paul Prew Ecolab Eagan, MN paul.p...@ecolab.com CONFIDENTIALITY NOTICE: =\ \ This e-mail communication a...{{dropped: 12}} CONFIDENTIALITY NOTICE: =\ \ This e-mail communication a...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any difference between - and =
Alan Zaslavsky wrote: I would argue that this is a matter of preference and the arguments on principle for one side or another are not particularly compelling. indeed; i have argued (i think...) for treating them as equals, the vhoice being a matter of taste. When the = was introduced for assignment, an argument was made that name=value function arguments are also implicitly a kind of assignment. sure they are. you assign (or not, depending on whether the arguments are actually used) to function-call-local variables, that is, the function's parameters. While Duncan has pointed out a typical example of how this could be ambiguous, - also has its problems. A syntactic confusion with - arises in expressions like x-3 which could be read either as an assignment or as a logical expression comparing x to -3. ha! cool. Perhaps obviously ambiguous when written naked like this but when buried in a larger expression, it's easy to write an expression like that and discover that you have overwritten x. even worse if the code is processed in some way that might remove spaces, thus turning - into -. Some might (and have, most emphatically) advise that we should routinely insert spaces in our typing in a way that disambiguates such expressions but I find an argument that relies on spaces, which are usually syntactically unmeaningful, not very compelling. Besides, I just find that clumsy two-character arrow ugly! :) This is an esthetic matter -- reminds me too much of an emoticon. :-( For over 10 years I used the alternative _ underscore for S assignment (nice as a single character with no competing syntactic meaning) but that has gone away, as far as I can tell primarily due to discomfort (disdain?) of developers who find it unattractive because of the use of _ as a connecting special category in OTHER contexts (C and shell programming). However, a mutually satisfactory solution is at hand!! If growth in the number of R programmers continues exponentially at its current rate, by the year 2097 the number of R programmers will exceed the population of the earth. At that point they will rise up and demand the restoration of the APL arrow key (remembered by some doddering guru who heard about it from her grandfather) to the standard keyboard, and our problem will be solved. (But there will be a minor irritation because in the New Zealand keyboard that key code will have been assigned to the locally popular sheep icon.) by that time r programs will be scanned directly from your head, i suppose, and the intelligent scanner will as gladly take - as it will =, so the problem will rather vanish. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] updating packages?
I am trying to update the packages that I have installed but I get the following warning messages: package 'tseries' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'tseries' bundle 'forecasting' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'forecast' What does that mean? How can I update these packages? Thank you. Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] code to find all distinct subsets of size r from a set of size n
If your subsets are to be taken from the rows of a dataframe, df, and the size is r, then something like this could satisfy: apply(combn(nrow(df), r), 2, function(x) df[x, ]) (Although these are not really permutations as I understand that term.) -- David Winsemius On Mar 13, 2009, at 8:35 AM, Dale Steele wrote: I'm doing a permutation test and need to efficiently generate all distinct subsets of size r from a set of size n. P 138 of MASS (4th ed) notes that The code to generate this efficiently is in the scripts. I was unable to find this code on quick inspection of the \library\MASS\scripts file for Chapter 5 and 'subsets' is not a function in MASS. I did find this problem is discussed in RNews, Programmer's Niche 1(1):27 - 30 and RNews, 1(2):29-31. Is there function in 'base' R or other package to do this? Thanks. --Dale __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] updating packages?
Maybe they are loaded, use search() to see if they are. If yes, then use detach() to unload them first. Best 2009/3/13 rkevinbur...@charter.net: I am trying to update the packages that I have installed but I get the following warning messages: package 'tseries' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'tseries' bundle 'forecasting' successfully unpacked and MD5 sums checked Warning: cannot remove prior installation of package 'forecast' What does that mean? How can I update these packages? Thank you. Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- HUANG Ronggui, Wincent Tel: (00852) 3442 3832 PhD Candidate Dept of Public and Social Administration City University of Hong Kong Home page: http://asrr.r-forge.r-project.org/rghuang.html A sociologist is someone who, when a beautiful women enters the room and everybody look at her, looks at everybody. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there any difference between - and =
thanks for your supportive comments! by that time r programs will be scanned directly from your head, i suppose, and the intelligent scanner will as gladly take - as it will =, so the problem will rather vanish. Yes, and maybe the scanner will be more intelligent than the programmer so when the programmer is confused about what he/she wants, the scanner will figure it out! :-) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] print median and sd...
Hii Jholtman, I will make a graph of the median values and not to print to the console. I tried to plot with: plot(V3 ~ grup, data = median) ?? but I get an error message. I also tried to print the output of median-with(x, tapply(V3, grup, median)) to a text file with the X and Y Koordinates to plot it explicit with plot(x,y) but I could not figure out the X Values. I have not su much experience with R, I would be thankful if you could help me... jholtman wrote: Where do you want to print it? Is it the console (if so, try 'print(median)') or if it is the plot, use 'text' with the appropriate parameters. It would help if you listed the I tried many things but without success... and what you were expecting vs. what you got. Reproducible code would be useful (and required). On Thu, Mar 12, 2009 at 10:42 PM, johnhj jhar...@web.de wrote: Hii, Can anybody help me, I don't know how to print the median. Below is my code snipplet... x -read.table(file=D:/Uni/Diplom/Diplom/Grafiken/R/BATMAN/Kabel/Batman1hop/Standardabweichung__output_30_1_Kabel(30m)_b.txt) png(filename = D:/Grafiken/R/Standardabweichung/Kopie.png, width = 640, height = 480,pointsize = 12, bg = white, res = NA) median-with(x, tapply(V3, grup, median)) ??? dev.off() I will print, the median values with a simple line.. I tried many things but without success... I would be very appreciate, if anyone could help me... greetings, John -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22489185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22495481.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using package ROCR
library(ROCR) library(randomForest) plot(results,significant) Error in as.double(x) : cannot coerce type 'S4' to vector of type 'double' After try with all the possibilities, it shows same error in simpleaffy data plot for the results. please someone guide me wiener30 wrote: I am trying to use package ROCR to analyze classification accuracy, unfortunately there are some problems right at the beginning. Question 1) When I try to run demo I am getting the following error message library(ROCR) demo(ROCR) if(dev.cur() = 1) [TRUNCATED] Error in get(getOption(device)) : wrong first argument When I issue the command dev.cur() it returns null device 1 It seems something is wrong with my R-environment ? Could somebody provide a hint, what is wrong. Question 2) When I run an example commands from the manual library(ROCR) data(ROCR.simple) pred - prediction( ROCR.simple$predictions, ROCR.simple$labels ) perf - performance( pred, tpr, fpr ) plot( perf ) the plot command issues the following error message Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double' How this could be fixed ? Thanks for the support -- View this message in context: http://www.nabble.com/Using-package-ROCR-tp22198213p22495365.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Save the elements of an atomic vector to a text fil
Hii, I will save the elements of the vector median-with(x, tapply(V3, grup, median)). The output of this vector is: 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 17.8 17.8 17.5 17.8 17.7 17.6 17.7 17.6 17.8 17.7 17.6 17.7 17.8 17.7 17.8 17.8 17.8 17.8 17.7 17.7 Can anybody help me how to do it. I will save it to a text file... greetings, johnh -- View this message in context: http://www.nabble.com/Save-the-elements-of-an-atomic-vector-to-a-text-fil-tp22498222p22498222.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
library(colorRamps) image(matrix(1:150, 10), col = blue2green2red(15)) Regards, Olivier Delaigue Ross Culloch wrote: Dear all, This seems like a simple problem but i've searched the help files and tried various options but failed, so apologies in advance for asking what i'm sure is an easy thing to do! In short, I have displayed behavioural data using the TraMineR package such that there is a colour change between the transition of behaviours, however, all the methods that i have used thus far have given me gradual changes in colour such that it is impossible to tell the difference from several of the behaviours. I have looked in the help section here, and looked at various books and help files in R, but most seem intent on gradual changes in colour for heat, terrain, depth, etc - i may not be looking in the correct places, or perhaps i don't know what i'm looking for, exactly. The code below is the closest i can get to colours being not too similar, but it's still hard to tell apart: col - rainbow(15,start = 0, end = 1, gamma = 0.5) What i ideally want to do is create a palette with random colours that are no where near one another so that i can tell the 15 different behaviours apart - is this possible? If anyone can help i would be most greatful! Best wishes, Ross -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22495842.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Finance] Problem with RBloomberg (not the usual one)
Sergey, Sorry I missed your post earlier. I had this same problem and I reinstalled the DDE Server and Excel Add-In, rebooted and it fixed it. I thought they were already installed as I could pull down data in Excel from Bloomberg, but reinstalling them fixed my R problem. You can find the downloads at http://about.bloomberg.com/contact_softwaresupport_upgr.html Good luck. Kent -Original Message- From: Sergey Goriatchev [mailto:serg...@gmail.com] Sent: Friday, February 27, 2009 1:54 AM To: r-sig-fina...@stat.math.ethz.ch; r-help@r-project.org Subject: Re: [R-SIG-Finance] Problem with RBloomberg (not the usual one) Hello, again, everyone I went through the code and narrowed down the problem in blpConnect: COMCreate(Bloomberg.Data.1) which then calls getCOMInstance does not work, because getCLSID(Bloomberg.Data.1) returns Fehler: Invalid class string What is this problem??? Best, Sergey On Fri, Feb 27, 2009 at 09:16, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone! I have a problem with RBloomberg and this is not the usual no administrator rights problem. I have R 2.7.2, RBloomberg 0.1-10, RDCOMclient 0.92-0 RDCOMClient, chron, zoo, stats: these packages load OK. Then, trying to connect, I get following error message: conn - blpConnect(show.days=week, na.action=previous.days, periodicity=daily) Warning messages: 1: In getCOMInstance(name, force = TRUE, silent = TRUE) : Couldn't get clsid from the string 2: In blpConnect(show.days = week, na.action = previous.days, periodicity = daily) : Seems like this is not a Bloomberg Workstation: Error : Invalid class string Anyone encountered this problem? What is wrong and how can I solve it? Online, I found just one instance of this problem discussed, and it was in Chinese: http://cos.name/bbs/read.php?tid=12821fpage=3 Thank you for your help! Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten EMF kochind.com made the following annotations. -- The information in this e-mail and any attachments is co...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] print median and sd...
Can you provide a reproducible example with the data so that we understand what you are working with. Need to see what the structure of 'x' and 'median' are. On Fri, Mar 13, 2009 at 8:35 AM, johnhj jhar...@web.de wrote: Hii Jholtman, I will make a graph of the median values and not to print to the console. I tried to plot with: plot(V3 ~ grup, data = median) ?? but I get an error message. I also tried to print the output of median-with(x, tapply(V3, grup, median)) to a text file with the X and Y Koordinates to plot it explicit with plot(x,y) but I could not figure out the X Values. I have not su much experience with R, I would be thankful if you could help me... jholtman wrote: Where do you want to print it? Is it the console (if so, try 'print(median)') or if it is the plot, use 'text' with the appropriate parameters. It would help if you listed the I tried many things but without success... and what you were expecting vs. what you got. Reproducible code would be useful (and required). On Thu, Mar 12, 2009 at 10:42 PM, johnhj jhar...@web.de wrote: Hii, Can anybody help me, I don't know how to print the median. Below is my code snipplet... x -read.table(file=D:/Uni/Diplom/Diplom/Grafiken/R/BATMAN/Kabel/Batman1hop/Standardabweichung__output_30_1_Kabel(30m)_b.txt) png(filename = D:/Grafiken/R/Standardabweichung/Kopie.png, width = 640, height = 480,pointsize = 12, bg = white, res = NA) median-with(x, tapply(V3, grup, median)) ??? dev.off() I will print, the median values with a simple line.. I tried many things but without success... I would be very appreciate, if anyone could help me... greetings, John -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22489185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22495481.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Save the elements of an atomic vector to a text fil
'str(x)' would help. I assume that this is a named list, so this might plot it for you: plot(names(x), x) On Fri, Mar 13, 2009 at 10:59 AM, johnhj jhar...@web.de wrote: Hii, I will save the elements of the vector median-with(x, tapply(V3, grup, median)). The output of this vector is: 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 17.8 17.8 17.5 17.8 17.7 17.6 17.7 17.6 17.8 17.7 17.6 17.7 17.8 17.7 17.8 17.8 17.8 17.8 17.7 17.7 Can anybody help me how to do it. I will save it to a text file... greetings, johnh -- View this message in context: http://www.nabble.com/Save-the-elements-of-an-atomic-vector-to-a-text-fil-tp22498222p22498222.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Save the elements of an atomic vector to a text fil
Hi, take a look to ?write.table regards 2009/3/13 johnhj jhar...@web.de Hii, I will save the elements of the vector median-with(x, tapply(V3, grup, median)). The output of this vector is: 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 17.8 17.8 17.5 17.8 17.7 17.6 17.7 17.6 17.8 17.7 17.6 17.7 17.8 17.7 17.8 17.8 17.8 17.8 17.7 17.7 Can anybody help me how to do it. I will save it to a text file... greetings, johnh -- View this message in context: http://www.nabble.com/Save-the-elements-of-an-atomic-vector-to-a-text-fil-tp22498222p22498222.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to combine xtable and minipage with Sweave ?
Ptit_Bleu ptit_bleu at yahoo.fr writes: Concerning the point 3, I'm a bit lost. Is it a problem of place to put the table and the graph side by side (my english is quite as low as my skills in Latex) ? I tried with \begin{minipage}{0.45\textwidth} instead of 0.7 and I put //tiny but no success. There is an example in the German latex FAQ http://www.faqs.org/faqs/de-tex-faq/part6/ and I am sure there is the same in the englisch/french. For further details, use the tex output produce by rnw, massage it (not rnw) until it works in latex. Detailed queries should be posted on the latex forum, because this is definitively not an R problem. And do not forget to boil it down to the absolute minimum self-consistency before you post it on the latex forum, the people there are even more picky if the example is not minimal than here. Cetero censeo: on the latex forum, pruning the quoted text to the minimum required and assuming people can handle a thread reader is a nice habit not followed here. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Save the elements of an atomic vector to a text fil
?cat On Mar 13, 2009, at 10:59 AM, johnhj wrote: Hii, I will save the elements of the vector median-with(x, tapply(V3, grup, median)). The output of this vector is: 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 17.8 17.8 17.5 17.8 17.7 17.6 17.7 17.6 17.8 17.7 17.6 17.7 17.8 17.7 17.8 17.8 17.8 17.8 17.7 17.7 Can anybody help me how to do it. I will save it to a text file... greetings, johnh -- View this message in context: http://www.nabble.com/Save-the-elements-of-an-atomic-vector-to-a-text-fil-tp22498222p22498222.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-SIG-Finance] Problem with RBloomberg (not the usual one)
Hi, Kent Thank you for that! I'll pass the info to our systems administrator, he is the only one who is allowed to do things like that. Have a nice weekend! Best, Serge On Fri, Mar 13, 2009 at 15:32, Voss, Kent vo...@kochind.com wrote: Sergey, Sorry I missed your post earlier. I had this same problem and I reinstalled the DDE Server and Excel Add-In, rebooted and it fixed it. I thought they were already installed as I could pull down data in Excel from Bloomberg, but reinstalling them fixed my R problem. You can find the downloads at http://about.bloomberg.com/contact_softwaresupport_upgr.html Good luck. Kent -Original Message- From: Sergey Goriatchev [mailto:serg...@gmail.com] Sent: Friday, February 27, 2009 1:54 AM To: r-sig-fina...@stat.math.ethz.ch; r-help@r-project.org Subject: Re: [R-SIG-Finance] Problem with RBloomberg (not the usual one) Hello, again, everyone I went through the code and narrowed down the problem in blpConnect: COMCreate(Bloomberg.Data.1) which then calls getCOMInstance does not work, because getCLSID(Bloomberg.Data.1) returns Fehler: Invalid class string What is this problem??? Best, Sergey On Fri, Feb 27, 2009 at 09:16, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone! I have a problem with RBloomberg and this is not the usual no administrator rights problem. I have R 2.7.2, RBloomberg 0.1-10, RDCOMclient 0.92-0 RDCOMClient, chron, zoo, stats: these packages load OK. Then, trying to connect, I get following error message: conn - blpConnect(show.days=week, na.action=previous.days, periodicity=daily) Warning messages: 1: In getCOMInstance(name, force = TRUE, silent = TRUE) : Couldn't get clsid from the string 2: In blpConnect(show.days = week, na.action = previous.days, periodicity = daily) : Seems like this is not a Bloomberg Workstation: Error : Invalid class string Anyone encountered this problem? What is wrong and how can I solve it? Online, I found just one instance of this problem discussed, and it was in Chinese: http://cos.name/bbs/read.php?tid=12821fpage=3 Thank you for your help! Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten EMF kochind.com made the following annotations. -- The information in this e-mail and any attachments is confidential and intended solely for the attention and use of the named addressee(s). It must not be disclosed to any person without proper authority. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorized to and must not disclose, copy, distribute, or retain this message or any part of it. == -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to color certain area under curve
I did similar things with polygon(). Le mar. 10 mars à 13:30, g...@ucalgary.ca a écrit : For a given random variable rv, for instance, rv = rnorm(1000), I plot its density curve and calculate some quantiles: plot(density(rv)) P10P50P90 = = quantile(rv,probs = c(10,50,90)/100) I would like to color the area between P10 and P90 and under the curve and mark the P50 on the curve. rv = rnorm(1000) plot(density(rv)) P10P50P90 = = quantile(rv,probs = c(10,50,90)/100) Could you please teach me how to do these using R? Thanks, -james __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to combine xtable and minipage with Sweave ?
Thanks Dieter for the link. In fact it may be a problem with R. The .tex created with R for the table put \begin{table}[ht] and \end{table}\ between \begin{minipage} and \end{minipage} (see below) If I manually change these positions, according to your link, there is no more error ... but the table is below the graph and not side by side. Any idea ? Have a nice week-end, Ptit bleu. File .tex created by Sweave : \begin{minipage}{0.45\textwidth} % latex table generated in R 2.7.2 by xtable 1.5-4 package % Fri Mar 13 17:00:06 2009 \begin{table}[ht] \begin{center} {\tiny \begin{tabular}{lrr} \hline Date kWh\_m2 Nbremesures \\ \hline 2009-03-08 4.53 142 \\ 2009-03-09 1.70 142 \\ 2009-03-10 1.96 147 \\ \hline \end{tabular} } \end{center} \end{table}\end{minipage} -- View this message in context: http://www.nabble.com/How-to-combine-xtable-and-minipage-with-Sweave---tp22493636p22499672.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cross-validation - lift curve
This may be somewhat useful, but I might have more later. http://florence.acadiau.ca/collab/hugh_public/index.php?title=R:CheckBinFit (the code below is copied from the URL above) CheckBinFit - function(y,phat,nq=20,new=T,...) { if(is.factor(y)) y - as.double(y) y - y-mean(y) y[y0] - 1 y[y=0] - 0 quants - quantile(phat,probs=(1:nq)/(nq+1)) names(quants) - NULL quants - c(0,quants,1) phatD - rep(0,nq+1) phatF - rep(0,nq+1) for(i in 1:(nq+1)) { which - ((phat=quants[i+1])(phatquants[i])) phatF[i] - mean(phat[which]) phatD[i] - mean(y[which]) } if (new) plot(phatF,phatD,xlab=phat,ylab=data, main=paste('R^2=',cor(phatF,phatD)^2),...) else points(phatF,phatD,...) abline(0,1) return(invisible(list(phat=phatF,data=phatD))) } On Thu, Mar 12, 2009 at 1:30 PM, Eric Siegel e...@predictionimpact.comwrote: Hi all, I'd like to do cross-validation on lm and get the resulting lift curve/table (or, alternatively, the estimates on 100% of my data with which I can get lift). If such a thing doesn't exist, could it be derived using cv.lm, or would we need to start from scratch? Thanks! -- Eric Siegel, Ph.D. President Prediction Impact, Inc. Predictive Analytics World Conference More info: www.predictiveanalyticsworld.com LinkedIn Group: www.linkedin.com/e/gis/1005097 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] search for string insider a string
Hi, sorry if it is a too stupid question, but how do I a string search in R: I have a dataframe A with A$test like: test1 bcdtestblabla2.1bla cdtestblablabla3.88blabla and I want to search for string that start with 'dtest' and ends with number and return the location of that substring and the number, so the end result would be: NANA 32.1 23.88 I find grep can probably do this but I am new to the function so would like a good example. Thanks, Richard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selecting / creating unique colours for behavioural / transitional data
Hi Ross, If you really need 15 colors, maybe you can use the Set3 palette provided by RColorBrewer (this is the one used by TraMineR up to 12 states) and add yourself 3 more colors ? For example (you can mix the hexadecimal color numbers from the RColorBrewer palette and real color names in the same vector) : library(RColorBrewer) mycolors - brewer.pal(12,Set3) mycolors - c(mycolors, blue, green, yellow) All the best, Alexis. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting / creating unique colours for behavioural / transitional data
Hi Alexis, In my opinion you are nothing short of genius! That worked a treat, i thought it would be something simple, but i could not find the script or an example anywhere!!! That was a massive help and has salvaged my day! :clap: Thanks very much to everyone else that helped, it was much appreciated! I only hope i can get to a point in R where i can help people solely for the sake of helping them! Cheers, Ross Hi Ross, If you really need 15 colors, maybe you can use the Set3 palette provided by RColorBrewer (this is the one used by TraMineR up to 12 states) and add yourself 3 more colors ? For example (you can mix the hexadecimal color numbers from the RColorBrewer palette and real color names in the same vector) : library(RColorBrewer) mycolors - brewer.pal(12,Set3) mycolors - c(mycolors, blue, green, yellow) All the best, Alexis. -- View this message in context: http://www.nabble.com/Selecting---creating-unique-colours-for-behavioural---transitional-data-tp22492438p22500457.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find maximum values on the density function of arandom variable
Yes, a random variable, discrete or continuous one, should associate with a probability space and a measurable space. I thought that graph of density(rv) below could give us an example of a density function. I am very sorry for confusing you. My question is how to find/estimate maximum values of a given density function (even any given function within a given domain). The number of these maximum values might be 1 but the global one is unique. Any ideas and references? Thanks, -james There is some considerable confusion in both the question and the reply. rv is **not** a random variable. It is an (iid) sample from (i.e. a realization of) a random variable. It has *no* density function and the density() function is simply a procedure to **estimate** the density of the underlying random variable from which rv was sampled at a finite number of points. The result of density()and the max given in the reply will depend on the particular parameters given to density()(see ?density for details), as well as the data. In other words, both the question and answer posted are nonsense. Now let me contradict what I just said. **If** you consider rv a finite, discrete distribution (i.e. the whole population), then, in fact, it does have a discrete density, with point mass j(i)/n at each unique sample value i, where n is the total sample size (= 1 in the example) and j(i) is the number of samples values == i, which would probably be 1 for all i. Then, of course, one can talk about the density of this finite distribution in the obvious way and its maximum or maxima, occur at those i for which n(i) is largest. But of course that's not what the poster really meant, so that brings us back to the nonsense question and answer. What James probably meant to ask was: How can the maximum of the underlying population density function be estimated? Well, that's a complicated issue. One could, of course, use some sort of density estimate -- there are tons -- and find its max; that was the approach taken in the answer, but it's not so simple as it appears because of the need to choose the **appropriate** estimate (including the parameters of the statistical algorithm doing the estimating ). This is the sort of thing that actually requires some careful thought and statistical expertise. You will find, I believe, that the prescription for finding the max suggested below can give quite different answers depending on the parameters chosen for this estimate, and on the estimate used. So if you need to do this right, may I suggest consulting the literature on density estimation or perhaps talking with your local statistician? -- Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mike Lawrence Sent: Thursday, March 12, 2009 5:40 PM To: g...@ucalgary.ca Cc: r-help@r-project.org Subject: Re: [R] How to find maximum values on the density function of arandom variable rv - rbinom(1,1,0.1) + rnorm(1) d.rv = density(rv) d.x = d.rv$x d.y = d.rv$y d.rv.max = d.rv$x[which.max(d.rv$y)] plot(d.rv) abline(v=d.rv.max) #that what you want? On Thu, Mar 12, 2009 at 6:28 PM, g...@ucalgary.ca wrote: I would like to find the maximum values on the density function of a random variable. For example, I have a random variable rv - rbinom(1,1,0.1) + rnorm(1) Its density function is given by density(rv) and can be displayed by plot(density(rv)). How to calculate its maximum values? A density function may have a few (global and local) maximum values. Please help. Thanks, -james __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tinyurl.com/mikes-public-calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] More basic equivalent of TukeyHSD
This is a simple question, but I'm going on the supposition that the only stupid question is the one not asked. 1. I have many sets of 5 proportions that are different from each other (prop.test), and want to know which proportions are different from each other. In other words, I want the equivalent of Tukey's HSD test, but for proportions rather than anova. Here is one of the sets of number of successes; the denominator is 151 for all cases. Parents School Peers Church No one Menstruation 79 5855 3 38 As proportions: round(topics.sum[1,], digits=3) Parents School Peers Church No one 0.523 0.384 0.364 0.020 0.252 Intuitively, it looks like there are 3 or 4 groups that are different from each other, but is there a function that does this? parents school and peers ? no one church 2. I am displaying this data in a bar graph. How do I show graphically which proportions are different? I'm not interested in using error bars since they can be ambiguous, but probably something like putting a different symbol over each bar to show which bars are the same and which differ. I've made efforts at this before, but they've always looked a bit clumsy. Thanks, Janet __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selecting / creating unique colours for behavioural / transitional data
Hi Ross, If you really need 15 colors, maybe you can use the Set3 palette provided by RColorBrewer (this is the one used by TraMineR up to 12 states) and add yourself 3 more colors ? For example (you can mix the hexadecimal color numbers from the RColorBrewer palette and real color names in the same vector) : library(RColorBrewer) mycolors - brewer.pal(12,Set3) mycolors - c(mycolors, blue, green, yellow) All the best, Alexis. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] print median and sd...
Ok, sorry... here is my code so far... x -read.table(file=D:/output.txt) x$grup - 25*rep(1:144, each=5) median-with(x, tapply(V3, grup, median)) sd-with(x, tapply(V3, grup, sd)) I will plot to types of graph. One graph with the median values for example with the plot() function, the other one is the standard derivation. I will plot the s.d. with barplot(). What do you think, is it generally common to plot the s.d. with his histograms ? jholtman wrote: Can you provide a reproducible example with the data so that we understand what you are working with. Need to see what the structure of 'x' and 'median' are. On Fri, Mar 13, 2009 at 8:35 AM, johnhj jhar...@web.de wrote: Hii Jholtman, I will make a graph of the median values and not to print to the console. I tried to plot with: plot(V3 ~ grup, data = median) ?? but I get an error message. I also tried to print the output of median-with(x, tapply(V3, grup, median)) to a text file with the X and Y Koordinates to plot it explicit with plot(x,y) but I could not figure out the X Values. I have not su much experience with R, I would be thankful if you could help me... jholtman wrote: Where do you want to print it? Is it the console (if so, try 'print(median)') or if it is the plot, use 'text' with the appropriate parameters. It would help if you listed the I tried many things but without success... and what you were expecting vs. what you got. Reproducible code would be useful (and required). On Thu, Mar 12, 2009 at 10:42 PM, johnhj jhar...@web.de wrote: Hii, Can anybody help me, I don't know how to print the median. Below is my code snipplet... x -read.table(file=D:/Uni/Diplom/Diplom/Grafiken/R/BATMAN/Kabel/Batman1hop/Standardabweichung__output_30_1_Kabel(30m)_b.txt) png(filename = D:/Grafiken/R/Standardabweichung/Kopie.png, width = 640, height = 480,pointsize = 12, bg = white, res = NA) median-with(x, tapply(V3, grup, median)) ??? dev.off() I will print, the median values with a simple line.. I tried many things but without success... I would be very appreciate, if anyone could help me... greetings, John -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22489185.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22495481.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/print-median-and-sd...-tp22489185p22499716.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sorting rows of a matrix independent of each other
Oh, this seemed so simple (and I'm sure the answer will be, as usual, so thanks in advance for enlightening me). I need to sort each row of a matrix independent of the others. For example, test - matrix(c(8,7,1,2,6,5,9,4,3),nrow=3) test [,1] [,2] [,3] [1,]829 [2,]764 [3,]153 I can get each row sorted well enough. sort(test[1,]) [1] 2 8 9 sort(test[2,]) [1] 4 6 7 sort(test[3,]) [1] 1 3 5 Now I just need the resulting matrix: 2 8 9 4 6 7 1 3 5 But when I try to turn this into something more automated, I only get the last row. for(e in 1:3) sorted - sort(test[e,]) sorted [1] 1 3 5 I've tried various incarnations of rbind around my loop, but to no avail. I've search my books and the forums, and I'm sure there is some nifty R function out there, but I can't seem to find it and/or apply it correctly. Cheers, Kev- -- View this message in context: http://www.nabble.com/Sorting-rows-of-a-matrix-independent-of-each-other-tp22498636p22498636.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to add labels to existing plot for the subset of data
Dear: I am trying to plot x against y for a particular subset of data, say z=1, and labelling data by another variable say, k. My data are: y-c(69.7, 82.3, 66.3, 107.3, 90.1, 63.7, 82, 74.4, 61.7, 93.4, 73.4, NA, NA, 70.7, 67.7, NA, NA) x-c(71.2, 82.6, 67.4, 107.1, 90.5, 66.7, 83.9, 73.9, 61, 93.1, 75.8, 79, 83.8, 73.1, 69.7, 73.3, 85.5) z-c(1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1) k-c(9, 10, 11, 12, 16, 23, 24, 25, 20, 19, 8, 21, 13, 17, 14, 15, 18) plot(y~x,subset=z==1) text(x=x,y=y,labels=k)---for this command, how can I only plot the label for z=1? For example, give a constrict: subet=z==1. however this command is not working for text. Anyone has this experience? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Save the elements of an atomic vector to a text fil
Thank you all, I did it with write.table... greetings, johnh johnhj wrote: Hii, I will save the elements of the vector median-with(x, tapply(V3, grup, median)). The output of this vector is: 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 17.8 17.8 17.5 17.8 17.7 17.6 17.7 17.6 17.8 17.7 17.6 17.7 17.8 17.7 17.8 17.8 17.8 17.8 17.7 17.7 Can anybody help me how to do it. I will save it to a text file... greetings, johnh -- View this message in context: http://www.nabble.com/Save-the-elements-of-an-atomic-vector-to-a-text-fil-tp22498222p22499918.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find maximum values on the density function of arandom variable
If you are trying to build your own function then presumably you do not want the global maximum, since that is trivially returned by max. So what do you really want? Is this a programming question or just a general statistics question? If you want to search along a (specific) sequence for local maxima, then you could try programming with second differences looking for shifts in sign from positive to negative. vec - c(1:5, 6, 5:1) diff(diff(vec)) [1] 0 0 0 0 -2 0 0 0 0 It is a bit ambiguous what you would do with this vector: vec2 - c(1:5,rep(6,3),5:1) diff(diff(vec2)) [1] 0 0 0 0 -1 0 -1 0 0 0 0 -- David Winsemius On Mar 13, 2009, at 12:48 PM, g...@ucalgary.ca wrote: Yes, a random variable, discrete or continuous one, should associate with a probability space and a measurable space. I thought that graph of density(rv) below could give us an example of a density function. I am very sorry for confusing you. My question is how to find/estimate maximum values of a given density function (even any given function within a given domain). The number of these maximum values might be 1 but the global one is unique. Any ideas and references? Thanks, -james There is some considerable confusion in both the question and the reply. rv is **not** a random variable. It is an (iid) sample from (i.e. a realization of) a random variable. It has *no* density function and the density() function is simply a procedure to **estimate** the density of the underlying random variable from which rv was sampled at a finite number of points. The result of density()and the max given in the reply will depend on the particular parameters given to density()(see ?density for details), as well as the data. In other words, both the question and answer posted are nonsense. Now let me contradict what I just said. **If** you consider rv a finite, discrete distribution (i.e. the whole population), then, in fact, it does have a discrete density, with point mass j(i)/n at each unique sample value i, where n is the total sample size (= 1 in the example) and j(i) is the number of samples values == i, which would probably be 1 for all i. Then, of course, one can talk about the density of this finite distribution in the obvious way and its maximum or maxima, occur at those i for which n(i) is largest. But of course that's not what the poster really meant, so that brings us back to the nonsense question and answer. What James probably meant to ask was: How can the maximum of the underlying population density function be estimated? Well, that's a complicated issue. One could, of course, use some sort of density estimate -- there are tons -- and find its max; that was the approach taken in the answer, but it's not so simple as it appears because of the need to choose the **appropriate** estimate (including the parameters of the statistical algorithm doing the estimating ). This is the sort of thing that actually requires some careful thought and statistical expertise. You will find, I believe, that the prescription for finding the max suggested below can give quite different answers depending on the parameters chosen for this estimate, and on the estimate used. So if you need to do this right, may I suggest consulting the literature on density estimation or perhaps talking with your local statistician? -- Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Mike Lawrence Sent: Thursday, March 12, 2009 5:40 PM To: g...@ucalgary.ca Cc: r-help@r-project.org Subject: Re: [R] How to find maximum values on the density function of arandom variable rv - rbinom(1,1,0.1) + rnorm(1) d.rv = density(rv) d.x = d.rv$x d.y = d.rv$y d.rv.max = d.rv$x[which.max(d.rv$y)] plot(d.rv) abline(v=d.rv.max) #that what you want? On Thu, Mar 12, 2009 at 6:28 PM, g...@ucalgary.ca wrote: I would like to find the maximum values on the density function of a random variable. For example, I have a random variable rv - rbinom(1,1,0.1) + rnorm(1) Its density function is given by density(rv) and can be displayed by plot(density(rv)). How to calculate its maximum values? A density function may have a few (global and local) maximum values. Please help. Thanks, -james __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tinyurl.com/mikes-public-calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org mailing list
Re: [R] How to combine xtable and minipage with Sweave ?
On 3/13/2009 12:07 PM, Ptit_Bleu wrote: Thanks Dieter for the link. In fact it may be a problem with R. The .tex created with R for the table put \begin{table}[ht] and \end{table}\ between \begin{minipage} and \end{minipage} (see below) If I manually change these positions, according to your link, there is no more error ... but the table is below the graph and not side by side. Any idea ? You can use \includegraphics explicitly yourself, and avoid the automatic code generated by Sweave. For example, testfn, fig=true, include=false= curve(f, from = 1, to = 5) @ That generates the figure, but doesn't include it; then \begin{figure} \begin{center} \includegraphics{-testfn} \caption{The function $f(x) = |x-3.5| + (x-2)^2$.\label{fig:testfn}} \end{center} \end{figure} will do the include. You need to name the chunk that creates the figure for this to be workable, and if you have set a prefix in your SweaveOpts, you need to use it in the \includegraphics call. (Actually I forget if the hyphen is needed; I stripped off a prefix from the real example to show you this.) Duncan Murdoch Have a nice week-end, Ptit bleu. File .tex created by Sweave : \begin{minipage}{0.45\textwidth} % latex table generated in R 2.7.2 by xtable 1.5-4 package % Fri Mar 13 17:00:06 2009 \begin{table}[ht] \begin{center} {\tiny \begin{tabular}{lrr} \hline Date kWh\_m2 Nbremesures \\ \hline 2009-03-08 4.53 142 \\ 2009-03-09 1.70 142 \\ 2009-03-10 1.96 147 \\ \hline \end{tabular} } \end{center} \end{table}\end{minipage} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sorting rows of a matrix independent of each other
Kevski wrote: Oh, this seemed so simple (and I'm sure the answer will be, as usual, so thanks in advance for enlightening me). I need to sort each row of a matrix independent of the others. For example, apply(matrix, 1, sort) vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sorting rows of a matrix independent of each other
Now I just need the resulting matrix: 2 8 9 4 6 7 1 3 5 On Mar 13, 2009, at 1:26 PM, Wacek Kusnierczyk wrote: Kevski wrote: Oh, this seemed so simple (and I'm sure the answer will be, as usual, so thanks in advance for enlightening me). I need to sort each row of a matrix independent of the others. For example, apply(matrix, 1, sort) Actually this give the transpose of what was requested, since the results from apply come back as column vectors. Try a slight refinement: outm - t(apply(test,1,sort)) outm [,1] [,2] [,3] [1,]289 [2,]467 [3,]135 -- David Winsemius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting rows of a matrix independent of each other
On Fri, Mar 13, 2009 at 5:26 PM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: Oh, this seemed so simple (and I'm sure the answer will be, as usual, so thanks in advance for enlightening me). I need to sort each row of a matrix independent of the others. For example, apply(matrix, 1, sort) t(apply(test,1,sort)) Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find maximum values on the density function of arandom variable
Thanks for your ideas. I would like to find all possible maximums - mountains on a graph of a given density function but I have no ideas. In calculus, there is a general approach for a given function f(x): Find derivative of f(x) and estimate all zeros of f'(x). These zeros give us locations of mountains if f(x) is differentiable. If f(x) is not differentiable (f(x) is not continuous in this case), we cannot use this approach. Bur in discrete case, we can still talk about local maximums, I guess. Your ideas are very helpful. -james If you are trying to build your own function then presumably you do not want the global maximum, since that is trivially returned by max. So what do you really want? Is this a programming question or just a general statistics question? If you want to search along a (specific) sequence for local maxima, then you could try programming with second differences looking for shifts in sign from positive to negative. vec - c(1:5, 6, 5:1) diff(diff(vec)) [1] 0 0 0 0 -2 0 0 0 0 It is a bit ambiguous what you would do with this vector: vec2 - c(1:5,rep(6,3),5:1) diff(diff(vec2)) [1] 0 0 0 0 -1 0 -1 0 0 0 0 -- David Winsemius On Mar 13, 2009, at 12:48 PM, g...@ucalgary.ca wrote: Yes, a random variable, discrete or continuous one, should associate with a probability space and a measurable space. I thought that graph of density(rv) below could give us an example of a density function. I am very sorry for confusing you. My question is how to find/estimate maximum values of a given density function (even any given function within a given domain). The number of these maximum values might be 1 but the global one is unique. Any ideas and references? Thanks, -james There is some considerable confusion in both the question and the reply. rv is **not** a random variable. It is an (iid) sample from (i.e. a realization of) a random variable. It has *no* density function and the density() function is simply a procedure to **estimate** the density of the underlying random variable from which rv was sampled at a finite number of points. The result of density()and the max given in the reply will depend on the particular parameters given to density()(see ?density for details), as well as the data. In other words, both the question and answer posted are nonsense. Now let me contradict what I just said. **If** you consider rv a finite, discrete distribution (i.e. the whole population), then, in fact, it does have a discrete density, with point mass j(i)/n at each unique sample value i, where n is the total sample size (= 1 in the example) and j(i) is the number of samples values == i, which would probably be 1 for all i. Then, of course, one can talk about the density of this finite distribution in the obvious way and its maximum or maxima, occur at those i for which n(i) is largest. But of course that's not what the poster really meant, so that brings us back to the nonsense question and answer. What James probably meant to ask was: How can the maximum of the underlying population density function be estimated? Well, that's a complicated issue. One could, of course, use some sort of density estimate -- there are tons -- and find its max; that was the approach taken in the answer, but it's not so simple as it appears because of the need to choose the **appropriate** estimate (including the parameters of the statistical algorithm doing the estimating ). This is the sort of thing that actually requires some careful thought and statistical expertise. You will find, I believe, that the prescription for finding the max suggested below can give quite different answers depending on the parameters chosen for this estimate, and on the estimate used. So if you need to do this right, may I suggest consulting the literature on density estimation or perhaps talking with your local statistician? -- Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Mike Lawrence Sent: Thursday, March 12, 2009 5:40 PM To: g...@ucalgary.ca Cc: r-help@r-project.org Subject: Re: [R] How to find maximum values on the density function of arandom variable rv - rbinom(1,1,0.1) + rnorm(1) d.rv = density(rv) d.x = d.rv$x d.y = d.rv$y d.rv.max = d.rv$x[which.max(d.rv$y)] plot(d.rv) abline(v=d.rv.max) #that what you want? On Thu, Mar 12, 2009 at 6:28 PM, g...@ucalgary.ca wrote: I would like to find the maximum values on the density function of a random variable. For example, I have a random variable rv - rbinom(1,1,0.1) + rnorm(1) Its density function is given by density(rv) and can be displayed by plot(density(rv)). How to calculate its maximum values? A density function may have a few (global and local) maximum values. Please help. Thanks,
Re: [R] Sorting rows of a matrix independent of each other
Got the answer: t(apply(test,1,sort)) I had played with the apply fn at one point, but noticed the results were not quite right. Wrapping it in t was the trick! Thanks! Now to use the nicely sorted rows in my real problem at hand... Cheers, Kev- -- View this message in context: http://www.nabble.com/Sorting-rows-of-a-matrix-independent-of-each-other-tp22498636p22501189.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] search for string insider a string
Try this. We use regexpr to get the positions and strapply puts the values in list s. The unlist statement converts NULL to NA and simplifies the list, s, to a numeric vector. For more info on strapply see http://gsubfn.googlecode.com library(gsubfn) # strapply x - ctest1, bcdtestblabla2.1bla, cdtestblablabla3.88blabla) dtest.info - cbind(posn = regexpr(dtest, x), value = { s - strapply(x, dtest[^0-9]*([0-9][0-9.]*), as.numeric) unlist(ifelse(sapply(s, length), s, NA)) }) # the above may be sufficient but # if its important to NA out rows with no match add dtest.info[dtest.info[,1] 0,] - NA dtest.info pos value [1,] NANA [2,] 3 2.10 [3,] 2 3.88 Why do you want the position? Is there a further transformation needed? What is it? There may be even easier approaches to the entire problem. On Fri, Mar 13, 2009 at 12:25 PM, Tan, Richard r...@panagora.com wrote: Hi, sorry if it is a too stupid question, but how do I a string search in R: I have a dataframe A with A$test like: test1 bcdtestblabla2.1bla cdtestblablabla3.88blabla and I want to search for string that start with 'dtest' and ends with number and return the location of that substring and the number, so the end result would be: NA NA 3 2.1 2 3.88 I find grep can probably do this but I am new to the function so would like a good example. Thanks, Richard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to find maximum values on the density function of arandom variable
In discrete math, first differences are the analogues of first derivatives and second differences are the analogues of second derivatives. (I thought I learned this in Knuth, vol 1 25 years ago, but I cannot find it, so maybe it was in some the time series stuff I read 20 years ago). So a negative second difference may signal a local maximum ( and a positive second difference would signal a local minimum). You may need to also check for plateaus that are not really local maxima. They would result in a signal like (-1 0 0 1) vec3 - c(1:5,5,5:10) diff(diff(vec3)) [1] 0 0 0 -1 0 1 0 0 0 0 # a discrete inflection I think the -2's would not need to be checked further, but the -1 's would need to be further verified. Since the differenced sequences get shortened with each application you also need to adjust before for using the results as indexes. vec [1] 1 2 3 4 5 6 5 4 3 2 1 which(diff(diff(vec))==-2) [1] 5 vec[which(diff(diff(vec))==-2)] [1] 5# off by one vec[which(diff(diff(vec))==-2)+1] [1] 6# correct maximum There must be worked out algorithms for peak finding in the R package universe. -- David Winsemius On Mar 13, 2009, at 1:38 PM, g...@ucalgary.ca wrote: Thanks for your ideas. I would like to find all possible maximums - mountains on a graph of a given density function but I have no ideas. In calculus, there is a general approach for a given function f(x): Find derivative of f(x) and estimate all zeros of f'(x). These zeros give us locations of mountains if f(x) is differentiable. If f(x) is not differentiable (f(x) is not continuous in this case), we cannot use this approach. Bur in discrete case, we can still talk about local maximums, I guess. Your ideas are very helpful. -james If you are trying to build your own function then presumably you do not want the global maximum, since that is trivially returned by max. So what do you really want? Is this a programming question or just a general statistics question? If you want to search along a (specific) sequence for local maxima, then you could try programming with second differences looking for shifts in sign from positive to negative. vec - c(1:5, 6, 5:1) diff(diff(vec)) [1] 0 0 0 0 -2 0 0 0 0 It is a bit ambiguous what you would do with this vector: vec2 - c(1:5,rep(6,3),5:1) diff(diff(vec2)) [1] 0 0 0 0 -1 0 -1 0 0 0 0 -- David Winsemius On Mar 13, 2009, at 12:48 PM, g...@ucalgary.ca wrote: Yes, a random variable, discrete or continuous one, should associate with a probability space and a measurable space. I thought that graph of density(rv) below could give us an example of a density function. I am very sorry for confusing you. My question is how to find/estimate maximum values of a given density function (even any given function within a given domain). The number of these maximum values might be 1 but the global one is unique. Any ideas and references? Thanks, -james There is some considerable confusion in both the question and the reply. rv is **not** a random variable. It is an (iid) sample from (i.e. a realization of) a random variable. It has *no* density function and the density() function is simply a procedure to **estimate** the density of the underlying random variable from which rv was sampled at a finite number of points. The result of density()and the max given in the reply will depend on the particular parameters given to density()(see ?density for details), as well as the data. In other words, both the question and answer posted are nonsense. Now let me contradict what I just said. **If** you consider rv a finite, discrete distribution (i.e. the whole population), then, in fact, it does have a discrete density, with point mass j(i)/n at each unique sample value i, where n is the total sample size (= 1 in the example) and j(i) is the number of samples values == i, which would probably be 1 for all i. Then, of course, one can talk about the density of this finite distribution in the obvious way and its maximum or maxima, occur at those i for which n(i) is largest. But of course that's not what the poster really meant, so that brings us back to the nonsense question and answer. What James probably meant to ask was: How can the maximum of the underlying population density function be estimated? Well, that's a complicated issue. One could, of course, use some sort of density estimate -- there are tons -- and find its max; that was the approach taken in the answer, but it's not so simple as it appears because of the need to choose the **appropriate** estimate (including the parameters of the statistical algorithm doing the estimating ). This is the sort of thing that actually requires some careful thought and statistical expertise. You will find, I believe, that the prescription for finding the max suggested below can give quite different answers depending on the parameters chosen for this estimate, and on the