Christian Satzky
2013-Apr-01 06:37 UTC
[R] Parameter Estimation in R with Sums and Lagged Variables
Hi guys, I am afraid I am stuck with an estimation problem. I have two variables, X and Y. Y is explained by the weighted sum of n lagged values of X. My aim is to estimate the two parameters c(alpha0,alpha1) in: Yt = Sum from j=1 to n of ( ( alpha0 + alpha1 * j ) * Xt-j ) Where Xt-j denotes the jth lag of X. I came up with this approach because I thought it would be a good idea to estimate the slope of the weights rather than estimating one parameter for each lag of X added (I intent to set n very large). Is that easily doable in R? My first try looks like this: parameters<-function(alpha,y){ logl<- for(i in 1:n){ sum((alpha[1]+alpha[2]*i)*lag(xvar,i)) } return(-logl) } optim(c(0.001,0.001),parameters,y=yvar) It is really hard to find any clear sources when it comes to optimization including lags. I would really appreciate if someone could help me out on this one! Kind regards & Happy Easter, Christian [[alternative HTML version deleted]]
Mark Leeds
2013-Apr-01 14:45 UTC
[R] Parameter Estimation in R with Sums and Lagged Variables
Hi: Google for koyck distributed lag. Based on what you wrote, I think that's what you're looking for or something close to it. There is tons of literature on that model and if you read enough about it, you'll see that through a transformation, reduces to something that much simpler to estimate. There are so many papers that I wouldn't know which one to send you. As far as textbooks, Baltagi's has the best explanation that I've seen. There is tons of literature on that model On Mon, Apr 1, 2013 at 2:37 AM, Christian Satzky <c.satzky@gmail.com> wrote:> Hi guys, > > I am afraid I am stuck with an estimation problem. > > I have two variables, X and Y. Y is explained by the weighted sum of n > lagged values of X. My aim is to estimate the two parameters > c(alpha0,alpha1) in: > > Yt = Sum from j=1 to n of ( ( alpha0 + alpha1 * j ) * Xt-j ) > > Where Xt-j denotes the jth lag of X. > > I came up with this approach because I thought it would be a good idea to > estimate the slope of the weights rather than estimating one parameter for > each lag of X added (I intent to set n very large). Is that easily doable > in R? > > My first try looks like this: > > parameters<-function(alpha,y){ > logl<- for(i in 1:n){ > sum((alpha[1]+alpha[2]*i)*lag(xvar,i)) > } > return(-logl) > } > optim(c(0.001,0.001),parameters,y=yvar) > > It is really hard to find any clear sources when it comes to optimization > including lags. > > I would really appreciate if someone could help me out on this one! > > Kind regards & Happy Easter, > > Christian > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]