Skip to content

Instantly share code, notes, and snippets.

View dsjohnson's full-sized avatar

Devin Johnson dsjohnson

  • NOAA Fisheries
  • Loveland, CO
  • 07:19 (UTC -06:00)
View GitHub Profile
@dsjohnson
dsjohnson / stpp_rsf_helper.R
Created December 11, 2013 21:17
Helper functions for analyzing animal telemetry data with point process models from Devin S. Johnson, Mevin B. Hooten, and Carey E. Kuhn (2013) Estimating animal resource selection from telemetry data using point process models. Journal of Animal Ecology 82:1155--1164.
## Spatio-temporal point process RSF helper functions
###
### Create spatial polygons object from a SpatialPoints object
###
voronoiPoly <- function(layer){
require(deldir)
require(sp)
crds <- layer@coords
z <- deldir(crds[,1], crds[,2], rw=as.vector(t(bbox(layer))))
@dsjohnson
dsjohnson / run_nfs_analysis_pop_INLA.R
Created December 11, 2013 21:26
Fur seal analysis from Devin S. Johnson, Mevin B. Hooten, and Carey E. Kuhn (2013) Estimating animal resource selection from telemetry data using point process models. Journal of Animal Ecology 82:1155--1164.
library(sp)
library(rgdal)
library(RColorBrewer)
library(spdep)
library(INLA)
library(grid)
library(gridExtra)
Greys <- colorRampPalette(brewer.pal(9,"Greys"))
#source("stpp_rsf_helper.R")
load("nfs_analysis/JAE_analysis_data_spatial.RData")
@dsjohnson
dsjohnson / run_nfs_analysis_indiv.R
Last active December 31, 2015 02:09
Individual space-time analysis of fur seal data from : Devin S. Johnson, Mevin B. Hooten, and Carey E. Kuhn (2013) Estimating animal resource selection from telemetry data using point process models. Journal of Animal Ecology 82:1155--1164
library(sp)
library(rgdal)
library(raster)
library(gstat)
library(rgeos)
library(automap)
library(mgcv)
source("stpp_rsf_helper.R")
load("nfs_analysis/JAE_analysis_data_st.RData")
# load("stQuadList_countVersion.RData")
@dsjohnson
dsjohnson / run_nfs_data_assimilation.R
Created December 11, 2013 21:30
Building data for fur seal analysis in: Devin S. Johnson, Mevin B. Hooten, and Carey E. Kuhn (2013) Estimating animal resource selection from telemetry data using point process models. Journal of Animal Ecology 82:1155--1164
library(sp)
library(rgdal)
library(raster)
library(gstat)
library(rgeos)
library(automap)
library(adehabitatHR)
source("stpp_rsf_helper.R")
# Read in telemtry
@dsjohnson
dsjohnson / NFS_CR_simulation.R
Last active January 2, 2016 20:39
Simulation of a Northern fur seal CR data set
library("marked")
#### Some preliminaries ###
ilogit = function(x){log(x/(1-x))}
min.adult.age=5
additional.resight=3
adult.age="stable"
set.seed(111)
n.rel.pup=c(138,57,38,250,rep(100,4))
@dsjohnson
dsjohnson / R symlinks
Last active August 29, 2015 14:00
Symliks to add for R 3.1.0 (Mavericks version) to run and compile packages
@dsjohnson
dsjohnson / logistic_funcs.R
Last active November 9, 2015 19:46
Fit logistic growth model like "nlsList" but allow user to specify a design matrix for each parameter
### New growth function
logistic_growth = function(x, phi1, phi2, phi3){
phi1/(1 + exp(-(x-phi2)/phi3))
}
ll_logistic = function(par, y, xvar, phi1_dm, phi2_dm, phi3_dm, sigma_dm, sigma=1, predict=FALSE, scale=-2){
n1 = ncol(phi1_dm)
n2 = ncol(phi2_dm)
n3 = ncol(phi3_dm)
if(!missing(sigma_dm)) n4 = ncol(sigma_dm)
library(rstan)
devtools::source_gist("8f675b9aa74ab9900fb4")
load("Sig_test_DJ.RData")
data = all_model
data$Year = factor(data$Year)
data = droplevels(data)
### Add beach variables
data$Beach4 = ifelse(data$Beach=="4", 1, 0)
data$Beach7 = ifelse(data$Beach=="7", 1, 0)
@dsjohnson
dsjohnson / logistic_analysis_stan_summary.R
Created November 13, 2015 19:18
Summary of logistic growth MCMC output from stan
library(cowplot)
library(coda)
load("Sig_test_DJ.RData")
data = all_model
data$Year = factor(data$Year)
data = droplevels(data)
### Add beach variables
data$Beach4 = ifelse(data$Beach=="4", 1, 0)
data$Beach7 = ifelse(data$Beach=="7", 1, 0)
### Load packages ###
# Must have 'marked' v >= 1.1.8
library(marked)
# The splines package is only necessary for fitting b-spline curves used in the paper
# It is not required for the multivate models in the marked package
library(splines)
### Import and process data ###