[R] nonlinearity and interaction

William Simpson william.a.simpson at gmail.com
Fri May 14 10:25:59 CEST 2010


I have the following set-up.

6 values of a continuous variable (let's say light intensity) are
presented to a system.
The input is presented as a random series of blocks lasting (say) 5 sec each.
              ----
     ----
----                         etc
         ----
time ->

The output is measured and sampled at say 10 samples/sec. Please
ignore the fact that this is a time series and don't suggest things
like ar() and arima(). I have looked at the autocorrelation function
of the output and it is an amazing spike at a lag of zero and zilch
elsewhere.

Call the input x and the output y.

I can find the relationship between x and y by
fit<-lm(y~x)
coef(fit) tells me the line that best fits x vs y (as shown in the
plot of the 6 values of x vs the mean values of y at those values).

****Question:
Suppose that the system is nonlinear such that the response to the
sequence 0,2 is not the same as the response to 2, 0 -- it is not just
a change of the response by the same amount. Or nonlinear in other
weird ways (I don't just mean simple things like y~x^2).

I am thinking that a way to characterise this might be to pretend that
x is not a continuous variable and to represent it with 5 indicator
variables. And then interactions between them would tell me about
nonlinear effects?
e.g.
lm(y~ d1 + d2 + d3 + d4 + d5 + d1*d2) etc
Does this make any sense? If so, please suggest a good way to go about
this; how to set up the dummy variables and how to interpret the
results.

Ideally, the same lm() fit would tell me about the linear effect y~x
and the nonlinearities. Both sorts of effect will co-exist.

Thanks very much for any help!

Bill



More information about the R-help mailing list