Asimpleexampleof
Asimpleexampleof
We want to obtain MLE’s for a simple example in which a relatively small (n = 5) data set has been
sampled from a normal distribution with mean µ and finite variance σ 2. The data values are: x 1=1,
x 2=3, x 3=4, x 4 =5, and x 5=7 .
We will use SAS PROC NLP to obtain simultaneous MLE’s for both parameters using the Nelder-Mead
Simplex algorithm, followed by refinement of the parameter estimates using Newton’s method.
The Nelder-Mead method (without modification) does not necessarily converge to a minimum point for
general non-convex functions. However, it does tend to produce “a rapid initial decrease in function
values…” 1 regardless of the form of the function.
In this example, we are finding the extreme point of a convex function; hence the Nelder-Mead method
should work well. The SAS program for implementing the first algorithm is shown below, followed by
an explanation of the options and statements in the PROC, and the output.
data Ex1;
input x @@;
datalines;
1 3 4 5 7
;
proc nlp data=Ex1 tech=nmsimp vardef=df covariance=h pcov phes;
max loglik;
parms mean=0., sigma=1.;
bounds sigma > 1e-12;
loglik=-0.5*((x-mean)/sigma)**2-log(sigma);
;
run;
c) “vardef” specifies the divisor to be used in the calculation of the covariance matrix and standard
errors. The default value is N, the sample size. Here, “df” specifies that the degrees of freedom
should be used as the divisor. (See p. 371 of the manual.)
d) “covariance” specifies that an approximate covariance matrix for the parameter estimates is to be
computed. There are several ways to do this (See p. 370 of the manual.) The option “h” used
here specifies that, since the “max” statement is used in the procedure, the covariance matrix
n −1
should be computed as G , where G is the Hessian matrix (the matrix of second
max { 1 ,n−df }
partial derivatives of the objective function, (1), with respect to the parameters.)
e) “pcov” tells SAS to display the covariance matrix.
f) “phes” tells SAS to display the Hessian matrix.
Other statements:
a) The “max” statement specifies that the maximum point for the objective function (1) is to be
found. The “loglik” variable denotes the objective function.
b) The “parms” statement specifies initial values of the parameters, to be used in this case to
generate the initial simplex for starting the Nelder-Mead algorithm. (See p. 374 of the manual.)
c) The “bounds” statement specifies constraints on the values of the parameters. Here, the only
constraint is that σ must be positive. (See p. 325 of the manual.)
d) The objective function to be maximized is defined by a statement in the procedure. Here, we
( )
2
( ) −1 x−μ
define loglik μ , σ = −ln ( σ ).
2 σ
Hessian Matrix
mean sigma
mean -5 -40.00000001
sigma -40.00000001 -295.0000001
Determinant = -124.9999997
Matrix has 1 Positive Eigenvalue(s)
3
Optimization Start
Active Constraints 0
Objective Function -50
Optimization Results
Iterations 6 Function Calls 60
Restarts 0 Active Constraints 0
Objective Function -5.965738194 Std Dev of Simplex Values 6.9541052E-7
Deltax 1 Size 0.0045923843
NOTE: At least one element of the (projected) gradient is greater than 1e-3.
Hessian Matrix
mean sigma
mean -1.250060277 -0.002392044
sigma -0.002392044 -2.500304826
Determinant = 3.1255260207
Matrix has Only Negative Eigenvalues
Factor sigm = 1
Determinant = 0.3199461445
Determinant = 0.9999981693
Matrix has 2 Positive Eigenvalue(s)
The final parameter estimates obtained using the Nelder-Mead method were ^μ=3.998087 and
σ^ =1.999952. We will use these as our initial guesses of the parameters, and refine these values by
using Newton’s method.
The program for implementing Newton’s method is listed below, followed by the output. The final
MLE’s for the parameters (after 1 iteration) were found to be ^μ=4.000000 and σ^ =1.9999 99.
data Ex1;
input x @@;
datalines;
1 3 4 5 7
;
proc nlp data=Ex1 tech=newrap vardef=n covariance=h pcov phes;
max loglik;
parms mean=3.998087, sigma=1.999952;
bounds sigma > 1e-12;
loglik=-0.5*((x-mean)/sigma)**2-log(sigma);
;
run;
The SAS System
PROC NLP: Nonlinear Maximization
Gradient is computed using analytic formulas.
Hessian is computed using analytic formulas.
The SAS System
PROC NLP: Nonlinear Maximization
Optimization Start
Parameter Estimates
Gradient Lower Upper
Objective Bound Bound
N Parameter Estimate Function Constraint Constraint
1 mean 3.998087 0.002391 . .
2 sigma 1.999952 0.000122 1E-12 .
Hessian Matrix
mean sigma
mean -1.250060002 -0.002391422
sigma -0.002391422 -2.500303451
Determinant = 3.125523618
Optimization Results
Iterations 1 Function Calls 3
Hessian Calls 2 Active Constraints 0
Objective Function -5.965735903 Max Abs Gradient Element 2.2942694E-6
Slope of Search Direction -4.580223E-6 Ridge 0
Hessian Matrix
mean sigma
mean -1.250001147 -1.125884E-7
sigma -1.125884E-7 -2.500005736
Determinant = 3.1250100374
Matrix has Only Negative Eigenvalues
Factor sigm = 1
Determinant = 0.3199989722
Matrix has 2 Positive Eigenvalue(s)
Determinant = 1
1
Lagarias, J. C.; Reeds, J. A.; Wright, M. H.; and Wright, P. E. (1998). “Convergence Properties of the Nelder-
Mead simplex method in low dimensions,” SIAM Journal on Optimization, 9, 1, pp. 112-147.