class_docstr: Linear Mixed Effects Model
  
  Parameters
  ----------
  endog : 1d array_like
      The dependent variable
  exog : 2d array_like
      A matrix of covariates used to determine the
      mean structure (the "fixed effects" covariates).
  groups : 1d array_like
      A vector of labels determining the groups -- data from
      different groups are independent
  exog_re : 2d array_like
      A matrix of covariates used to determine the variance and
      covariance structure (the "random effects" covariates).  If
      None, defaults to a random intercept for each group.
  exog_vc : VCSpec instance or dict-like (deprecated)
      A VCSPec instance defines the structure of the variance
      components in the model.  Alternatively, see notes below
      for a dictionary-based format.  The dictionary format is
      deprecated and may be removed at some point in the future.
  use_sqrt : bool
      If True, optimization is carried out using the lower
      triangle of the square root of the random effects
      covariance matrix, otherwise it is carried out using the
      lower triangle of the random effects covariance matrix.
  missing : str
      The approach to missing data handling
  
  Notes
  -----
  If `exog_vc` is not a `VCSpec` instance, then it must be a
  dictionary of dictionaries.  Specifically, `exog_vc[a][g]` is a
  matrix whose columns are linearly combined using independent
  random coefficients.  This random term then contributes to the
  variance structure of the data for group `g`.  The random
  coefficients all have mean zero, and have the same variance.  The
  matrix must be `m x k`, where `m` is the number of observations in
  group `g`.  The number of columns may differ among the top-level
  groups.
  
  The covariates in `exog`, `exog_re` and `exog_vc` may (but need
  not) partially or wholly overlap.
  
  `use_sqrt` should almost always be set to True.  The main use case
  for use_sqrt=False is when complicated patterns of fixed values in
  the covariance structure are set (using the `free` argument to
  `fit`) that cannot be expressed in terms of the Cholesky factor L.
  
  Examples
  --------
  A basic mixed model with fixed effects for the columns of
  ``exog`` and a random intercept for each distinct value of
  ``group``:
  
  >>> model = sm.MixedLM(endog, exog, groups)
  >>> result = model.fit()
  
  A mixed model with fixed effects for the columns of ``exog`` and
  correlated random coefficients for the columns of ``exog_re``:
  
  >>> model = sm.MixedLM(endog, exog, groups, exog_re=exog_re)
  >>> result = model.fit()
  
  A mixed model with fixed effects for the columns of ``exog`` and
  independent random coefficients for the columns of ``exog_re``:
  
  >>> free = MixedLMParams.from_components(
                   fe_params=np.ones(exog.shape[1]),
                   cov_re=np.eye(exog_re.shape[1]))
  >>> model = sm.MixedLM(endog, exog, groups, exog_re=exog_re)
  >>> result = model.fit(free=free)
  
  A different way to specify independent random coefficients for the
  columns of ``exog_re``.  In this example ``groups`` must be a
  Pandas Series with compatible indexing with ``exog_re``, and
  ``exog_re`` has two columns.
  
  >>> g = pd.groupby(groups, by=groups).groups
  >>> vc = {}
  >>> vc['1'] = {k : exog_re.loc[g[k], 0] for k in g}
  >>> vc['2'] = {k : exog_re.loc[g[k], 1] for k in g}
  >>> model = sm.MixedLM(endog, exog, groups, vcomp=vc)
  >>> result = model.fit()
