Skip to content

Instantly share code, notes, and snippets.

View alexpghayes's full-sized avatar

alex hayes alexpghayes

View GitHub Profile
library(tidyverse)
library(tidygraph)
library(netmediate)
data <- read.csv("final_regime.IGO.sanction.csv") |>
# remove some columns of missing data to avoid downstream issues & unnnecessary columns
select(-1, -AMCOW, -MOPAN, - year, -version)
node_data <- data |>
select(country, ccode, polity2, democracy, sanction) |>
library(tidyverse)
library(tidygraph)
library(netmediate)
data <- read_csv("final_regime.IGO.sanction.csv") |>
# remove some columns of missing data to avoid downstream issues
select(-1, -AMCOW, -MOPAN)
node_data <- data |>
select(country, ccode, polity2, democracy, sanction)
``` r
library(tidyverse)
library(glue)
library(unglue)
#> Warning: package 'unglue' was built under R version 4.2.3
"~/../Desktop/patty-restaurants.txt" |>
readLines() |>
unglue_data("- [{visited}] {name}") |>
arrange(visited, name) |>
# rotate Y to align it to X
mypro <- function(X, Y) {
XY <- crossprod(X, Y)
s <- svd(XY)
rotation <- s$v %*% t(s$u)
Yrot <- Y %*% rotation
diff <- X - Yrot
colwise_loss <- Matrix::colSums(diff^2)
two_infty_loss <- max(sqrt(Matrix::rowSums(diff^2)))
library(tidyverse)
library(qgam)
library(gratia)
library(furrr)
library(mgcv)
plan(multisession, workers = 5)
hap <- read_csv("https://osf.io/download/kpnjf/")
x <- c(
-0.54660789, 2.43686553, 1.24397260, -0.73957557, 2.33131378,
-0.97341652, -0.48911950, 0.35658630, -0.77824579, 1.55796356,
0.10641176, 0.89764371, 0.64903636, 1.89822592, -0.35568742,
1.52124163, 0.01328800, 1.33453143, -1.08829020, 0.83033763,
0.68018922, 1.93419047, 1.14073253, 2.56650893, 1.90859128,
1.39105347, 1.37547130, -0.07223141, 0.43142589, 1.78035482,
1.90837367, 1.84173396, -0.09760825, 1.66610817, 0.03379679,
0.97277154, 0.78599263, 0.75538460, 1.23006396, 0.83001685
)
library(tidyverse)
data <- read_csv("data.csv")
X <- as.matrix(data) # i presume this is the starting state of the data
plot_at_threshold <- function(mat, threshold) {
colnames(mat) <- 1:NCOL(mat)
rownames(mat) <- 1:NROW(mat)
library(sandwich)

n <- 10
d <- 3

p <- 4

X <- matrix(
  rnorm(n * d),
library(fastRG)
library(estimatr)
library(tidyverse)
set.seed(27)
get_one_estimate <- function() {
k <- 5
n <- 1000
B <- matrix(stats::runif(k * k), nrow = k, ncol = k)
``` r
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union