[R] Scale time series in a way that 90% of the data is in the -0.-9/ +0.9 range
Jerome Asselin
jerome.asselin.stat at gmail.com
Fri May 13 01:08:49 CEST 2011
On Thu, 2011-05-12 at 06:40 -0700, Mr.Q wrote:
> Hello,
>
> How can i scale my time series in a way that 90% of the data is in the
> -0.-9/ +0.9 range?
>
I have two methods to suggest. One that uses the ranks to scale, hence
is nonparametric and will work with any data distribution. The other
uses a normal approximation of the distribution you're trying to scale.
> N <- 200
> y <- rnorm(N,mean=10,sd=5)
>
> scale.by.rank <- (rank(y)/(N+1)-0.5)*2
> quantile(scale.by.rank, c(0.05, 0.95))
5% 95%
-0.891 0.891
>
> scale.by.normal.approx <- (y - mean(y))/sd(y)/qnorm(0.95)*0.9
> quantile(scale.by.normal.approx, c(0.05, 0.95))
5% 95%
-0.925 0.887
>
> all.equal(rank(scale.by.rank), rank(scale.by.normal.approx))
[1] TRUE
The normal approximation will work only if your time series data is
normally distributed. For example, it will not work as expected if your
data is generated with:
y <- rexp(N)
HTH,
Jerome
More information about the R-help
mailing list