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
# get UN resolutions | |
# Annoyingly the UN website is not very crawl-able. | |
# Using RSelenium you can download Resolution data | |
library(RSelenium) | |
library(stringr) | |
# download directory | |
dl_dir <- path.expand("~/Downloads/UN69/") |
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
## This is a very silly script to get JSON data for an R twitter bot that produces | |
## tweets of the form "verb that noun" using verbs from package:base and nouns from | |
## built in R data. | |
## | |
## It uses @v21's http://cheapbotsdonequick.com/ | |
## | |
## David L. Miller 2015 MIT license | |
## update from Nick Golding 2018 | |
cat("{\n") |
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(rphylopic) | |
# get a (sperm) whale! (this is "Physeter catodon" by Noah Schlottman) | |
# http://phylopic.org/image/dc76cbdb-dba5-4d8f-8cf3-809515c30dbd/ | |
whale <- image_data("dc76cbdb-dba5-4d8f-8cf3-809515c30dbd", size=512) | |
# failwhale | |
image(whale[[1]][,,4]) |
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
# makes plots (somewhat) like those in ver Hoef and Boveng (2007) | |
# Jay M. Ver Hoef and Peter L. Boveng 2007. QUASI-POISSON VS. NEGATIVE BINOMIAL REGRESSION: HOW SHOULD WE MODEL OVERDISPERSED COUNT DATA? Ecology 88:2766–2772. http://dx.doi.org/10.1890/07-0043.1 | |
# http://www.utstat.utoronto.ca/reid/sta2201s/QUASI-POISSON.pdf | |
# calling with something like: | |
# par(mfrow=c(1,2)) | |
# # define the breaks |
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
# Markov Random Fields with temporal interactions | |
# David L Miller 2015 | |
# Released under MIT license, YMMV | |
# example from ?mgcv::smooth.construct.mrf.smooth.spec | |
library(mgcv) | |
## Load Columbus Ohio crime data (see ?columbus for details and credits) | |
data(columb) ## 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
# David L Miller 2015, MIT license | |
library(numDeriv) | |
library(animation) | |
# function taken from the "Gu & Wahba 4 term additive example" from mgcv::gamSim | |
f2 <- function(x) 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10 | |
xvals <- seq(0,1,len=100) |
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
# example from ?mgcv::concurvity | |
library(mgcv) | |
## simulate data with concurvity... | |
set.seed(8);n<- 200 | |
f2 <- function(x) 0.2 * x^11 * (10 * (1 - x))^6 + 10 * | |
(10 * x)^3 * (1 - x)^10 | |
t <- sort(runif(n)) ## first covariate | |
## make covariate x a smooth function of t + noise... | |
x <- f2(t) + rnorm(n)*3 |
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
# plot of size versus distance and sea state versus distance | |
# w. linear model and LOESS smoother overlay | |
# base graphics | |
par(mfrow=c(1,2)) | |
plot(distdata[c("size","distance")], xlab="Group size", ylab="Distance (m)",pch=19,col=rgb(0,0,0,0.4), cex=0.6) | |
# increase span from default 0.75 for slightly smoother curve | |
lo <- loess(distance ~ size, distdata, span=0.8) | |
lmm <- lm(distance ~ size, distdata) | |
preddat <- data.frame(size=seq(0,8,1)) |
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
### analysis of ribbon seal data using a frequentist | |
### approach to a GAM | |
### David L Miller dave@ninepointeightone.net | |
### License: GNU GPL v3 | |
# load data from | |
# https://github.com/pconn/SpatPred/blob/master/SpatPred/data/Ribbon_data.rda | |
load("Ribbon_data.rda") |
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
load("best_model.Rdata") | |
library(dsm) | |
library(raster) | |
# lazily get the plot data for the rug plot | |
plotdat <- plot(M) | |
# load the raster and mudge it into the format I want | |
dists <- stack("NA_Shore_Dist_10km_mean_10km.img") | |
dists <- as.data.frame(dists) |