Learn R Programming

Overview

netchain is a R package for causal inference on collective outcomes under social network. Our paper proposed and justified a parsimonious parametrization for social network data generated from causal directed acyclic graph (DAG), approximating a particular family of graphical models known as chain graphs under some conditions.

We provide a function simGibbs() to generate binary outcomes, treatments, and confounders from chain graph model. A function chain.causal.multi() is to infer parameters in the conditional log-linear models that feature hybrid graphical models of undirected graphs and directed acyclic graphs (DAG). This function generates counterfactual outcomes using Gibbs sampling given treatment assignment and the estimated parameters to derive the probability associated with collective outcomes. We also provide a function of causal.influence() to identify the most (causally) influential subjects in social network based on the their causal effect on the collective outcomes.

Package information

Installation

You can download the package by:

install.packages("netchain")

# or you can directly download the development version from author's Github
install.packages("devtools")
library(devtools)
install_github("youjin1207/netchain")

Usage

Here is a R vignettes for guidance. Or you can access to vignettes via:

install_github("youjin1207/netchain", build_vignettes = TRUE)
vignette("chainapprox", package = "netchain")

Example

library(netchain)
# set direct effect and two-way interaction effect on undirected graphs (weight.matrix)
weight.matrix = matrix(c(0.5, 1, 0, 1, 0.3, 0.5, 0, 0.5, -0.5), 3, 3)
simobs = simGibbs(n.unit = 3, n.gibbs = 10, n.sample = 10, 
                   weight.matrix,
                   treat.matrix = 0.5*diag(3), cov.matrix= (-0.3)*diag(3) )
inputY = simobs$inputY
inputA = simobs$inputA
inputC = simobs$inputC

# define relational matrix (R.matrix)
R.matrix = ifelse(weight.matrix==0, 0, 1)      
diag(R.matrix) = 0

# infer conditional log-linear model following chain graph models.
result = chain.causal.multi(targetoutcome = "mean", treatment = c(1,0,0), inputY, inputA, listC = inputC, R.matrix = R.matrix, E.matrix = diag(3), edgeinfo = list(rbind(c("Y", 1), c("C", 1)), rbind(c("Y", 2), c("C", 2)), rbind(c("Y", 3), c("C", 3))), n.obs = 1000, n.burn = 100)
print(result)

# measure influence for each node by evaluating average of collective outcomes under each treatment.
influence = causal.influence(targetoutcome = "mean", Avalues = c(1,0), 
                            inputY, inputA, listC = inputC, R.matrix, E.matrix = diag(3), 
                            edgeinfo = list(rbind(c("Y", 1), c("C", 1)), rbind(c("Y", 2), c("C", 2)), rbind(c("Y", 3), c("C", 3))), n.obs = 100, n.burn = 10)
print(influence)

Reference

Ogburn, E. L., Shpitser, I., & Lee, Y. (2018). Causal inference, social networks, and chain graphs. arXiv preprint arXiv:1812.04990.

Copy Link

Version

Install

install.packages('netchain')

Monthly Downloads

31

Version

0.2.0

License

GPL (>= 3) | file LICENSE

Maintainer

Youjin Lee

Last Published

February 16th, 2020

Functions in netchain (0.2.0)

netchain-package

netchain: causal inference on collective outcomes
multiloglikechain

Derive log-likelihood of conditional log-linear model given parameters.
chain.causal.multi

Causal estimation on collective outcomes under multiple confounders and interference.
causal.influence

Identifying causally influential units on social network
multimainfunction

Extracting factors for conditional log-linear model
chaingibbs

Generate Gibbs samplers for counterfactual collective outcomes.
multipartition

Calculating normalizing constant in conditional log-linear model.
simGibbs

Generate binary (Y, A, C) from chain graph model under simplest scenario.