Local Regression and Likelihood, Figure 6.3. Author: Catherine Loader Local smooth of CO2 dataset. Estimate the main trend, then use periodic smoothing of the residuals to estimate the annual effect. A periodic smooth is specified by 'style','a'. Note that year+month/12 scales the predictor to have a period of 1. The 'scale' argument to locfit() is period/(2*pi).
0001 % Local Regression and Likelihood, Figure 6.3. 0002 % Author: Catherine Loader 0003 % 0004 % Local smooth of CO2 dataset. Estimate the main trend, 0005 % then use periodic smoothing of the residuals to estimate 0006 % the annual effect. 0007 % 0008 % A periodic smooth is specified by 'style','a'. 0009 % Note that year+month/12 scales the predictor to have a period 0010 % of 1. The 'scale' argument to locfit() is period/(2*pi). 0011 0012 load co2; 0013 fit1 = locfit(year+month/12,co2,'alpha',0.5,'deg',1); 0014 res = residuals(fit1); 0015 fit2 = locfit(year+month/12,res,'alpha',[0 2],'style','a','scale',1/(2*pi)); 0016 figure('Name','fig6_3: CO2 Dataset: Local smoothing' ); 0017 lfplot(fit2,'nodata');