inst/examples/fishcollapse_knit_.md

Warning Signals in Fish Collapse

Set up markdown format and image uploads.

Load required libraries

Load the data

Visualize data

Compute some indicators

Define some indicators <!--begin.rcode window_var <- function(X, windowsize=(length(X)/2)){ out <- sapply(0:(length(X)-windowsize), function(i){ var(X[(i+1):(i+windowsize)]) }) c(rep(NA, length(X)-length(out)), out) }

window_autocorr <- function(X, windowsize=(length(X)/2)){ out <-sapply(0:(length(X)-windowsize), function(i) acf(X[(i+1):(i+windowsize)], lag.max=1, plot=F)$acf[2]) c(rep(NA, length(X)-length(out)), out) } end.rcode-->

Reformat the data, uses data.table to perform computations over species <!--begin.rcode require(data.table) fish <- data.table(subset(dat_scotia, Year < 1992)) tmp <- data.frame(species = fish$variable, Year = fish$Year, Stock = fish$value, variance = fish[, window_var(value), by="variable"]$V1, acor = fish[, window_autocorr(value), by="variable"]$V1)

dat <- melt(tmp, id=c("Year", "species")) end.rcode-->

Cod are approaching a crash, but lobster are going strong, but both seem to show the same pattern.

Note the indicator patterns vary widly and rather arbitrarily among species



cboettig/warningsignals documentation built on May 13, 2019, 2:12 p.m.