Skip to content

automatic transformation, scaling or scaling checks or preprocessing #1131

Open

Description

@josef-pkt

I ran into an example with some badly scaled variables (Cameron Trivedi count data similar to randhi).

It took me a while to figure out that the bad scaling was the reason for numerical problems:

  • very large condition number, almost singular
  • fmin_bfgs goes out of range (huge numbers)
  • fmin ("nm") was still ok, but not very precise

Stata doesn't seem to have a problem with the original unscaled data. As far as I know, Stata treats the constant differently, but I haven't read that they also rescale.
I haven't tried if demeaning would be enough in this case.

In my case the user wouldn't see part of the rescaling gmm instruments or first stage of IV2SLS.
For other cases, we would have to transform the parameters to adjust for any scaling.

At least a warning would be useful to point out the problem to users.


An idea for stronger numerical stabilisation: use pinv like transformation (analog to linear model)

If the underlying exog dependent part is linear x dot beta, then we can transform the exog before fitting and retransform after fitting.
Instead of just rescaling exog, we can orthogonalize exog, which is just a linear, possibly rank reduced, transformation of the data and the linear parameters, beta.
This would correspond to using the analog of a PCA (SVD) regression internally during the optimization, but we report the results in the original exog space.

From my previous experiments, OLS with pinv produces numerically unstable results only in very extreme cases of bad scaling or almost perfect multicollinearity. (one NIST case)
Non-linear optimization like in the discrete models are numerically much less robust.

related for Hessian: #953 linalg.inv in Newton fails relatively easily

Activity

  1. josef-pkt commented on May 16, 2014

    @josef-pkt
    MemberAuthor

    Another example using squares
    restricted least squares rls has an example with x and x**2 in the exog. However, x is large. Without rescaling x, rank(exog) is full rank, the estimated cov_params has reduced rank.
    Looks like pinv truncation might not be kicking in yet, but inverting for cov_params produces a eigenvalue of around 1e-18, and np.linalg.matrix_rank(res.cov_params()) shows reduce rank

    (The actual example is not clear yet, because I only use the restricted model where we have on intentional singularity, perfect correlation among exogs that is removed by one linear restriction.)

  2. josef-pkt commented on May 27, 2014

    @josef-pkt
    MemberAuthor

    see comment about behavior of fmin_cg #1641 (comment)

  3. changed the title [-]automatic scaling or scaling checks or preprocessing[/-] [+]automatic transformation, scaling or scaling checks or preprocessing[/+] on May 27, 2014
  4. josef-pkt commented on Jun 20, 2014

    @josef-pkt
    MemberAuthor

    partial transformation: make it possible that we only standardize or transform some of the exog.

    example usecase
    we have 5 parameters that we are interested in and don't want to penalize, we have another set of potential explanatory variables where we don't care about the parameters.
    -> Transform and penalize only the extra variables ("confounders")

  5. josef-pkt commented on Dec 14, 2014

    @josef-pkt
    MemberAuthor

    another reference:
    Beta Regression article (*) has an online appendix that mentions several optimization problems, one of them is that larger values of exog cause problems with log link (exp mean function).
    Sounds like same problem that I ran into with Poisson and Negative Binomial.

    (*) #2030 (comment) "A Better Lemon Squeezer"

  6. jseabold commented on Dec 15, 2014

    @jseabold
    Member

    There was also a recent StackOverflow question where a logistic regression was failing because of badly scaled variables, which makes sense. Would be nice to have a cookbook notebook using the current scaling using StandardizeTransform to point to.

  7. josef-pkt commented on Dec 15, 2014

    @josef-pkt
    MemberAuthor

    The stackoverflow question triggered that I look into this again.
    But besides scaling, we also need better default start_params.
    GLM might have better starting values in cases like this.
    BetaRegression also can run into optimization problems if the starting values are not good.

  8. josef-pkt commented on Sep 25, 2015

    @josef-pkt
    MemberAuthor

    Another case, the first time I see it explicit in Stata
    Stata slogit standardizes exog for the optimization with option nonormalize to turn it off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions