r - Lag dependent variable -


i want compute following time series regression using r:

$\delta y_t=\beta_1 \delta x_t+\beta_2 \delta z_t+\beta_3 \delta m_t+\beta_4 \delta y_{t−1}$

since have not experience r want ask if following r code gives me want:

y <- ts(diff(yy)) x <- ts(diff(xx)) z <- ts(diff(zz)) m <- ts(diff(mm)) l1 <- lag(y, k=-1) int <- ts.intersect(y, x, z, m, l1) reg1 <- lm(y~x+z+m+l1, data=int) summary(reg1)`  

sorry can`t find typo in formula.

here data sample:

date         yy     xx       zz      mm 03.01.2005  2.154   2.089   0.001   344999 04.01.2005  2.151   2.084   0.006   344999 05.01.2005  2.151   2.087   -0.007  333998 06.01.2005  2.15    2.085   -0.005  333998 07.01.2005  2.146   2.086   -0.006  333998 10.01.2005  2.146   2.087   -0.007  333998 11.01.2005  2.146   2.089   -0.009  333998 12.01.2005  2.145   2.085   -0.005  339999 13.01.2005  2.144   2.084   -0.004  339999 14.01.2005  2.144   2.085   -0.005  339999 17.01.2005  2.143   2.085   -0.005  339999 18.01.2005  2.144   2.085   -0.005  347999 19.01.2005  2.143   2.086   -0.006  354499 20.01.2005  2.144   2.087   -0.007  354499 21.01.2005  2.143   2.087   -0.007  354499 24.01.2005  2.143   2.086   -0.006  354499 25.01.2005  2.144   2.086   -0.006  354499 26.01.2005  2.143   2.086   -0.006  347999 27.01.2005  2.144   2.085   -0.005  352998 28.01.2005  2.144   2.084   -0.004  352998 31.01.2005  2.142   2.084   -0.004  352998 01.02.2005  2.142   2.083   -0.003  352998 02.02.2005  2.141   2.083   -0.003  357499 03.02.2005  2.144   2.088   -0.008  357499 04.02.2005  2.142   2.084   -0.004  357499 07.02.2005  2.142   2.084   -0.004  359999 08.02.2005  2.141   2.083   -0.003  355500 

i tried fg nu answered original question error message. 1. zoox = zoo(test4[, -1], order.by = test4$date) comand works fine. (the first column of data set date column, dataset looks data sample in question.) 2. ran regression: lmx = dynlm(d(yy) ~ d(xx) + d(zz) + d(mm) + l(yy, 1), data = zoox) here following error message: error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-na) cases in addition: warning message: in dynlm(d(yy) ~ d(xx) + d(zz) + d(mm) + l(yy, 1), data = zoox) : empty model frame specified bug overseeing?

use dynlm package. here example using data supplied:

library(dynlm)  dfx = read.table(   textconnection(     "date         yy     xx       zz      mm   03.01.2005  2.154   2.089   0.001   344999   04.01.2005  2.151   2.084   0.006   344999   05.01.2005  2.151   2.087   -0.007  333998   06.01.2005  2.15    2.085   -0.005  333998   07.01.2005  2.146   2.086   -0.006  333998   10.01.2005  2.146   2.087   -0.007  333998   11.01.2005  2.146   2.089   -0.009  333998   12.01.2005  2.145   2.085   -0.005  339999   13.01.2005  2.144   2.084   -0.004  339999   14.01.2005  2.144   2.085   -0.005  339999   17.01.2005  2.143   2.085   -0.005  339999   18.01.2005  2.144   2.085   -0.005  347999   19.01.2005  2.143   2.086   -0.006  354499   20.01.2005  2.144   2.087   -0.007  354499   21.01.2005  2.143   2.087   -0.007  354499   24.01.2005  2.143   2.086   -0.006  354499   25.01.2005  2.144   2.086   -0.006  354499   26.01.2005  2.143   2.086   -0.006  347999   27.01.2005  2.144   2.085   -0.005  352998   28.01.2005  2.144   2.084   -0.004  352998   31.01.2005  2.142   2.084   -0.004  352998   01.02.2005  2.142   2.083   -0.003  352998   02.02.2005  2.141   2.083   -0.003  357499   03.02.2005  2.144   2.088   -0.008  357499   04.02.2005  2.142   2.084   -0.004  357499   07.02.2005  2.142   2.084   -0.004  359999   08.02.2005  2.141   2.083   -0.003  355500"   ), header = true) dfx$date = as.date(dfx$date, format = "%d.%m.%y")  # convert zoo format zoox = zoo(dfx[, -1], order.by = dfx$date)  # run regression time transformed regressors lmx = dynlm(d(yy) ~ d(xx) + d(zz) + d(mm) + d(l(yy, 1)), data = zoox) summary(lmx) 

this gives output:

> summary(lmx)  time series regression "zoo" data: start = 2005-01-05, end = 2005-02-08  call: dynlm(formula = d(yy) ~ d(xx) + d(zz) + d(mm) + d(l(yy, 1)),      data = zoox)  residuals:        min         1q     median         3q        max  -0.0039592 -0.0003746  0.0000854  0.0006254  0.0018715   coefficients:               estimate std. error t value pr(>|t|)   (intercept) -5.008e-04  2.766e-04  -1.811   0.0853 . d(xx)        2.943e-01  2.409e-01   1.222   0.2359   d(zz)        2.038e-03  1.715e-01   0.012   0.9906   d(mm)        7.808e-08  8.251e-08   0.946   0.3553   d(l(yy, 1)) -1.677e-01  2.103e-01  -0.797   0.4346   --- signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  residual standard error: 0.001248 on 20 degrees of freedom multiple r-squared:  0.2579,    adjusted r-squared:  0.1095  f-statistic: 1.738 on 4 , 20 df,  p-value: 0.1813 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -