Skip to content

Instantly share code, notes, and snippets.

View alexpghayes's full-sized avatar

alex hayes alexpghayes

View GitHub Profile
``` r
library(withr) # for local random seeds
library(tidymodels)
library(palmerpenguins)
splitting_seed <- 9023
training_seed <- 2342
penguins_complete <- na.omit(penguins)
library(tidyverse)
library(invertiforms) # RoheLab/invertiforms
library(igraphdata)
library(igraph)
library(RSpectra)
library(scales)
data("enron", package = "igraphdata")
A <- enron %>%
#' @references http://arxiv.org/abs/2101.10880
usp1 <- function(I, J, epsilon = 0) {
P <- matrix(0, nrow = I, ncol = J)
for (i in 1:I) {
for (j in 1:J) {
P[i, j] <- 2^(-(i + j)) / ((1 - 2^(-I)) * (1 - 2^(-J)))
}
# a Pandas dataframe with columns:
#
# - doi<string>
# - search_term<string>
# - year<int>
# - authors<list<string>>
# - cites<list<string>>: DOIs of papers cited by this paper
#
# where doi and search_term together form a primary key and cites is a list
# that contains a foreign key to some table of metadata for all papers
library(Matrix)
library(tidyverse)
# need these two packages that are not on CRAN
# if something goes wrong, let me know, i wrote them and will fix
# to install:
#
# > install.packages("pak")
# > pak::pkg_install("RoheLab/fastRG")
library(nnet)
library(pdp)
library(tidyverse)
library(broom)
augment.multinom <- function(object, newdata) {
newdata <- as_tibble(newdata)
class_probs <- predict(object, newdata, type = "prob")
``` r
set.seed(27)
n <- 100
k <- 5
A <- matrix(rnorm(n * n), nrow = n, ncol = n)
s <- svd(A, k, k)
# generate two n x k orthonormal bases
``` r
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
# As an example, let's say I have a dataframe of birthdays:
library(tidyverse)
library(here)
library(skimr)
library(lubridate)
library(rsample)
library(furrr)
library(arrow)
plan(sequential)
plan(multisession, workers = parallel::detectCores() - 1)
library(tidyverse)
regress <- function(x_bar, y_bar, s_x, s_y, rho, n, alpha = 0.05) {
beta_hat <- rho * s_y / s_x
alpha_hat <- y_bar - beta_hat * x_bar
ssr <- (1 - rho^2) * s_y^2 * (n - 1)
sigma_sq_hat <- ssr / (n - 2)