Skip to content

Instantly share code, notes, and snippets.

View swihart's full-sized avatar

Bruce Swihart swihart

View GitHub Profile
@bbolker
bbolker / glmulti_mixed.R
Last active December 11, 2024 20:21
tools for using glmulti with lme4/glmmTMB model fits
library(lme4)
library(glmmTMB)
library(glmulti)
set.seed(101)
## updated 3 March 2024; take random effects as formulas so that e.g. `ar1()` terms work
## FIXME: better data so we don't get convergence weirdness etc.?
## A random vector of count data
vy1 <- round(runif(100, min=1,max=20)*round(runif(100,min=1,max=20)))
ruler <- function(width = getOption("width")) {
x <- seq_len(width)
y <- dplyr::case_when(
x %% 10 == 0 ~ as.character((x %/% 10) %% 10),
x %% 5 == 0 ~ "+",
TRUE ~ "-"
)
cat(y, "\n", sep = "")
cat(x %% 10, "\n", sep = "")
}
@gadenbuie
gadenbuie / join-animations-with-gganimate.R
Last active January 11, 2022 15:48
Animated dplyr joins with gganimate
# 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)
@gavinsimpson
gavinsimpson / compare-glmmTMB-with-mgcv.R
Last active April 30, 2024 20:09
A quick R script I knocked up to compare the glmmTMB and mgcv packages for fitting zero-inflated GLMMs to the Salamander and Owls data sets from Brooks et al (2017)
## Compare Brooks et al glmmTMB paper with mgcv
## Packages
library("glmmTMB")
library("mgcv")
library("ggplot2")
theme_set(theme_bw())
library("ggstance")
## Salamander

This hit #rstats today:

Has anyone made a dumbbell dot plot in #rstats, or better yet exported to @plotlygraphs using the API? https://t.co/rWUSpH1rRl

— Ken Davis (@ken_mke) October 23, 2015
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

So, I figured it was worth a cpl mins to reproduce.

While the US gov did give the data behind the chart it was all the data and a pain to work with so I used WebPlotDigitizer to transcribe the points and then some data wrangling in R to clean it up and make it work well with ggplot2.

It is possible to make the top "dumbbell" legend in ggplot2 (but not by using a guide) and color the "All Metro A

@jennybc
jennybc / r-fcsn-in-wild-search.md
Last active January 6, 2020 08:09
Search for "natural" usage of a function across all CRAN packages

What if a function in a package has no examples? Or is poorly exampled? Wouldn't it be nice to find functioning instances of it "in the wild"?

Via Twitter, Noam Ross taught me a clever way to do such searches on GitHub. Put this into the GitHub search box to see people using the llply() function from plyr:

"llply" user:cran language:R

Or just click here.

@sachsmc
sachsmc / Rjobs
Last active August 29, 2015 14:09
Parallel Jobs on Biowulf
Rscript --vanilla run.R 1 > run-1.Rout
Rscript --vanilla run.R 2 > run-2.Rout
Rscript --vanilla run.R 3 > run-3.Rout
Rscript --vanilla run.R 4 > run-4.Rout
Rscript --vanilla run.R 5 > run-5.Rout
Rscript --vanilla run.R 6 > run-6.Rout
Rscript --vanilla run.R 7 > run-7.Rout
Rscript --vanilla run.R 8 > run-8.Rout
Rscript --vanilla run.R 9 > run-9.Rout
Rscript --vanilla run.R 10 > run-10.Rout
@benmarwick
benmarwick / .emacs
Last active June 1, 2020 15:22
Notes on using Emacs
;;Record startup timestamp
(defvar Emacs/invokation-time
(current-time))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (tango-plus)))
@dsparks
dsparks / colors.R
Last active December 23, 2020 22:12
Sunlight Foundation palettes, based on the Wes Anderson code
# Sunlight Foundation style guide: http://design.sunlightlabs.com/projects/Sunlight-StyleGuide-DataViz.pdf
# Ram's original Wes Anderson code: https://github.com/karthik/wesanderson/blob/master/R/colors.R
#' A Wes Anderson palette generator
#'
#' These are a handful of color palettes from Wes Anderson movies.
#' @param n Number of colors desired. Unfortunately most palettes now only have 4 or 5 colors. But hopefully we'll add more palettes soon. All color schemes are derived from the most excellent Tumblr blog: \href{http://wesandersonpalettes.tumblr.com/}{Wes Anderson Palettes}
#' @param name Name of desired palette. Choices are: \code{GrandBudapest}, \code{Moonrise1}, \code{Royal1}, \code{Moonrise2}, \code{Cavalcanti}, \code{Royal2}, \code{GrandBudapest2}, \code{Moonrise3}, \code{Chevalier}, \code{BottleRocket}, \code{darjeeling}, \code{darjeeling2}
#' @param type Set to continuous if you require a gradient of colors similar to how heat map works.
#' @export
@casallas
casallas / rjags_mac.md
Last active January 31, 2024 23:16
Installing rjags on a Mac

To install

  1. Install jags: in the terminal using homebrew brew install jags
  2. Install rjags: in R
install.packages("rjags")
library(rjags)

Potential issues