Science Score: 49.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.8%) to scientific vocabulary
Keywords
causal-inference
causal-models
causality-algorithms
counterfactual
counterfactuals
directed-acyclic-graph
identifiability
Last synced: 6 months ago
·
JSON representation
Repository
cfid: R package for identifying counterfactuals.
Basic Info
Statistics
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
- Releases: 0
Topics
causal-inference
causal-models
causality-algorithms
counterfactual
counterfactuals
directed-acyclic-graph
identifiability
Created over 4 years ago
· Last pushed over 1 year ago
Metadata Files
Readme
Changelog
License
Codemeta
README.Rmd
---
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
collapse = TRUE,
comment = "#>"
)
```
# cfid: An R Package for Identification of Counterfactual Queries in Causal Models
[](https://www.repostatus.org/#active)
[](https://github.com/santikka/cfid/actions)
[](https://app.codecov.io/gh/santikka/cfid?branch=main)
[](https://CRAN.R-project.org/package=cfid)
```{r, echo = FALSE, warning=FALSE}
library("cfid")
```
## Overview
This package facilitates the identification of counterfactual queries in structural causal
models via the ID* and IDC* algorithms by Shpitser, I. and Pearl, J. (2007, 2008)
https://arxiv.org/abs/1206.5294,
https://jmlr.org/papers/v9/shpitser08a.html. A simple interface is provided for
defining causal graphs and counterfactual conjunctions. Construction of parallel
worlds graphs and counterfactual graphs is done automatically based on the
counterfactual query and the causal graph.
For further information, see the tutorial paper on this package published in *The R Journal*: https://doi.org/10.32614/RJ-2023-053
## Installation
You can install the latest development version by using the devtools package:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("santikka/cfid")
```
## Graphs
Directed acyclic graphs (DAG) can be defined using the function `dag` in a syntax
similar to the [`dagitty`](https://cran.r-project.org/package=dagitty) package.
This function accepts
edges of the form `X -> Y`, `X <- Y`, and `X <-> Y`, where the last variant is
a shorthand for a latent confounder affecting both `X` and `Y` (a so-called
bidirected edge). Subgraphs can be defined using curly braces `{...}`. Edges
to and from subgraphs connect to all vertices present in the subgraph. Subgraphs
can also be nested. Some examples of valid constructs include:
```{r, eval = FALSE}
dag("X -> Y <- Z <-> W")
dag("{X Y Z} -> {A B}")
dag("X -> {Z <-> {Y W}}")
```
which define the following DAGs:
```mermaid
flowchart LR;
X((X))-->Y((Y));
Z((Z))-->Y;
W((W))<-.->Z;
```
```mermaid
flowchart LR;
X((X))-->A((A));
Y((Y))-->A;
Z((Z))-->A;
X-->B((B));
Y-->B;
Z-->B;
```
```mermaid
flowchart LR;
X((X))-->Z((Z));
X-->Y((Y));
X-->W((W));
Z<-.->Y;
Z<-.->W;
```
## Counterfactual variables and conjunctions
A counterfactual variable is defined by its name, value, and the submodel that
it originated from (a set of interventions). For example, $y_x$ is a counterfactual
variable named $Y$ with the value assignment $y$ that originated from a submodel
where the intervention $do(X = x)$ took place.
The function `counterfactual_variable`
and its shorthand alias `cf` can be used to construct counterfactual variables.
This function takes three arguments: `var`, `obs`, and `sub` that correspond
to the variable name, observed value assignment and subscript (the submodel).
For example, $y_x$ is defined as follows:
```{r}
cf(var = "Y", obs = 0, sub = c(X = 0))
```
by default, the value 0 is the "default" or baseline level, and integer values
different from 0 are denoted by primes. For example $y'_x$ is a similar counterfactual
variable to $y_x$, except that it was observed to take the value $y'$ instead of $y$
This can be accomplished by changing the `obs` argument:
```{r}
cf(var = "Y", obs = 1, sub = c(X = 0))
```
Purely observational counterfactual variables (of the original causal model)
can be defined by omitting the `sub` argument.
Conjunctions of multiple counterfactual variables can be constructed using the
function `counterfactual_conjunction` or its shorthand alias `conj`. This
function simply takes an arbitrary number of `"counterfacual_variable"` objects
as its argument. For example, the counterfactual conjunction
$y \wedge y'_x$ can be defined as follows:
```{r}
v1 <- cf("Y", 0)
v2 <- cf("Y", 1, c("X" = 0))
conj(v1, v2)
```
## Identification
Identifiability of (conditional) counterfactual conjunctions can be determined
via the function `identifiable`. This function takes the conjunction `gamma` to
be identified from the set of all interventional distributions $P_*$ of the causal
model represented by the `"dag"` object `g`. An optional conditioning conjunction
`delta` can also be provided. The solution is provided in LaTeX syntax if the
query is identifiable. For instance, we can consider the identifiability
of $P(y_x|x' \wedge z_d \wedge d)$ in the DAG shown below as follows:
```mermaid
flowchart TB;
X((X))-->W((W));
W-->Y((Y));
D((D))-->Z((Z));
Z-->Y;
X<-.->Y;
```
```{r}
g1 <- dag("X -> W -> Y <- Z <- D X <-> Y")
v1 <- cf("Y", 0, c(X = 0))
v2 <- cf("X", 1)
v3 <- cf("Z", 0, c(D = 0))
v4 <- cf("D", 0)
c1 <- conj(v1)
c2 <- conj(v2, v3, v4)
identifiable(g = g1, gamma = c1, delta = c2)
```
For more information and examples, please see the package documentation.
## Related packages
- The [`causaleffect`](https://cran.r-project.org/package=causaleffect)
package provides the ID and IDC algorithms for
the identification of causal effects (among other algorithms).
- The [`dosearch`](https://cran.r-project.org/package=dosearch)
package provides a heuristic search algorithm that uses
do-calculus to identify causal effects from an arbitrary combination of
input distributions.
- The [`dagitty`](https://cran.r-project.org/package=dagitty)
package provides various tools for causal modeling, such as finding
adjustment sets and instrumental variables.
- The [`R6causal`](https://cran.r-project.org/package=R6causal)
package implements an R6 class for structural causal models, and provides
tools to simulate counterfactual scenarios for discrete variables.
Owner
- Name: Santtu Tikka
- Login: santikka
- Kind: user
- Location: Finland
- Company: University of Jyväskylä
- Website: http://users.jyu.fi/~santikka/
- Repositories: 4
- Profile: https://github.com/santikka
Postdoctoral researcher at University of Jyväskylä, Department of Mathematics and Statistics.
CodeMeta (codemeta.json)
{
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"identifier": "cfid",
"description": "Facilitates the identification of counterfactual queries in structural causal models via the ID* and IDC* algorithms by Shpitser, I. and Pearl, J. (2007, 2008) <arXiv:1206.5294>, <https://jmlr.org/papers/v9/shpitser08a.html>. Provides a simple interface for defining causal diagrams and counterfactual conjunctions. Construction of parallel worlds graphs and counterfactual graphs is carried out automatically based on the counterfactual query and the causal diagram.",
"name": "cfid: Identification of Counterfactual Queries in Causal Models",
"codeRepository": "https://github.com/santikka/cfid",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.4",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.2.1 (2022-06-23 ucrt)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"author": [
{
"@type": "Person",
"givenName": "Santtu",
"familyName": "Tikka",
"email": "santtuth@gmail.com",
"@id": "https://orcid.org/0000-0003-4039-4342"
}
],
"maintainer": [
{
"@type": "Person",
"givenName": "Santtu",
"familyName": "Tikka",
"email": "santtuth@gmail.com",
"@id": "https://orcid.org/0000-0003-4039-4342"
}
],
"softwareSuggestions": [
{
"@type": "SoftwareApplication",
"identifier": "covr",
"name": "covr",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=covr"
},
{
"@type": "SoftwareApplication",
"identifier": "dagitty",
"name": "dagitty",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=dagitty"
},
{
"@type": "SoftwareApplication",
"identifier": "igraph",
"name": "igraph",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=igraph"
},
{
"@type": "SoftwareApplication",
"identifier": "mockery",
"name": "mockery",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=mockery"
},
{
"@type": "SoftwareApplication",
"identifier": "testthat",
"name": "testthat",
"version": ">= 3.0.0",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=testthat"
}
],
"softwareRequirements": {
"SystemRequirements": null
},
"fileSize": "149.405KB",
"releaseNotes": "https://github.com/santikka/cfid/blob/master/NEWS.md",
"readme": "https://github.com/santikka/cfid/blob/main/README.md",
"contIntegration": [
"https://codecov.io/gh/santikka/cfid",
"https://github.com/santikka/cfid/actions"
],
"keywords": [
"counterfactual",
"counterfactuals",
"identifiability",
"causal-models",
"causal-inference",
"causality-algorithms",
"directed-acyclic-graph"
]
}
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 48
- Total Committers: 3
- Avg Commits per committer: 16.0
- Development Distribution Score (DDS): 0.083
Top Committers
| Name | Commits | |
|---|---|---|
| Santtu Tikka | s****a@j****i | 44 |
| Santtu Tikka | s****a@p****m | 3 |
| Santtu Tikka | s****h@g****m | 1 |
Committer Domains (Top 20 + Academic)
jyu.fi: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 289 last-month
- Total dependent packages: 1
- Total dependent repositories: 0
- Total versions: 4
- Total maintainers: 1
cran.r-project.org: cfid
Identification of Counterfactual Queries in Causal Models
- Homepage: https://github.com/santikka/cfid
- Documentation: http://cran.r-project.org/web/packages/cfid/cfid.pdf
- License: GPL (≥ 3)
-
Latest release: 0.1.7
published about 2 years ago
Rankings
Stargazers count: 21.1%
Forks count: 21.9%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Average: 35.5%
Downloads: 69.4%
Maintainers (1)
Last synced:
6 months ago
Dependencies
DESCRIPTION
cran
- R >= 4.1 depends
- covr * suggests
- dagitty * suggests
- igraph * suggests
- mockery * suggests
- testthat >= 3.0.0 suggests
.github/workflows/check-standard.yaml
actions
- actions/checkout v2 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml
actions
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite