diff --git a/R/check_dag.R b/R/check_dag.R index cc5acfea7..dca48df3f 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -347,7 +347,7 @@ check_dag <- function( # - required is NULL and current adjustment not NULL # - OR we have a collider in current adjustments incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || - (!is.null(collider) && collider %in% adjustment_nodes), # nolint + (!is.null(collider) && any(collider %in% adjustment_nodes)), # nolint current_adjustments = adjustment_nodes, minimal_adjustments = minimal_adjustments, collider = collider diff --git a/inst/WORDLIST b/inst/WORDLIST index d9394796d..847ab8bbe 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -62,6 +62,7 @@ Dominicy Dordrecht Dorie Dunson +Dunkler Durbin Dxy Döring @@ -88,6 +89,8 @@ Gabry Gazen Gelman Gnanadesikan +Graham +Gregorich Guilford Hartig HDI @@ -158,6 +161,7 @@ Michalos Moosbrugger Monette Mora +Morrissey Multicollinearity MuMIn NFI @@ -178,6 +182,9 @@ OSF OSX Olkin PNFI +Papeş +Pandey +Park Pek Petrov polychoric @@ -202,6 +209,7 @@ Rousseeuw Routledge Rouder Rouder's +Ruxton SEM SRMR Scheepers @@ -220,6 +228,7 @@ Specifity Sphericity Springer Stata +Strohmaier Subscales TLI Technometrics diff --git a/tests/testthat/test-check_dag.R b/tests/testthat/test-check_dag.R index a25d2ff1f..4414635c2 100644 --- a/tests/testthat/test-check_dag.R +++ b/tests/testthat/test-check_dag.R @@ -201,3 +201,21 @@ test_that("check_dag, formula-interface", { ) expect_identical(dag, dag2) }) + + +test_that("check_dag handles multiple colliders correctly - issue #878", { + # This test reproduces the error from issue #878 + # The DAG has multiple colliders (both 'a' and 'b' are colliders) + # because they both have multiple incoming paths from 'c' and 'd' + # This test FAILS while bug exists, PASSES after fix + expect_no_error( + check_dag( + y ~ x + a + b, + a ~ c + d, + b ~ c + d, + outcome = "y", + exposure = "x", + adjusted = ~ a + b + ) + ) +})