Skip to content

Instantly share code, notes, and snippets.

@karlrohe
karlrohe / sp500_frames.R
Created January 11, 2022 16:07
PCA of SP500
library(rARPACK)
library(dplyr)
library(tidyr)
library(RColorBrewer)
library(BatchGetSymbols)
# 4 years of data
first.date <- Sys.Date()-365*4
last.date <- Sys.Date()
@karlrohe
karlrohe / PCA_on_handwritten_2s.R
Created January 7, 2022 22:48
PCA on mnist handwritten 2's
# PCA on n=6990 images of handwritten 2's, each with d = 784 pixels.
# install.packages("remotes")
# remotes::install_github("jlmelville/snedata")
# thank you jlmelville for making this data so easy to access!
library(snedata)
library(magrittr)
library(Matrix)
library(rARPACK)
@karlrohe
karlrohe / PresidentialApprovalSpreads
Created May 1, 2020 14:25
This plots some presidential approval data over time. This in particular: (VoterDisapprove - VoterApprove) - (AdultDisapprove - AdultApprove)
library(tidyverse)
library(lubridate)
x = read_csv("https://projects.fivethirtyeight.com/trump-approval-data/approval_topline.csv")
x %>%
select(subgroup, approve_estimate, disapprove_estimate, timestamp) %>%
mutate(spreadd = disapprove_estimate - approve_estimate) %>%
filter(subgroup != "All polls") %>%
mutate(date = parse_date_time(timestamp, orders = "H!:M!:S! d! b! Y!")) %>%
@karlrohe
karlrohe / app.R
Last active February 23, 2020 13:43
demo the buttons
library(shiny)
# taken from https://shiny.rstudio.com/tutorial/written-tutorial/lesson3/
# Define UI ----
ui <- fluidPage(
titlePanel("Basic widgets"),
fluidRow(