Here is one example from this link:

http://stats.stackexchange.com/questions/9931/exponentially-weighted-moving-linear-regression

I am not sure this is the best solution...

If you think of the exponential moving average of volatility(Risk Metrics
standard), that is more elegant)???

R> x <- 1:10    ## mean of this is 5.5
R> lm(x ~ 1)    ## regression on constant computes mean

Call:
lm(formula = x ~ 1)

Coefficients:
(Intercept)
        5.5

R> lm(x ~ 1, weights=0.9^(seq(10,1,by=-1)))

Call:
lm(formula = x ~ 1, weights = 0.9^(seq(10, 1, by = -1)))

Coefficients:
(Intercept)
       6.35

R>



On Thu, Jan 5, 2012 at 9:37 AM, Michael <comtech.usa@gmail.com> wrote:

> What I am looking for is some kind of "exponential moving average linear
> regression"...
>
> In a typical linear regression, we divide the time series into trunks...
>
> For example, we run Linear Regression on the following trunks of time
> series data (window size K):
>
> 1... K,
> 2... (K+1),
> 3... (K+2),
> ...
> ...
> (N-K+1) ... N
> ----------------
>
> Are you saying that I can use the exponentially weighted linear regression
> on the time series as data become available?
>
> 1 ... K,
> 1 ... (K+1),
> 1 ... (K+2),
> 1 ... (K+3),
> ...
> ...
> 1 ... N
>
> Then each time what should be my "exponentially decaying" weights?
>
> ----------------
>
> Thanks a  lot!
>  On Thu, Jan 5, 2012 at 9:22 AM, Zachary Mayer <zach.mayer@gmail.com>wrote:
>
>> I'm not following you.  What do you mean by "a divided trunk of data?"
>>  As far as I know, lm and glm will take as much data as you give them,
>> until you run out of memory.  Why not run the lm on the whole time series?
>>
>> Perhaps you could post a reproducible example, so we can see what you're
>> trying to do.
>>
>>
>> On Thu, Jan 5, 2012 at 10:16 AM, Michael <comtech.usa@gmail.com> wrote:
>>
>>>
>>> Thanks Zach.
>>>
>>> The problem with these functions (e.g. lm or glm with weights argument)
>>> is that they still do it on a divided trunk of data... i.e. block by block,
>>> not the whole time series...
>>>
>>> If we think about the exponential moving average estimate of volatility
>>> with a decay factor lamda, it is actually on the whole time series... not
>>> divided trunk of data.
>>> Any thoughts?
>>>
>>> On Thu, Jan 5, 2012 at 8:40 AM, Zachary Mayer <zach.mayer@gmail.com>wrote:
>>>
>>>> Hi Michael,
>>>>
>>>> R has lots of functions for exponential smoothing.  ets<http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=forecast:forecast.ets> in
>>>> the forecast package<http://cran.r-project.org/web/packages/forecast/index.html> is
>>>> particularly useful.  Additionally, many models in R (including lm and glm)
>>>> have a weights argument.  You can come up with any weighting scheme you
>>>> wish, and pass it to your model as a weights argument.
>>>>
>>>> There may be more useful references on the CRAN time-series task view<http://cran.r-project.org/web/views/TimeSeries.html>
>>>> .
>>>>
>>>> Regards,
>>>>
>>>> Zach
>>>>
>>>>  On Thu, Jan 5, 2012 at 9:30 AM, Michael <comtech.usa@gmail.com> wrote:
>>>>
>>>>>  Hi all, Happy New Year!
>>>>>
>>>>> Is there a function for exponentially weighted linear regression in R?
>>>>>
>>>>> Usually, a linear regression is on a trunk of data...
>>>>>
>>>>> And if I run linear regression on time series, I divide the time series
>>>>> into "overlapped/rolling" windows and run linear regression on each
>>>>> rolling
>>>>> chunk of data...
>>>>>
>>>>> Is there a way to turn the rolling linear regression on the whole time
>>>>> series into an exponentially weighted one, i.e. using a decay factor
>>>>> lambda
>>>>> to give more weights to the newer observations...?
>>>>>
>>>>> Are there packages in R which can do that?
>>>>>
>>>>> Thanks a lot!
>>>>>
>>>>>        [[alternative HTML version deleted]]
>>>>>
>>>>> _______________________________________________
>>>>> R-SIG-Finance@r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>>>> -- Also note that this is not the r-help list where general R
>>>>> questions should go.
>>>>>
>>>>
>>>>
>>>
>>
>

	[[alternative HTML version deleted]]

