[Sex Age Pulse] ...
    = textread('NHanes_Youth.txt','%s%f%f','headerlines',1);

x = Age;
y = Pulse;
n = length(y);
b1 = corr(x,y)*std(y)/std(x)
b0 = mean(y) - b1*mean(x)

figure(1);
plot(x,y,'k.');
hold on;
plot([min(x) max(x)], [b0+b1*min(x) b0+b1*max(x)], 'b-');
hold off;
xlabel('Age in Years');
ylabel('Resting Pulse (bpm)');
title('Figure 4.4');

figure(2);
boxplot(Pulse, Sex);
ylabel('Pulse Rate');
title('Figure 4.5');

%for j=1:n
%    if strcmp(Sex(j),'Male') == 1
%        Sex01(j) = 0;
%    else
%        Sex01(j) = 1;
%    end
%end
Sex01 = strcmp(Sex,'Female');
M = (Sex01==0);
F = (Sex01==1);

A = [ones(n,1) Age Sex01];
b = A\y
figure(3);
plot(Age(M), Pulse(M), 'Marker','*', 'MarkerFaceColor',[0 0.5 1], 'LineStyle','none'); 
hold on;
plot(Age(F), Pulse(F), 'Marker','x', 'MarkerFaceColor',[1 0.5 0], 'LineStyle','none'); 
plot([min(x) max(x)], [b(1)+b(2)*min(x) b(1)+b(2)*max(x)], 'k-'); 
plot([min(x) max(x)], [b(1)+b(3)+b(2)*min(x) b(1)+b(3)+b(2)*max(x)], 'r-'); 
hold off;
xlabel('Age in Years');
ylabel('Resting Pulse (bpm)');
title('Figure 4.6')

A = [ones(n,1) Age Sex01 Age.*Sex01];
b = A\y
figure(4);
plot(Age(M), Pulse(M), 'Marker','*', 'MarkerFaceColor',[0 0.5 1], 'LineStyle','none'); 
hold on;
plot(Age(F), Pulse(F), 'Marker','x', 'MarkerFaceColor',[1 0.5 0], 'LineStyle','none'); 
plot([min(x) max(x)], [b(1)+b(2)*min(x) b(1)+b(2)*max(x)], 'k-'); 
plot([min(x) max(x)], [b(1)+b(3)+(b(2)+b(4))*min(x) b(1)+b(3)+(b(2)+b(4))*max(x)], 'r-'); 
hold off;
xlabel('Age in Years');
ylabel('Resting Pulse (bpm)');
title('Figure 4.7')
