Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / geospatial_test.R
Last active January 22, 2019 14:11
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
#'------------------------------
#'
#' 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 January 3, 2019 19:46
Makes thresholded sf multipolygons from user classifications for floating forests with a sample data set
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 January 2, 2019 18:28
a sample sf multipolygon set
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 November 4, 2018 02:58
Some residual methods for tidybayes
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
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,
@jebyrnes
jebyrnes / bayesian_posthoc.R
Last active February 10, 2023 20:29
Posthoc contrasts with emmeans, tidybayes, and brms
library(tidyverse)
library(emmeans)
library(brms)
library(tidybayes)
warp.brms <- brm(breaks ~ wool * tension, data = warpbreaks)
#get the adjusted means
warp_em <- emmeans (warp.brms, ~ tension | wool)
warp_em
@jebyrnes
jebyrnes / sst_lambert.R
Created October 6, 2018 03:10
SST change in the lambert projection
library(raster)
#devtools::install_github("jebyrnes/hadsstr")
library(hadsstr) #from jebyrnes/hadsstr
library(ggplot2)
library(sf)
library(rnaturalearth)
#get the world in the lambert projection
countries_50_sf <- ne_download(scale = 50, category = 'cultural', type = 'countries', returnclass="sf")
countries_lambert <- st_transform(oceans, 2154)
@jebyrnes
jebyrnes / glm_profile.R
Last active April 22, 2019 21:20
Take a glm and creates a deviance profile, as MASS::profile only returns a transformed version of the deviance.
library(ggplot2)
#A glm from the glm helpfile
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
print(d.AD <- data.frame(treatment, outcome, counts))
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
#The old way...
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggplot2)
oceans <- ne_download(type = "ocean", category = "physical", returnclass="sf")
ocean_antarctic <- st_transform(oceans, 2154)
ggplot(ocean_antarctic) +
geom_sf(fill = "lightblue", color=NA)
@jebyrnes
jebyrnes / discrete_grrrowth.R
Created October 2, 2018 03:58
How to use purrr::iwalk to do discrete time logistic growth models.
#'----------------
#' Discrete time logistic growth model
#' Using purrr and iwalk
#'----------------
library(purrr)
r <- 3.95237783423
n0 <- 0.3