% % Examples 9.15 and 9.17 % % 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; clc; addpath('../../Code/CSTool'); load filip; [xs,inds] = sort(x); ys = y(inds); % plot the original data: fd=figure; ho = plot( x, y, 'k.' ); hold on; grid on; title( 'the filip data' ); line_styles={'-',':','--','-.'}; line_colors='cmkg'; data_plt_h = []; res_plt_h = []; fr=figure; hold on; poly_degs = [ 2,4,6,10 ]; for ii=1:length(poly_degs), deg = poly_degs(ii); % assume we *know* the dimension of the polynomial to fit: [pcoef,s] = polyfit(x,y,deg); % evaluate this polynomial model: yp = polyval(pcoef,x); % plot this polynomial model: figure(fd); tph=plot( x, yp, ['-',line_colors(ii)] ); data_plt_h(end+1) = tph; % plot the residuals v.s. the fitted value yp: res = y-yp; figure(fr); tph=plot( x, res, [line_colors(ii)] ); xlabel( 'predictor x' ); ylabel( 'residual' ); title( ['residual dependence plot for a polynomial model of degree', num2str(ii)] ); %axis( [0 1 -2.5 2.5] ); res_plt_h(end+1) = tph; %pause; end figure(fd); legend(data_plt_h, {'deg 2','deg 4','deg 6','deg 10'}, 'location', 'northwest' ); saveas( gcf, '../../WriteUp/Graphics/Chapter10/prob_10_5_data_w_models', 'epsc' ); figure(fr); legend(res_plt_h, {'deg 2','deg 4','deg 6','deg 10'}, 'location', 'northeast' ); saveas( gcf, '../../WriteUp/Graphics/Chapter10/prob_10_5_res_plts', 'epsc' ); clear functions;