On Sun, Jul 29, 2012 at 4:04 PM, Ian Langmore <
ianla...@gmail.com> wrote:
> I see two difficulties with returning results for only the nonzero params.
> First, the nonzero params differ between targets. Second, some results are
> naturally computed using the zero params as well (e.g. the log likelihood).
>
> How about this: Some of our previous results are no longer valid, and we
> have some new results. Let's create l1ModelResults (extending
> LikelihoodModelResults). It will return float('nan') in place of results
> that don't make sense. So, e.g. if params[0] = 0, then results.bse[0] =
> float('nan'). Does this seem like a good first step?
>
> I started (see this commit), but am having a difficulty using the
> ResultsWrapper and @cache_readonly. Inside l1ModelResults, I have
> @cache_readonly
> def bse(self):
> bse = super(l1ModelResults, self).bse
> # self.zero_param_idx is populated during init
> bse[self.zero_param_idx] = float('nan')
> return bse
>
> The wrapper overrides this by calling MultinomialResults.bse. If I
> preemptively call l1ModelResults.bse (e.g. inside __init__), then my results
> are preserved, but they are not shaped right (normally, MultinomialResults
> creates and shapes bse).
Can you please bottom or inline post? We are used to that convention
in numpy/scipy/... related mailing lists?
Makes it easier to follow the thread.
I think the problem is not the result wrapper, but that discrete
models have their own subclasses for the results.
for example for multinomial in statsmodels/discrete/discrete_model.py
MultinomialResults(DiscreteResults)
We need this to add results that are specific to binary, count or
multinomial response models. That is related to my initial question
whether we have to add L1 specific code to all the results
(sub)classes.
The result sub-classes still inherit most of the statistical results,
however multinomial is a special case for bse because params is 2d
instead of the usual 1d.
I think the direct approach for multinomial would be to overwrite the
MultinomialModel.fit method and return a L1MultinomialResults.
I don't know if there is a more general solution (mixins?).
Code reuse and model specific results have the unfortunate side-effect
that everything got a bit spread out across classes.
Now, I think I understand why you mention target, before I didn't pay
enough attention to realize that your demo example uses multinomial
which is a 2d problem. I see the problem with returning a standard
result instance if the variable selection varies by target/multinomial
choice.
In analogy to system of equation models where we don't necessarily
have the same number of regressors in each equation, the way out would
be to work only with the flattened params and bse. (But it's more work
to change or add this.)
Is there a special reason you picked multinomial as example and not
Logit or Poisson for example?
aside: in l1ModelResults(LikelihoodModelResults) it looks like you
copied the entire super class. Most of it will be inherited and
doesn't need to be copied, isn't it?
Josef