Skip to content

Instantly share code, notes, and snippets.

View ThierryO's full-sized avatar

Thierry Onkelinx ThierryO

View GitHub Profile
@ThierryO
ThierryO / lmm
Created January 26, 2015 08:14
Simulate a linear mixed model with random slope
library(ggplot2)
library(lme4)
library(mvtnorm)
fixed.intercept <- 1
n.subject <- 10
n.replicate <- 10
mean.subject <- c(1, 2, 3, 3, 2, 1)
sd.subject <- 0.1 * diag(length(mean.subject))
sd.noise <- 0.5
@ThierryO
ThierryO / jasja.R
Created January 13, 2015 22:45
create lines from consecutive coordinates
library(sp)
library(plyr)
library(reshape2)
library(rgdal)
n <- 1e4
dataset <- data.frame(
ID = seq_len(n),
X = runif(n),
Y = runif(n),
@ThierryO
ThierryO / abuff.R
Last active August 29, 2015 14:01 — forked from barryrowlingson/abuff.R
abuff <- function(spgeom, ratio = 1.1, precision = 0.00001, maxsteps = 20){
require(rgeos)
spgeom.area <- gArea(spgeom)
spgeom.perimeter <- gLength(spgeom)
buffer.width <- (ratio - 1) * spgeom.area / spgeom.perimeter
buffered.spgeom <- gBuffer(spgeom, width = buffer.width)
achieved.precision <- gArea(buffered.spgeom) / spgeom.area - ratio
steps <- 1