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

Categorical variable coded as integer fails #27

Closed
edwindj opened this issue Oct 14, 2020 · 1 comment
Closed

Categorical variable coded as integer fails #27

edwindj opened this issue Oct 14, 2020 · 1 comment
Labels

Comments

@edwindj
Copy link
Member

edwindj commented Oct 14, 2020

When a categorical variable is coded as an integer, the resulting mip solver, does not know that it is categorical.

library(errorlocate)

## Loading required package: validate

rules <- validator(if (sector %in% c(1,2)) turnover > 0)

# faulty record
data <- data.frame(sector = 1, turnover = 0)
weight <- c(sector = 2, turnover = 1)

# no errors found!
locate_errors(data, rules, weight=weight)$errors

##      sector turnover
## [1,]  FALSE    FALSE

This works though:

library(errorlocate)
rules <- validator(if (sector %in% c("1","2")) turnover > 0)

# faulty record
data <- data.frame(sector = "1", turnover = 0)
weight <- c(sector = 2, turnover = 1)

# turnover is faulty
locate_errors(data, rules, weight=weight)$errors

##      sector turnover
## [1,]  FALSE     TRUE

Thanks to Jeffrey Hoogland for reporting

@edwindj edwindj added the bug label Oct 14, 2020
edwindj added a commit that referenced this issue Oct 14, 2020
@edwindj
Copy link
Member Author

edwindj commented Oct 14, 2020

It now creates a warning:

library(errorlocate)

## Loading required package: validate

rules <- validator(if (sector %in% c(1,2)) turnover > 0)

# faulty record
data <- data.frame(sector = 1, turnover = 0)
weight <- c(sector = 2, turnover = 1)

# no errors found, but a warning is given
locate_errors(data, rules, weight=weight)$errors

## Warning: 'sector' seems a categorical variable, please recode it as a factor in the data.
## Only use character or logical values in %in% statements to prevent this warning.

##      sector turnover
## [1,]  FALSE    FALSE

Recoding sector as factor fixes the issue:

data$sector <- factor(data$sector)
locate_errors(data, rules, weight=weight)$errors

## Warning: 'sector' seems a categorical variable, please recode it as a factor in the data.
## Only use character or logical values in %in% statements to prevent this warning.

##      sector turnover
## [1,]  FALSE     TRUE

edwindj added a commit that referenced this issue Oct 14, 2020
@edwindj edwindj closed this as completed Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant