Skip to content

Instantly share code, notes, and snippets.

@dhicks
dhicks / mwe.R
Created July 10, 2018 19:02
Spatial Durbin Model
library(rstan)
## options(mc.cores = parallel::detectCores())
## Data should be here: <https://drive.google.com/open?id=1BUV8mChrZ0UkyW2G4EHB5wc1taUpMZUM>
load('mwe.Rdata')
## dataf: The data; response is `w_use`
## W_3nn: row-normalized spatial weights matrix, based on 3 nearest neighbors, in triplet sparse form
## W_dnn: row-normalized spatial weights matrix, distance-based, in triplet sparse form
parsed = stanc(file = 'sdm.stan', verbose = TRUE)
@mbinna
mbinna / effective_modern_cmake.md
Last active May 1, 2024 12:35
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
@ChunMinChang
ChunMinChang / README.md
Last active August 29, 2019 04:46
A counter examples for writing a share library

Duplicate symbol when compiling

We will have duplicate symbol for architecture x86_64 when we compile the programs as follows:

$ g++ -c -Wall bye.cpp   # Generate bye.o
$ g++ -c -Wall hello.cpp # Generate hello.o
$ g++ -Wall main.cpp bye.o hello.o -o run
duplicate symbol __Z3LOGNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE in:
    bye.o
@thomasp85
thomasp85 / animate.R
Created February 3, 2016 19:43
Animating graph over time
library(ggraph)
library(gganimate)
library(igraph)
# Data from http://konect.uni-koblenz.de/networks/sociopatterns-infectious
infect <- read.table('out.sociopatterns-infectious', skip = 2, sep = ' ', stringsAsFactors = FALSE)
infect$V3 <- NULL
names(infect) <- c('from', 'to', 'time')
infect$timebins <- as.numeric(cut(infect$time, breaks = 100))
# We want that nice fading effect so we need to add extra data for the trailing
@mick001
mick001 / copulas_example.R
Last active April 15, 2023 09:17
Modelling dependence with copulas. Full article at: http://datascienceplus.com/modelling-dependence-with-copulas/
#Load library mass and set seed
library(MASS)
set.seed(100)
# We are going to use 3 random variables
m <- 3
# Number of samples to be drawn
n <- 2000
@kyrcha
kyrcha / sigmoid.R
Last active November 26, 2019 08:13
Fitting a sigmoind curve in R
# function needed for visualization purposes
sigmoid = function(params, x) {
params[1] / (1 + exp(-params[2] * (x - params[3])))
}
x = 1:53
y = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.18,0.18,0.18,0.33,0.33,0.33,0.33,0.41,
0.41,0.41,0.41,0.41,0.41,0.5,0.5,0.5,0.5,0.68,0.58,0.58,0.68,0.83,0.83,0.83,
0.74,0.74,0.74,0.83,0.83,0.9,0.9,0.9,1,1,1,1,1,1,1)
@jeroen
jeroen / fortran.R
Created September 16, 2015 10:11
Find CRAN packages with FORTRAN code
# Find all CRAN package with FORTRAN code
packages <- c()
base_url <- 'https://api.github.com/search/repositories?q=user:cran%20language:fortran'
for(page in 1:100){
url <- paste0(base_url, "&page=", page)
cat("Reading", url, "\n")
repos <- jsonlite::fromJSON(url)
if(!length(repos$items))
break
packages <- c(packages, repos$items$name)
abstract Person
type Adult <: Person
age::Int
height::Float64
position::Int
end
type Child <: Person
age::Int
@statguy
statguy / gist:3184ea6ff4ebb927c747
Last active February 16, 2018 16:50
INLA spatial parameters test
library(INLA)
m = 50
points = matrix(runif(m*2), m, 2)
mesh = inla.mesh.2d(loc=points,cutoff=0.05,offset=c(0.1, 0.4),max.edge=c(0.05, 0.5) )
bnd = inla.nonconvex.hull(points, convex=0.12)
mesh = inla.mesh.2d(boundary=bnd,cutoff=0.05,offset = c(1, 0.5),max.edge=c(0.1, 0.5) )
A = inla.spde.make.A(mesh, loc=points)
sigma0 = 1 ## Field std.dev. for theta=0
size = min(c(diff(range(mesh$loc[,1])), diff(range(mesh$loc[,2]))))
range0 = size/5 ## A fifth of the approximate domain width.