Skip to content

using filter() to sum up

3 messages · T.Riedle, Peter Dalgaard

#
Hi everybody,

I am trying to create a code for the formula in the attachment. I first tried following code:

ltau <- m + theta*sum(psi*X[t-k])

but it does not work and I get for X[t-k] every third element in my vector three times which looks as follows:
X[t-k]
[1] -0.25 -0.25 -0.25 0.50 0.50 0.50 -0.44 -0.44 -0.44 0.15 0.15 0.15

Thus, I tried the filter() function in R which looks as follows:
ltau <- m + theta* filter(f.USA$UTS, phi(K, omega1, omega2), sides=1, method="conv")

Reading the description of this function I am unsure whether this provides the sum of the k lags. The appreviation "conv" provides, as far as I understand, the moving average instead of the sum.

Does anybody have an idea how the R code for the formula attached must look like? Is the filter() function appropriate?

Thanks in advance.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tau.png
Type: image/png
Size: 8142 bytes
Desc: tau.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150504/7ceb3dd1/attachment.png>
#
On 04 May 2015, at 21:38 , T.Riedle <tr206 at kent.ac.uk> wrote:

            
That's not going to work. It might work with something like

sum(psi*X[(t-1):(t-K)])
I would assume that it means convolution. Which is what you have in the formula.
It's barking up the right tree, but do your own checks...

-pd

  
    
12 days later
#
Hi,
I tried the formula

sum(psi*X[(t-1):(t-K)])

but it provides the vector of all observations. Thus, I changed K to k where 

K<-3 and k<-1:K

This yields better results but not what I want since I should get 3 values as K=3.
[1] 0.1
Warning message:
In (t - 1):(t - k) :
  numerical expression has 3 elements: only the first used

Why do I get this error message and how can I avoid it??

Thanks in advance


-----Original Message-----
From: peter dalgaard [mailto:pdalgd at gmail.com] 
Sent: 05 May 2015 11:41
To: T.Riedle
Cc: r-help at r-project.org
Subject: Re: [R] using filter() to sum up
On 04 May 2015, at 21:38 , T.Riedle <tr206 at kent.ac.uk> wrote:

            
That's not going to work. It might work with something like

sum(psi*X[(t-1):(t-K)])
I would assume that it means convolution. Which is what you have in the formula.
It's barking up the right tree, but do your own checks...

-pd
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com









-------------- next part --------------
A non-text attachment was scrubbed...
Name: tau.png
Type: image/png
Size: 8142 bytes
Desc: tau.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150517/d2ecc266/attachment.png>