class_docstr: A simple ordinary least squares model.
  
  Parameters
  ----------
  design : array-like
      This is your design matrix.  Data are assumed to be column ordered with
      observations in rows.
  
  Methods
  -------
  model.__init___(design)
  model.logL(b=self.beta, Y)
  
  Attributes
  ----------
  design : ndarray
      This is the design, or X, matrix.
  wdesign : ndarray
      This is the whitened design matrix.  `design` == `wdesign` by default
      for the OLSModel, though models that inherit from the OLSModel will
      whiten the design.
  calc_beta : ndarray
      This is the Moore-Penrose pseudoinverse of the whitened design matrix.
  normalized_cov_beta : ndarray
      ``np.dot(calc_beta, calc_beta.T)``
  df_resid : scalar
      Degrees of freedom of the residuals.  Number of observations less the
      rank of the design.
  df_model : scalar
      Degrees of freedome of the model.  The rank of the design.
  
  Examples
  --------
  >>> from nipy.algorithms.statistics.api import Term, Formula
  >>> data = np.rec.fromarrays(([1,3,4,5,2,3,4], range(1,8)),
  ...                          names=('Y', 'X'))
  >>> f = Formula([Term("X"), 1])
  >>> dmtx = f.design(data, return_float=True)
  >>> model = OLSModel(dmtx)
  >>> results = model.fit(data['Y'])
  >>> results.theta
  array([ 0.25      ,  2.14285714])
  >>> results.t()
  array([ 0.98019606,  1.87867287])
  >>> print(results.Tcontrast([0,1]))  #doctest: +FLOAT_CMP
  <T contrast: effect=2.14285714286, sd=1.14062281591, t=1.87867287326,
  df_den=5>
  >>> print(results.Fcontrast(np.eye(2)))  #doctest: +FLOAT_CMP
  <F contrast: F=19.4607843137, df_den=5, df_num=2>
class_docstr_tok: ["A","simple","ordinary","least","squares","model",".","Parameters","--","--","--","--","--","design",":","array-like","This","is","your","design","matrix",".","Data","are","assumed","to","be","column","ordered","with","observations","in","rows",".","Methods","--","--","--","-","model.__init___","(","design",")","model.logL","(","b=self.beta",",","Y",")","Attributes","--","--","--","--","--","design",":","ndarray","This","is","the","design",",","or","X",",","matrix",".","wdesign",":","ndarray","This","is","the","whitened","design","matrix",".","`","design","`","==","`","wdesign","`","by","default","for","the","OLSModel",",","though","models","that","inherit","from","the","OLSModel","will","whiten","the","design",".","calc_beta",":","ndarray","This","is","the","Moore-Penrose","pseudoinverse","of","the","whitened","design","matrix",".","normalized_cov_beta",":","ndarray","``","np.dot","(","calc_beta",",","calc_beta.T",")","``","df_resid",":","scalar","Degrees","of","freedom","of","the","residuals",".","Number","of","observations","less","the","rank","of","the","design",".","df_model",":","scalar","Degrees","of","freedome","of","the","model",".","The","rank","of","the","design",".","Examples","--","--","--","--",">",">",">","from","nipy.algorithms.statistics.api","import","Term",",","Formula",">",">",">","data","=","np.rec.fromarrays","(","(","[","1,3,4,5,2,3,4","]",",","range","(","1,8",")",")",",","...","names=","(","'","Y","'",",","'","X","'",")",")",">",">",">","f","=","Formula","(","[","Term","(","``","X","''",")",",","1","]",")",">",">",">","dmtx","=","f.design","(","data",",","return_float=True",")",">",">",">","model","=","OLSModel","(","dmtx",")",">",">",">","results","=","model.fit","(","data","[","'","Y","'","]",")",">",">",">","results.theta","array","(","[","0.25",",","2.14285714","]",")",">",">",">","results.t","(",")","array","(","[","0.98019606",",","1.87867287","]",")",">",">",">","print","(","results.Tcontrast","(","[","0,1","]",")",")","#","doctest",":","+FLOAT_CMP","<","T","contrast",":","effect=2.14285714286",",","sd=1.14062281591",",","t=1.87867287326",",","df_den=5",">",">",">",">","print","(","results.Fcontrast","(","np.eye","(","2",")",")",")","#","doctest",":","+FLOAT_CMP","<","F","contrast",":","F=19.4607843137",",","df_den=5",",","df_num=2",">"]
docstr: 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.
code: 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.0 * np.log(2 * np.pi * sigmasq) - SSE / (
          2 * sigmasq
      )
      return loglf
  
imports: import warnings
  import numpy
  import numpy.linalg
  import scipy.linalg
  from nibabel.onetime import auto_attr
  from scipy import stats
  from nipy.algorithms.utils.matrices import matrix_rank, pos_recipr
  from .model import LikelihoodModel, LikelihoodModelResults
label_desc: Use image node_id 3 for calling the OLSModel obj's underlying member method code with example usage: obj.logL(beta, Y, nuisance) and returns: loglf