# The package requires the packages TMB (available from tmb-project.org) and mvtnorm (available from CRAN). It is very important that the operating system specific instructions are followed for installing TMB. # When these packages are installed, argosTrack can be installed with # install.packages("argosTrack.tar.gz",repos=NULL,type="source") # if the file "argosTrack.tar.gz is in the working directory. # On Windows, it may be necessary to run "library(TMB)" first. library(argosTrack) # This example uses the subadult ringed seal data dat <- subadult_ringed_seal # To use the adult seal data run the line below without the "#" # dat <- adult_ringed_seal # We declare the arguments to pass to the model: # lon is the longitude from the data # lat is the latitude from the data # dates is the time stamps for the observations # locationclass is the location class for the observations # verbose = FALSE reduces the output written to the terminal during estimation # errordistribution = "t" specifies that the measurement errors should be modelled as t distributed # dfMap = factor(1:7) specifies that the degrees of freedom should be estimated for each location class. As default classes with less than 20 observations are grouped with the better location class # timeunit determines the unit to be used when the time difference is calculated between observations. The default is minutes. args <- list(lon = dat$lon, lat = dat$lat, dates = as.character(dat$date), locationclass = dat$lc, verbose=FALSE, errordistribution="t", dfMap = factor(1:7), timeunit = "hours" ) # To estimate run: fitobj <- do.call(argosTrack,args) # Print the result to the terminal fitobj summary(fitobj) # Plot the result plot(fitobj) # To estimate with Gaussian measurement erros use errordistribution="n" args <- list(lon = dat$lon, lat = dat$lat, dates = as.character(dat$date), locationclass = dat$lc, verbose=FALSE, errordistribution="n", timeunit = "hours" ) fitobjn <- do.call(argosTrack,args) fitobjn plot(fitobjn) # The model can be estimated with different betas and different gammas by equalbetas = FALSE and fixgammas=FALSE args <- list(lon = dat$lon, lat = dat$lat, dates = as.character(dat$date), locationclass = dat$lc, verbose=FALSE, equalbetas=FALSE, fixgammas=FALSE, errordistribution="n", timeunit = "hours" ) fitobj <- do.call(argosTrack,args) fitobj plot(fitobj) # To simulate from the model use simdat <- simulate(fitobj) plot(t(simdat$observation)[,2:1],pch=16,col=simdat$locationclass) lines(t(simdat$position)[,2:1]) # The include argument can be used to exclude observations (by e.g. a swim speed filter) and still estimate the true location at that time point. To exclude observations 10-20 use incl <- rep(TRUE,length(dat$lon)) incl[10:20] <- FALSE args <- list(lon = dat$lon, lat = dat$lat, dates = as.character(dat$date), locationclass = dat$lc, verbose=FALSE, include=incl, errordistribution="n", timeunit = "hours" ) fitobjrm <- do.call(argosTrack,args) fitobjrm par(mfrow=c(1,2)) plot(fitobjrm$observations[1,1:40],pch=16,col=incl[1:40]+1,ylab="Latitude") lines(fitobjrm$positions[1,1:40]) lines(fitobjn$positions[1,1:40],lty=2) legend("topleft",legend=c("Full data","Reduced"),lty=c(2,1)) plot(fitobjrm$observations[2,1:40],pch=16,col=incl[1:40]+1,ylab="Longitude") lines(fitobjrm$positions[2,1:40]) lines(fitobjn$positions[2,1:40],lty=2) legend("topleft",legend=c("included","not included"),col=c(2,1),pch=16)