  In the framework of structural causal models, counterfactual queries describe
events that concern multiple alternative states of the system under study.
Counterfactual queries often take the form of "what if" type questions such as
"would an applicant have been hired if they had over 10 years of experience,
when in reality they only had 5 years of experience?" Such questions and
counterfactual inference in general are crucial, for example when addressing
the problem of fairness in decision-making. Because counterfactual events
contain contradictory states of the world, it is impossible to conduct a
randomized experiment to address them without making several restrictive
assumptions. However, it is sometimes possible to identify such queries from
observational and experimental data by representing the system under study as a
causal model, and the available data as symbolic probability distributions.
Shpitser and Pearl (2007) constructed two algorithms, called ID* and IDC*, for
identifying counterfactual queries and conditional counterfactual queries,
respectively. These two algorithms are analogous to the ID and IDC algorithms
by Shpitser and Pearl (2006) for identification of interventional
distributions, which were implemented in R by Tikka and Karvanen (2017) in the
causaleffect package. We present the R package cfid that implements the ID* and
IDC* algorithms. Identification of counterfactual queries and the features of
cfid are demonstrated via examples.
