Skip to content

Instantly share code, notes, and snippets.

Jarrett Byrnes jebyrnes

Block or report user

Report or block jebyrnes

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
@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,
@jebyrnes
jebyrnes / bayesian_posthoc.R
Last active Sep 25, 2019
Posthoc contrasts with emmeans, tidybayes, and brms
View bayesian_posthoc.R
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 Oct 6, 2018
SST change in the lambert projection
View sst_lambert.R
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 Apr 22, 2019
Take a glm and creates a deviance profile, as MASS::profile only returns a transformed version of the deviance.
View glm_profile.R
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...
View ocean_lambert.R
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 Oct 2, 2018
How to use purrr::iwalk to do discrete time logistic growth models.
View discrete_grrrowth.R
#'----------------
#' Discrete time logistic growth model
#' Using purrr and iwalk
#'----------------
library(purrr)
r <- 3.95237783423
n0 <- 0.3
@jebyrnes
jebyrnes / nesting_models.R
Created May 17, 2018
Using gapminder to show how tidyr and broom and dplyr can fit a lot of models all at once.
View nesting_models.R
library(tidyverse)
library(gapminder)
library(broom)
library(ggplot2)
life_exp_mods <- gapminder %>%
#do this for each country
group_by(country) %>%
@jebyrnes
jebyrnes / plot_poly_fits.R
Created May 16, 2018
plot predictions of a model with an interaction and a poly term
View plot_poly_fits.R
library(tidyverse)
library(ggplot2)
library(visreg)
#some fake data
set.seed(35)
my_data <- data.frame(x1 = runif(100,-50,50), x2 = runif(100, -50, 50)) %>%
mutate(y = rnorm(100, 0.001*x2*(x1 - x1^2), 100))
#let's see that data
You can’t perform that action at this time.