This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tibble) | |
df = tibble( | |
var1 = rnorm(5), | |
var2 = rnorm(5) | |
) | |
first = function(data, x){ | |
x = substitute(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tidy Tuesday (on Friday) | |
# 25 October 2019 | |
# Tyson S. Barrett | |
# Packages ---- | |
library(tidyverse) # CRAN | |
library(dtplyr) # CRAN | |
library(data.table) # CRAN | |
library(tidyfast) # remotes::install_github("tysonstanley/tidyfast") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |