--
title: "Introduction to slimmmingDive"
author: "Fer Arce"
date: "r Sys.Date()
"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This is a minimal example to introduce the usage of slimmingDive with Southern elephant seals summarized dive information kindly provided by the Australian Integrated Marine Observing System (IMOS). It requires the external software JAGS (Just another Gibs sampler) to be installed or slimmingDive will fail to install.
slimmingDive is not on cran, so you need to download and install it
locally. You can also use either remotes
or devtools
packages.
## remotes::install_github('farcego/slimmingDive')
Load the package and the build-in data:
library(slimmingDive) data(ele)
These type of datasets tipically contain a large number of columns, innecesary to our purposes, so better to pre-process the data and get rid of them. This first step remove certain dives. First, it will remove dives shallower than 100 m depth and 300 s of duration. These are a minority of dives and it should not have an impact on drift dives. It will sort the data by date (it should be already sorted), andremove repeated rows (if any) and those with have certain errors like more than one inflection point at the same time.
ele <- formatDives(ele)
Next step is to otain the order in which the inflection points were generated onboard the tag, and the residual of the last point, as the drifing segment and drift rate toguether plus furter calculations depend on them.
ele[c('order','minresid')] <- t(apply(ele,1,RBSM,retrieve='both')) ele$minresid <- as.numeric(ele$minresid)
We can now generate the variables needed for the filtering process:
eleProc <- newVarsVect(Data)
And get the Drift rate estimate and drifting segment: This step could actually have been perform above, but as NDE needs explicitly imput from the variables we prefered to keep it separately)
eleProc[c('NDE','ds')] <- t(apply(eleProc,1,NDE, extract='both'))
We have a bunch of candidate drift dives with associated drift rates, but most of them are non drift dives and will be rejected at the next step:
plotDrift(eleProc, xlab = 'foraging days', ylab = 'Drift rate', cex.lab = 1.5, cex = 2)
to get ride of those that are certainly non drift dives, we pass a flexible filter based on the previously calculated variables:
D1 <- driftFilter(eleProc)
And we can see again how the drifting trajectory looks like:
plotDrift(D1, xlab = 'foraging days', ylab = 'Drift rate', cex.lab = 1.5, cex = 2)
A pattern aroses, but a last step is required to filter the unrealistic values still retained by the filtering process. Because it is time consuming, we can load the same seal but fully processed. The data cames cames as a list:
## if you want to run the kalman filter, uncomment the line below and run it. ## D2 <- kalman(D1,400000, 10000, n.adap = 10000) data(elek) ## class(elek) <- append(class(elek), 'kalman')
##load('../data/elek.RData') D2 <- postKalman(elek) ## At this point, we need to set a zeta threshold (Z = probability of ## a given drift rate being in the drifting trajectory of the ## seal. Most of the case, any value above 0.5 will yield indeitcal or ## close to identical results, as the distribution oz Z is storngly ## bimodal towards either 0 or 1. If there is going to be some ## smoothiing afterwards, I would guess that any value above 0.5 ## should yield practical identiocal fits
D2 <- D2[D2$zetas > .5, ] plotDrift(D2, xlab = 'foraging days',cex.lab = 1.5, cex = 2, ylab = 'Drift rate')
## And now we make the gam D3 <- makeTheGam(D2) plotDrift(D2, xlab = 'foraging days',cex.lab = 1.5, cex = 2, ylab = 'Drift rate') lapply(D3, function(fo){points(fo$Date, fo$pred, type = 'l', col = 'firebrick', lwd = 3)}) drift help('help') browseURL('drift')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.