Skip to content

Instantly share code, notes, and snippets.

View jebyrnes's full-sized avatar

Jarrett Byrnes jebyrnes

View GitHub Profile
@jebyrnes
jebyrnes / sim_coefs.R
Created December 8, 2020 14:59
Shows how to use coefs and their vcov matrix to get simulated means and SE- will work for any model! And this example uses a categorical variable. Using the model.matrix avoids having to understand the treatment contrasts.
library(mvtnorm)
library(dplyr)
#make cyl a factor, like site
mtcars$cyl <- as.character(mtcars$cyl)
#fit a model
mod <- lm(mpg ~ cyl*hp, data = mtcars)
@jebyrnes
jebyrnes / predict_intervals_lm.R
Created September 8, 2020 14:04
posthoc distribution from linear models
#-------------------------------
# Let's explore simulating from lm
# fits!
#
# Jarrett Byrnes
# 2020-09-08
#-------------------------------
#some useful libraries
@jebyrnes
jebyrnes / prediction_ranef.R
Created August 11, 2020 17:52
Predictions of models with nominal or continuous variables using predictInterval and lmer
#fit a model
library(lme4)
sleepstudy$c_Days <- as.character(sleepstudy$Days)
#same model, one continuous, one nominal
m1_c <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy)
m1_n <- lmer(Reaction ~ c_Days + (1 | Subject), sleepstudy)
#Making data grid with nominal variables
@jebyrnes
jebyrnes / coauthors_nsf_coa.R
Last active August 1, 2020 20:04
Get your coauthors for the last 4 years, nsf-style
library(scholar)
library(dplyr)
library(purrr)
library(tidyr)
id <- "hJKBuhkAAAAJ"
#me <- get_profile(id)
pubs <- get_publications(id) %>% as_tibble
@jebyrnes
jebyrnes / goog_mobility_wtg.R
Created May 27, 2020 20:54
Google Mobility on world tile map
#devtools::install_github("hrbrmstr/worldtilegrid")
library(worldtilegrid)
library(dplyr)
library(ggplot2)
goog <- refresh_covid19mobility_google_country()
data(wtg)
goog_april <- filter(goog,
as.character(date) %in% c("2020-04-15", "2020-02-15", "2020-03-15", "2020-05-15"),
data_type=="retail_and_recreation_percent_change_from_baseline") %>%
@jebyrnes
jebyrnes / iso_3166_2_subdivision_scrape.R
Created May 27, 2020 19:08
Get the iso subdivision codes from wikipedia
library(rvest)
library(dplyr)
library(purrr)
library(tidyr)
# https://en.wikipedia.org/wiki/ISO_3166-2
baseurl <- "https://en.wikipedia.org"
url <- "https://en.wikipedia.org/wiki/ISO_3166-2"
# get the tables from which spring links!
library(tidyverse)
library(readr)
get_buoy <- function(a_year){
one_buoy <- read_buoy(a_year) %>%
format_buoy %>%
make_monthly_buoy
return(one_buoy)
}
library(coronavirus)
library(dplyr)
library(ggplot2)
library(rnaturalearth)
library(sf)
library(ggrepel)
library(wesanderson)
coronavirus <- update_coronavirus()
usa <- ne_states(country = "United States of America", returnclass = "sf")
@jebyrnes
jebyrnes / coronavirus_heatmap.R
Created March 7, 2020 21:18
A first stab at making useful heatmaps from the coronavirus data
#devtools::install_github("RamiKrispin/coronavirus")
library(coronavirus)
library(dplyr)
library(ggplot2)
library(tidyr)
library(rnaturalearth)
library(sf)
#note, above this, use rtweet
#instructions for getting api keys and the like
#from http://dev.twitter.com
library(rtweet)
library(tweetbotornot)
library(ggplot2)
library(dplyr)
library(ggridges)
token <- create_token(