Data Frame and Linear Regression

3

With this date frame I need to run some regressions. I want to do regressions with terms that are high to 3 and out of date.

I searched the lm package and could not implement it.

I want to, for example, rotate the first column in logarithm against the 2nd, 3rd and 4th column squared plus the lagged term of the first column.

  AnoTrimestreLAG1 ENGTrimestralemT ENGTrimestralemLAG1 CotatoTrimestralemLAG1 CotatodTrimestralLAG12
2       2014-12-31        0.7695652           0.9367866                   -1.6                  2.56
3       2014-09-30        0.9367866           1.7134771                   -0.2                  0.04
4       2014-06-30        1.7134771           2.7852691                   -0.6                  0.36
5       2014-03-31        2.7852691           2.9320260                   -1.2                  1.44
6       2013-12-31        2.9320260           3.1011732                    2.7                  7.29
7       2013-09-30        3.1011732           2.7699729                    2.1                  4.41

How can I implement? can I do a function that does this? Any tip would be enough.

Thank you.

    
asked by anonymous 16.10.2015 / 18:06

1 answer

6

To make log you can put directly into the formula. Example:

# sem log
lm(mpg ~ cyl, mtcars)

# com log
lm(log(mpg) ~ cyl, mtcars)

To put the quadratic term you will use the I() auxiliary function. For more details see the question: How to include a variable in the regression an .

Example:

lm(mpg ~ cyl + I(cyl^2), mtcars)

To put lag is more complicated. You can not use the lag function directly. The most appropriate would be to manually create or use own packages for time series.

    
16.10.2015 / 22:52