class_docstr_tok: ["Linear","Mixed","Effects","Model","Parameters","--","--","--","--","--","endog",":","1d","array_like","The","dependent","variable","exog",":","2d","array_like","A","matrix","of","covariates","used","to","determine","the","mean","structure","(","the","``","fixed","effects","''","covariates",")",".","groups",":","1d","array_like","A","vector","of","labels","determining","the","groups","--","data","from","different","groups","are","independent","exog_re",":","2d","array_like","A","matrix","of","covariates","used","to","determine","the","variance","and","covariance","structure","(","the","``","random","effects","''","covariates",")",".","If","None",",","defaults","to","a","random","intercept","for","each","group",".","exog_vc",":","VCSpec","instance","or","dict-like","(","deprecated",")","A","VCSPec","instance","defines","the","structure","of","the","variance","components","in","the","model",".","Alternatively",",","see","notes","below","for","a","dictionary-based","format",".","The","dictionary","format","is","deprecated","and","may","be","removed","at","some","point","in","the","future",".","use_sqrt",":","bool","If","True",",","optimization","is","carried","out","using","the","lower","triangle","of","the","square","root","of","the","random","effects","covariance","matrix",",","otherwise","it","is","carried","out","using","the","lower","triangle","of","the","random","effects","covariance","matrix",".","missing",":","str","The","approach","to","missing","data","handling","Notes","--","--","-","If","`","exog_vc","`","is","not","a","`","VCSpec","`","instance",",","then","it","must","be","a","dictionary","of","dictionaries",".","Specifically",",","`","exog_vc","[","a","]","[","g","]","`","is","a","matrix","whose","columns","are","linearly","combined","using","independent","random","coefficients",".","This","random","term","then","contributes","to","the","variance","structure","of","the","data","for","group","`","g","`",".","The","random","coefficients","all","have","mean","zero",",","and","have","the","same","variance",".","The","matrix","must","be","`","m","x","k","`",",","where","`","m","`","is","the","number","of","observations","in","group","`","g","`",".","The","number","of","columns","may","differ","among","the","top-level","groups",".","The","covariates","in","`","exog","`",",","`","exog_re","`","and","`","exog_vc","`","may","(","but","need","not",")","partially","or","wholly","overlap",".","`","use_sqrt","`","should","almost","always","be","set","to","True",".","The","main","use","case","for","use_sqrt=False","is","when","complicated","patterns","of","fixed","values","in","the","covariance","structure","are","set","(","using","the","`","free","`","argument","to","`","fit","`",")","that","can","not","be","expressed","in","terms","of","the","Cholesky","factor","L.","Examples","--","--","--","--","A","basic","mixed","model","with","fixed","effects","for","the","columns","of","``","exog","``","and","a","random","intercept","for","each","distinct","value","of","``","group","``",":",">",">",">","model","=","sm.MixedLM","(","endog",",","exog",",","groups",")",">",">",">","result","=","model.fit","(",")","A","mixed","model","with","fixed","effects","for","the","columns","of","``","exog","``","and","correlated","random","coefficients","for","the","columns","of","``","exog_re","``",":",">",">",">","model","=","sm.MixedLM","(","endog",",","exog",",","groups",",","exog_re=exog_re",")",">",">",">","result","=","model.fit","(",")","A","mixed","model","with","fixed","effects","for","the","columns","of","``","exog","``","and","independent","random","coefficients","for","the","columns","of","``","exog_re","``",":",">",">",">","free","=","MixedLMParams.from_components","(","fe_params=np.ones","(","exog.shape","[","1","]",")",",","cov_re=np.eye","(","exog_re.shape","[","1","]",")",")",">",">",">","model","=","sm.MixedLM","(","endog",",","exog",",","groups",",","exog_re=exog_re",")",">",">",">","result","=","model.fit","(","free=free",")","A","different","way","to","specify","independent","random","coefficients","for","the","columns","of","``","exog_re","``",".","In","this","example","``","groups","``","must","be","a","Pandas","Series","with","compatible","indexing","with","``","exog_re","``",",","and","``","exog_re","``","has","two","columns",".",">",">",">","g","=","pd.groupby","(","groups",",","by=groups",")",".groups",">",">",">","vc","=","{","}",">",">",">","vc","[","'","1","'","]","=","{","k",":","exog_re.loc","[","g","[","k","]",",","0","]","for","k","in","g","}",">",">",">","vc","[","'","2","'","]","=","{","k",":","exog_re.loc","[","g","[","k","]",",","1","]","for","k","in","g","}",">",">",">","model","=","sm.MixedLM","(","endog",",","exog",",","groups",",","vcomp=vc",")",">",">",">","result","=","model.fit","(",")"]
docstr: Evaluate the (profile) log-likelihood of the linear mixed
  effects model.
  
  Parameters
  ----------
  params : MixedLMParams, or array_like.
      The parameter value.  If array-like, must be a packed
      parameter vector containing only the covariance
      parameters.
  profile_fe : bool
      If True, replace the provided value of `fe_params` with
      the GLS estimates.
  
  Returns
  -------
  The log-likelihood value at `params`.
  
  Notes
  -----
  The scale parameter `scale` is always profiled out of the
  log-likelihood.  In addition, if `profile_fe` is true the
  fixed effects parameters are also profiled out.
