Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store set of categories in CategoricalVariable #74

Closed
slwu89 opened this issue Mar 14, 2021 · 6 comments
Closed

Store set of categories in CategoricalVariable #74

slwu89 opened this issue Mar 14, 2021 · 6 comments
Labels
enhancement New feature or request small We have estimated that the issue should be one of the quicker fixes (1 point)

Comments

@slwu89
Copy link
Collaborator

slwu89 commented Mar 14, 2021

I think it might be a good idea to store the set of valid states within CategoricalVariable. I have a use case where I'll need multiple categorical variables and having each object know its set of valid states makes rendering output easier. I'm considering writing a rendering prefab to take in an indeterminate number of categorical variables to output counts of each, which would be greatly eased by storing states within the variables (for outputting the marginals or intersections).

@slwu89 slwu89 added enhancement New feature or request small We have estimated that the issue should be one of the quicker fixes (1 point) labels Mar 14, 2021
@giovannic
Copy link
Member

This feels quite related to #47

Is it a duplicate?

Deffo needed

@slwu89
Copy link
Collaborator Author

slwu89 commented Mar 15, 2021

Ah, even more simple, just adding a value to CategoricalVariable that stores the unique categories (passed as argument categories in the constructor).

@giovannic
Copy link
Member

Ah ok, but then how do we initialise individuals who have more than one category?

@slwu89
Copy link
Collaborator Author

slwu89 commented Mar 15, 2021

Oh, this isn't touching issue #47. This one would be as simple as adding a line like:

self$.categories <- categories

to CategoricalVariable$initialize. I just opened an issue for it because I was wanted to make sure this doesn't go against some design philosophy I'm not aware of. It's probably superfluous to have opened an entire issue for such a small change...

@giovannic
Copy link
Member

Oh I seeeee!

Yes that would be useful.

self$.categories <- categories

would not be DRY.

A bitset_get_categories function that gets the categories from the C++ class is the principled way to do it

@slwu89
Copy link
Collaborator Author

slwu89 commented Mar 16, 2021

Cool =] So it was a good idea to check.

Yeah I mostly wanted it so I can do something like this to get marginal counts, or something more elegant to get the cross tabulation table of counts. I see now how it originally came across as being similar to #47

render_multiple_categorical_variables <- function(renderer, ...) {
  vars <- match.call(expand.dots = FALSE)$`...`
   function(t) {
    for( v in vars) {
       for (c in v$get_categories()) {
          renderer$render(paste0(v,"_",c, '_count'), v$get_size_of(c), t)
       }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request small We have estimated that the issue should be one of the quicker fixes (1 point)
Projects
None yet
Development

No branches or pull requests

2 participants