% % % 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 human; X = [ females; males ]; age = X(:,1); fat = X(:,2); [sage,inds] = sort(age); sfat = fat(inds); x=sage; y=sfat; fd1=figure; rd=plot( age, fat, '.k' ); hold on; xlabel( 'age' ); ylabel( 'fat' ); fd2=figure; rd=plot( age, fat, '.k' ); hold on; xlabel( 'age' ); ylabel( 'fat' ); x_sample = linspace( min(age), max(age), 50 ); 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.3, 0.5, 0.6, 0.7, 0.9 ]; for ai=1:length(a_array), alpha = a_array(ai); deg=1; y_loess = csloess(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 = csloess(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); title( 'the human data with loess models of degree 1' ); legend( ph_deg_1, tt_deg_1, 'location', 'southeast' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter10/prob_10_10_loess_deg_1'], 'epsc' ); figure(fd2); title( 'the human data with loess models of degree 2' ); legend( ph_deg_2, tt_deg_2, 'location', 'southeast' ); saveas( gcf, ['../../WriteUp/Graphics/Chapter10/prob_10_10_loess_deg_2'], 'epsc' ); clear functions;