simple examples of filter function, recursive option specifically

前端 未结 4 1747
走了就别回头了
走了就别回头了 2020-12-02 15:36

I am seeking some simple (i.e. - no maths notation, long-form reproducible code) examples for the filter function in R I think I have my head around the convolu

4条回答
  •  不思量自难忘°
    2020-12-02 16:24

    With recursive, the sequence of your "filters" is the additive coefficient for the previous sums or output values of the sequence. With filter=c(1,1) you're saying "take the i-th component in my sequence x and add to it 1 times the result from the previous step and 1 times the results from the step before that one". Here's a couple examples to illustrate

    I think the lagged effect notation looks like this:

    ## only one filter, so autoregressive cumsum only looks "one sequence behind"
    > filter(1:5, c(2), method='recursive')
    Time Series:
    Start = 1 
    End = 5 
    Frequency = 1 
    [1]  1  4 11 26 57
    
    1 = 1
    2*1 + 2 = 4
    2*(2*1 + 2) + 3 = 11
    ...
    
    ## filter with lag in it, looks two sequences back
    > filter(1:5, c(0, 2), method='recursive')
    Time Series:
    Start = 1 
    End = 5 
    Frequency = 1 
    [1]  1  2  5  8 15
    
    1= 1
    0*1 + 2 = 2
    2*1 + 0*(0*1 + 2) + 3 = 5
    2*(0*1 + 2) + 0 * (2*1 + 0*(0*1 + 2) + 3) + 4 = 8
    2*(2*1 + 0*(0*1 + 2) + 3) + 0*(2*(0*1 + 2) + 0 * (2*1 + 0*(0*1 + 2) + 3) + 4) + 5 = 15
    

    Do you see the cumulative pattern there? Put differently.

    1 = 1
    0*1 + 2 = 2
    2*1 + 0*2 + 3 = 5
    2*2 + 0*5 + 4 = 8
    2*5 + 0*8 + 5 = 15
    

提交回复
热议问题