Skip to content

carloscinelli/generalizing

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
R
 
 
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

generalizing: Generalizing Experimental Results By Leveraging Knowledge of Mechanisms

AppVeyor build status Travis build status

generalizing implements methods for generalizing experimental results leveraging the invariance of probabilities of causation, as discussed in Cinelli, C. and Pearl, J. (2020+) “Generalizing Experimental Results By Leveraging Knowledge of Mechanisms.” European Journal of Epidemiology (accepted).

Development version

To install the development version on GitHub make sure you have the package devtools installed.

# install.packages("devtools") 
devtools::install_github("carloscinelli/generalizing")

CRAN

The CRAN version should be available soon.

Basic Usage

# loads package
library(generalizing)

# loads data
data("Aceh")
data("West.Java")
data("Sarlahi")

#### ACEH to WEST JAVA 

# flat prior
Aceh_to_WJ   <- generalize(sources = Aceh, target = West.Java, n.iter = 1e5)

# monotonic prior
Aceh_to_WJ_m <- generalize(sources = Aceh, target = West.Java, 
                           monotonic = TRUE, n.iter = 1e5) 


# posterior samples histograms
par(mfrow = c(1,2))
mark <- West.Java$n1/West.Java$N1

## hist of P(Y1 = 1) for West Java -- flat prior
hist(Aceh_to_WJ, main = "Flat prior")
abline(v = mark, col = "red", lty = 2, lwd = 2)

## hist of P(Y1 = 1) for West Java -- monotonic prior
hist(Aceh_to_WJ_m, main = "Monotonic prior")
abline(v = mark, col = "red", lty = 2, lwd = 2)

#### ACEH + WEST JAVA to SARLAHI
AcehWJ_to_Sarlahi   <- generalize(sources = list(Aceh, West.Java), 
                                  target = Sarlahi, 
                                  n.iter = 1e5)
# posterior samples histograms
par(mfrow = c(1, 3))
mark <- Sarlahi$n1/Sarlahi$N1

## hist prob of sufficient for saving
hist(AcehWJ_to_Sarlahi, var = "PS01")

## hist prob of sufficient for harming
hist(AcehWJ_to_Sarlahi, var = "PS10")

## hist of P(Y1 = 1) for Sarlahi
hist(AcehWJ_to_Sarlahi, var = "P11s")
abline(v = mark, col = "red", lty = 2, lwd = 2)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages