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
# generate a random phylogenetic tree, then apply multidimensional | |
# scaling to the distances and see what the 2D plot looks like | |
library(ape) | |
layout(matrix(1:12, 3, 4, byrow=TRUE)) | |
for (i in 1:3){ | |
# generate a tree | |
rr <- rtree(20) |
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 using an MRF for ordered categorical predictors | |
library(mgcv) | |
# simulate some data... | |
set.seed(2) | |
dat <- gamSim(1,n=400,dist="normal",scale=2) | |
# fit a simple model |
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(ggplot2) | |
library(emoGG) | |
library(readr) | |
library(tidyr) | |
library(dplyr) | |
# let's visualise the content of season 1 of Bob Ross' The Joy of Painting | |
dat <- read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/bob-ross/elements-by-episode.csv") | |
# just get what we need and select season 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
Transect | CorMdA | distmm | ElMod | Hard | |
---|---|---|---|---|---|
1 | C | 0.015 | 5.3 | 0.13 | |
1 | C | 0.045 | 6.5 | 0.21 | |
1 | C | 0.06 | 6.7 | 0.19 | |
1 | C | 0.075 | 5.2 | 0.14 | |
1 | C | 0.195 | 7.1 | 0.14 | |
1 | C | 0.21 | 6.1 | 0.11 | |
1 | C | 0.225 | 5.6 | 0.1 | |
1 | C | 0.24 | 8 | 0.15 | |
1 | C | 0.255 | 7.5 | 0.15 |
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
# find bad variable/function names in a package | |
library(stringr) | |
# retrieve args and functions exported by a package | |
get_pkgdat <- function(pkgname){ | |
contents <- objects(paste0("package:", pkgname)) | |
fns <- Filter(function(x) is.function(eval(parse(text=x))), contents) |
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
# need to define half-normal point transect detection function pdf | |
dhnpt <<- nimbleFunction( | |
run = function(x = double(0), b0 = double(0), b1 = double(0), | |
covar = double(0), width = double(0), | |
log = integer(0, default = 0)) { | |
returnType(double(0)) | |
# calculate scale parameter | |
sigma <- exp(b0 + b1*covar) |
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
#' USFWS palette generator | |
#' | |
#' Palettes taken from https://www.instagram.com/p/CFP2H7JBSxR/ | |
#' | |
#' @param n Number of colours desired (max 5!). If omitted, uses all colours. | |
#' @param name one of "sockeye", "coaster", "dolly" or "florida" | |
#' @param type Either "continuous" or "discrete". Use continuous if you want | |
#' to automatically interpolate between colours. | |
#' @return A vector of colours. | |
#' @export |
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
# put all yr models in a list | |
model_list <- list(b_norm, b_term, b_term_sel) | |
# name them for nice labels | |
names(model_list) <- c("No selection", "Shrinkage smoother", "Extra penalty") | |
# all the terms (there's probably a gratia built-in for this) | |
term_list <- c("s(Depth)", "s(Bottom)", "s(Surface)") | |
library(gratia) | |
# pre-storage |
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 | |
# based on https://gist.github.com/dill/ecfe7d2f0e542bb274ff | |
# David L Miller 2020 | |
# 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) |
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
# extrapolating into the future with B-splines | |
# based on code in ?smooth.construct.bs.smooth.spec | |
library(mgcv) | |
# annual diameter of women’s skirts at the hem 1866 to 1911 | |
# Hipel and McLeod, 1994 | |
skirts <- scan("http://robjhyndman.com/tsdldata/roberts/skirts.dat",skip=5) | |
skirtseries <- data.frame(year=1866:1911, diam=skirts) |
NewerOlder