Skip to content

Instantly share code, notes, and snippets.

@benmarwick
benmarwick / a-scientific-computing-environment-for-archaeology.txt
Last active May 14, 2018 19:32
Scientific Computing Environment for archaeology: Installing R, Rstudio and other things on a lightweight Linux in a VirtualBox virtual machine
Short instructions to setup a Lubuntu Virtual Machine with
R & RStudio:
1. Download these:
http://lubuntu.net/ (Intel x86 desktop cd)
https://www.virtualbox.org/wiki/Downloads (Oracle VM VirtualBox)
2. Install Oracle VM VirtualBox, open it (if using windows,
run as administrator), click 'New' button, at
'Name' put Lubuntu, 'Type' choose Linux, 'Version' choose
@jennybc
jennybc / reverse-categorical-axis-ggplot2.r
Created October 10, 2014 01:06
Reverse the order of a categorical axis in ggplot2
scale_x_discrete(limits = rev(levels(the_factor)))
@bl4ck5un
bl4ck5un / palatino.tex
Created September 26, 2015 02:04
Using Palatino font in LaTeX
\usepackage{tgpagella} % text only
\usepackage{mathpazo} % math & text
@Junuxx
Junuxx / class_projects.py
Last active March 2, 2023 16:20
Solution for a StackOverflow scheduling problem
'''
Created on 26 jan. 2016
@author: Jeroen Kools
Based on the following StackOverflow question:
https://stackoverflow.com/questions/35002027/maximizing-a-combination-of-a-series-of-values#comment57732451_35002027
- 18 students
- 12 dates
@noamross
noamross / source_rmd.R
Last active December 13, 2023 18:52
Source an RMD file
#' Source the R code from an knitr file, optionally skipping plots
#'
#' @param file the knitr file to source
#' @param skip_plots whether to make plots. If TRUE (default) sets a null graphics device
#'
#' @return This function is called for its side effects
#' @export
source_rmd = function(file, skip_plots = TRUE) {
temp = tempfile(fileext=".R")
knitr::purl(file, output=temp)
@mike-lawrence
mike-lawrence / gp_regression.stan
Last active April 7, 2020 18:15
GP Regression example
functions{
// GP: computes noiseless Gaussian Process
vector GP(real volatility, real amplitude, vector normal01, int n_x, real[] x ) {
matrix[n_x,n_x] cov_mat ;
real amplitude_sq_plus_jitter ;
amplitude_sq_plus_jitter = amplitude^2 + 1e-6 ;
cov_mat = cov_exp_quad(x, amplitude, 1/volatility) ;
for(i in 1:n_x){
cov_mat[i,i] = amplitude_sq_plus_jitter ;
}
@backroot
backroot / pandoc_install.sh
Last active February 22, 2023 14:32
installing pandoc on CentOS 7
#!/bin/bash
sudo yum -y install epel-release
sudo yum -y install haskell-platform --enablerepo=epel
cabal update
cabal install pandoc --force-reinstall
library(gganimate) # thomasp85/gganimate
library(cartogram)
library(geogrid) # Need github version jbaileyh/geogrid
library(rnaturalearth)
library(sf)
library(scico)
us <- ne_states('united states of america', returnclass = 'sf')
us <- us[!us$woe_name %in% c('Alaska', 'Hawaii'), ]
us <- st_transform(us, '+proj=eqdc +lat_0=39 +lon_0=-96 +lat_1=33 +lat_2=45 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs')
@benmarwick
benmarwick / gist:8cf22ecb74ac511f8ac1c70aef6038a7
Last active April 29, 2023 21:31
How to make diamond plots after Bergstrom and West (2018) "Why scatter plots suggest causality, and what we can do about it"
# https://arxiv.org/pdf/1809.09328.pdf & https://twitter.com/CT_Bergstrom/status/1035327464644333568
# they use Mathematica, boo! So let's make them with R
# starting with https://stackoverflow.com/q/33396168/1036500
library(ggplot2)
p <- ggplot() +
geom_point(data = anscombe,
library(data.table)
library(dplyr)
library(R.utils)
# JUST MASS
mass <- gunzip("arcos-ma-statewide-itemized.tsv.gz")
mass_opioids <- fread(file = 'arcos-ma-statewide-itemized.tsv')
glimpse(mass_opioids) # 2,574,240 observations
summary(mass_opioids)