[R] Moving average with loess

Downey, Patrick PDowney at urban.org
Fri Mar 9 15:33:20 CET 2012


Hi Robert,

If you type
?loess
It pulls up the documentation. What about that function do you not like? As
you said, it needs two variables, but typically the second is just your
time index. Try this:

n <- 50
x <- rep(0,n)
for(i in 2:n){
  x[i] <- rnorm(1,x[i-1])
}
loess(x ~ seq(1,n))
plot(1:n,x,type='l')
lines(predict(loess(x ~ seq(1,n))),col=4,type='l')

This might also help:
http://research.stowers-institute.org/efg/R/Statistics/loess.htm


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Faryabi, Robert (NIH/NCI) [F]
Sent: Thursday, March 08, 2012 6:43 PM
To: r-help at r-project.org
Subject: [R] Moving average with loess

Hello All,

I just have a very simple question. I recently switching from Matlab to R,
so cannot figure out some of the easy tasks in the new environment.

Is there any weighted local regression smoothing in R? Basically, I want to
have weighted moving average. All the functions that I know of need two
variables for fitting.

Best,
Robert

______________________________________________
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.



More information about the R-help mailing list