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
#Test case for calculating metabolism | |
library(LakeMetabolizer) | |
#set up test example where DO starts and ends at same level, is at saturation (= no flux) | |
DOobs = c(3, 2, 3, 4, 3, 2) | |
DOsat = c(3, 2, 3, 4, 3, 2) | |
kGas = c(.2, .2, .2, .2, .2, .2) | |
zMix = c(1, 1, 1, 1, 1, 1) | |
irr = c(0, 1, 1, 0, 0, 0) |
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
x = arima.sim(model=list(ar=0.9), n=200) | |
acf(x) | |
pacf(x |
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
#' Scatter plot with certain groups of points getting own regression and fitted line | |
#' | |
#' @param Data a data.table | |
#' @param x,y,lineBy character, name of column in \code{Data} | |
#' @param ptCol,lineCol character or quoted expression (call) for point or line color, repsectively | |
#' @param ... arguments to be passed to \code{\link{plot}} and \code{link{lines}} | |
#' | |
#' @examples | |
#' dt <- data.table( | |
#' x=x<-rnorm(9, sd=2), # why <- is better than = |
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
# ============================== | |
# = Simulating Spreading Range = | |
# ============================== | |
# ---- setup ---- | |
nspp <- 25 | |
nsite <- 25 | |
nr <- nsite | |
nc <- nspp | |
n_iter <- 25 |
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
nspp <- 10 | |
nsites <- 10 | |
Y_1sppPer <- diag(x=1, nrow=nspp, ncol=nsites) | |
Y_allSpp1Site <- rbind(rep(1,nspp), matrix(rep(0,nspp*nsites-nspp),nrow=nsites-1)) | |
# euclidean distance | |
euc <- function(x){ | |
sum(scale(x,scale=FALSE)^2)/(nrow(x)-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
library(reshape2) | |
hasDT <- library(data.table, logical.return=TRUE) # load package, if not installed return FALSE | |
# ================== | |
# = Make Fake Data = | |
# ================== | |
# ---- Options affecting size of 'big' ---- | |
nScaff <- 50 # number of scaffolds (or 'pages') | |
nIndex <- 100 # number of loci or indices (or 'words') |
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
la <- c(Okanagan=348, Seneca=173, Cayuga=172, Ballston=1.10884, Reindeer=5650, Somyn=NA, Thetis=8.336524, Manitoba=4624, Cold=373, Winnipegosis=5370, Crescent=18.401866, Simcoe=722, Muskrat=12.02, Superior=127700, Ontario=7340, Timiskaming=295, Memphremagog=110, Tahoe=490, Tarpon=10, Fulks=NA, Flathead=510, Hopatcong=10, Champlain=1331, Willoughby=1687, Erie=25667, Bear=280, Raystown=33.6, GreatSalt=4400, Arenal=85, NahuelHuapi=530, Dilolo=12.35, MamfePool=NA, DiloloSwamps=NA, Edward=2325, MaikaMarshes=NA, Victoria=68800, Makele=NA, Tangankyika=32900, Bangweulu=15100, KafueFlats=NA, Mweru=5120, IshibaNgandu=NA, Kariba=5580, Bassenthwaite=5.1, Ness=56, Morar=26.7, Maree=28.6, Lagarfljot=53, LoughLeane=19, Muckross=2.7, UpperLake=1.7, Como=146, Seljordsvatnet=16.7, Storsjon=464, Gryttjen=NA, Brosno=7.55, Labynkyr=61, LakeVan=3755, Kanas=45.73, TianChiHeaven=9.82, Ikeda=11, Kussharo=79.3, Pinatubo=1.83, Modewarre=NA, Utopia=14) # area in km^2; Dilolo I measured on google maps and I excluded the NE corner that lo |
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
# dev.new(width=3.5, height=3.5) | |
png("~/Desktop/test2.png", width=3.5, height=3.5, res=150, units='in') | |
par(mfrow=c(2,1), mar=c(2.5,2.5,0.25,2.5), ps=8, cex=1, mgp=c(1,0.25,0), tcl=-0.15) | |
plot(1:10, xlab="x", ylab="y", type='o') | |
par(new=TRUE) | |
plot(x=1:10, y=cumsum(rnorm(10)), xlab="", ylab="", type='o', col='red', xaxt="n", yaxt="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
### Get a list of all your installed packages (so that you can reinstall them after updating R) | |
a <- installed.packages() | |
my_pkgs <- dimnames(a)[[1]] | |
save(my_pkgs, file="my_pkgs.RData") | |
# exit R, reopen R, then continue to following | |
load("my_pkgs.RData") |
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
set.seed(1337) | |
mean_true_sppA <- 0.25 | |
mean_true_sppB <- 0.75 | |
grid_w <- 5 | |
grid_h <- 5 | |
environment <- seq(0.8, 1.2, length.out=grid_w*grid_h) # makes it so the 2 distributions are not independent | |
n_reps <- 20 | |
probs_true_sppA <- plogis(rnorm(grid_w*grid_h, qlogis(mean_true_sppA*environment))) # the GAM model estimates these values |
NewerOlder