Skip to content
Prev 198 / 523 Next

[RsR] Seasonal adjustment; What's a good `blackbox' robust lm() function?

On Sun, Jun 8, 2008 at 10:19 AM, Ajay Shah <ajayshah at mayin.org> wrote:
Check out:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/40254.html

Also more below.
Noting that months(chron.object) and quarters(chron.object)
gives an ordered factor, here are a few approaches to the coefs:

library(chron)
library(quantreg)
rq(cpi ~ months(as.chron(date)) -1, data = n, method = "fn")

or what is basically the same, the median

tapply(n$cpi, list(month = months(as.chron(n$date))), median, na.rm = TRUE)

or a trimmed mean:

tapply(n$cpi, list(month = months(as.chron(n$date))), mean, trim =
0.1, na.rm = TRUE)


Note that we can simplify the adjustment function using ave. The
following subtracts out
monthly trimmed means from each data point:

ave(n$cpi, months(as.chron(n$date)), FUN = function(x) x - mean(x,
trim = 0.1, na.rm = TRUE))