fig6_4.m 755 B

1234567891011121314151617181920
  1. % Local Regression and Likelihood, Figure 6.4.
  2. % Author: Catherine Loader
  3. %
  4. % Local smooth of CO2 dataset. Estimate the main trend,
  5. % then use periodic smoothing of the residuals to estimate
  6. % the annual effect. Add main trend and periodic components
  7. % to get overall smooth.
  8. %
  9. % A periodic smooth is specified by 'style','a'.
  10. % Note that year+month/12 scales the predictor to have a period
  11. % of 1. The 'scale' argument to locfit() is period/(2*pi).
  12. load co2;
  13. fit1 = locfit(year+month/12,co2,'alpha',0.5,'deg',1);
  14. res = residuals(fit1);
  15. fit2 = locfit(year+month/12,res,'alpha',[0 2],'style','a','scale',1/(2*pi));
  16. f1 = fitted(fit1);
  17. f2 = fitted(fit2);
  18. figure('Name','fig6_4: CO2 dataset local smoothing' );
  19. plot(year+month/12,f1+f2);