Skip to content

Instantly share code, notes, and snippets.

View mbjoseph's full-sized avatar

Max Joseph mbjoseph

View GitHub Profile
@mbjoseph
mbjoseph / community_occ.R
Created January 23, 2013 04:22
Dynamic community occupancy model in R and JAGS example
# Multi-species dynamic occupancy model with R and JAGS
# Written by Max Joseph
# maxwell.b.joseph@colorado.edu
# see http://www.colorado.edu/eeb/gradstudents/joseph/community_occ.html
# for details
# convenience functions
logit <- function(x) {
log(x/(1 - x))
}
@mbjoseph
mbjoseph / vioplot2.R
Last active December 9, 2020 17:06
Slight change to the vioplot function from Daniel Adler that plots median lines instead of points, and gives the option to plot either side of a violin rather than always both.
vioplot2 <- function (x, ..., range = 1.5, h = NULL, ylim = NULL, names = NULL,
horizontal = FALSE, col = "magenta", border = "black", lty = 1,
lwd = 1, rectCol = "black", colMed = "white", pchMed = 19,
at, add = FALSE, wex = 1, drawRect = TRUE, side="both")
{
datas <- list(x, ...)
n <- length(datas)
if (missing(at))
at <- 1:n
upper <- vector(mode = "numeric", length = n)
@mbjoseph
mbjoseph / bivar_pois.R
Last active September 2, 2018 18:12
Initial pass at a bivariate Poisson model in Stan
## Simple bivariate Poisson model in stan
## following parameterization in Karlis and Ntzoufras 2003
## Simulate data
n <- 50
# indpendent Poisson components
theta <- c(2, 3, 1)
X_i <- array(dim=c(n, 3))
for (i in 1:3){
@mbjoseph
mbjoseph / modis.py
Created June 13, 2016 17:28
Python script to grab modus data
#===============================================================================
# Date: May 22, 2016
# Author: Lindy Nelson
# Purpose: This script downloads monthly MODIS burn data from
#
#
# FTP Server: fuoco.geog.umd.edu
#
#
---
title: "Coloring lidar point clouds with RGB imagery in R"
author: "Max Joseph"
date: "June 30, 2016"
output:
html_document:
keep_md: true
---
```{r setup, echo = FALSE}
# Script to get MCD14ML MODIS data
library(RCurl)
library(dplyr)
# fetch_MCD14ML() downloads all of the zipped data files for the
# MODIS MCD14ML data product
#
# args:
# dir: the name of a directory to store the zip files (string)
# overwrite: should existing data be overrwitten? (logical)
@mbjoseph
mbjoseph / template.Rmd
Created August 22, 2016 19:53
A R markdown beamer template that doesn't suck that much.
---
title: "Your title here"
subtitle: a clever subtitle
author: "Your name"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
beamer_presentation:
latex_engine: xelatex
fonttheme: "structurebold"
header-includes:
# Importing data from USDA into large data file ---------------------------
library(stringr)
library(dplyr)
path_to_data <- "~/Desktop/ams_cattle_data/"
data_files <- list.files(path = path_to_data, pattern = "cattle",
full.names = TRUE)
# Define helper functions -------------------------------------------------
@mbjoseph
mbjoseph / lm_segs.stan
Last active September 12, 2016 04:38
Piecewise regression w/ unknown breakpoint in Stan
data {
int<lower=1> n;
vector[n] x;
vector[n] y;
}
parameters {
real alpha;
vector[2] beta;
real<lower=0> sigma;
@mbjoseph
mbjoseph / leung_drton_factor_analysis.R
Last active January 16, 2020 08:56
Factor analysis sandbox
# Simulation script for factor analysis ala Leung & Drton (2016) ----------
library(rstan)
library(bayesplot)
m <- 5 # dimension of observed data (e.g., # traits)
k <- 2 # number of latent factors
n <- 100 # number of sample units (e.g., # species)
# residual variance matrix (is diagonal)
Omega <- diag(.3 + abs(rnorm(m, sd = .3)))