book_3_50.m

Plot group mean residuals.

load fly

uniqueTemp = unique(Temperature);
nT = length(uniqueTemp);
meanFacet = nan(nT,1);

for ii = 1:nT
   index = Temperature==uniqueTemp(ii);
   meanFacet(ii) = mean(FacetNumber(index));
end

p = polyfit(uniqueTemp(:),meanFacet(:),1);
fitFacet = polyval(p,uniqueTemp);
residual = meanFacet(:)-fitFacet(:);

plot(uniqueTemp,residual,'o',[min(uniqueTemp) max(uniqueTemp)],[0 0],'-')
xlabel('Temperature (deg C)')
ylabel('Residual Facet Number')
title('Fly')