function [mle, info, n] = varhetsec(y, x, mu0, mu1, TOL, Nmax) % ************************************************************************* % % FILE: varhetsec.m % % Date Created: Feb 10, 2004 % Author: Mark E. Irwin % % Contents: Finds MLE and information for variance heterogeneity model % Y ~ N(mu, (mu*x)^2) by Secant method. The information is % based on a numerical approximation to the derivative. % % Revision History % Date Name Changes/Reasons % % ************************************************************************* % % Input: % % y: response vector % x: variance covariate vector % mu0: initial guess for MLE % mu1: second guess for MLE % TOL: convergence tolerance % Nmax: number of functional iterations % % Output: % % mle: mle % info: information % n: number of iterations until convergence % % ************************************************************************* % Initialize loop i = 0; diff = 2 * TOL; % guarantees at least one pass through loop while (i < Nmax && diff > TOL) i = i + 1; f0 = hetscore(y, x, mu0); f1 = hetscore(y, x, mu1); deriv = (f1 - f0)/(mu1 - mu0); mui = mu1 - f1/deriv; diff = abs(mu1 - mui); mu0 = mu1; mu1 = mui; end if (diff > TOL) warning('Method did not converage after Nmax steps'); end mle = mui; info = -deriv; n = i;