[R] nlme formula from model specification
Mikkel Meyer Andersen
mikl at mikl.dk
Thu Sep 2 13:30:15 CEST 2010
Dear R-community,
I'm analysing some noise using the nlme-package. I'm writing in order
to get my usage of lme verified.
In practise, a number of samples have been processed by a machine
measuring the same signal at four different channels. I want to model
the noise. I have taken the noise (the signal is from position 1 to
3500, and after that there is only noise).
My data looks like this:
channel.matrix:
pos channel0 channel1 channel2 channel3 samplenumber
1 3501 8 3 12 1 1
2 3502 3 7 0 14 1
3 3503 9 1 13 3 1
4 3504 3 7 3 14 1
5 3505 6 5 4 5 1
6 3506 7 0 16 0 1
...
495 3995 5 2 9 9 1
496 3996 2 4 6 10 1
497 3997 3 2 7 7 1
498 3998 2 4 3 9 1
499 3999 3 1 6 11 1
500 4000 0 3 6 7 1
2301 3501 1 4 3 9 2
2302 3502 3 3 4 13 2
2303 3503 4 1 8 5 2
2304 3504 3 1 10 2 2
2305 3505 2 3 5 8 2
2306 3506 0 5 8 2 2
...
The model is
channel0 ~ alpha_i + eps_{i, j} + channel1 + channel2 + channel3
where i is sample number, j is position, and:
alpha_i: fixed effect for each samplenumber
eps_{i, j}: random effect, here with correlation
structure as AR(1)
channel1, ..., channel3: fixed effect for each channel not depending on
samplenumber nor position
(And then afterwards I would model channel1 ~ ... + channel2 + channel3 etc.)
I then use this function call:
channel.matrix.grouped <- groupedData(channel0 ~ pos | samplenumber,
data = channel.matrix)
fit <- lme(channel0 ~ pos + samplenumber + channel1 + channel2 + channel3,
random = ~ pos | samplenumber,
correlation = corAR1(value = 0.5, form = ~ pos | samplenumber),
data = channel.matrix.grouped)
Is that the right way to express the model in (n)lme-notation?
Cheers, Mikkel.
More information about the R-help
mailing list