calbertsen / argosTrack

R package for fitting animal movement models to Argos (or other types of location) data
12 stars 7 forks source link

error running vignette examples #3

Closed florianorgeret closed 5 years ago

florianorgeret commented 5 years ago

Good day, I am not able to run the code example argosTrack.R that I found in the supplementary of the Ecology2015 paper with the subadult_ringed_seal dataset here http://esapubs.org/archive/ecol/E096/229/suppl-1.php even if TMB run properly in my computer. The error appears when trying to fit the argosTrack function fitobj <- do.call(argosTrack,args) and get "Error in as.character(sys.call(sys.parent())[[1L]]) : cannot coerce type 'closure' to vector of type 'character' "

R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit)

Thank you for your help and your work on this package best regards

calbertsen commented 5 years ago

The package changed substantially from version 0.1.1 to version 1.0.0, so the code example from the Ecology paper only works up to version 0.1.1.The package version archived in the supplementary material is 0.0.2. You get the error because the argosTrack function is now defunct.

You can either install an early version of the package to run the code or modify the code to work with the new package versions. Information on how to use the new package versions can be found in the package vignette and in

help("argosTrack-defunct")

An updated version of the script (working with argosTrack version 1.2.1 - commit 9c42fb6ab5bdd6252b7f203bb3ed26e210b09030; make sure you update to this version) would look something like this:

library(argosTrack)
dat <- subadult_ringed_seal

obs <- Observation(lat = dat$lat,
                   lon = dat$lon,
                   dates = as.POSIXct(dat$date),
                   locationclass = dat$lc)
mov <- CTCRW(dates = unique(as.POSIXct(dat$date)),
             timeunit = "hours")
meas <- Measurement("t")

anim <- Animal(obs, mov, meas)

# To estimate run:
fitTrack(anim, equaldecay = TRUE, fixdrift = TRUE, inner.control = list(maxit = 100))

# Print the result to the terminal
anim

# Plot the result
plot(anim)

## To estimate with Gaussian measurement
movn <- CTCRW(dates = unique(as.POSIXct(dat$date)),
             timeunit = "hours")
measn <- Measurement("n")

animn <- Animal(obs, movn, measn)
fitTrack(animn, equaldecay = TRUE, fixdrift = TRUE)
animn
plot(animn)

# The model can be estimated with different betas and different gammas
movn2 <- CTCRW(dates = unique(as.POSIXct(dat$date)),
             timeunit = "hours")
measn2 <- Measurement("n")

animn2 <- Animal(obs, movn2, measn2)
fitTrack(animn2)
animn2

# To simulate from the model use
simdat <- simTrack(anim,1)

par(mfrow=c(1,1))
plot(t(simdat[,1]$Y[1:2,]),type="p")
lines(t(simdat[,1]$X[1:2,]))

plot(simdat[,1]$Animal)

# The include argument can be used to exclude observations 
incl <- rep(TRUE,length(dat$lon))
incl[10:20] <- FALSE

obsrm <- Observation(lat = dat$lat,
                   lon = dat$lon,
                   dates = as.POSIXct(dat$date),
                   locationclass = dat$lc,
                   include = incl)
movrm <- CTCRW(dates = unique(as.POSIXct(dat$date)),
             timeunit = "hours")
measrm <- Measurement("n")

animrm <- Animal(obsrm, movrm, measrm)

fitTrack(animrm, equaldecay = TRUE, fixdrift = TRUE)
plotLat(animrm, sd = TRUE, obsArgs = list(col = c("purple","black")[as.integer(incl)+1]))
plotLon(animrm, sd = TRUE, obsArgs = list(col = c("purple","black")[as.integer(incl)+1]))

There may be differences in the results.