Skip to content

Instantly share code, notes, and snippets.

@mingjiphd
mingjiphd / R Script
Created January 29, 2026 01:43
Machine Learning using R Dimensionality Reduction using SOM
########################################################################
# Machine Learning using R Dimensionality Reduction by SOM #
########################################################################
###### A Brief Overview of SOM (Self Organizing Maps)
### Self-organizing maps (SOMs) are unsupervised neural networks that
## project high-dimensional data onto a low-dimensional (usually
## 2D) grid while preserving neighborhood structure.
@mingjiphd
mingjiphd / R Script
Created January 28, 2026 02:26
Machine Learning using R How to Implement Multidimentional Scaling
#############################################################################################
# Machine Learning using R How to Implement Multidimsional Scaling #
#############################################################################################
#### Multidimensional Scaling (MDS)
## visualizes similarities/dissimilarities between objects
## by placing them in low-dimensional space (usually 2D/3D)
## where distances reflect original relationships
@mingjiphd
mingjiphd / R Script
Created January 28, 2026 02:23
Machine Learning using R How to use the superSOM function for Dimensionality Reduction
###########################################################################
# Machine Learning using R How to use the superSOM function #
############################################################################
### In the R package kohonen, there is another function superSOM
### Features of superSOM
### Unified Multi-Layer Architecture:
# Trains a single 2D grid where each node holds representative profiles
# (codebooks) for multiple data layers, such as features and labels.
@mingjiphd
mingjiphd / R Script
Created January 28, 2026 02:18
Machine Learning using R Dimensionality Reduction using UMAP
#################################################################################
# Machine Learning using R Dimensionality Reduction by using UMAP #
#################################################################################
############## Brief Overview of UMAP (Uniform Manifold Approximation and Projection
### UMAP excels as a dimensionality reduction technique by preserving
## both local neighborhood structure and global data topology simultaneously.
@mingjiphd
mingjiphd / R Script
Created January 28, 2026 02:15
Machine Learning using R Regression and Classification using Shallow Neural Networks
###########################################################################################
# Machine Learning using R Regression and Classification using Shallow Neural Networks #
###########################################################################################
# Load necessary libraries
library(nnet) # For shallow neural networks
library(neuralnet) # For visualizing and custom training
library(caret) # For data splitting and evaluation
install.packages("NeuralNetTools")
@mingjiphd
mingjiphd / R Script
Created January 27, 2026 18:59
Causal Analysis using R G Estimation by using the CausalModels Package
#### Causal Analysis using R G Estimation by the R package CausalModels
# Install and load CausalModels package if not installed
if (!requireNamespace("CausalModels", quietly = TRUE)) {
install.packages("CausalModels")
}
library(CausalModels)
library(causaldata)
data(nhefs)
@mingjiphd
mingjiphd / R Script
Created January 27, 2026 18:57
Causal Analysis using R G Estimation by using GEE Models
#### Causal Analysis using R G Estimation using GEE
## James Robins' G estimation is one of the g methods, a class of causal inference techniques
## including the g formula and marginal structural models, designed for complex longitudinal
## studies with time-varying confounders.​
#### It specifically focuses on structural nested models and uses the conditional independence
## between treatment and potential outcomes to consistently estimate causal effects
## under weaker assumptions than standard regression.​
@mingjiphd
mingjiphd / Readme.txt
Created January 27, 2026 18:54
Causal Analysis using R How to Implement the DO Calculus by Judea Pearl
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). Furthermore, we showed how to perform causal mediational analysis and how to interpret its outputs.
A step by step video demonstration can be found at: https://youtu.be/yNzpoWRgZdE?si=MJIpRcp74uqfqhjc
@mingjiphd
mingjiphd / R Script
Last active January 28, 2026 17:53
Causal Analysis using R Path Analysis
### How to Perform a Path Analysis using R
# Path analysis is an extension of regression that models both direct and indirect relationships
# among a set of observed variables within a system of structured equations.
# It allows variables to act as both predictors and outcomes, thus examining complex causal chains,
# not just single dependencies.
# The method breaks down effects into direct effects (immediate influence) and indirect effects
# (mediated through other variables), clarifying how causal influence travels through the network.
# Path analysis is commonly visualized using a path diagram, where arrows represent hypothesized
# causal connections, and it serves as a subset of structural equation modeling with only observed
@mingjiphd
mingjiphd / R Script
Last active January 27, 2026 18:32
Causal Analysis using R How to Perform Propensity Score Matching Analysis
## How to Perform a Propensity Score Matching Analysis using R
#The propensity score is the probability that an individual receives a treatment given
# their #observed characteristics.
#It is used in observational studies to create a balance between treated and untreated
# groups, aiming to mimic the conditions of a randomized controlled trial.
#By matching or comparing individuals with similar propensity scores, researchers can
# reduce bias due to confounding factors.
#Propensity scores are commonly estimated using logistic regression models based on #baseline covariates.
# Methods using propensity scores include matching, stratification, weighting, and