I found `nparams` used a few other places (e.g. gmm,
base.genericlikelihoodmodel).  I wanted a member variable containing the
number of parameters in the model (i.e. the length of params) before I see
an actual params vector.  It's not always exog.shape[1], e.g. in MixedLM
there is a exog and an exog_re, and the length of params is exog.shape[1] +
exog_re.shape[1]*(exog_re.shape[1]+1)/2.

By "number of parameters" here I mean the number of parameters that are
free variables in the optimization, so scale parameters that are computed
outside the optimization don't count.

The motivation here is that the solution_path code should be usable with
any model that has a fit_regularized method.  A generic fit_regularized
method will treat `params` generically, so I needed to know that dimension
of params ahead of time.

I could work around this by waiting until the first instance of `params` is
seen, then setting everything up based on the length of that vector (rather
than relying on an instance variable that gives the length of `params`
ahead of time).  But that's a bit clunkier.

I added nparams to discrete because it wasn't there already, and I was
looking to confirm that solution_path worked outside of MixedLM.

Is there a better way to handle this?



On Tue, May 6, 2014 at 1:51 AM, Skipper Seabold <notifications@github.com>wrote:

> In statsmodels/discrete/discrete_model.py:
>
> > @@ -117,6 +117,9 @@ def __init__(self, endog, exog, **kwargs):
> >          super(DiscreteModel, self).__init__(endog, exog, **kwargs)
> >          self.raise_on_perfect_prediction = True
> >
> > +        # Default, change in subclass if needed.
> > +        self.nparams = self.exog.shape[1]
>
> By convention, we have k to pre-fix column-wise counts and n to predict
> row-wise counts, so this should be k_params (or, better yet, k_exog set
> up the inheritance chain, but we will fix that later)
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/statsmodels/statsmodels/pull/1529/files#r12289848>
> .
>