Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Tyson Barrett TysonStanley

🏠
Working from home
Block or report user

Report or block TysonStanley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@TysonStanley
TysonStanley / dplyr_datatable_memory.R
Created Oct 12, 2019
Using `profmem` package to understand data summaries by group for both `data.table` and `dplyr`
View dplyr_datatable_memory.R
library(bench) # assess speed and memory
library(data.table) # data.table for all of its stuff
library(dplyr) # compare it to data.table
library(profmem) # assess the process of R functions
set.seed(84322)
# Example Data
d <- data.table(
grp = sample(c(1,2), size = 1e6, replace = TRUE) %>% factor,
@TysonStanley
TysonStanley / server.R
Created Jul 16, 2019 — forked from withr/server.R
Encrypt password with md5 for Shiny-app.
View server.R
library(shiny)
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {
@TysonStanley
TysonStanley / beta_power.R
Last active Feb 26, 2019
Preliminary Power Analysis with Beta Regression
View beta_power.R
## Beta Regression Power Analysis
## Simulations to assess statistical power given alpha, n, effect size
## Tyson S. Barrett
library(tidyverse)
library(betareg)
set.seed(84322)
## Population Model
View join-animations-with-gganimate.R
# Animated dplyr joins with gganimate
# * Garrick Aden-Buie
# * garrickadenbuie.com
# * MIT License: https://opensource.org/licenses/MIT
# Note: I used Fira Sans and Fira Mono fonts.
# Use search and replace to use a different font if Fira is not available.
library(tidyverse)
library(gganimate)
View evergreen_data_plot.r
## Code for Example Plot for @evergreendata
## Tyson S. Barrett
## Data
x_num = c(4.2, 4.5, 4, 4.5, 3.9, 3.6)
year = c(2011:2016)
x_per = c(.52, .58, .6, .63, .64, .67)
df = data.frame(x_num, year, x_per)
## Libraries and Plots
@TysonStanley
TysonStanley / Density_ShotChart
Last active Aug 29, 2015
Density Shot Chart of Stephen Curry 2015 (ggplot2 & hexbin & png)
View Density_ShotChart
# Steph Curry Shot Selection in 2015
# Data from: NBAsavant.com (awesome data source)
packs <- c("png","grid","ggplot2")
lapply(packs, require, character.only=TRUE)
steph <- read.csv("data.csv") # from NBAsavant.com
court <- readPNG("court.png") # diagram of NBA court
g <- rasterGrob(court, interpolate=TRUE)
@TysonStanley
TysonStanley / DensityPlots
Created May 4, 2015
Two Dimensional Density and Hexbin Plots with Simulated Data (ggplot2 & hexbin)
View DensityPlots
# Simulating Correlated Data
# (this is a variant of something I found online but I can't find out who posted it...)
n <- 2000 # length
rho <- 0.6 # desired correlation = cos(angle)
theta <- acos(rho) # corresponding angle
pred <- rnorm(n, 1, 1) # predictor vector
x2 <- rnorm(n, 2, 0.5) # new random data for response vector
X <- cbind(pred, x2) # matrix of pred and x2
Xctr <- scale(X, center=TRUE, scale=FALSE) # centered columns (mean 0)
Id <- diag(n) # an identity matrix
You can’t perform that action at this time.