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

Types of features should be validated. #25

Open
zero323 opened this Issue Mar 28, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@zero323
Copy link

zero323 commented Mar 28, 2019

Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request

If you are reporting (1) a bug or (2) a question about code, please supply:

Right now package doesn't validate if features are factors. It leads to rather errors like this

## load package
library("cregg")

df <- tibble::tibble(
  choice = c(0, 1), f1 = c("a", "b"), f2 = c("d", "e"), id = c("1", "2")
)

mm(df, choice ~ f1 + f2, id = ~id)

## Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column
## In addition: Warning messages:
## 1: Setting row names on a tibble is deprecated. 
## 2: Setting row names on a tibble is deprecated. 
## Called from: fix.by(by.y, y)

That's because make_term_levels_df blindly assumes that features are factors and ends up with a list of NULLs

lapply(df[c("f1", "f2")], levels)
## $f1
## NULL
## 
## $f2
## NULL

The problem affects at least amce, cj and mm.

A quick fix would be to simply test if that's the case:

if(!all(sapply(data[feature_names], is.factor))) stop("All features should be factors")

Alternatively one could attempt to fix the problem by explicitly casting to factors (maybe with a warning).

@zero323 zero323 changed the title Type of features should be validated. Types of features should be validated. Mar 28, 2019

@leeper

This comment has been minimized.

Copy link
Owner

leeper commented Mar 29, 2019

Thanks. Good points. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.