get_S_causal_steps: Get the steps for generating MC samples for coalitions...

View source: R/asymmetric_and_casual_Shapley.R

get_S_causal_stepsR Documentation

Get the steps for generating MC samples for coalitions following a causal ordering

Description

Get the steps for generating MC samples for coalitions following a causal ordering

Usage

get_S_causal_steps(S, causal_ordering, confounding, as_string = FALSE)

Arguments

S

Integer matrix of dimension n_coalitions_valid x m, where n_coalitions_valid equals the total number of valid coalitions that respect the causal ordering given in causal_ordering and m equals the total number of features.

causal_ordering

List. Not applicable for (regular) non-causal or asymmetric explanations. causal_ordering is an unnamed list of vectors specifying the components of the partial causal ordering that the coalitions must respect. Each vector represents a component and contains one or more features/groups identified by their names (strings) or indices (integers). If causal_ordering is NULL (default), no causal ordering is assumed and all possible coalitions are allowed. No causal ordering is equivalent to a causal ordering with a single component that includes all features (list(1:n_features)) or groups (list(1:n_groups)) for feature-wise and group-wise Shapley values, respectively. For feature-wise Shapley values and causal_ordering = list(c(1, 2), c(3, 4)), the interpretation is that features 1 and 2 are the ancestors of features 3 and 4, while features 3 and 4 are on the same level. Note: All features/groups must be included in the causal_ordering without any duplicates.

confounding

Logical vector. Not applicable for (regular) non-causal or asymmetric explanations. confounding is a vector of logicals specifying whether confounding is assumed or not for each component in the causal_ordering. If NULL (default), then no assumption about the confounding structure is made and explain computes asymmetric/symmetric conditional Shapley values, depending on the value of asymmetric. If confounding is a single logical, i.e., FALSE or TRUE, then this assumption is set globally for all components in the causal ordering. Otherwise, confounding must be a vector of logicals of the same length as causal_ordering, indicating the confounding assumption for each component. When confounding is specified, then explain computes asymmetric/symmetric causal Shapley values, depending on the value of asymmetric. The approach cannot be regression_separate and regression_surrogate as the regression-based approaches are not applicable to the causal Shapley value methodology.

as_string

Boolean. If the returned object is to be a list of lists of integers or a list of vectors of strings.

Value

Depends on the value of the parameter as_string. If a string, then results[j] is a vector specifying the process of generating the samples for coalition j. The length of results[j] is the number of steps, and results[j][i] is a string of the form features_to_sample|features_to_condition_on. If the features_to_condition_on part is blank, then we are to sample from the marginal distribution. For as_string == FALSE, then we rather return a vector where results[[j]][[i]] contains the elements Sbar and S representing the features to sample and condition on, respectively.

Author(s)

Lars Henry Berge Olsen

Examples

## Not run: 
m <- 5
causal_ordering <- list(1:2, 3:4, 5)
S <- shapr::feature_matrix_cpp(get_valid_causal_coalitions(causal_ordering = causal_ordering),
  m = m
)
confounding <- c(TRUE, TRUE, FALSE)
get_S_causal_steps(S, causal_ordering, confounding, as_string = TRUE)

# Look at the effect of changing the confounding assumptions
SS1 <- get_S_causal_steps(S, causal_ordering,
  confounding = c(FALSE, FALSE, FALSE),
  as_string = TRUE
)
SS2 <- get_S_causal_steps(S, causal_ordering, confounding = c(TRUE, FALSE, FALSE), as_string = TRUE)
SS3 <- get_S_causal_steps(S, causal_ordering, confounding = c(TRUE, TRUE, FALSE), as_string = TRUE)
SS4 <- get_S_causal_steps(S, causal_ordering, confounding = c(TRUE, TRUE, TRUE), as_string = TRUE)

all.equal(SS1, SS2)
SS1[[2]] # Condition on 1 as there is no confounding in the first component
SS2[[2]] # Do NOT condition on 1 as there is confounding in the first component
SS1[[3]]
SS2[[3]]

all.equal(SS1, SS3)
SS1[[2]] # Condition on 1 as there is no confounding in the first component
SS3[[2]] # Do NOT condition on 1 as there is confounding in the first component
SS1[[5]] # Condition on 3 as there is no confounding in the second component
SS3[[5]] # Do NOT condition on 3 as there is confounding in the second component
SS1[[6]]
SS3[[6]]

all.equal(SS2, SS3)
SS2[[5]]
SS3[[5]]
SS2[[6]]
SS3[[6]]

all.equal(SS3, SS4) # No difference as the last component is a singleton

## End(Not run)

NorskRegnesentral/shapr documentation built on Feb. 11, 2025, 6:41 a.m.