% % % epage 432 % % 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; drawnow; clc; addpath( '../../Code/eda_toolbox' ); addpath( '../../Code/eda_data' ); addpath( '../Chapter1/'); data = load_votfraud(1,1); %x = absentee; %y = machine; x = data(:,1); y = data(:,2); fd1=figure; rd=plot( x, y, '.k' ); hold on; xlabel( 'x' ); ylabel( 'y' ); fd2=figure; rd=plot( x, y, '.k' ); hold on; xlabel( 'x' ); ylabel( 'y' ); x_sample = linspace( min(x), max(x), 10 ); ph_deg_1 = []; tt_deg_1 = {}; ph_deg_2 = []; tt_deg_2 = {}; ln_colors = 'rbgcmk'; nc = length(ln_colors); % pick different values for the alpha parameter: a_array = [ 0.2, 0.5, 0.8 ]; for ai=1:length(a_array), alpha = a_array(ai); deg=1; y_loess = loess(x,y,x_sample,alpha,deg); figure(fd1); ph_deg_1(end+1) = plot(x_sample,y_loess,['-',ln_colors(mod(ai,nc)+1)]); tt_deg_1{end+1} = ['alpha = ',num2str(alpha)]; deg=2; y_loess = loess(x,y,x_sample,alpha,deg); figure(fd2); ph_deg_2(end+1) = plot(x_sample,y_loess,['-',ln_colors(mod(ai,nc)+1)]); tt_deg_2{end+1} = ['alpha = ',num2str(alpha)]; end % add in this loess correction to the main model: figure(fd1); axis([-2.5,2.5,-2.75,2.5]); title( 'the votfraud data (scaled) with loess models of degree 1' ); legend( ph_deg_1, tt_deg_1, 'location', 'northwest' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter7/prob_7_6_loess_deg_1'], 'epsc' ); figure(fd2); axis([-2.5,2.5,-2.75,2.5]); title( 'the votfraud data (scaled) with loess models of degree 2' ); legend( ph_deg_2, tt_deg_2, 'location', 'northwest' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter7/prob_7_6_loess_deg_2'], 'epsc' ); clear functions;