function NLL=NLLLpl(Bet,Y,Bss,Tau);
%
%**************************************************************************
%Illustration of non-stationary extreme value modelling in MATLAB accompanying 
%Threshold modeling of nonstationary extremes
%Paul Northrop, Philip Jonathan and David Randell
%in 
%Extreme Value Modeling and Risk Analysis: Methods and Applications
%Dipak Dey and Jun Yan (Editors)
%2015
%**************************************************************************
%
%**************************************************************************
%NEGATIVE LOG LIKELIHOOD FOR LAPLACE IN EXTREME VALUE THRESHOLD ESTIMATION
%
%Bet      p x 1 Spline parameter vector 
%Y        n x 1 Responses
%Bss      n x p Spline basis evaluated at the covariate values corresponding to responses
%Tau      1 x 1 Non-exceedance probability for extreme value threshold 
%
%NLL      1 x 1 Negative log likelihood
%**************************************************************************

%Calculate fitted values and residuals
Yh=Bss*Bet;  %threshold estimate
R=Y-Yh;  %residuals estimates

%Calculate the sample penalised negative log likelihood
%Sum over individuals to get negative log liklihood
%Add roughness penalty term
NLL=sum(R.*(Tau-(R<=0)));

return;