# [R-SIG-Finance] How to solve it? Y is not only related with the same year's X, but also the previsous few years' X and Y

Gabor Grothendieck ggrothendieck at gmail.com
Sun Mar 8 02:58:48 CET 2009

```See VAR in the vars package.

On Sat, Mar 7, 2009 at 8:17 PM, zhijie zhang <rusers.sh at gmail.com> wrote:
> Dear all,
>  Does R have function or method to finish the following task.
> Say i have a dataset. The response variable is Y, and the indepedent
> variables are X1, X2, X3, and YEAR. See an example.
> Y              X1            X2            X3          X4            YEAR
> 13.4         2.8           3.5              2.5      1.8          1990
> 10.5        1.8            2.4              2          3           1991
>            ....          .....
>  In ecology, Y may be not only related with X1, X2, X3 in the same year as
> Y, but also may be related with X1, X2, X3 and Y in the previous one , two
> or more years as Y. But which year has the closest relationship is not know
> and this may be one of the analysis aim.
> Take Year=1995 as an example,
>  Y_1995 may be related with
>      X1_1995 , X2_1995 , X3_1995,
>      X1_1994 , X2_1994 , X3_1994,  Y_1994,   (previous one year)
>     X1_1993 , X2_1993 , X3_1993, Y_1993      (previous two years)
>                ...         ...                                    (previous
> more years)
>  So the possible model seems like Y_1995= (X1_1995 + X2_1995 + X3_1995)
>                                                                +(X1_1994 +
> X2_1994 + X3_1994 + Y_1994)
>                                                                +(X1_1993 +
> X2_1993 + X3_1993 + Y_1993)
>                                                                +...
>  Pay attention to the situation that Y may be not only related with the
> same year's X,  but also the previsous few years' X and Y. I had checked out
> the methods of time series (TS), but i did not find the right method. I
> think this should be related with TS, but i am not sure if it cannot solve
> it. TS may only considers the autocorrelation of Y in different time, but
> not Xs. Besides Y, i also have several independent variables that have
> effects on Y in the next few years .
>   Anybody knows whether R have functions or methods to finish the above
>  I hope i have explained it clearly. Any suggestions or help are greatly
> appreciated.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>

```