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
#!/Users/alal/miniforge3/envs/llm/bin/python | |
# this needs to point to a python virtualenv with ollama-python | |
# your system should also have ollama installed | |
# if you have an nvidia gpu, install lshw first before installing ollama | |
import argparse | |
import ollama | |
def main(msg, mod='gemma3:27b', outfile=None): | |
response = ollama.chat(model=mod, messages=[ |
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
#!/bin/bash | |
# Directory to search | |
DIRECTORY=$1 | |
# Additional extensions to search, if provided | |
EXTENSIONS="tex" | |
if [ ! -z "$2" ]; then | |
EXTENSIONS="$EXTENSIONS|$2" |
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
# %% | |
import functools | |
from typing import Callable, TypeVar, Any | |
import pandas as pd | |
import numpy as np | |
T = TypeVar("T") | |
# %% |
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
library(momentfit); library(car); library(tictoc) | |
set.seed(42) | |
# %% | |
dgp = \(n=500, k = 2){ | |
X = matrix(rnorm(n * 2), n, 2) | |
Y1 = X[, 1] + X[, 1]^2 + runif(n, -0.5, 0.5) | |
Y0 = X[, 2] + X[, 2]^2 + runif(n, -1, 1) | |
Z = rbinom(n, 1, 0.6) | |
Y = Z * Y1 + (1-Z) * Y0 | |
data.frame(Y, Z, X) |
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
from joblib import Parallel, delayed | |
import numpy as np | |
import pandas as pd | |
class LinearMediation: | |
def __init__(self): | |
pass | |
def fit(self, X, W, y, store=True): |
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
\documentclass[% | |
article, | |
% beamer, | |
beameroptions={ignorenonframetext,14pt}, | |
articleoptions={a4paper,12pt}, | |
also={trans,handout,article} | |
]{beamerswitch} | |
\handoutlayout{nup=3plus,border=1pt} | |
\articlelayout{maketitle,frametitles=none} | |
\mode<article>{\usepackage[hmargin=2cm,vmargin=2cm]{geometry}} |
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
import numpy as np | |
import pandas as pd | |
from scipy.stats import norm | |
from sklearn.model_selection import cross_val_predict, KFold | |
# learners | |
from xgboost import XGBRegressor | |
from glum import GeneralizedLinearRegressorCV | |
from sklearn.kernel_ridge import KernelRidge |
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
library(estimatr) | |
data(auto) | |
# %% FWL regression coefficient | |
auto$ytil = lm(price ~ displacement, auto)$resid | |
auto$x2til = lm(weight ~ displacement, auto)$resid | |
(fwlest = lm_robust(ytil ~ x2til, auto, se_type = "HC0") | |
%>% summary %>% .$coefficients %>% .[2, 1:2]) | |
# %% | |
(fullest = | |
lm_robust(price ~ weight + displacement, auto, se_type = "HC0") %>% |
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
import numpy as np | |
from scipy.linalg import lstsq | |
np.random.seed(42) | |
# %% | |
def ols(X, y, vcov = 'HC1', driver = 'gelsy'): | |
""" | |
Fast, minimal implementation of least squares regression with robust SEs | |
Args: | |
X: n X p array of covariates |
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
# %% | |
pacman::p_load(knitr, tidyverse, DeclareDesign, glmnet) | |
set.seed(42) | |
# %% estimator functions | |
p_hacker = function(data) { | |
fit_1 = lm_robust(Y ~ Z + X1, data = data) | |
fit_3 = lm_robust(Y ~ Z + X1 + X2, data = data) | |
fit_2 = lm_robust(Y ~ Z + X2 + X3 + X4, data = data) | |
fit_4 = lm_robust(Y ~ Z + X3 + X4 + X5 + X6 + X7 + X8 + X9, data = data) |
NewerOlder