It looks like prctile(X,p) is the same as quantile(X,p) i.e x<-0:100 quantile(x,0.5) is the median(x) and quantile(x,0.1)=10 is the value that is greater than 10% percent of the values in X "Jos? Luis Aznarte M." wrote:> > Hi there! Still struggling to translate Matlab code into R's tsDyn > package. > Here is my question: Is there in R an equivalent function to Matlab's > prctile()? To the moment I thought it was quantile(), but I just > realized I was wrong. The definition of the Matlab function: > > prctile > Percentiles of a sample > SyntaxY = prctile(X,p) > Description > Y = prctile(X,p) calculates a value that is greater than p percent of > the values in X. The values of p must lie in the interval [0 100]. For > instance, if p = 50 then Y is the median of X > > Thanks!! > > -- > -- -- > Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte > Department of Computer Science and Artificial Intelligence > Universidad de Granada Tel. +34 - 958 - 24 04 67 > GRANADA (Spain) Fax: +34 - 958 - 24 00 79 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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/Percentiles-in-R-tf4423440.html#a12617896 Sent from the R help mailing list archive at Nabble.com.
Hola Jose Luis, Sure, you can use quantile(). Use the probs argument. For example, to get the median do quantile(X,probs=0.5). Do ?quantile to learn about the different type of quantiles calculated by the funcion. Saludos, Julian Jose Luis Aznarte M. wrote:> Hi there! Still struggling to translate Matlab code into R's tsDyn package. > Here is my question: Is there in R an equivalent function to Matlab's > prctile()? To the moment I thought it was quantile(), but I just > realized I was wrong. The definition of the Matlab function: > > prctile > Percentiles of a sample > SyntaxY = prctile(X,p) > Description > Y = prctile(X,p) calculates a value that is greater than p percent of > the values in X. The values of p must lie in the interval [0 100]. For > instance, if p = 50 then Y is the median of X > > Thanks!! > >-- Julian M. Burgos Fisheries Acoustics Research Lab School of Aquatic and Fishery Science University of Washington 1122 NE Boat Street Seattle, WA 98105 Phone: 206-221-6864
Hi there! Still struggling to translate Matlab code into R's tsDyn package. Here is my question: Is there in R an equivalent function to Matlab's prctile()? To the moment I thought it was quantile(), but I just realized I was wrong. The definition of the Matlab function: prctile Percentiles of a sample SyntaxY = prctile(X,p) Description Y = prctile(X,p) calculates a value that is greater than p percent of the values in X. The values of p must lie in the interval [0 100]. For instance, if p = 50 then Y is the median of X Thanks!! -- -- -- Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte Department of Computer Science and Artificial Intelligence Universidad de Granada Tel. +34 - 958 - 24 04 67 GRANADA (Spain) Fax: +34 - 958 - 24 00 79
-------- Original Message -------- Subject: Re: [R] Percentiles in R From: Jose Luis Aznarte M. <jlaznarte at decsai.ugr.es> To: r-help at stat.math.ethz.ch Date: 11.09.2007 19:09> Thank you all! But the problem is that quantile() returns "how many > data" are greater than p percent, and not a value in the domain of the > vector under scrutiny. For example, I have a vector > > > x > [1] "-0,39559" "1,1916" "0,23214" "1,656" "-0,3439" "-0,50568" > [7] "0,52281" "0,96209" "0,0087242" "-0,030727" "1,0935" "0,35159" > [13] "0,79229" "0,81791" "0,3186" "1,0165" "0,65567" "-0,56474" > [19] "-0,34662" "0,70435" "-0,73285" "-0,60452" "-0,92526" "-0,296" > [25] "0,51298" "0,38654" "0,32469" "-0,92555" "0,53023" "0,050059" > [31] "1,09" "-0,35462" "0,37674" "1,1409" "0,072098" "1,4234" > [37] "1,43" "0,68532" "0,078089" "0,61944" > >It looks like you imported x as strings not as numbers. look at this:> x<-rnorm(50,mean=1) > x[1] 0.21491438 0.03133966 3.60057440 4.15322486 0.96381522 1.34283032 [7] -0.44273854 -0.53095683 -0.80736505 0.63407897 0.74989143 0.76629350 [13] 1.47503369 1.33359076 0.55049496 2.38543014 0.29774612 0.95834111 [19] 0.27763564 -0.15241260 -0.25558855 1.99413840 0.93002691 0.65026853 [25] 2.89999171 1.57017766 -0.20427214 1.05860619 0.74690706 0.95646603 [31] 0.90801464 -0.18236578 0.24682773 1.57208695 1.05569796 0.79504514 [37] 0.78895742 0.66675315 1.33666759 0.87238647 -1.12956668 0.44982951 [43] 0.25748181 0.82173105 0.86385613 1.03523168 0.17719826 2.59587957 [49] 2.22803895 2.45127783> quantile(x,probs=0.1)10% -0.2094038 Stefan -=-=- ... When the center does not hold, the circle falls apart. (Lao Tzu)
Thank you all! But the problem is that quantile() returns "how many data" are greater than p percent, and not a value in the domain of the vector under scrutiny. For example, I have a vector > x [1] "-0,39559" "1,1916" "0,23214" "1,656" "-0,3439" "-0,50568" [7] "0,52281" "0,96209" "0,0087242" "-0,030727" "1,0935" "0,35159" [13] "0,79229" "0,81791" "0,3186" "1,0165" "0,65567" "-0,56474" [19] "-0,34662" "0,70435" "-0,73285" "-0,60452" "-0,92526" "-0,296" [25] "0,51298" "0,38654" "0,32469" "-0,92555" "0,53023" "0,050059" [31] "1,09" "-0,35462" "0,37674" "1,1409" "0,072098" "1,4234" [37] "1,43" "0,68532" "0,078089" "0,61944" and, if I want to see the 10th percentile, in Matlab I go >> prctile(x, 10) ans -0.4067 But in R: > quantile(x, probs=.1) 10% 51.5 I need to obtain -0.4067, do you see what I mean? Thanks a lot again!! Jose Luis Aznarte M. escribi?:> Hi there! Still struggling to translate Matlab code into R's tsDyn package. > Here is my question: Is there in R an equivalent function to Matlab's > prctile()? To the moment I thought it was quantile(), but I just > realized I was wrong. The definition of the Matlab function: > > prctile > Percentiles of a sample > SyntaxY = prctile(X,p) > Description > Y = prctile(X,p) calculates a value that is greater than p percent of > the values in X. The values of p must lie in the interval [0 100]. For > instance, if p = 50 then Y is the median of X > > Thanks!! > >-- -- -- Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte Department of Computer Science and Artificial Intelligence Universidad de Granada Tel. +34 - 958 - 24 04 67 GRANADA (Spain) Fax: +34 - 958 - 24 00 79
Ok, of course you were right. As Stefan pointed out, it was a problem of the type of the vector: it was a factor and hence the quantile was not what expected. Thank you all!! Jose Luis Aznarte M. escribi?:> Hi there! Still struggling to translate Matlab code into R's tsDyn package. > Here is my question: Is there in R an equivalent function to Matlab's > prctile()? To the moment I thought it was quantile(), but I just > realized I was wrong. The definition of the Matlab function: > > prctile > Percentiles of a sample > SyntaxY = prctile(X,p) > Description > Y = prctile(X,p) calculates a value that is greater than p percent of > the values in X. The values of p must lie in the interval [0 100]. For > instance, if p = 50 then Y is the median of X > > Thanks!! > >-- -- -- Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte Department of Computer Science and Artificial Intelligence Universidad de Granada Tel. +34 - 958 - 24 04 67 GRANADA (Spain) Fax: +34 - 958 - 24 00 79