in dowhy/causal_refuter.py [0:0]
def choose_variables(self, required_variables):
'''
This method provides a way to choose the confounders whose values we wish to
modify for finding its effect on the ability of the treatment to affect the outcome.
'''
invert = None
if required_variables is False:
self.logger.info("All variables required: Running bootstrap adding noise to confounders, instrumental variables and effect modifiers.")
return None
elif required_variables is True:
self.logger.info("All variables required: Running bootstrap adding noise to confounders, instrumental variables and effect modifiers.")
return self._variables_of_interest
elif type(required_variables) is int:
if len(self._variables_of_interest) < required_variables:
self.logger.error("Too many variables passed.\n The number of variables is: {}.\n The number of variables passed: {}".format(
len(self._variables_of_interest),
required_variables )
)
raise ValueError("The number of variables in the required_variables is greater than the number of confounders, instrumental variables and effect modifiers")
else:
# Shuffle the confounders
random.shuffle(self._variables_of_interest)
return self._variables_of_interest[:required_variables]
elif type(required_variables) is list:
# Check if all are select or deselect variables
if all(variable[0] == '-' for variable in required_variables):
invert = True
required_variables = [variable[1:] for variable in required_variables]
elif all(variable[0] != '-' for variable in required_variables):
invert = False
else:
self.logger.error("{} has both select and delect variables".format(required_variables))
raise ValueError("It appears that there are some select and deselect variables. Note you can either select or delect variables at a time, but not both")
# Check if all the required_variables belong to confounders, instrumental variables or effect
if set(required_variables) - set(self._variables_of_interest) != set([]):
self.logger.error("{} are not confounder, instrumental variable or effect modifier".format( list( set(required_variables) - set(self._variables_of_interest) ) ))
raise ValueError("At least one of required_variables is not a valid variable name, or it is not a confounder, instrumental variable or effect modifier")
if invert is False:
return required_variables
elif invert is True:
return list( set(self._variables_of_interest) - set(required_variables) )
else:
self.logger.error("Incorrect type: {}. Expected an int,list or bool".format( type(required_variables) ) )
raise TypeError("Expected int, list or bool. Got an unexpected datatype")