This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### How to perform a Weighted Propensity Score Analysis | |
| library(WeightIt) | |
| library(cobalt) | |
| # Use the lalonde dataset from cobalt package | |
| data("lalonde", package = "cobalt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### How to Implement Directed Acyclic Graphs for Causal Inference in R: The Simple Case | |
| ##A Directed Acyclic Graph (DAG) is a finite graph composed of nodes connected | |
| ## by directed edges with no cycles, meaning it's impossible to start at any node | |
| ## and follow a sequence of edge directions that returns to the same node. | |
| ##in DAGs, nodes to be arranged in a linear order that respects the direction of | |
| ## edges and represents dependencies or causal relationships. | |
| ##Directed Acyclic Graphs (DAGs) are used in causal inference to visually represent | |
| ## assumptions about causal relationships, identify confounders, guide variable | |
| ## selection for adjustment, and clarify the pathways affecting causal effect estimation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Causal Analysis using R: Sophisticated DAGs | |
| ###Generate Data | |
| # Install if needed | |
| #if (!requireNamespace("simDAG", quietly = TRUE)) { | |
| # install.packages("simDAG") | |
| #} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Causal Analysis using R The Difference in Difference Method | |
| ##DiD estimates causal effects by comparing changes over time between treatment and control groups. | |
| ##It uses before-and-after differences in outcomes to isolate the treatment effect. | |
| ##The critical assumption is parallel trends, meaning both groups would follow similar outcome paths | |
| #if untreated. | |
| ##Suitable for observational data where randomization is not possible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Causal Analysis using R A Simple Case Bayesian Network Analysis | |
| ##Bayesian Networks are directed acyclic graphs representing variables and their dependencies. | |
| ##Nodes represent variables; edges show conditional dependencies between them. | |
| A | |
| ##Each node has a probability function based on its parent nodes. | |
| ## They use Bayes' theorem to update probabilities with new evidence. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Causal Analysis using R: A More Sophiscated Example of Bayesian Networks | |
| ##In this video, we present an example of using the R package bnlearn | |
| ##for Bayesian Network Analysis | |
| ## The Following topics are covered: | |
| #Generates a mixed-type synthetic data set | |
| #Applies multiple structure learning algorithms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Causal Analysis using R Instrumental Variables | |
| ## Instrumental variables (IVs) are special variables used in statistics and econometrics | |
| ## to estimate causal effects when ordinary regression methods would be biased due to | |
| ## endogeneity—meaning the explanatory variable is correlated with unobserved factors or the error term. | |
| ## Two Key Criterias of IVs | |
| ## It is correlated with the problematic (endogenous) explanatory variable. | |
| ## It is not correlated with the error term and only affects the outcome through | |
| ## the explanatory variable (called the exclusion restriction). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### Causal Analysis using R The Weak Instrument Test | |
| # Load necessary packages | |
| library(AER) # for ivreg | |
| library(car) # for linearHypothesis (optional) | |
| set.seed(11152025) | |
| # Generate synthetic data | |
| n <- 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This R script is a step by step tutorial on how to implement the DO Calculus developed by Judea Pearl. The R packages used include: causaleffect, mediation, igraph and dplyr. We demonstrate how to create a simulated data set, how to define a DAG, how to estimate the expression identified by the DO Calculus and how to use that expression to calculate average causal effect (ACE). | |
| A link to a video demonstration on YouTube is: https://youtu.be/yNzpoWRgZdE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This scirpt shows how to perform dimensionality reduction using Shallow Autoencoder in R. The R packages neuralnet and mlbench are used to show how ot fit an autoencoder (which is a simple neural network) for a synthetic data set. Subsequent analyses such as visualizing the latent space, computing the reconstruction errors, anamoly detection, clustering in latent space and comparing autoencoder to PCA. |