Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bedward mbedward

View GitHub Profile
@mbedward
mbedward / gist:850fe1923d9b87e3d3c5f9a66fb7e7ca
Created Aug 21, 2018
Model observed proportions as Beta distributed with JAGS
View gist:850fe1923d9b87e3d3c5f9a66fb7e7ca
# Some test data for proportions with mean 0.4
p <- rbeta(20, 4, 6)
# JAGS model
modelTxt <- "model {
for(i in 1:length(p)) {
p[i] ~ dbeta(alpha, beta)
}
alpha <- mu * phi
beta <- (1-mu) * phi
@mbedward
mbedward / example.R
Created Mar 7, 2017
This function retrieves data for a specified smooth term from a fitted gam object (package mgcv) which is handy when you want to graph the smoother with ggplot.
View example.R
library(ggplot2)
library(mgcv)
# Toy data set
dat <- data.frame(
x = seq(0, 2*pi, length.out = 100),
y = sin(3*x) / sin(x/2)
)
# Randomly thin the data
@mbedward
mbedward / convex_hulls.png
Last active Jun 10, 2019
Example of drawing convex hulls around grouped points in R using dplyr and ggplot.
@mbedward
mbedward / gist:6e3dbb232bafec0792ba
Last active Jun 30, 2020
Scala macro to convert between a case class instance and a Map of constructor parameters. Developed by Jonathan Chow (see http://blog.echo.sh/post/65955606729/exploring-scala-macros-map-to-case-class-conversion for description and usage). This version simply updates Jonathan's code to Scala 2.11.2
View gist:6e3dbb232bafec0792ba
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait Mappable[T] {
def toMap(t: T): Map[String, Any]
def fromMap(map: Map[String, Any]): T
}
object Mappable {
@mbedward
mbedward / pom.xml to create GeoTools uber-jar
Created Nov 27, 2013
An example of how to safely combine GeoTools component jars into a single (uber) jar. It uses the Maven shade plugin to properly combine the META-INF/services entries of the individual GeoTools jars.
View pom.xml to create GeoTools uber-jar
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.geotools</groupId>
<artifactId>gt-uber</artifactId>
<!-- The version of the GeoTools jars to combine -->
<version>10.2</version>
You can’t perform that action at this time.