function fh = hazardize(grid,sample,h,met); 
%Hazard rate estimator. (the hazard being f(x)/F(x))
% 
%hazardize(grid,sample,h,method) returns a vector of estimates of the
%hazard rate at each point of the "grid" vector, calculated from a the
%vector of observations "sample", using the kernel specified by "method".
%
%"grid" is a vector of points at which the density os to be evaluated;
%"sample" is a vector of i.i.d. observations from the distribution; 
%"h" is the bandwidth; 
% method is one of the following: 
% 'normal' or 'n' 
% 'epanechikov' or 'e'

% copyright 2001 Leonardo Rezende.
% This program can be freely copied, used and modified, as long as this
% copyright notice is kept in place. Please inform the author of any
% useful modifications, at lrezende@stanford.edu.

n = size(sample,1);
sample = sort(sample);

X=(ones(size(sample))*grid'-sample*ones(size(grid')))/h;

d = (1./[1:n]);

switch lower(met)
case {'normal','n'}
	k = exp(-X.^2/2)/sqrt(2*pi); 		%Normal Kernel.
case {'epanechnikov','e'}
	S = X.*X;
	k = 3/4*(1-S).*(S<=1);
end

fh=(d*(k/h))';




