Set up markdown format and image uploads.
Load required libraries
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.