Skip to content

Instantly share code, notes, and snippets.

Avatar

alex hayes alexpghayes

View GitHub Profile
View varimax-log-log-scaling.R
library(scales)
y_long <- fa %>%
get_varimax_y() %>%
pivot_longer(
names_to = "factor",
cols = contains("y"),
values_to = "loading"
)
View starmans-predictivity.R
library(readxl)
library(tidyverse)
library(caret)
library(brglm2)
df <- read_xlsx("~/../Desktop/190610-Data-All Studies.xlsx") %>%
filter(StudyNumber == 1) %>%
dplyr::mutate(
IsPhilosopher = map_lgl(Field, ~.x == "Philosophy")
) %>%
View big-fuckin-yikes.R
library(glmnet)
library(tidyverse)
# want to fit a model with formula: as.factor(am) ~ mpg + wt * as.factor(gear)
# data prep
nice_data <- mtcars %>%
mutate_at(vars(am, gear), as.factor)
# be careful about intercepts, see the intercept argument to glmnet
View jupyter-notebooks-as-blogdown-posts.R
library(reticulate)
library(here)
library(glue)
library(fs)
library(stringr)
#' Turn a Jupyter notebook into a blogdown post
#'
#' This function makes several key assumptions:
#'
View #maga vs #resist space
Basis vector 1
- # (0.691)
- resist (0.408)
- no. (0.32)
- № (0.314)
- resists (0.292)
- 027 (0.284)
- 4026 (0.275)
- 102 (0.273)
View frequency-space-basis.md

Basis vector 1

  • 4 (0.496)
  • 3 (0.493)
  • 5 (0.491)
  • 6 (0.488)
  • 10 (0.484)
  • 1 (0.48)
  • 2 (0.479)
  • 12 (0.475)
View scotus-basis.md

Basis vector 1

  • the (0.352)
  • your (0.314)

Basis vector 2

  • appellate (0.555)
  • habeas (0.515)
  • remand (0.494)
View elon-tweets-code.R
library(riingo)
library(tidyverse)
riingo_browse_signup()
# tweeted at 2020-05-01 15:11:26 UTC
# https://twitter.com/elonmusk/status/1256239815256797184
View sparse-matrix-coercion.R
library(Matrix)
n <- 10
d <- 12
A <- rsparsematrix(n, d, density = 0.1)
class(A)
#> [1] "dgCMatrix"
#> attr(,"package")
View covariance-example.R
n <- 50 # number of observations
d <- 4 # number of dimensions
X <- matrix(rnorm(n * d), nrow = n, ncol = d)
covariance_helper <- function(x, y) {
x_centered <- x - mean(x)
y_centered <- y - mean(y)
sum(x_centered * y_centered) / (length(x) - 1)
}
You can’t perform that action at this time.