Detecting patterns in residual plot I wish to automatically (not by visual inspection) detect where large deviations occur in a residual plot from a regression. For example, suppose I have the residual plot below:

I want to automatically detect the observations from about 30:35 deviate from a normal residual pattern.  Some clues are that the magnitude is quite large and the residuals do not appear independent in this region.  How can I go about this?
 A: A dependent mixture model (hidden Markov model) may be of use, depending on the type of deviations expected. 
Assume that your observations come from two distributions (or states), both of which are normally distributed, but have different mean and variance.
A number of parameters can be estimated: The initial state probabilities (2 parameters), the state transition probabilities between neighbouring data points (4 parameters) and finally the mean and variance of the two distributions (4 parameters).
In R, this model can be estimated using the depmixS4 package:
library(depmixS4)

set.seed(3)
y = rnorm(100)
y[30:35] <- rnorm(6,mean=4,sd=2)
plot(1:100,y,"l")

m <- depmix(y~1,nstates=2,ntimes=100)
fm <- fit(m)

means <- getpars(fm)[c(7,9)]
lines(1:100,means[fm@posterior$state],lwd=2,col=2)


See http://cran.r-project.org/web/packages/depmixS4/vignettes/depmixS4.pdf for references
A: Residual plots like this can be used to harvest unspecified deterministic predictor series. If the data is known to be non-spatial or non-chronological then the result would be that there are a few pulses(additive outliers). If however the data has spatial or chronological characteristics then it is possible not only to detect pulses BUT seasonal pulses or Level/step shifts or Local Time Trends that are statistically evident in the residuals via Intervention Detection procedures. Detection and subsequent incorporation of these effects into the final model are very important in providing a robust prediction. Try searching the web for "automatic intervention detection" or simply "intervention detection". Be aware that if there is ARIMA structure that needs to be accounted for things get a little tricky as one needs to simultaneously identify the ARIMA structure and the required Intervention Detected structure. In a number of cases one needs to identify the ARIMA component first and then the needed intervention variables. Alternatively one might need to identify the intervention variables first and then the ARIMA structure. Analytics will tell you which approach is best for any one particular example.
When you have user-suggested causal variables the problem becomes even trickier as you have even more combinations to consider (6) to determine how to best integrate causal structure , arima structure and Intervention Detected structure. 
