Git Product home page Git Product logo

Comments (4)

matthewwardrop avatar matthewwardrop commented on July 2, 2024 1

Thanks again for reporting this @tomicapretto . This should be resolved as of 0.6.5+.

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 2, 2024

Hi @tomicapretto ,

Thanks for taking the time to report this. However, this is actually expected behaviour due to the ordered nature of formulae and the automatic full-rank algorithm (where terms to the left take precedence over terms to the right in terms of materialization).

That is:

>>> print(model_matrix("0 + g + 1", df))
   g[T.a]  g[T.b]
0       1       0
1       1       0
2       1       0
3       0       1
4       0       1
>>> print(model_matrix("0 + 1 + g", df))
   Intercept  g[T.b]
0        1.0       0
1        1.0       0
2        1.0       0
3        1.0       1
4        1.0       1

These model matrices are equivalent, and the columns span the vector space (i.e. the model matrix is full rank). In both cases the intercept is spanned, but in the former case it is spanned by the categorical factors.

I'll close this one out for now, but let me know if have further questions!

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 2, 2024

Hmm... but this does, upon further reflection, not match the behaviour expected by users of R or patsy. It might be worth special casing the full rank algorithm to deal with the intercept. Point taken. I'll fix this!

from formulaic.

tomicapretto avatar tomicapretto commented on July 2, 2024

@matthewwardrop your explanation makes perfect sense (i.e. terms to the left take precedence over terms to the right). But as you said, it may be surprising to users coming from Patsy or R. I don't have a strong preference. But if you decide to continue with the current approach, it would be good to leave a note in the documentation explaining why it works the way it works in this specific case. I could open a PR 😄

from formulaic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.