Skip to content

Commit fe4e304

Browse files
authored
Merge pull request #1569 from exploratory-io/fix/issue-37308
fix(corresp): remove practical-significance params, simplify CA/MCA judgement (#37308)
2 parents 23f709a + d6a9dd8 commit fe4e304

4 files changed

Lines changed: 18 additions & 63 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: exploratory
22
Type: Package
33
Title: R package for Exploratory
4-
Version: 16.0.23
4+
Version: 16.0.24
55
Date: 2026-07-28
66
Authors@R: c(person("Hideaki", "Hayashi", email = "hideaki@exploratory.io", role = c("aut", "cre")), person("Hide", "Kojima", email = "hide@exploratory.io", role = c("aut")), person("Kan", "Nishida", email = "kan@exploratory.io", role = c("aut")), person("Kei", "Saito", email = "kei@exploratory.io", role = c("aut")), person("Yosuke", "Yasuda", email = "double.y.919.quick@gmail.com", role = c("aut")))
77
URL: https://github.com/exploratory-io/exploratory_func

R/corresp.R

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
exp_mca <- function(df, ..., max_nrow = NULL, allow_single_column = FALSE, ncp = 5,
99
quanti_sups = NULL, seed = 1,
1010
overall_adjust_method = "holm", cell_adjust_method = "holm", alpha = 0.05,
11-
missing_method = "listwise", featured_rule = "statistical",
12-
simulation_count = 20000, suppress_cell_p_when_sparse = TRUE,
13-
practical_ratio_upper = 1.20, practical_ratio_lower = 0.80,
14-
practical_minimum_difference = NULL, require_overall_significance = TRUE) {
11+
missing_method = "listwise",
12+
simulation_count = 20000) {
1513
all_cols <- colnames(df)
1614
selected_cols <- tidyselect::vars_select(names(df), !!! rlang::quos(...))
1715
grouped_cols <- grouped_by(df)
@@ -127,11 +125,7 @@ exp_mca <- function(df, ..., max_nrow = NULL, allow_single_column = FALSE, ncp =
127125
data = association_data, variables = effective_vars,
128126
overall_adjust_method = overall_adjust_method, cell_adjust_method = cell_adjust_method,
129127
alpha = alpha, missing_method = missing_method, simulation_count = simulation_count,
130-
seed = seed, suppress_cell_p_when_sparse = suppress_cell_p_when_sparse,
131-
featured_rule = featured_rule, practical_ratio_upper = practical_ratio_upper,
132-
practical_ratio_lower = practical_ratio_lower,
133-
practical_minimum_difference = practical_minimum_difference,
134-
require_overall_significance = require_overall_significance
128+
seed = seed
135129
)
136130
} else {
137131
fit$association <- list(

R/corresp_report.R

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ ca_create_significance_marker <- function(adjusted_p_value) {
8080
# ------------------------------------------------------------
8181
ca_analyze_one_variable_pair <- function(
8282
data, variable_1, variable_2, pair_index,
83-
cell_adjust_method, alpha, simulation_count, seed,
84-
suppress_cell_p_when_sparse,
85-
practical_ratio_upper, practical_ratio_lower, practical_minimum_difference
83+
cell_adjust_method, alpha, simulation_count, seed
8684
) {
8785
pair_data <- data %>%
8886
dplyr::transmute(
@@ -168,12 +166,6 @@ ca_analyze_one_variable_pair <- function(
168166
names(cell_results) <- c("row_category", "column_category", "observed_count")
169167
n <- sum(contingency_table)
170168

171-
minimum_difference <- if (is.null(practical_minimum_difference)) {
172-
max(5, 0.005 * n)
173-
} else {
174-
practical_minimum_difference
175-
}
176-
177169
cell_results <- cell_results %>%
178170
dplyr::mutate(
179171
expected_count = as.vector(pearson_test$expected),
@@ -189,13 +181,8 @@ ca_analyze_one_variable_pair <- function(
189181
cell_p_value = 2 * pnorm(abs(adjusted_standardized_residual), lower.tail = FALSE)
190182
)
191183

192-
if (!asymptotic_approximation_ok && suppress_cell_p_when_sparse) {
193-
cell_results <- cell_results %>%
194-
dplyr::mutate(cell_p_value = NA_real_, cell_adjusted_p_value = NA_real_)
195-
} else {
196-
cell_results <- cell_results %>%
197-
dplyr::mutate(cell_adjusted_p_value = p.adjust(cell_p_value, method = cell_adjust_method))
198-
}
184+
cell_results <- cell_results %>%
185+
dplyr::mutate(cell_adjusted_p_value = p.adjust(cell_p_value, method = cell_adjust_method))
199186

200187
cell_results <- cell_results %>%
201188
dplyr::mutate(
@@ -205,10 +192,6 @@ ca_analyze_one_variable_pair <- function(
205192
adjusted_standardized_residual < 0 ~ "less_than_expected",
206193
TRUE ~ "as_expected"
207194
),
208-
practical_difference = (
209-
(observed_expected_ratio >= practical_ratio_upper | observed_expected_ratio <= practical_ratio_lower) &
210-
absolute_count_difference >= minimum_difference
211-
),
212195
significance_marker = ca_create_significance_marker(cell_adjusted_p_value),
213196
cell_label = paste0(sprintf("%.2f", adjusted_standardized_residual), significance_marker)
214197
) %>%
@@ -218,7 +201,6 @@ ca_analyze_one_variable_pair <- function(
218201
n = n, test_method = test_method,
219202
expected_count_warning = !asymptotic_approximation_ok,
220203
cell_adjust_method = cell_adjust_method,
221-
practical_minimum_difference = minimum_difference,
222204
.before = 1
223205
)
224206

@@ -251,16 +233,9 @@ build_pairwise_association_results <- function(
251233
alpha = 0.05,
252234
missing_method = c("listwise", "pairwise"),
253235
simulation_count = 20000,
254-
seed = 123,
255-
suppress_cell_p_when_sparse = TRUE,
256-
featured_rule = c("statistical", "statistical_and_practical"),
257-
practical_ratio_upper = 1.20,
258-
practical_ratio_lower = 0.80,
259-
practical_minimum_difference = NULL,
260-
require_overall_significance = TRUE
236+
seed = 123
261237
) {
262238
missing_method <- match.arg(missing_method)
263-
featured_rule <- match.arg(featured_rule)
264239

265240
supported_adjust_methods <- c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none")
266241
if (!overall_adjust_method %in% supported_adjust_methods) stop("overall_adjust_method is invalid.")
@@ -286,11 +261,7 @@ build_pairwise_association_results <- function(
286261
ca_analyze_one_variable_pair(
287262
data = analysis_data, variable_1 = pair[[1]], variable_2 = pair[[2]],
288263
pair_index = pair_index, cell_adjust_method = cell_adjust_method,
289-
alpha = alpha, simulation_count = simulation_count, seed = seed,
290-
suppress_cell_p_when_sparse = suppress_cell_p_when_sparse,
291-
practical_ratio_upper = practical_ratio_upper,
292-
practical_ratio_lower = practical_ratio_lower,
293-
practical_minimum_difference = practical_minimum_difference
264+
alpha = alpha, simulation_count = simulation_count, seed = seed
294265
)
295266
}
296267
)
@@ -324,11 +295,7 @@ build_pairwise_association_results <- function(
324295
settings <- list(
325296
variables = variables, analysis_n = nrow(analysis_data),
326297
overall_adjust_method = overall_adjust_method, cell_adjust_method = cell_adjust_method,
327-
alpha = alpha, missing_method = missing_method, simulation_count = simulation_count,
328-
suppress_cell_p_when_sparse = suppress_cell_p_when_sparse, featured_rule = featured_rule,
329-
practical_ratio_upper = practical_ratio_upper, practical_ratio_lower = practical_ratio_lower,
330-
practical_minimum_difference = practical_minimum_difference,
331-
require_overall_significance = require_overall_significance
298+
alpha = alpha, missing_method = missing_method, simulation_count = simulation_count
332299
)
333300

334301
if (nrow(residual_heatmap_data) == 0) {
@@ -353,22 +320,13 @@ build_pairwise_association_results <- function(
353320
) %>%
354321
dplyr::mutate(
355322
statistically_featured = (
356-
cell_significant & !expected_count_warning &
357-
(!require_overall_significance | pair_significant)
323+
cell_significant & !expected_count_warning
358324
),
359-
# featured_rule is a scalar: "statistical" -> statistically_featured;
360-
# "statistical_and_practical" -> also require practical_difference.
361-
featured_combination = statistically_featured &
362-
(featured_rule == "statistical" | practical_difference),
325+
featured_combination = statistically_featured,
363326
# language-neutral final judgement enum
364327
final_judgement = dplyr::case_when(
365-
expected_count_warning & suppress_cell_p_when_sparse ~ "sparse_suppressed",
366-
require_overall_significance & !pair_significant ~ "exploratory_pair_not_significant",
367-
!cell_significant ~ "no_clear_difference",
368-
adjusted_standardized_residual > 0 & practical_difference ~ "significantly_more",
369-
adjusted_standardized_residual < 0 & practical_difference ~ "significantly_less",
370-
adjusted_standardized_residual > 0 ~ "more_but_small",
371-
adjusted_standardized_residual < 0 ~ "less_but_small",
328+
cell_significant & adjusted_standardized_residual > 0 ~ "significantly_more",
329+
cell_significant & adjusted_standardized_residual < 0 ~ "significantly_less",
372330
TRUE ~ "no_clear_difference"
373331
),
374332
heatmap_fill_value = adjusted_standardized_residual,
@@ -391,7 +349,7 @@ build_pairwise_association_results <- function(
391349
pair_index, pair_id, variable_1, variable_2, rank_within_pair, category_pair,
392350
row_category, column_category, observed_count, expected_count, count_difference,
393351
observed_expected_ratio, adjusted_standardized_residual, cell_p_value,
394-
cell_adjusted_p_value, practical_difference, final_judgement, n, cramers_v, association_strength
352+
cell_adjusted_p_value, final_judgement, n, cramers_v, association_strength
395353
)
396354

397355
list(

tests/testthat/test_corresp_2.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ test_that("MCA branch: 3 variables produce mca_exploratory with all new tidy typ
3535
rc <- m %>% tidy_rowwise(model, type = "residual_cells")
3636
expect_true(all(c("row_category", "column_category", "adjusted_standardized_residual",
3737
"final_judgement", "heatmap_fill_value") %in% colnames(rc)))
38+
# #37308: judgement simplified to exactly 3 outcomes, no more sparse-suppressed p-values.
39+
expect_true(all(rc$final_judgement %in% c("significantly_more", "significantly_less", "no_clear_difference")))
40+
expect_true(all(!is.na(rc$cell_adjusted_p_value)))
3841
expect_true(nrow(m %>% tidy_rowwise(model, type = "dimension_summary")) >= 1)
3942
expect_true(all(c("variable", "category", "dimension", "coordinate", "contribution_pct", "cos2")
4043
%in% colnames(m %>% tidy_rowwise(model, type = "dimension_matrix"))))

0 commit comments

Comments
 (0)