This example calculates confidence intervals based on the profile likelihood for the parameters estimated in the previous example. The following introduction on profilelikelihood methods is based on the paper of Venzon and Moolgavkar (1988).
Let be the maximum likelihood estimate (MLE) of a parameter vector and let be the loglikelihood function defined for parameter values .
The profilelikelihood method reduces to a function of a single parameter of interest, , where , by treating the others as nuisance parameters and maximizing over them. The profile likelihood for is defined as

where . Define the complementary parameter set and as the optimizer of for each value of . Of course, the maximum of function is located at . The profilelikelihoodbased confidence interval for parameter is defined as

where is the th quantile of the distribution with one degree of freedom. The points are the endpoints of the profilelikelihoodbased confidence interval for parameter . The points and can be computed as the solutions of a system of nonlinear equations in parameters, where :

where is the constant threshold . The first of these equations defines the locations and where the function cuts , and the remaining equations define the optimality of the parameters in . Jointly, the equations define the locations and where the function cuts the constant threshold , which is given by the roots of . Assuming that the two solutions exist (they do not if the quantile is too large), this system of nonlinear equations can be solved by minimizing the sum of squares of the functions :

For a solution of the system of nonlinear equations to exist, the minimum value of the convex function must be zero.
The following code defines the module for the system of nonlinear equations to be solved:
start f_plwei2(x) global(carcin,ipar,lstar); /* x[1]=sigma, x[2]=c */ like = f_weib2(x); grad = g_weib2(x); grad[ipar] = like  lstar; return(grad`); finish f_plwei2;
The following code implements the LevenbergMarquardt algorithm with the NLPLM subroutine to solve the system of two equations for the left and right endpoints of the interval. The starting point is the optimizer , as computed in the previous example, moved toward the left or right endpoint of the interval by an initial step (refer to Venzon and Moolgavkar (1988)). This forces the algorithm to approach the specified endpoint.
/* quantile of chi**2 distribution */ chqua = cinv(1prob,1); lstar = fopt  .5 * chqua; optn = {2 0}; do ipar = 1 to 2; /* Compute initial step: */ /* Choose (alfa,delt) to go in right direction */ /* Venzon & Moolgavkar (1988), p.89 */ if ipar=1 then ind = 2; else ind = 1; delt =  inv(hes2[ind,ind]) * hes2[ind,ipar]; alfa =  (hes2[ipar,ipar]  delt` * hes2[ind,ipar]); if alfa > 0 then alfa = .5 * sqrt(chqua / alfa); else do; print "Bad alpha"; alfa = .1 * xopt[ipar]; end; if ipar=1 then delt = 1  delt; else delt = delt  1; /* Get upper end of interval */ x0 = xopt + (alfa * delt)`; /* set lower bound to optimal value */ con2 = con; con2[1,ipar] = xopt[ipar]; call nlplm(rc,xres,"f_plwei2",x0,optn,con2); f = f_plwei2(xres); s = ssq(f); if (s < 1.e6) then xub[ipar] = xres[ipar]; else xub[ipar] = .; /* Get lower end of interval */ x0 = xopt  (alfa * delt)`; /* reset lower bound and set upper bound to optimal value */ con2[1,ipar] = con[1,ipar]; con2[2,ipar] = xopt[ipar]; call nlplm(rc,xres,"f_plwei2",x0,optn,con2); f = f_plwei2(xres); s = ssq(f); if (s < 1.e6) then xlb[ipar] = xres[ipar]; else xlb[ipar] = .; end; print "ProfileLikelihood Confidence Interval"; print xlb xopt xub;
The results, shown in Output 14.5.1, are close to the results shown in Output 14.4.2.
Output 14.5.1: Confidence Interval Based on Profile Likelihood
ProfileLikelihood Confidence Interval 
xlb  xop2  xub 

215.1963  234.31861  255.2157 
4.1344126  6.0831471  8.3063797 