# [R] writing equations

Steven Boker sboker at mpipks-dresden.mpg.de
Sat May 5 00:30:35 CEST 2001

```On Friday 04 May 2001 22:17, Antonio Olinto wrote:
> Dear R-list members,
>
> I have a data frame with two columns (X, Y). How can I write the following
> equation (using nls)
>
> log(X2/X1) ~ a + b * (Y1+Y2)/2 + c * (X1+X2)/2
>
> To calculate the fitted values for each line (Xi) I have to use numbers in
> consecutive lines (Xi, Xi+1, Yi and Yi+1).
>

What I do is build a lagged version of the data frame.  Since I tend to
use lagged data with different lags a lot, I'll generally predefine a lag
called tau (in your example tau=1) and then use it like so:

tau <- 1
theFrame <- data.frame(x1=X[1:(length(X)-tau)],
x2=X[(1+tau):length(X)],
y1=Y[1:(length(X)-tau)],
y2=Y[(1+tau):length(X)])

Now you can use these new lagged variables however you want in your formula.

Cheers,
Steve Boker
sboker at nd.edu
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```