Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Removed unsued logL
Browse files Browse the repository at this point in the history
  • Loading branch information
bthirion committed Oct 11, 2018
1 parent de34a0b commit 7037cf6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
10 changes: 2 additions & 8 deletions nistats/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, theta, Y, model, cov=None, dispersion=1., nuisance=None,
multiplicative factor in front of `cov`
nuisance : None of ndarray
parameter estimates needed to compute logL
parameter estimates needed to compute log-lokelohood
rank : None or scalar
rank of the model. If rank is not None, it is used for df_model
Expand Down Expand Up @@ -76,14 +76,8 @@ def __init__(self, theta, Y, model, cov=None, dispersion=1., nuisance=None,
self.df_model = model.df_model
# put this as a parameter of LikelihoodModel
self.df_resid = self.df_total - self.df_model

@setattr_on_read
def logL(self):
"""
The maximized log-likelihood
"""
return self.model.logL(self.theta, self.Y, nuisance=self.nuisance)


def t(self, column=None):
"""
Return the (Wald) t-statistic for a given parameter estimate.
Expand Down
71 changes: 0 additions & 71 deletions nistats/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class OLSModel(object):
Methods
-------
model.__init___(design)
model.logL(b=self.beta, Y)
Attributes
----------
Expand Down Expand Up @@ -98,70 +97,6 @@ def initialize(self, design):
self.df_model = matrix_rank(self.design, eps)
self.df_resid = self.df_total - self.df_model

def logL(self, beta, Y, nuisance=None):
r''' Returns the value of the loglikelihood function at beta.
Given the whitened design matrix, the loglikelihood is evaluated
at the parameter vector, beta, for the dependent variable, Y
and the nuisance parameter, sigma.
Parameters
----------
beta : ndarray
The parameter estimates. Must be of length df_model.
Y : ndarray
The dependent variable
nuisance : dict, optional
A dict with key 'sigma', which is an optional estimate of sigma. If
None, defaults to its maximum likelihood estimate (with beta fixed)
as ``sum((Y - X*beta)**2) / n``, where n=Y.shape[0], X=self.design.
Returns
-------
loglf : float
The value of the loglikelihood function.
Notes
-----
The log-Likelihood Function is defined as
.. math::
\ell(\beta,\sigma,Y)=
-\frac{n}{2}\log(2\pi\sigma^2) - \|Y-X\beta\|^2/(2\sigma^2)
The parameter :math:`\sigma` above is what is sometimes referred to as a
nuisance parameter. That is, the likelihood is considered as a function
of :math:`\beta`, but to evaluate it, a value of :math:`\sigma` is
needed.
If :math:`\sigma` is not provided, then its maximum likelihood estimate:
.. math::
\hat{\sigma}(\beta) = \frac{\text{SSE}(\beta)}{n}
is plugged in. This likelihood is now a function of only :math:`\beta`
and is technically referred to as a profile-likelihood.
References
----------
.. [1] W. Green. "Econometric Analysis," 5th ed., Pearson, 2003.
'''
# This is overwriting an abstract method of LikelihoodModel
X = self.wdesign
wY = self.whiten(Y)
r = wY - np.dot(X, beta)
n = self.df_total
SSE = (r ** 2).sum(0)
if nuisance is None:
sigmasq = SSE / n
else:
sigmasq = nuisance['sigma']
loglf = - n / 2. * np.log(2 * np.pi * sigmasq) - SSE / (2 * sigmasq)
return loglf

def whiten(self, X):
""" Whiten design matrix
Expand Down Expand Up @@ -353,12 +288,6 @@ def __init__(self, results):
# put this as a parameter of LikelihoodModel
self.df_resid = self.df_total - self.df_model

def logL(self, Y):
"""
The maximized log-likelihood
"""
raise ValueError('can not use this method for simple results')

def resid(self, Y):
"""
Residuals from the fit.
Expand Down

0 comments on commit 7037cf6

Please sign in to comment.