Skip to content

Instantly share code, notes, and snippets.

View baogorek's full-sized avatar

Ben Ogorek baogorek

  • spencer Health Solutions, Inc.
  • Raleigh, NC
  • X @benogorek
View GitHub Profile
@baogorek
baogorek / bayesian-sequential-with-brms.R
Last active February 12, 2022 13:49
Simulation demonstrating the Frequentist Properties of Bayesian Sequential Analysis
library(dplyr)
library(tidyr)
library(ggplot2)
library(brms)
library(qcc)
#set.seed(1569) # First 100
set.seed(8536) # Next 1000
# B <- 100 # First time through
@baogorek
baogorek / regression-coding.R
Created February 10, 2022 16:09
Showing deviation coding for R's lm
library(dplyr)
library(tidyr)
sim_df <- bind_rows(
tibble(group='A', y=rnorm(100, mean=33)),
tibble(group='B', y=rnorm(10000, mean=30)),
tibble(group='C', y=rnorm(100, mean=33.1))
)
@baogorek
baogorek / do-calculus.R
Last active October 26, 2021 20:43
Companion code to Medium article
library(dplyr)
# Structural Equations ---------------------------------------------------
get_subject_affinity <- function(N) {
# u ~ Uniform(1, 20)
runif(N, min=1, max=20)
}
get_time_resources <- function(N) {
# w ~ Gamma(3, 1)
@baogorek
baogorek / eeio.R
Created September 11, 2021 22:28
Environmentally Extended Input Output example with eeior and matrix math
# See Wiki @ https://github.com/USEPA/useeior/Wiki for install instructions
library(useeior)
seeAvailableModels()
# explanation of model names can be found at
# https://github.com/USEPA/USEEIO/blob/master/VersioningScheme.md
# LCI: direct perspective life cycle inventory result
# LCIA: life cycle impact assessment
# Build USEEIO v2.0-GHG
@baogorek
baogorek / ananke.py
Created July 15, 2021 23:33
ananke exploration
# pip install ananke-causal
from ananke import graphs
from ananke import identification
from ananke.estimation import CausalEffect
import numpy as np
import pandas as pd
# Simulate front-door situation with confounder Z
N = 100000
import pandas as pd
import numpy as np
import patsy
import tensorflow as tf
class SleepReg(tf.Module):
def __init__(self, sleepdata_path):
"""Initializing tensorflow variables and other necessary matrices"""
# These two TensorFlow variables show up in the trainable_variables
@baogorek
baogorek / non-invertible-ma-process.R
Created June 25, 2019 20:51
non-invertible-ma-process.R
N <- 10000
theta <- 1.4
e <- rnorm(N)
e_lag <- c(NA, e[1:(N-1)])
y <- e - theta * e_lag
acf(y[2:N])
@baogorek
baogorek / kalman-derivations.ipynb
Last active February 3, 2023 04:29
Gist version of Miscellaneous/methods/kalman-filter/kalman-derivations.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(dplyr)
library(ggplot2)
library(splines)
days_grid <- 0:180
interior_knots <- c(2, 6, 25)
#interior_knots <- c(6, 25, 80)
my_spline <- ns(days_grid, knots = interior_knots)
library(dplyr)
library(gridExtra)
library(ggplot2)
exp_decay <- function(t, tau) {
exp(-t / tau)
}
convolve_training<- function(training, n, tau) {
sum(training[1:(n - 1)] * exp_decay((n - 1):1, tau))