Re: [R] Scale time series in a way that 90% of the data is in the -0.-9/ +0.9 range

From: Jerome Asselin <jerome.asselin.stat_at_gmail.com>
Date: Thu, 12 May 2011 19:08:49 -0400

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



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. Received on Thu 12 May 2011 - 23:11:42 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 May 2011 - 00:10:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive