Repeated measures ANOVA in R with monotonically increasing, nonlinear timeseries data I am trying to determine whether there is a difference between two
treatments, in a response variable that was measured repeatedly over
time. We know (from theory and observation) that the response variable
increases monotonically but nonlinearly as a function of time,
asymptotically approaching some maximum.
It seems like repeated measures ANOVA would be the thing to use here,
but I am having difficulty with it. I definitely do not completely
understand repeated measures ANOVA. (I also don’t think I really
understand what my null hypothesis is, other than ‘are these two
treatements different’).
First, I’ll simulate some data using a saturating function plus random
noise:
library(dplyr)
library(tidyr)
library(purrr)
library(ggplot2)

# Function to create simulated data
mm_fun <- function(args) {
  time <- args$time
  Vmax <- args$Vmax
  half.sat <- args$half.sat
  y <- (time * Vmax)/(time + half.sat) + rnorm(length(time), mean=0, sd=1)
  df <- data.frame(time=time, y=y)
}

# The domain of the data
time <- 0:100 # All data sets have the same domain
set.seed(0)

# List of parameters with which to make 6 data sets
param_l <- list(
  a1 = list(time=time, Vmax = 20, half.sat=25),
  a2 = list(time=time, Vmax=22, half.sat=28),
  a3 = list(time=time, Vmax=18, half.sat=23),
  b1 = list(time=time, Vmax=5, half.sat=50),
  b2 = list(time=time, Vmax= 5.5, half.sat=53),
  b3 = list(time=time, Vmax=4.5, half.sat=48)
)

# Calculate data from parameters
d <- map_df(param_l, mm_fun, .id = "sample")

# Add column identifying reps
d$treatment <- substr(d$sample, 0, 1)

# Plot
ggplot(d, aes(x=time, y=y, colour=treatment)) +
  geom_line(aes(group=sample))


Clearly treatment a is behaving differently somehow than treatment
b, but within a treatment, there isn’t much difference between
replicates.
I’ve coded repeated measures ANOVA as follows:
# Try a repeated measures anova
mod <- aov(y ~ time + Error(treatment/time), data=d)
summary(mod)

## 
## Error: treatment
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  1  14169   14169               
## 
## Error: treatment:time
##           Df Sum Sq Mean Sq F value Pr(>F)
## time       1   3047    3047   2.463  0.361
## Residuals  1   1237    1237               
## 
## Error: Within
##            Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 602   1410   2.343

I read this as reporting no significant difference by treatment and no
interaction between treatment and time, both of which seem wrong. But
then I don’t really understand how Error() works, or what an appropriate null hypothesis for these treatments are different would be.
 A: Why not use a linear mixed model instead? You can consider sample to be a random effect in this context. The relationship might not be linear, but a monotone transformation yields an approximately linear relationship:  


*

*Square-root transformation of time ($\sqrt{\text{time}}$) 

*Logarithmic transformation of time ($\log(\text{time} + 1)$, add one because your time series starts at 0 and $\log(0)$ is undefined)

*Squared transformation of the response ($y^2$)


I don't know how to include the output on this forum yet, but here is an example using your data:
plot(y ~ log(time + 1), data = d)
plot(y ~ sqrt(time), data = d)
plot(y^2 ~ time, data = d)

library(lme4) # for linear mixed models
# Using a square-root transformation:
LMM.sqrt <- lmer(y ~ sqrt(time) * treatment + (1|sample), data = d)

# Or a logarithmic relationship:
LMM.log <- lmer(y ~ log(time + 1) * treatment + (1|sample), data = d)

# Squared response:
LMM.sqry <- lmer(y^2 ~ time * treatment + (1|sample), data = d)

Now sample is a random effect (I guess this is also what you will want to put in Error() for the RM-ANOVA) affecting the intercept.
The best model in terms of AIC turns out to be the log-transformed model:  
anova(LMM.sqrt, LMM.log, LMM.sqry)

You can get the effect of treatment by looking at the fixed effects under the summary:
summary(LMM.log)

You can get confidence intervals for inference:
confint(LMM.log)

The effect of the random effect is small, but significant at $\alpha = 0.05$. Treatments differ significantly and the interaction between time and treatment is also significant. This means a starts higher than b and also increases with time more than b.
A: 
I also don’t think I really understand what my null hypothesis is, other than ‘are these two treatements different’

In a traditional hypotheses setup, you would have:
H: Y differs between treatments A & B
H0 (null): Y does not differ between treatments A & B
And I'll definitely second Frans' advice to run this as a linear mixed model instead (you might also see it called a linear mixed-effects model - either way, abbreviated as LMM). Some of the advantages to this approach are explained here: http://www.theanalysisfactor.com/advantages-of-repeated-measures-anova-as-a-mixed-model/
