Skip to content

Confusion in 'quantile' and getting rolling estimation of sample quantiles

5 messages · Saji Ren, Gabor Grothendieck

#
Guys:

1).When I using the 'quantile' function, I get really confused. Here is what
I met:
400 
1.060258
80% 
0.9986075

why do the results display different? Is that because of the different type
of the class?

2).And I want to use the 'rollapply' function to compute a rolling
estimation of the sample quantile.
the command i used is below:
Here the 'x' is the one generated above in 1).
And the R told me:

"mistakes in match.fun(FUN) : 
  'quantile(x, 0.8)' is not a function, character or symbol"

Can anyone help? Thank you in advanced.


-----
------------------------------------------------------------------
Saji Ren
from Shanghai China
GoldenHeart Investment Group
------------------------------------------------------------------
#
There is no quantile method defined for zoo objects so it falls
through to the default method but that method does not work for zoo
objects.  Try this:

set.seed(123)
rn <- rnorm(500)
quantile(rn, 0.8)
quantile(coredata(zoo(rn)), 0.8)

In the second question the error message tells you what the problem
is.  FUN is supposed to be a function but a vector of numbers has been
supplied rather than a function.  Try:

uprange=rollapply(x,width=10,FUN=function(x)quantile(x,0.8),align='right')
On Sat, Jan 16, 2010 at 10:08 PM, Saji Ren <saji.ren at gmail.com> wrote:
1 day later
#
Gabor, 
about problem 1. , now I understand.
But in problem 2. , I do as your recommandation. and it still doesn't work.
I wonder is there any detail introduction about the form of the 'FUN' in the
'rollapply'?
Can you help me again?

Thank you very much!

Best regard
Saji


There is no quantile method defined for zoo objects so it falls
through to the default method but that method does not work for zoo
objects.  Try this:

set.seed(123)
rn <- rnorm(500)
quantile(rn, 0.8)
quantile(coredata(zoo(rn)), 0.8)

In the second question the error message tells you what the problem
is.  FUN is supposed to be a function but a vector of numbers has been
supplied rather than a function.  Try:

uprange=rollapply(x,width=10,FUN=function(x)quantile(x,0.8),align='right')



-----
------------------------------------------------------------------
Saji Ren
from Shanghai China
GoldenHeart Investment Group
------------------------------------------------------------------
#
sorry for bothering you again,
the problem solved. the command should be :

uprange=rollapply(zoo(x),width=10,FUN=function(x)quantile(x,0.8),align='right')
Gabor Grothendieck wrote:
-----
------------------------------------------------------------------
Saji Ren
from Shanghai China
GoldenHeart Investment Group
------------------------------------------------------------------
#
My post was based on the definitions in yours so x had already been
defined as a zoo object, x <- zoo(rnorm(500,0,1)).
On Mon, Jan 18, 2010 at 1:17 AM, Saji Ren <saji.ren at gmail.com> wrote: