% script plotWght.m
% plots canonical versions of the l_1, Hampel, Huber, and biweight
% influence functions and corresponding weight functions.
% 
% P.B. Stark  stark@stat.berkeley.edu
% 25 July 1997.

% parameters for the weight functions
hubPar = 3;
biwPar = 8;
hamPar = [2, 4, 8];
l1par = 1;
scale = 1;

x = [-10:.02:10];
figure
plot(x, x.*l1wght(x,1,l1par),'r')
hold
plot(x, x.*hampel(x, 1, hamPar),'y--')
plot(x, x.*huber(x, 1, hubPar),'g-.')
plot(x, x.*biwght(x, 1, biwPar),'b:')
lx = [-9, -5];
lxx = -4.7
ly = [1, 1];
plot(lx,3*ly,'r')
text(lxx,3,'l_1')
plot(lx,2.5*ly,'y--')
text(lxx,2.5,'Hampel(2, 4, 8)')
plot(lx,2*ly,'g-.')
text(lxx,2,'Huber(3)')
plot(lx,1.5*ly,'b:')
text(lxx,1.5,'Biweight(8)')
title('Influence Functions')
xlabel('Residual')
ylabel('Influence')
print -depsc2 influence.ps

figure

hold
plot(x, hampel(x, 1, hamPar),'y--')
plot(x, huber(x, 1, hubPar),'g-.')
plot(x, biwght(x, 1, biwPar),'b:')
axis([-11, 11, -0.1, 1.5]); % freeze the scaling because the l1 weight is singular
plot(x, l1wght(x,1,l1par),'r')
lx = [-10, -7];
lxx = -6.7
ly = [1, 1];
plot(lx,1.4*ly,'r')
text(lxx,1.4,'l_1 (truncated)')
plot(lx,1.3*ly,'y--')
text(lxx,1.3,'Hampel(2, 4, 8)')
plot(lx,1.2*ly,'g-.')
text(lxx,1.2,'Huber(3)')
plot(lx,1.1*ly,'b:')
text(lxx,1.1,'Biweight(8)')
title('Weight Functions')
xlabel('Residual')
ylabel('Weight')
print -depsc2 weight.ps
