Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I've made replicate measurements of a parameter (fluorescence) which is expected to increase with time, and I'm having a hard time understanding how to test for significance of the slope of the parameter vs. time (using a linear least squares model).

Intuitively, it makes sense to me to combine all time-fluorescence pairs for each replicate into a grand dataset, and look at the significance of the slope of that fit. However, the intercept of the parameter is expected to differ between replicates due to an instrumental artifact. It's not clear to me whether it is legitimate to combine the data for each replicate due to the expected difference in intercepts. Many thanks for any help.

to put this in R terms:

t1 <- 1:10
f1 <- rnorm(10)
t2 <- 1:10
f2 <- rnorm(10)
t3 <- 1:10
f3 <- rnorm(10)

Is it legitimate to look at the significance of the slope of

model <- lm(c(f1, f2, f3) ~ c(t1, t2, t3))

Or should I be doing something different?

share|improve this question

2 Answers

up vote 2 down vote accepted

It's not legitimate to just fit a line through the whole thing for two reasons:

  • even if you had only one replicate, you will have autocorrelation in the residuals over time. Observation at $t_n$ is related to the observation at $t_{n-1}$ so you can't treat them as independent. There is actually less information in each observation than if they were independent. So you need a model that takes this into account.

  • as it happens, you have three replicates. The intercept and the slope are likely to vary for each replicate. You could address this by allowing an interaction of slope and intercept with a fixed factor for replicate, but better is just to treat this as a source of grouped randomness.

The lme() function in Pinheiro and Bates' library(nlme) can solve both of these problems for you (although working out the exact way to treat the residuals can be quite an involved issue).

In terms of how the data should be structured, I think it's best to have three columns - one for which replicate you have, and one each for the time and for the actual measurement. As well as being a good format to fit a model to, this is also a good format for drawing plots easily using ggplot2.

enter image description here

So something like this.

library(ggplot2)
library(nlme)

t1 <- 1:10
f1 <- rnorm(10,13,1) + t1 * rnorm(10,3,1)
t2 <- 1:10
f2 <- rnorm(10,14,2) + t1 * rnorm(10,2,.5)
t3 <- 1:10
f3 <- rnorm(10,14,1)  + t1 * rnorm(10,4, 1.5)
fALL <- c(f1, f2, f3)
tALL <- c(t1, t2, t3)
replicate <- rep(c("One", "Two", "Three"), rep(10,3))
fluoro <- data.frame(fALL, tALL, replicate)
rm(f1, f2, f3, t1, t2, t3, replicate) # clean up
fluoro

p <- ggplot(fluoro, aes(x=tALL, y=fALL, color=replicate))
# couple of different versions of the plots
p + geom_line()
p + geom_smooth(method="lm") + geom_point()

 # example only - this may be the wrong error structure
model <- lme(fALL ~ tALL, data=fluoro, random=~1|replicate, correlation=corAR1())
share|improve this answer
In the original poster's formulation how is there autocorrelation in the residuals? The dependent variables are 30 iid $N(0,1)$ variables. In the verbal description, the poster seems to describe a situation where there's a deterministic trend in the mean over time, not temporal autocorrelation. – Macro Mar 8 '12 at 4:13
In the OP's code they are indeed iid $N(0,1)$ but in his description they are ten measurements in time on the same variable - although he does not state it himself I am sure there is likely to be autocorrelation in addition to the deterministic trend. Imagine the time between measurements approaching zero. – Peter Ellis Mar 8 '12 at 13:54
I think @PeterEllis is right. The actual measurements are a physical parameter of a sample (fluorescence). The measured fluorescence is probably given by something like Fm = F0 + noise + drift(time), where F0 is the 'true' fluorescence signal, noise is random and drift(time) is some long-wavelength instrumental drift that is a function of time. I guess F0 and drift(time) must both introduce autocorrelation. – Drew Steen Mar 8 '12 at 19:55

If you want to include a different intercept for each of the three sequences of values, you can try

n <- factor(rep(1:3, each=10))
lm( c(f1, f2, f3) ~ c(t1, t2, t3) + n )
share|improve this answer
Or if you also want to allow a different slope you could try lm( c(f1, f2, f3) ~ c(t1, t2, t3) * n ). But this doesn't get around the problem that the residuals are related to eachother over time. – Peter Ellis Mar 8 '12 at 0:09
(also @PeterEllis): These are good points; I hadn't thought about the autocorrelation issue. The slopes are my real 'measurement' (they represent a rate). Perhaps then it is conservative, but not overconservative, to simply do a one-sample t-test on the fitted slopes, like so: t.test(c(slope1, slope2, slope3), mu=0) – Drew Steen Mar 8 '12 at 1:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.