Suppose I have data which looks like this:
dat <- data.frame(t = c(rep(0,30), rep(5,30), rep(10,30), rep(15,30), rep(20,30)), y = c(rnorm(30, 5, .5), rnorm(30, 4, .5), rnorm(30, 3, .5), rnorm(30, 2, .5), rnorm(30, 1, .5)))
Which has a sequence of treatments which have a set order (e.g. lab rats exposed to the same chemical at different concentrations or long-distance runners placed in hyperbaric chambers for increasing periods of time). What is the best way to determine whether there is a linear relationship or a step change at a critical point as there is in this second dataset?
dat2 <- dat change <- which(dat2$t %in% 10) dat2$y[change] <- dat2$y[change] + 1 change <- which(dat2$t %in% 15) dat2$y[change] <- dat2$y[change] - 1
How can you tell when the step change is significant with enough confidence to say one way or the other? Or at least put a probability on the two possibilities.
Ideally I'd like only these two possibilities to be possible so that if something else with obvious outliers appeared in the data like this:
dat3 <- dat change <- which(dat3$t %in% 0) dat3$y[change] <- dat3$y[change] - 3
the obvious linear relationship would continue to be detected.
I have seen this question and note that changepoint analysis is probably not appropriate as there are multiple data points per treatment and not many treatments compared to a time series. I guess straightforward ANOVA or regression could be applied to identify a difference but I don't think it would identify a single step change. Although i'm happy to be proved wrong.