As far as my understanding goes residual is the difference between the observed values, and the expected values of a particular quantity. The expected values of that quantity can be any statistical measure - but in this case are the sample means.
Now, the stats output parameter will give the means field. This is the mean of each of the observed quantities.You can subtract the observations and the stats.means