This file contains hidden or 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
| #' Read JHo | |
| #' | |
| #' Read in a file formatted like Jennifer's data sets | |
| #' | |
| #' @param file a character indicating the file name (and possibly path) | |
| #' @param n_nrows integer indicating number of rows for each matrix | |
| #' @param n_matrices integer indicating number of matrices in the file | |
| #' @param n_comment integer indicating the number of comment lines preceding each matrix of data; should include blank lines | |
| #' @param n_top_comment integer indicating the number of comment lines that are unique to the start of the file; default is 0 lines | |
| #' @param ... arguments to be passed to \code{scan}, such as \code{what=numeric()} and \code{sep=","} |
This file contains hidden or 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
| # ============ | |
| # = Packages = | |
| # ============ | |
| # to do everything in this script, make sure the following packages are installed | |
| # install.packages(c("rgenoud", "strucchange")) | |
| # ============= | |
| # = Functions = |
This file contains hidden or 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("data.table") | |
| load("clean.neus.RData") | |
| s2c <- function (x, type = "list") | |
| { | |
| as.call(lapply(c(type, x), as.symbol)) | |
| } | |
| colsuwant <- c("depth","btemp","stemp","bsalin","ssalin") | |
| jho_cneus <- clean.neus[spp=="Paralichthys dentatus", structure(lapply(eval(s2c(colsuwant)),meanna, na.rm=TRUE),.Names=colsuwant),by=c("reg","datetime","year","stratum","lon","lat","haulid","season","station","spp","common")] | |
| setkey(jho_cneus, datetime, year, stratum, station) |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |