Skip to content

Instantly share code, notes, and snippets.

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / gam_v_cor.R
Created Apr 8, 2019
Does a gam act like a fixed effect for autocorrelation?
View gam_v_cor.R
library(MASS)
library(tidyverse)
library(ggplot2)
library(mgcv)
gaussprocess <- function(from = 0, to = 1, K = function(s, t) {min(s, t)},
start = NULL, m = 1000) {
# Simulates a Gaussian process with a given kernel
#
# args:
View spike_wave.R
library(heatwaveR)
library(tsibble)
library(lubridate)
library(dplyr)
# Detect the events in a time series
ts <- ts2clm(sst_WA, climatologyPeriod = c("1982-01-01", "2011-12-31"))
mhw <- detect_event(ts, minDuration = 1, maxGap = 0)
@jebyrnes
jebyrnes / raster_fade.R
Created Feb 20, 2019
crossfading between raster layers in gganimate
View raster_fade.R
library(ggplot2)
library(gganimate)
mygridstart <- tidyr::crossing(x = 1:10, y = 1:10)
mygrid <- rbind(mygridstart, mygridstart, mygridstart)
mygrid$rep <- sort(rep(1:3, nrow(mygrid)/3))
mygrid$pointgroup <- rep(1:100, 3)
mygrid$f <- factor(sample(1:3, replace=TRUE, size = nrow(mygrid)))
@jebyrnes
jebyrnes / bayesian_updating.R
Created Feb 1, 2019
A little animation of Bayesian updating with a
View bayesian_updating.R
library(dplyr)
library(tidyr)
library(stringr)
library(ggplot2)
library(gganimate)
#make those samples!
set.seed(3003)
samps <- replicate(9, rbinom(1,1,prob = 0.3))
running_samps <- cumsum(samps)
@jebyrnes
jebyrnes / same_model_many_responses.R
Created Jan 23, 2019
Quick reprex for @ jess_carilli
View same_model_many_responses.R
#some libraries
library(dplyr)
library(tidyr)
library(broom)
library(purrr)
#let's use the npk data
head(npk)
#but make up a few extra columns
@jebyrnes
jebyrnes / geospatial_test.R
Last active Jan 22, 2019
Try this and make sure there are no errors. If it all runs, you're in good shape! Should make three plots, and install rnaturalearth, which is pretty cool
View geospatial_test.R
#'------------------------------
#'
#' Script to make sure everything works
#' for you for the 2019-01-22 Geospatial
#' Data Carpentry workshop at UMB
#'------------------------------
# Make sure we have rnaturalearth installed
# If you do, comment out the install.packages line
#or just don't run it.
@jebyrnes
jebyrnes / threshold_classifications_sf.R
Created Jan 3, 2019
Makes thresholded sf multipolygons from user classifications for floating forests with a sample data set
View threshold_classifications_sf.R
library(sf)
library(fasterize)
library(spex)
library(dplyr)
library(purrr)
library(ggplot2)
library(lwgeom)
test_set <- devtools::source_gist("c95701bd444cda3e342838fd9a090fb3",
@jebyrnes
jebyrnes / test_set.R
Created Jan 2, 2019
a sample sf multipolygon set
View test_set.R
structure(list(classification_id = c(82289537L, 82386012L, 84461998L,
85718077L, 91018956L, 102059723L, 102656990L, 103374144L, 105820504L,
108510525L, 113891667L, 120531542L, 133372372L, 133644897L, 134776350L
), geometry = structure(list(structure(list(structure(list(structure(c(314658.101094576,
314658.101094576, 314637.103677284, 314616.106259993, 314616.106259993,
314595.108842701, 314595.108842701, 314574.111425409, 314553.114008117,
314553.114008117, 314532.116590825, 314532.116590825, 314511.119173533,
314511.119173533, 314511.119173533, 314511.119173533, 314511.119173533,
314511.119173533, 314511.119173533, 314532.116590825, 314532.116590825,
314553.114008117, 314574.111425409, 314595.108842701, 314616.106259993,
@jebyrnes
jebyrnes / tidy_residuals.R
Created Nov 4, 2018
Some residual methods for tidybayes
View tidy_residuals.R
tidy_residuals <- function(model){
UseMethod("tidy_residuals")
}
tidy_residuals.brmsfit <- function(model){
res <- residuals(model, summary=FALSE)
props <- summary(model)
nchains <- props$chains
iter <- props$iter - props$warmup
View data.r
brainGene <- structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("control", "schizo", "bipolar"
), class = "factor"), PLP1.expression = c(-0.02, -0.27, -0.11,
0.09, 0.25, -0.02, 0.48, -0.24, 0.06, 0.07, -0.3, -0.18, 0.04,
-0.16, 0.25, -0.1, -0.31, -0.05, 0.11, -0.38, 0.23, -0.23, -0.28,
-0.36, -0.22, -0.4, -0.19, -0.34, -0.29, -0.12, -0.34, -0.39,
You can’t perform that action at this time.