Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MixedLM.hessian() returns a tuple instead of just the hessian matrix, causing MixedLM.fit to fail when minimizing with methods that require the hessian #9139

Open
pcuestas opened this issue Feb 3, 2024 · 1 comment

Comments

@pcuestas
Copy link

pcuestas commented Feb 3, 2024

Describe the bug

MixedLM.hessian() returns a tuple:

def hessian(self, params):
"""
Returns the model's Hessian matrix.
Calculates the Hessian matrix for the linear mixed effects
model with respect to the parameterization in which the
covariance matrix is represented directly (without square-root
transformation).
Parameters
----------
params : MixedLMParams or array_like
The model parameters at which the Hessian is calculated.
If array-like, must contain the packed parameters in a
form that is compatible with this model instance.
Returns
-------
hess : 2d ndarray
The Hessian matrix, evaluated at `params`.
sing : boolean
If True, the covariance matrix is singular and a
pseudo-inverse is returned.
"""

However, it is supposed to return just the hessian matrix, as stated in LikelyhoodModel.hessian():

def hessian(self, params):
"""
The Hessian matrix of the model.
Parameters
----------
params : ndarray
The parameters to use when evaluating the Hessian.
Returns
-------
ndarray
The hessian evaluated at the parameters.
"""

The fact that MixedLM.hessian() returns a tuple causes optimization to fail when the hessian matrix is used in the minimization algorithm, when the following function is called (within MixedLM.fit()):

def hess(params, *args):
return -self.hessian(params, *args) / nobs

(The exception TypeError: bad operand type for unary -: 'tuple' is thrown).

@kshedden
Copy link
Contributor

kshedden commented Feb 4, 2024

As I recall that Hessian function is intended to be used for standard errors, not for optimization. The optimization uses a different parameterization that is not compatible with the Hessian function you are referring to. Optimization should use a first order or zeroth order approach that do not rely on Hessian matrices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants