R/calculate.R
changed.
Other files ignored by Codecov
tests/testthat/test-calculate.R
has changed.
306 | 306 | res[["statistic"]] |
|
307 | 307 | } |
|
308 | 308 | ||
309 | + | # Warn about possible unused factor levels |
|
310 | + | if (has_unused_levels(x[[expl_var]])) { |
|
311 | + | warning_glue("Explanatory variable has unused factor levels.") |
|
312 | + | } |
|
313 | + | if (has_unused_levels(x[[resp_var]])) { |
|
314 | + | warning_glue("Response variable has unused factor levels.") |
|
315 | + | } |
|
316 | + | ||
317 | + | # Compute result |
|
309 | 318 | result <- x %>% |
|
310 | 319 | dplyr::nest_by(.key = "data") %>% |
|
311 | 320 | dplyr::summarise(stat = chisq_indep(data), .groups = "drop") |
308 | 308 | } |
|
309 | 309 | } |
|
310 | 310 | ||
311 | + | has_unused_levels <- function(x) { |
|
312 | + | if (is.factor(x)) { |
|
313 | + | present_levels <- unique(as.character(x)) |
|
314 | + | unused_levels <- setdiff(levels(x), present_levels) |
|
315 | + | ||
316 | + | length(unused_levels) > 0 |
|
317 | + | } else { |
|
318 | + | FALSE |
|
319 | + | } |
|
320 | + | } |
|
321 | + | ||
311 | 322 | # Helpers for hypothesize() ----------------------------------------------- |
|
312 | 323 | ||
313 | 324 | match_null_hypothesis <- function(null) { |
519 | 530 | } |
|
520 | 531 | ||
521 | 532 | TRUE |
|
522 | - | } |
Files | Coverage |
---|---|
R | 99.84% |
Project Totals (15 files) | 99.84% |