1616# '
1717# ' @returns Logical scalar.
1818# '
19+ # ' @examples
20+ # ' cg <- caugi_graph(
21+ # ' C %-->% X,
22+ # ' X %-->% F,
23+ # ' X %-->% D,
24+ # ' A %-->% X,
25+ # ' A %-->% K,
26+ # ' K %-->% Y,
27+ # ' D %-->% Y,
28+ # ' D %-->% G,
29+ # ' Y %-->% H,
30+ # ' class = "DAG"
31+ # ' )
32+ # '
33+ # ' d_separated(cg, "X", "Y", Z = c("A", "D")) # TRUE
34+ # ' d_separated(cg, "X", "Y", Z = NULL) # FALSE
35+ # '
1936# ' @family adjustment
2037# ' @concept adjustment
2138# '
@@ -56,9 +73,28 @@ d_separated <- function(cg,
5673# ' @param X,Y Node names.
5774# ' @param X_index,Y_index Optional numeric 1-based indices.
5875# ' @param type One of `"parents"`, `"backdoor"`, `"optimal"`.
76+ # ' The `optimal` option computes the O-set.
5977# '
6078# ' @returns A tibble with a `name` column (possibly 0 rows).
6179# '
80+ # ' @examples
81+ # ' cg <- caugi_graph(
82+ # ' C %-->% X,
83+ # ' X %-->% F,
84+ # ' X %-->% D,
85+ # ' A %-->% X,
86+ # ' A %-->% K,
87+ # ' K %-->% Y,
88+ # ' D %-->% Y,
89+ # ' D %-->% G,
90+ # ' Y %-->% H,
91+ # ' class = "DAG"
92+ # ' )
93+ # '
94+ # ' adjustment_set(cg, "X", "Y", type = "parents") # C, A
95+ # ' adjustment_set(cg, "X", "Y", type = "backdoor") # C, A
96+ # ' adjustment_set(cg, "X", "Y", type = "optimal") # K
97+ # '
6298# ' @family adjustment
6399# ' @concept adjustment
64100# '
@@ -68,7 +104,7 @@ adjustment_set <- function(cg,
68104 Y = NULL ,
69105 X_index = NULL ,
70106 Y_index = NULL ,
71- type = c(" parents " , " backdoor " , " optimal " )) {
107+ type = c(" optimal " , " parents " , " backdoor " )) {
72108 is_caugi(cg , TRUE )
73109 if (length(X ) > 1 || length(Y ) > 1 ||
74110 length(X_index ) > 1 || length(Y_index ) > 1 ) {
@@ -100,7 +136,25 @@ adjustment_set <- function(cg,
100136# ' @param Z Optional node set for conditioning
101137# ' @param X_index,Y_index,Z_index Optional 1-based indices.
102138# '
103- # ' @returns Logical scalar.
139+ # ' @returns Logical value indicating if backdoor is valid or not.
140+ # '
141+ # ' @examples
142+ # ' cg <- caugi_graph(
143+ # ' C %-->% X,
144+ # ' X %-->% F,
145+ # ' X %-->% D,
146+ # ' A %-->% X,
147+ # ' A %-->% K,
148+ # ' K %-->% Y,
149+ # ' D %-->% Y,
150+ # ' D %-->% G,
151+ # ' Y %-->% H,
152+ # ' class = "DAG"
153+ # ' )
154+ # '
155+ # ' is_valid_backdoor(cg, X = "X", Y = "Y", Z = NULL) # FALSE
156+ # ' is_valid_backdoor(cg, X = "X", Y = "Y", Z = "K") # TRUE
157+ # ' is_valid_backdoor(cg, X = "X", Y = "Y", Z = c("A", "C")) # TRUE
104158# '
105159# ' @family adjustment
106160# ' @concept adjustment
@@ -143,6 +197,46 @@ is_valid_backdoor <- function(cg,
143197# ' @returns A list of character vectors, each an adjustment set
144198# ' (possibly empty).
145199# '
200+ # ' @examples
201+ # ' cg <- caugi_graph(
202+ # ' C %-->% X,
203+ # ' X %-->% F,
204+ # ' X %-->% D,
205+ # ' A %-->% X,
206+ # ' A %-->% K,
207+ # ' K %-->% Y,
208+ # ' D %-->% Y,
209+ # ' D %-->% G,
210+ # ' Y %-->% H,
211+ # ' class = "DAG"
212+ # ' )
213+ # '
214+ # ' all_backdoor_sets(cg, X = "X", Y = "Y", max_size = 3L, minimal = FALSE)
215+ # ' #> [[1]]
216+ # ' #> [1] "A"
217+ # ' #>
218+ # ' #> [[2]]
219+ # ' #> [1] "K"
220+ # ' #>
221+ # ' #> [[3]]
222+ # ' #> [1] "C" "A"
223+ # ' #>
224+ # ' #> [[4]]
225+ # ' #> [1] "C" "K"
226+ # ' #>
227+ # ' #> [[5]]
228+ # ' #> [1] "A" "K"
229+ # ' #>
230+ # ' #> [[6]]
231+ # ' #> [1] "C" "A" "K"
232+ # '
233+ # ' all_backdoor_sets(cg, X = "X", Y = "Y", max_size = 3L, minimal = TRUE)
234+ # ' #> [[1]]
235+ # ' #> [1] "A"
236+ # ' #>
237+ # ' #> [[2]]
238+ # ' #> [1] "K"
239+ # '
146240# ' @family adjustment
147241# ' @concept adjustment
148242# '
0 commit comments