Skip to content

Instantly share code, notes, and snippets.

View alexpghayes's full-sized avatar

alex hayes alexpghayes

View GitHub Profile
funchir::stale_package_check('mycode.R')
library(ggdag)
#> 
#> Attaching package: 'ggdag'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(tidyverse)
library(tidygraph)
#> 
library(fastadi)
library(here)
library(igraph)
library(Matrix)
library(rcrossref)
library(tidygraph)
library(tidyverse)
library(vsp)
# pull Ji and Jin 2016 data. see:

Aldrich, John. “R A Fisher on Bayes and Bayes’ Theorem.” Bayesian Analysis 3, no. 1 (March 2008): 161–70. https://doi.org/10.1214/08-BA306.

Bera, Anil K., and Yannis Bilias. “The MM, ME, ML, EL, EF and GMM Approaches to Estimation: A Synthesis.” Journal of Econometrics 107, no. 1–2 (March 2002): 51–86. https://doi.org/10.1016/S0304-4076(01)00113-0.

———. “Three Scores and 15 Years (1948-2023) of Rao’s Score Test: A Brief History.” arXiv, June 28, 2024. http://arxiv.org/abs/2406.19956.

Camic, Charles, and Yu Xie. “The Statistical Turn in American Social Science: Columbia University, 1890 to 1915.” American Sociological Review 59, no. 5 (October 1994): 773. https://doi.org/10.2307/2096447.

Cowles, Michael, and Caroline Davis. “On the Origins of the .05 Level of Statistical Significance.” American Psychologist 37, no. 5 (May 1982): 553–58.

library(tidyverse)
library(osfr)

meta <- osf_retrieve_file("5a9hb") |>
  osf_download(conflicts = "overwrite")

data <- meta$local_path |> 
  read_csv() |> 
  select(SAI_winsorized_IQ, Raven_IQ, SAIQ_IQ_dif) |> 
@alexpghayes
alexpghayes / one-two-ls-durbin-fits.md
Created February 28, 2024 19:02
One and two-stage least squares fits for spatial Durbin models
# pak::pak("gpiras/sphet")

library(fastRG)
#> Loading required package: Matrix
library(sphet)

# simulate from y = alpha + trt * gamma + G trt * delta + lambda G y

set.seed(26)
library(tidyverse)
library(mgcv)
#> Loading required package: nlme
#> 
#> Attaching package: 'nlme'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse
#> This is mgcv 1.8-41. For overview type 'help("mgcv-package")'.
library(tidyverse)

p_at_least_one_event <- function(p_event, periods = 50) {
  tibble(
    time = 1:periods,
    p_at_least_one_event = 1 - (1 - p_event)^(1:periods)
  )
}
library(ggplot2)
data(mcycle, package = "MASS")
f_approxfun <- approxfun(mcycle$times, mcycle$accel)
f_splinefun <- splinefun(mcycle$times, mcycle$accel)
mcycle |>
ggplot(aes(times, accel)) +
geom_point() +
``` r
# pak::pkg_install("stillmatic/MNIST")
library(MNIST)
# 1 is the most common digit in train
table(MNIST::mnist_train$y) / nrow(MNIST::mnist_train)
#>
#> 0 1 2 3 4 5 6
#> 0.09871667 0.11236667 0.09930000 0.10218333 0.09736667 0.09035000 0.09863333
#> 7 8 9