Git Product home page Git Product logo

Comments (1)

matthewwardrop avatar matthewwardrop commented on June 20, 2024

Hi @tomicapretto! I thought about this a bit over the weekend, and here is my proposal. Let me know what you think.

Rather than adding a commutative option to Operator objects, I propose to instead allow Term instances to override how resulting columns are named. This would allow you to subclass Term to say RandomEffectTerm. Random effect operators would then generated RandomEffectTerm instances instead of Term instances, but honour the same API. The result might look a bit like this (untested code):

data = pandas.DataFrame({'a': [1,2,3], 'b': ['a','b','c']})

class RandomEffectTerm(Term):
    def __init__(group_factors, group):
        self.group_factors = set(group_factors)
        self.group = group

    @property
    def factors(self):
         return self.group_factors | {self.group}

    def get_column_name(self, features):
         # features would look something like:
         # {'a': 'a', 'b': 'b[T.a]'}
         return ":".join(sorted(v for k, v in features.values if k != self.group.expr)) + "|" + features[self.group.expr]

model_matrix("(a|b)") -> columns of {"a|b[T.a]", "a|b[T.b]", ...}

If this looks good to you, I'll code it up when I get a chance. The last piece would then be to formalise how to surface the different segments of the model matrix (or perhaps how to store multiple of them), in order to get the "fixed effect" and "random effect" parts... but we can deal with that as a separate thread.

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.