Skip to content

Instantly share code, notes, and snippets.

View chelseaparlett's full-sized avatar

Chelsea Parlett Pelleriti chelseaparlett

View GitHub Profile
@chelseaparlett
chelseaparlett / R_EigenPCA_Plots.R
Last active April 19, 2024 10:45
Show students the relationship between Eigendecomp of Cor/Cov and the % variance explained for PCs
library(tidyverse)
library(MASS)
library(patchwork)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
# generate data with given cor matrix
a <- 0.9
s1 <- matrix(c(1,a,
a,1), ncol = 2)
@chelseaparlett
chelseaparlett / LegoCNN
Created October 3, 2023 05:51
Lego 5x5x3 Imagewith 3x3x3 kernel
library(brickr)
make_bricks <- function(brick_width = 5,
brick_length = 5,
n_layers = 3,
colors = c("Bright red",
"Bright green",
"Bright blue"),
render = FALSE){
x <- rep(sort(rep(1:brick_width, brick_length)), n_layers)
#libs
library(tidyverse)
#---CHELSEA---
# load in data
california <- read.csv("./Data/namesbystate/STATE.CA.TXT", header = FALSE)
colnames(california) <- c("State", "Gender", "Year", "Name", "Count")
# filter data
california_sub <- california %>% filter(Name == "Chelsea", Gender == "F")
library(tidyverse)
library(ggtext)
library(grid)
library(crayon)
title <- "The <b><span style='color:#FF0000'>Sigmoid Function</span></b> and its <b><span style='color:#0000FF'>Derivative</span></b>"
df <- data.frame(x = -5:5)
ggplot(df, aes(x)) +
library(tidyverse)
library(MASS)
# plot e^x
x <- -5:5
dat <- data.frame(x,y=exp(x))
f <- function(x) exp(x)
p <- ggplot(dat, aes(x,y)) +
stat_function(fun=f, colour="red") +
from shiny import App, render, ui, reactive
from pathlib import Path
# Import modules for plot rendering
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
library(tidyverse)
# create named list
l <- list(x = data.frame(a = rnorm(10), b = rnorm(10)),
y = data.frame(a = rnorm(10), b = rnorm(10)),
z = data.frame(a = rnorm(10), b = rnorm(10)))
for (i in names(l)){
if (i %in% c("x", "y")){ # if the name of the list item is in a specified sublist
l[[i]] <- l[[i]] %>% mutate(c = a + 1) # then do the mutate
library(readr)
library(tidyverse)
# read in data
urlfile <- "https://raw.githubusercontent.com/Z-Unlocked/Unlocked_Challenge_1/main/temperature_change_data_11-29-2021.csv"
mydata <-read_csv(url(urlfile))
# filter
countries <- c("China", "Germany", "Japan", "United States of America")
#libs--------------
library(grid)
library(tidyverse)
library(ggdark)
#funs--------------
irt <- function(a,b,c){
theta <- seq(-10,10, length = 500)
exponent <- exp(a*(theta-b))
phat <- c + (1-c)*(exponent/(1 + exponent))
terms <- c("error", "random", "model",
"mixed", "linear", "effects",
"variance")
probs <- c(0.1,0.1, 0.55, 0.05, 0.05, 0.1, 0.05)
new_jargon <- sample(terms,
size = sample(c(2,3),1),
prob = probs)
new_jargon <- paste(new_jargon, collapse = " ")