Skip to content

Instantly share code, notes, and snippets.

View aammd's full-sized avatar

Andrew MacDonald aammd

  • Université de Sherbrooke
  • Montreal, Canada
View GitHub Profile
@bearloga
bearloga / mkrproj.sh
Last active January 3, 2018 14:59
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
#!/bin/bash
# Usage: mkproj [projectname]
# projectname defaults to name of current directory
template="Version: 1.0\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 4\nEncoding: UTF-8\n\nRnwWeave: knitr\nLaTeX: pdfLaTeX"
wd=$(basename `pwd`)
if [ -z $1 ]; then
@mike-lawrence
mike-lawrence / cfa.stan
Created March 21, 2017 15:10
Demo using Stan for Confirmatory Factor Analysis
data{
# n_subj: number of subjects
int n_subj ;
# n_y: number of outcomes
int n_y ;
# y: matrix of outcomes
matrix[n_subj,n_y] y ;
# n_fac: number of latent factors
int n_fac ;
# y_fac: list of which factor is associated with each outcome
@emhart
emhart / birthday_song.R
Created August 8, 2016 15:45
Happy Birthday Oliver!
library("dplyr")
library("audio")
notes <- c(A = 0, B = 2, C = 3, D = 5, E = 7, F = 8, G = 10)
pitch <- "D D E D G F# D D E D A G D D D5 B G F# E C5 C5 B G A G"
duration <- c(rep(c(0.75, 0.25, 1, 1, 1, 2), 2),
0.75, 0.25, 1, 1, 1, 1, 1, 0.75, 0.25, 1, 1, 1, 2)
bday <- data_frame(pitch = strsplit(pitch, " ")[[1]],
duration = duration)
@MatsuuraKentaro
MatsuuraKentaro / model.stan
Last active March 5, 2024 06:08
Tweedie distribution in Stan
data {
int N;
int M;
real<lower=0> Y[N];
}
parameters {
real<lower=0> mu;
real<lower=0> phi;
real<lower=1, upper=2> theta;
@davharris
davharris / boot.R
Created June 12, 2014 20:17
code for plotting bootstrap predictions from a nonlinear model
set.seed(1)
# Create fake data
x = runif(100, 0, 5)
y = .25 * x^3 - x^2 + rnorm(length(x))
data = data.frame(x = x, y = y)
# Identify 500 points to include in the plots
x.sequence = seq(0, 5, length = 500)
@lauratboyer
lauratboyer / getmatch.r
Created July 24, 2013 18:11
This function allows you to extract the part of the string that matches the regular expression given as input. For instance, if you have species names and want to extract the gender only, you would type: getmatch("Echinometra mathaei", "^\\w+") # Echinometra
getmatch <<- function(x,str2match,...) {
unlist(regmatches(x,regexpr(str2match,x,...))) }
@mabarbour
mabarbour / ch2
Created November 5, 2012 20:43
Code for recreating figures in Chapter 2
######### These are my attempts to incorporate McCann's models into R to help me interpret these food web models ######################
### Section 2.2.5
# parameters and state variables for the R-M model
r <- 1.0 # per capita rate of increase in resource
K <- 2.0
e <- 0.5
Ro <- 0.5
m <- 0.5
a <- 1.6