This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Before running, load ecoregions, ecosections, bec, nr regions | |
-- to the db with the same schema.table name as in bcgw | |
-- This assumes using ogr2ogr for the load, it creates the objectid columns | |
-- ---------------------------- | |
-- first, overlay designatedlands with nr regions | |
-- ---------------------------- | |
DROP TABLE IF EXISTS nr_sub; | |
CREATE TABLE nr_sub AS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(dplyr) | |
library(fasterize) | |
shape <- "MULTIPOLYGON (((1126095 1246073, 1126221 1246053, 1126358 1246059, 1126383 1245909, 1126457 1245800, 1126605 1245831, 1126756 1245812, 1126812 1245652, 1126805 1245526, 1126841 1245377, 1126859 1245227, 1126868 1245077, 1126881 1244927, 1126949 1244805, 1126954 1244667, 1126806 1244635, 1126658 1244602, 1126508 1244591, 1126358 1244591, 1126283 1244701, 1126248 1244825, 1126256 1244951, 1126219 1245100, 1126197 1245249, 1126175 1245374, 1126145 1245498, 1126114 1245622, 1126025 1245743, 1125919 1245839, 1125803 1245897, 1125638 1245928, 1125547 1246037, 1125693 1246143, 1125842 1246150, 1126095 1246073)))" | |
tictoc::tic() | |
## Actually connect to the database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(gganimate) | |
library(mgcv) | |
library(mvtnorm) | |
# Fit a GAM to the data | |
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML") | |
# Get the linear prediction matrix | |
newdat = data.frame( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`derivSimulCI` <- function(mod, n = 200, eps = 1e-7, newdata, term, | |
samples = 10000) { | |
stopifnot(require("MASS")) | |
if(inherits(mod, "gamm")) | |
mod <- mod$gam | |
m.terms <- attr(terms(mod), "term.labels") | |
if(missing(newdata)) { | |
newD <- sapply(model.frame(mod)[, m.terms, drop = FALSE], | |
function(x) seq(min(x), max(x) - (2*eps), length = n)) | |
names(newD) <- m.terms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`simulate.gamm` <- function(object, nsim = 1, seed = NULL, newdata, | |
freq = FALSE, unconditional = FALSE, ...) { | |
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE)) | |
runif(1) | |
if (is.null(seed)) | |
RNGstate <- get(".Random.seed", envir = .GlobalEnv) | |
else { | |
R.seed <- get(".Random.seed", envir = .GlobalEnv) | |
set.seed(seed) | |
RNGstate <- structure(seed, kind = as.list(RNGkind())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## GOAL: | |
## re-create a figure similar to Fig. 2 in Wilson et al. (2018), | |
## Nature 554: 183-188. Available from: | |
## https://www.nature.com/articles/nature25479#s1 | |
## | |
## combines a boxplot (or violin) with the raw data, by splitting each | |
## category location in two (box on left, raw data on right) | |
# initial set-up ---------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install gdal, python, postgresql/postgis on Ubuntu 16.04 | |
# install dependencies | |
sudo apt install unzip | |
sudo apt-get update | |
sudo apt-get install python-pip | |
sudo add-apt-repository ppa:ubuntugis/ppa | |
sudo apt-get update | |
sudo apt-get install gdal-bin libgdal-dev | |
pip install --upgrade pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function git() { | |
for i do | |
lastArgument=$i # last argument can be the directory or the repository url | |
done | |
command git $@ | |
if [[ $? -eq 0 ]] # only show prompt if git command was successful | |
then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# bash prompt which asks for email address | |
# to configure for current git repository | |
# set your available emails | |
MAILS=([email protected] [email protected] [email protected]) | |
# prompt for email | |
echo |