% % % epage 433 % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clear all; close all; clc; addpath('../../Code/CSTool'); load helmets; [stime,inds] = sort(time); saccel = accel(inds); x=stime; y=saccel; fd1=figure; rd=plot( time, accel, '.k' ); hold on; grid on; xlabel( 'time' ); ylabel( 'accel' ); x_sample = linspace( min(time), max(time), 300 ); % the data is relativly "sparse" so we'll use a large value of alpha: alpha = 0.3; deg=1; %y_loess = csloessr(x,y,x_sample,alpha,deg); [y_loess,ylo,xlo,yup,xup] = csloessenv(x,y,x,alpha,deg,0); % <- regular (non-robust) loess %[y_loess,ylo,xlo,yup,xup] = csloessenv(x,y,x,alpha,deg,1); % <- robust loess figure(fd1); plot(x,y_loess,'-x',xlo,ylo,'-g',xup,yup,'-g'); % add in this loess correction to the main model: figure(fd1); title( 'the helmets data with a loess model of degree 1' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter10/prob_10_14_loess_deg_1'], 'epsc' ); fd2=figure; rd=plot( time, accel, '.k' ); hold on; grid on; xlabel( 'time' ); ylabel( 'accel' ); % the data is relativly "sparse" so we'll use a large value of alpha: %alpha = 0.5; alpha = 0.4; deg=2; [y_loess,ylo,xlo,yup,xup] = csloessenv(x,y,x,alpha,deg,0); % <- regular (non-robust) loess %[y_loess,ylo,xlo,yup,xup] = csloessenv(x,y,x,alpha,deg,1); % <- robust loess figure(fd2); plot(x,y_loess,'-x',xlo,ylo,'-g',xup,yup,'-g'); figure(fd2); title( 'the helmets data with a loess model of degree 2' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter10/prob_10_14_loess_deg_2'], 'epsc' ); clear functions;