docstr_tok: ["Evaluate","the","(","profile",")","log-likelihood","of","the","linear","mixed","effects","model",".","Parameters","--","--","--","--","--","params",":","MixedLMParams",",","or","array_like",".","The","parameter","value",".","If","array-like",",","must","be","a","packed","parameter","vector","containing","only","the","covariance","parameters",".","profile_fe",":","bool","If","True",",","replace","the","provided","value","of","`","fe_params","`","with","the","GLS","estimates",".","Returns","--","--","--","-","The","log-likelihood","value","at","`","params","`",".","Notes","--","--","-","The","scale","parameter","`","scale","`","is","always","profiled","out","of","the","log-likelihood",".","In","addition",",","if","`","profile_fe","`","is","true","the","fixed","effects","parameters","are","also","profiled","out","."]
code: def loglike(self, params, profile_fe=True):
      """
      Evaluate the (profile) log-likelihood of the linear mixed
      effects model.
  
      Parameters
      ----------
      params : MixedLMParams, or array_like.
          The parameter value.  If array-like, must be a packed
          parameter vector containing only the covariance
          parameters.
      profile_fe : bool
          If True, replace the provided value of `fe_params` with
          the GLS estimates.
  
      Returns
      -------
      The log-likelihood value at `params`.
  
      Notes
      -----
      The scale parameter `scale` is always profiled out of the
      log-likelihood.  In addition, if `profile_fe` is true the
      fixed effects parameters are also profiled out.
      """
  
      if type(params) is not MixedLMParams:
          params = MixedLMParams.from_packed(
              params, self.k_fe, self.k_re, self.use_sqrt, has_fe=False
          )
  
      cov_re = params.cov_re
      vcomp = params.vcomp
  
      # Move to the profile set
      if profile_fe:
          fe_params, sing = self.get_fe_params(cov_re, vcomp)
          if sing:
              self._cov_sing += 1
      else:
          fe_params = params.fe_params
  
      if self.k_re > 0:
          try:
              cov_re_inv = np.linalg.inv(cov_re)
          except np.linalg.LinAlgError:
              cov_re_inv = np.linalg.pinv(cov_re)
              self._cov_sing += 1
          _, cov_re_logdet = np.linalg.slogdet(cov_re)
      else:
          cov_re_inv = np.zeros((0, 0))
          cov_re_logdet = 0
  
      # The residuals
      expval = np.dot(self.exog, fe_params)
      resid_all = self.endog - expval
  
      likeval = 0.0
  
      # Handle the covariance penalty
      if (self.cov_pen is not None) and (self.k_re > 0):
          likeval -= self.cov_pen.func(cov_re, cov_re_inv)
  
      # Handle the fixed effects penalty
      if self.fe_pen is not None:
          likeval -= self.fe_pen.func(fe_params)
  
      xvx, qf = 0.0, 0.0
      for group_ix, group in enumerate(self.group_labels):
          vc_var = self._expand_vcomp(vcomp, group_ix)
          cov_aug_logdet = cov_re_logdet + np.sum(np.log(vc_var))
  
          exog = self.exog_li[group_ix]
          ex_r, ex2_r = self._aex_r[group_ix], self._aex_r2[group_ix]
          solver = _smw_solver(1.0, ex_r, ex2_r, cov_re_inv, 1 / vc_var)
  
          resid = resid_all[self.row_indices[group]]
  
          # Part 1 of the log likelihood (for both ML and REML)
          ld = _smw_logdet(
              1.0, ex_r, ex2_r, cov_re_inv, 1 / vc_var, cov_aug_logdet
          )
          likeval -= ld / 2.0
  
          # Part 2 of the log likelihood (for both ML and REML)
          u = solver(resid)
          qf += np.dot(resid, u)
  
          # Adjustment for REML
          if self.reml:
              mat = solver(exog)
              xvx += np.dot(exog.T, mat)
  
      if self.reml:
          likeval -= (self.n_totobs - self.k_fe) * np.log(qf) / 2.0
          _, ld = np.linalg.slogdet(xvx)
          likeval -= ld / 2.0
          likeval -= (
              (self.n_totobs - self.k_fe) * np.log(2 * np.pi) / 2.0
          )
          likeval += (
              (self.n_totobs - self.k_fe)
              * np.log(self.n_totobs - self.k_fe)
              / 2.0
          )
          likeval -= (self.n_totobs - self.k_fe) / 2.0
      else:
          likeval -= self.n_totobs * np.log(qf) / 2.0
          likeval -= self.n_totobs * np.log(2 * np.pi) / 2.0
          likeval += self.n_totobs * np.log(self.n_totobs) / 2.0
          likeval -= self.n_totobs / 2.0
  
      return likeval
  
imports: import warnings
  import numpy
  import pandas
  import patsy
  from scipy import sparse
  from scipy.stats.distributions import norm
  from statsmodels.base._penalties import Penalty
  import statsmodels.base.model
  from statsmodels.tools import data
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.tools.sm_exceptions import ConvergenceWarning
label_desc: Use image node_id 11 for calling the MixedLM obj's underlying member method code with example usage: obj.loglike(params, profile_fe) and returns: likeval