GithubHelp home page GithubHelp logo

ianjonsen / animotum Goto Github PK

View Code? Open in Web Editor NEW
36.0 6.0 13.0 194.94 MB

fit latent variable movement models to animal tracking data

Home Page: https://ianjonsen.github.io/aniMotum/

License: Other

R 6.29% C++ 0.40% HTML 93.31%
animal-movement animal-tracking r-package random-effects-model state-space-models tmb

animotum's Introduction

{aniMotum}

fit latent variable movement models to animal tracking data for location quality control and behavioural inference

aniMotum status badge Coverage status DOI R-CMD-check

{aniMotum} is an R package that fits continuous-time models in state-space form to filter error-prone animal movement data obtained via the Argos satellite system, and to estimate changes in movement behaviour. Template Model Builder {TMB} is used for fast estimation. Argos data can be either (older) Least Squares-based locations, (newer) Kalman Filter-based locations with error ellipse information, or a mixture of the two. The state-space models estimate two sets of location states: 1) corresponding to each observation, which are usually irregularly timed (fitted states); and 2) corresponding to (usually) regular time intervals specified by the user (predicted states). Locations are returned as both LongLat and on the Mercator projection (units=km). The models may be applied with appropriate caution to tracking data obtained from other systems, such as GPS and light-level geolocations.

Installation

First, ensure you have R version >= 4.0.0 installed (preferably R 4.2.0 or higher):

R.Version()

From R-Universe

As of v1.1, {aniMotum} is available via R-Universe. This is where the latest stable version can always be found. If you are on Mac or Windows and are certain you have the correct compilation tools and libraries installed (See From GitHub (source) below), then installation is:

# install from my R-universe repository
install.packages("aniMotum", 
                 repos = c("https://cloud.r-project.org",
                 "https://ianjonsen.r-universe.dev"),
                 dependencies = TRUE)

This installs all Imported and Suggested R packages from CRAN and R-universe. If queried, answer Yes to install the source version. Note, if you haven’t installed {aniMotum} previously then installation of dependent packages may take a while, especially if many of them need to be compiled. You should only need to go through this once, subsequent installation of {aniMotum} updates will be much faster.

To avoid typing the above every time you want to update {aniMotum}, you can add my R-Universe repo to your local list of repositories for package download in your .Rprofile. This ensures install.packages automatically grabs the latest version of {aniMotum}

#install.packages("usethis")
usethis::edit_r_profile()

# add the following text or replace existing repos option
options(repos = c(ianjonsen = 'https://ianjonsen.r-universe.dev',
                  CRAN = 'https://cloud.r-project.org'))

READ THIS CAREFULLY if you are unsure about compiler tools:

If you don’t have compiler tools installed, are uncertain if you do, or have trouble getting them to work then you can manually download a binary version of the {aniMotum} package for Windows or Mac from here https://ianjonsen.r-universe.dev/ui#package:aniMotum. There are 3 binary versions for Windows corresponding to a different major release of R, choose the one that matches your R version. You can check your R version by typing R.Version() in the R console. There are 4 binary versions for Macs, 2 for Arm 64 Macs (ie. M1 - Mx Macs) and 2 for Intel Macs (x86_64), within these 2 classes there are 2 versions for the latest release version of R and the previous version.

When downloading the binary version on a Mac, it is important to right click and choose “Download Linked File As…” so that the file isn’t automatically uncompressed. If you have downloaded the file correctly, its extension will be .tgz, not .tar. You can use the following command in the R console to install the file you’ve just downloaded (where path_to_file is wherever you saved the download):

# for Windows
install.packages("path_to_file\aniMotum_1.2-05.zip", 
                 repos=NULL, type="win.binary", dependencies = TRUE)

# for Mac
install.packages("path_to_file/aniMotum_1.2-05.tgz", 
                 repos=NULL, type="mac.binary", dependencies = TRUE)

Alternatively, in RStudio, you can use the GUI by clicking the Packages tab and then the Install button:

This will open an install box, where you want to select “Package Archive File (.tgz, .tar.gz)” option under “Install from:”. On a Mac, this looks like the following (Windows will be similar):

Then, click the “Browse” button to navigate to wherever you saved the .zip (Windows) or .tgz (Mac) binary file and click “Install”.

From GitHub (source)

If you prefer installing from GitHub via remotes::install_github() and know your way around the installation of compilers and associated libraries, then you will need to ensure you have the proper compilation tools and libraries installed.

On PC’s running Windows, ensure you have installed Rtools.

On Mac’s, ensure you have installed the Command Line Tools for Xcode by executing xcode-select --install in the terminal; or you can download the latest version from the URL (free developer registration may be required). A full Xcode install uses up a lot of disk space and is not required. Also, ensure you have a suitable Gnu Fortran compiler installed. The easiest install option is to download a compiled version from here https://github.com/fxcoudert/gfortran-for-macOS/releases. Just make sure you choose the version that matches your MacOS and processor (Intel vs Arm 64).

remotes::install_github("ianjonsen/aniMotum")

Note: there can be issues getting compilers to work properly. Often, this is due to missing or incorrect Xcode Command Line Tools and/or Fortran compiler. If you encounter install and compile issues, you may find a solution in the excellent documentation here glmmTMB.

If you don’t have the time & patience for sorting out compiler/library issues then just install the appropriate binary version. aniMotum models may not fit quite as fast as they could on your setup, but they will still be fast. We’re talking about differences of milliseconds to a few seconds per animal track, so you decide where your time is best spent!

Usage

{aniMotum} is intended to be as easy to use as possible. Here’s a simple example showing how to fit a move persistence state-space model to Argos tracking data and visualise the result:

library(aniMotum)

fit <- fit_ssm(sese, 
               vmax= 4, 
               model = "mp", 
               time.step = 24, 
               control = ssm_control(verbose = 0))

plot(fit, type = 3, pages = 1, ncol = 2)

map(fit, 
    what = "predicted", 
    crs = "+proj=stere +lon_0=68 +units=km +datum=WGS84")

Southern elephant seal silhouettes kindly provided by:

  • female southern elephant seal, Sophia Volzke (@SophiaVolzke, University of Tasmania)
  • male southern elephant seal, Anton Van de Putte (@AntonArctica, Université Libre de Bruxelles)

What to do if you encounter a problem

If you are convinced you have encountered a bug or unexpected/inconsistent behaviour when using {aniMotum}, you can post an issue here. First, have a read through the posted issues to see if others have encountered the same problem and whether a solution has been offered. You can reply to an existing issue if you have the same problem and have more details to share or you can submit a new issue. To submit an issue, you will need to clearly describe the unexpected behaviour, include a reproducible example with a small dataset, clearly describe what you expected to happen (but didn’t), and (ideally) post a few screenshots/images that nicely illustrate the problem.

How to Contribute

Contributions from anyone in the Movement Ecology/Bio-Logging communities are welcome. Consider submitting a feature request here to start a discussion. Alternatively, if your idea is well-developed then you can submit a pull request for evaluation here. Unsure about what all this means but still want to discuss your idea? then have a look through the GitHub pages of community-built R packages like tidyverse/dplyr for examples.

Code of Conduct

Please note that the aniMotum project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Acknowledgements

Development of this R package was funded by a consortium of partners including:

  • Macquarie University
  • US Office of Naval Research (ONR Marine Mammal Biology;grant N00014-18-1-2405)
  • Australia’s Integrated Marine Observing System (IMOS)
  • Canada’s Ocean Tracking Network (OTN)
  • Taronga Conservation Society
  • Birds Canada
  • Innovasea/Vemco
    Additional support was provided by France’s Centre de Synthèse et d’Analyse sur la Biodiversite, part of the Fondation pour la Recherche sur la Biodiversité.

Example southern elephant seal data included in the package were sourced from the IMOS Animal Tracking Facility. IMOS is a national collaborative research infrastructure, supported by the Australian Government and operated by a consortium of institutions as an unincorporated joint venture, with the University of Tasmania as Lead Agent. IMOS supported elephant seal fieldwork on Iles Kerguelen conducted as part of the IPEV program No 109 (PI H. Weimerskirch) and the SNO-MEMO program (PI C. Guinet). SMRU SRDL-CTD tags were partly funded by CNES-TOSCA and IMOS. All tagging procedures were approved and executed under University of Tasmania Animal Ethics Committee guidelines.

Animal silhouettes used in the aniMotum logo were obtained and modified from sources:

  • southern elephant seal, Anton Van de Putte (@AntonArctica, Université Libre de Bruxelles)
  • humpback whale, Chris Huh via Phylopic.org Creative Commons Attribution-ShareAlike 3.0 Unported
  • mallard duck, Maija Karala via Phylopic.org Creative Commons Attribution-ShareAlike 3.0 Unported
  • leatherback turtle, James R. Spotila & Ray Chatterji via Phylopic.org Public Domain Dedication 1.0
  • white shark, Margo Michaud via Phylopic.org Public Domain Dedication 1.0
  • king penguin, Steven Traver via Phylopic.org Public Domain Dedication 1.0

animotum's People

Contributors

ianjonsen avatar jamesgrecian avatar jganong avatar romainfrancois avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

animotum's Issues

Track segment anomalies when using CRW

Hi there,

I fitted an ssm model with crw on 100 seal Argos locs to filter the data.

  fit <- foieGras::fit_ssm(d = dt, time.step  = time.step, model = "crw", vmax = 4)

with R (version 3.6.3) and:

foieGras      0.4.01-3   2020-04-03 [1] Github (ianjonsen/foieGras@35f87db) 

Overall the fit seems appropriate. See an example here:

goo_track

However, in some case, especially when the seal track has segments with low loc densities, some anomalies appear which are unlikely representing the true seal movement. See an example here (red arrows are pointing these anomalies):

Bad_1

Bad_2

As an example, here the dataset of the seal F06-B-18_1 showed above:

F06-B-18_1_data.txt

And the results of the model fit:

Process model: crw 
Time interval: 1 hours 
number of observations: 4566 
number of regularised state estimates: 1885 

parameter estimates
-------------------
      Estimate Std. Error
D        5.290      0.119
rho_o    0.187      0.026
tau      0.067      0.001
tau      0.059      0.001
psi      8.083      0.977
-------------------
negative log-likelihood: 2067.689 
convergence: CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH 

I feel this issue appears in track segments when locations are at very low density. I guess that the correlation value is to high for these segments and results in some track anomalies/deviations. Yes I could just use a random walk model but is there a way to control and lower the correlation value or have a correlation value that is adjusted according to time difference between locations?

I tried this to set the initial value of Rho_o:

  fit <- foieGras::fit_ssm(d = dt, 
           time.step  = time.step, 
           model = "crw", 
           vmax = 4, 
            parameters = list(rho_o = 0.1))

But I've got this error:

fitting SSM...
Error in x$data : $ operator is invalid for atomic vectors
In addition: Warning message:
In MakeADFun(data, parameters, map = map, random = rnd, hessian = FALSE,  :
  Expected object. Got NULL.

Not sure how to specify initial values of parameters.

Any suggestions or recommendations of how to fix this?

Thanks so much.

Hassen

supplying a tibble of prediction times yields a single prediction

Describe the bug
supplying a tibble of prediction times yields a single prediction. sfilter() takes only the SECOND date from the tibble to use for prediction times.

To Reproduce
data(ellie)
ts <- tibble(id = rep(ellie$id[1], 100), date = sample_n(ellie, 100, replace=F)$date %>% sort())
fit <- fit_ssm(ellie, model="crw", time.step = ts)
fit$ssm[[1]]$predicted

Expected behavior
predicted locations should include all times provided in the ts tibble

Desktop (please complete the following information):

  • OS: MacOS 10.14.3
  • RStudio
  • R Version 3.5.2

Huge outliers

Hi Ian

I fit GPS locations (error < 100 m) to the foieGras model without too much trouble, except that the location output of some individuals exhibit a large outlier that deviates 500-1500 km from its neighbors. Interestingly, most of these outliers occur on day 2 (model timestep is 24 h).

fit=fit_ssm(data, model='crw', vmax=3, time.step=24)

The same tracks put through the speed filter, but not the SSM, exhibit no such outliers. I have included some example maps. Any thoughts?

Cheers

Malcolm

SSMOutlierMap-1
SSMOutlierMap-2
SSMOutlierMap-5

fit_mpm failing due to issue with select()

Describe the bug
Issue running jmpm model in fit_mpm. In the following, plocs is a data frame with 10 unique IDs. You can see the function pushes a weird error about how it expected to get only 1 value for model convergence instead of 10 (which is obviously not right because we expect 10, 1 for each unique ID).

mpm_fit <- foieGras::fit_mpm(plocs[,c('id','date','lon','lat')], model = 'jmpm')

fitting mpm...
Error: Column `converged` must be length 1 (the group size), not 10

Potential solution
I went into the fit_mpm code and changed the two instances of select() from dplyr to actually specify dplyr::select() and now the function works as expected. I've had other issues like this with some of the dplyr functions lately as if other functions (maybe in tidyverse?) are over-riding dplyr functions by the same name.

Package `foieGras` archived on CRAN and will be removed from the Tracking CTV

(Note: It is not clear to me whether aniMotum has simply replaced foieGras, so please don't hesitate to correct me here)

The package foieGras has been archived on CRAN for 60 days, and you are listed as the maintainer. This message is to let you know that your package is currently listed in the Tracking CRAN Task View, but is flagged as "Archived", which means it will not get installed automatically with the CTV.

If the problem on your package persists for another 4 weeks, and the package is not reinstated on CRAN, it will also be removed from the Tracking CTV. Details of the situation can be found here.

It seems to us that the main issue was that a dependency (package trip) was no longer available on CRAN. However, trip has been reinstated on CRAN since then, and it is not clear to us if there are other blocking issues. Reinstating foieGras itself on CRAN might not be too complicated in the end.

Of course, if you are able to fix the problems of the package after it has been removed from the Tracking CTV, you can always ask for reinstatement in the Tracking CTV. In the meanwhile, please feel free to respond to this message or, better, to comment on the issue above.

Best,
For the Tracking CTV maintainers,
Mathieu Basille

Longitudes unwrap when individuals cross the date line

When an individual's track crosses the date line (-180/+180), the fitted output is 'unwrapped' (i.e., has longitudes greater than 180 degrees). Should the interanl function wrap_lon be called in fit_ssm?

library(lubridate)
library(foieGras)
track <- data.frame(id = "bird",
                    date = seq(ymd_hms("2012-01-01 12:00:00"), ymd_hms("2012-01-03 12:00:00"), length.out = 40),
                    lc = "3",
                    lon = c(seq(150, 179, length.out = 20), seq(-179, -150, length.out = 20)),
                    lat = seq(-30, - 60, length.out = 40)
                    )

plot(track$lon, track$lat)

fit.track <- fit_ssm(track, time.step = 3, vmax = 1000)

plot(fit.track$ssm[[1]]$predicted$lon, fit.track$ssm[[1]]$predicted$lat)

fit_ssm() returns empty tibble & warnings when pf = TRUE

Describe the bug
Using fit_ssm just to pre-filter data via the pf = TRUE argument causes the following warning:
Warning messages:
1: Unknown or uninitialised column: 'data'.
2: Unknown or uninitialised column: 'data'.
3: Unknown or uninitialised column: 'data'.

and returns a 0x0 tibble

To Reproduce
data(rope)
fit <- fit_ssm(rope, min.dt = 180, vmax = 5, pf = TRUE)

Expected behavior
with pf = TRUE argument, fit_ssm should return a sf tibble with the same number of rows as the input data

error with map function

I have been using aniMotum this last week and after fitting a model I was making maps with the map function. Everything was working earlier in the week, but for the last few days, using the exact same code/script and keep getting the error:
Error in map(fit.rw, what = "predicted") :
argument ".f" is missing, with no default

I have tried to restart R and my computer multiple times. I have checked my code from everything I can find the code is correct.
Below is an example of the code - everything seems to work but the map function. I am sure I am doing something silly, but have not been able to figure out what has changed.
fit.crw <- fit_ssm(data_c,
model = "crw",
time.step = 3,
vmax=4,
control = ssm_control(se = TRUE))

plot(fit.crw, what = "fitted")
plot(fit.crw, what = "predicted")
plot(fit.crw, "p", type = 2, alpha = 0.1)

require(patchwork)
res.crw <- osar(fit.crw)
(plot(res.crw, type = "ts") | plot(res.crw, type = "qq")) /
(plot(res.crw, type = "acf") | plot_spacer())

map(fit.crw, what = "predicted")
map(fit.crw, what = "fitted")

installation and library(aniMotum) on M2 MBP

Hi. I tried to install the M1/M2 binary in RStudio following the directions you detail on the homepage. I am running a 2022/23 M2 MacBook Pro running Ventura 13.3. When I try to call library(aniMotum) I receive the following error:

Error: package or namespace load failed for ‘aniMotum’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so': dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so, 0x0006): Library not loaded: /opt/R/arm64/gfortran/lib/libgomp.1.dylib Referenced from: <B51A8EC6-9771-364E-92F3-500E0B19F3DC> /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so Reason: tried: '/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/usr/local/lib/libgomp.1.dylib' (no such file), '/usr/lib/libgomp.1.dylib' (no such file, not in dyld cache) In addition: Warning message: In checkMatrixPackageVersion() : Package version inconsistency detected. TMB was built with Matrix version 1.5.3 Current Matrix version is 1.5.1 Please re-install 'TMB' from source using install.packages('TMB', type = 'source') or ask CRAN for a binary version of 'TMB' matching CRAN's 'Matrix' package

I've made sure to have R ver. 4.2.2 and the latest version of R Studio installed and running. I restarted my environment, R session, computer, basically everything that I can restart and I'm still not able to attach aniMotum to my working environment. I've also been able to install gcc using my terminal and installed the packages TMB and glmmTMB. I'm not quite sure where to go from here and was hoping you might have some insight.

min.dt likely not working as intended

Hello!

The min.dt argument does not seem to work as intended, at least not the way I expected it to work. Instead of keeping all observations that will be at least separated by the specified time gap, it seems to filter out all locations having neighbouring locations with the specified time gap. This discards whole blocks of consecutive observations where several could be retained if only some observations were discarded. Perhaps the filtering is done on the result of a diff? Here is an example of what is kept win a min.dt = 72 hours. Only the ones with diff >= min.dt are kept, but several more could have been kept.

library(aniMotum)

step<-as.difftime(72,units="hours")

fit <- fit_ssm(ellie, 
               vmax = Inf, 
               ang=c(180,180),
               distlim = c(Inf, Inf),
               min.dt=as.numeric(step,units="secs"), 
               model = "crw", 
               time.step = 24, 
               control = ssm_control(verbose = 0)
              ) 

res<-grab(fit,"fitted")
nrow(res)
## [1] 6

m<-match(res$date,ellie$date)

c(NA,diff(ellie$date))
##  [1]       NA  23.76139  23.46556  16.99889  31.07861  19.71444  23.75889  27.15667  34.18917  23.91389  33.04583  47.29444
##  [13]  37.40750  26.82000  28.38111  26.45139  24.20083  22.06111  35.18556  25.62111  35.27667  28.55083  35.88028  30.36000
##  [25]  46.05861  27.46583  38.02083  33.67778  28.73806  41.37528  31.91194  41.69694  45.99000  46.97639  51.59778  41.30556
##  [37]  26.26028  25.50528  39.25556  52.79083  34.16806  42.31444  49.82639  28.74806  58.45861  51.70111  28.90222  50.58556
##  [49]  67.34806  42.93167  25.25472  52.13417  59.22444  58.19111  60.65667  69.71639  53.87000  60.23778  61.93556  77.85444
##  [61]  84.40944 116.21694  85.85556  84.90222

c(NA,diff(ellie$date))[m]
## [1]        NA  77.85444  84.40944 116.21694  85.85556  84.90222

res$date
## [1] "2012-03-05 05:09:33 UTC" "2012-06-09 14:25:11 UTC" "2012-06-13 02:49:45 UTC" "2012-06-17 23:02:46 UTC" "2012-06-## 21 12:54:06 UTC"
## [6] "2012-06-25 01:48:14 UTC"

ellie$date[m]
## [1] "2012-03-05 05:09:33 UTC" "2012-06-09 14:25:11 UTC" "2012-06-13 02:49:45 UTC" "2012-06-17 23:02:46 UTC" "2012-06-## 21 12:54:06 UTC"
## [6] "2012-06-25 01:48:14 UTC"

I haven't thought yet of an efficient way to keep all observations that will respect the min.dt threshold.

Happy holidays!
François

Error ellipses around mapped estimated locations

foieGras should provide the option to visualise estimation uncertainty when plotting maps of estimated tracks. The code to do this was used in Jonsen et al. 2020 and could be generalised for the fmap function and/or plot method (when type = 2).

Error ellipses would look like this, with appropriate alpha level so overlying point estimates are not obscured.
error_ellipses

Coastline Not Mapping in fmap

For an unknown reason, large sections of the North American coastline are not mapping correctly using the fmap function. The locations of the fit_ssm output are mapped correctly, including dates and error ellipses, but much of the northern hemisphere is not. I have tried several different dependencies for the fmap function (e.g., rgeos, geos, ggmap) but nothing seems to fix it. I would very much like to use these maps. Based on the shading, I am guessing something is wrong with how the function is processing land cover, perhaps related the crossing the date line in the map? Unsure. Any help would be appreciated! Below is the code I am using and a representative figure.

library(dplyr)
library(foieGras)
library(lubridate)
library(ggmap)
library(ggplot2)
library(ggsn)

#read in raw data, organize

sheardata<-na.omit(read.csv("SOSH_GLS_filtered.csv"))
sheardata$Tag<-as.factor(sheardata$Tag)
sheardata$Band<-as.factor(sheardata$Band)
sheardata$TOPPID<-as.factor(sheardata$TOPPID)
sheardata$Date<-as.POSIXct(sheardata$Date, format = "%m/%d/%y")
sheardata$Date<-sheardata$Date + hours(12) + minutes(00) + seconds(00)
colnames(sheardata)<-c("Species","DepID","Band","GLSNum","Date","Long","Lat")

#make data compatible with package
#error estimates from Shaffer et al 2005
fgshear<-sheardata[,c(2,5:7)]
colnames(fgshear)<-c("id","date","lon","lat")
fgshear$lc<-as.character("GL")
fgshear<-fgshear %>% relocate(lc, .before = lon)
fgshear$lonerr<-1.68
fgshear$laterr<-1.95

#fit CRW SSM to one example bird
onebirdexample<-fgshear[fgshear$id == "3105004",]
onebirdexample$id<-as.character(onebirdexample$id)
fitwater<-fit_ssm(onebirdexample, model = "crw", time.step = 24, vmax = 12.5)
fitwater

#plot example
plot(fitwater, what = "predicted", type = 1, pages = 1)
plot(fitwater, what = "fitted", type = 2, pages = 1)
fmap(fitwater, what = "fitted")

Rplot

fmap() not working on a single individual.

When I tried running the fmap() function on data for a single individual. It would plot all data points in the same colour and no index would appear.
Both the fit_ssm and the fit_mpm worked fine and when the fit_mpm was plotted the colour of the graph was varied and the index also appeared.

I tried joining the ssm and mpm manually as following

#joining movement persistence values to location values
fmp_loc <- foieGras::join(my_ssm,my_mpm, as_sf=F)

#Then plot, color by movement persistence
ggplot(fmp_locs) +
geom_point(aes(lon, lat, colour = g)) +
scale_colour_viridis_c(limits = c(0,1))

And this worked fine.

I also tried to do all of it with the example data in the package, ellie and ellies and that also had the same problem with fmap working fine on ellies, but only giving a single colour and no index on ellie.

I have added some screenshots and a copy of the script (with ellie and ellies) below.

Desktop

  • macOS Catalina 10.15.6
  • RStudio, version 1.3.1093

Rplot1
Rplot2
Rplot3
Rplot4

library(ggplot2)
library(ggmap)
library(ggsn)
library(foieGras)
library(dplyr)

#importing the data from within foiegras
data(ellie, package = "foieGras")
head(data.frame(ellie))

data(ellies, package = "foieGras")
head(data.frame(ellies))

#fit example with 2 elephant seals
data("ellies")
fit2 <- fit_ssm(ellies, model = "crw", time.step = 24, verbose = 0)
fit2$ssm[1]
#plotting graphs
plot(fit2, what = "predicted", type = 1)
plot(fit2, what = "fitted", type = 2)

#fit example with 1 elephant seal
fit1<- fit_ssm(ellie, model = "rw", time.step = 48, verbose = 0)
plot(fit1, what = "predicted", type = 1)
plot(fit1, what = "fitted", type = 2)
#plotting graphs
plot(fit1, what = "predicted", type = 1)
plot(fit1, what = "fitted", type = 2)

#for two elephant seals
fmp2 <- fit2 %>%
grab(what = "predicted", as_sf = FALSE) %>%
select(id, date, lon, lat) %>%
fit_mpm(model = "jmpm", verbose = 0)
plot(fmp2)
#Joining ssm and mpm and plotting on a map
fmap(fit2, fmp2, what = "predicted", crs = "+proj=stere +lon_0=99 +units=km +ellps=WGS84")

#for one elephant seal
fmp1 <- fit1 %>%
grab(what = "predicted", as_sf = FALSE) %>%
select(id, date, lon, lat) %>%
fit_mpm(model = "mpm", verbose = 0)
plot(fmp1)

#Joining ssm and mpm and plotting on a map (doesn't work on a single individual)
fmap(fit1, fmp1, what = "predicted", crs = "+proj=stere +lon_0=99 +units=km +ellps=WGS84")

duplicated date-time policy

I started to compare some trip stuff with foieGras and ran into the ole duplicated times thing in the ellie data - what do you generally do about that? What happens with dividing by zero durations and so forth? I noticed long ago that argosfilter just fudges over it with an epsilon but I consider that a mistake. ??

Combine Argos and GPS locations to fit ssm

Hi,

I have GPS and Argos locations on the same individuals. Is there a way to combine both (Argos and GPS) location types to fit a continuous ssm (with foieGras::fit_ssm()) to improve the filter of Argos locations and have a better overall track estimation?

Maybe including GPS locs as Argos with quality 3 and adjust error parameters accordingly (smaj, smin, and eor)?

Thanks!

not sure if bug or system issue

I am trying to run the following example code from the help file associated with the format_data function:

data(sese2_n)
head(sese2_n, 5)
d <- format_data(sese2_n, date = "time", coord = c("longitude","latitude"), tz = "America/Halifax")
fit <- fit_ssm(d, model = "crw", time.step = 24)

I got the following error:
fitting crw SSM to 2 tracks...
pars: 1 1 0 0 -1.82873 0 Error in nlminb(obj$par, ifelse(control$verbose == 1, myfn, obj$fn), obj$gr, :
NA/NaN gradient evaluation

Error in updateCholesky(L, hessian.random) :
function 'sexp_as_cholmod_sparse' not provided by package 'Matrix'
Error in rep$pdHess : $ operator is invalid for atomic vectors

Anyone else experiencing this or can provide some insight? Is this an issue on my end or is this a bug with the code?

Error in if (p.GL > 0.75) { : missing value where TRUE/FALSE needed

Hi Ian,

I'm trying to fit the SSM model to my GPS tracking data (for a seabird species) but I keep getting this error:
Error in if (p.GL > 0.75) { : missing value where TRUE/FALSE needed
I'm not sure what argument I'm not supplying

Here's a subset of my data:
Cleaned_GullTrackssubset.csv
df <- read.csv("Cleaned_GullTrackssubset.csv", row.names = FALSE)

I have tried various iterations of the arguments:
fitRw <- fit_ssm(df, model = "rw", time.step = NA)
fitCrw<- fit_ssm(df, model = "crw", time.step = NA)
fitMp <- fit_ssm(df, vmax = 5, model = "mp", time.step = NA,
control = ssm_control(verbose = 1))

I even tried to force the data into the right format, but still getting that error

d <- format_data(df, date = "date", coord = c("lon","lat"),
tz = "UTC")

fit <- fit_ssm(d, model = "crw", time.step = 24)

Could you please help me with figuring out what the problem is?

Thank you,
Esther

Addressing data gaps

Hi,

in my data set of tracked marine non-air breathing animals, I have data gaps of up to ~60 days. Is there a way to set a maximum time between relocations (let's say 10 days) for interpolation?

Cheers
Ingo

generic plotting/mapping functions for fit_mpm objects

unlike fG_ssm fit objects, no generic methods exist for fG_mpm fit objects.

  • should we include a 1-d time series plot function along with a mapping function?
  • how do we map location + behavioural index uncertainties?
    mpm

errors when running fit_ssm in animotum

Hi Ian
I have tried running fit_ssm for a 4 day track of a little penguin. I tried running the model with both a 1 hour time step and a 4 hour time step, and with and without the control option.
I got these two errors
Error in nlminb(obj$par, ifelse(control$verbose == 1, myfn, obj$fn), obj$gr, :
NA/NaN gradient evaluation

Error in updateCholesky(L, hessian.random) :
function 'sexp_as_cholmod_sparse' not provided by package 'Matrix'
Error: $ operator is invalid for atomic vectors

Here is my code

d <- read.csv("549470_GI_nb9_220815-220817_lotek_withTemp.csv")
d$date<-as.POSIXct(paste(d$UTC_Date, d$UTC_Time), format="%d/%m/%Y %H:%M:%S")
colnames(d)
str(d)
d$Tag_ID<-"549470"

head (d)
d<-d[,c(1,14,6,4,5,11,12,13)]

d2<-d%>%
filter(!is.na(Longitude))
head(d2)
locs<-format_data (d2, id="Tag_ID",lc="LQ", coord = c("Longitude","Latitude"),
epar=c("SemiMajor", "SemiMinor", "Orientation"))

head(locs)
fit <- fit_ssm(locs,
model = "crw",
time.step = 4,
vmax = 3,
control=ssm_control(verbose=1))

Here is my data

549470_GI_nb9_220815-220817_lotek_withTemp.csv

Desktop (please complete the following information):

  • OS: Windows 7, Ubuntu 16.04]
  • RStudio, 2023.09.1
  • R Version 4.2.0

When I do load all the packages i get several warnings that many of the packages were built undedr R 4.2.3
require(ggspatial)
Loading required package: ggspatial
Warning message:
package ‘ggspatial’ was built under R version 4.2.3

require(patchwork)
Loading required package: patchwork
Warning message:
package ‘patchwork’ was built under R version 4.2.3
require(sf)
Loading required package: sf
Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
Warning message:
package ‘sf’ was built under R version 4.2.3
require(aniMotum)
Loading required package: aniMotum

Attaching package: ‘aniMotum’

The following object is masked from ‘package:purrr’:

map

Warning message:
package ‘aniMotum’ was built under R version 4.2.3

As it is mentioned on github that R version >= 4.0.0 (preferably R 4.2.0 or higher), I didn't think it was likely that this would cause an issue.

Can you please advise what the errors are due to.

Cheers
Belinda

map fit_ssm

Describe the bug
Hi, I am new to using aniMotum (coming from foiegras) so I am trying on one individual. Not sure if this is an easier fix than I realize..

Followed example of elephant seals

When using the map function with my 'fit' it produces a model not in the right geographic location as the data inputted.

Snippet of data used:
Screen Shot 2023-02-21 at 1 40 51 PM

  • Code from fit and map*
    fit <- fit_ssm(df2,
    vmax= 1000,
    model = "mp",
    time.step = 8,
    control = ssm_control(verbose = 1))

map(fit, what="p")

Expected behavior
Map where the latitude and longitude are in the same geographic location as the original data.
(Should be off the US East Coast)

Expected map: **** Please note, different data and this used foiegras package. ****

Screen Shot 2023-02-21 at 1 45 52 PM

Screenshots of what is produced
Screen Shot 2023-02-21 at 1 36 59 PM

Perhaps I am just not understanding the map() function within aniMotum, maybe it's a matter of establishing boundaries or something else? I have not been able to figure it out. Any help is much appreciated to troubleshoot!
Thank you in advance for any advice.

Missing packages for Mac M1 binary?

Hi. I succeeded in installing aniMotum from source, but I wanted to let you know that I initially was unable to install aniMotum using your Mac M1 binary) on a Mac M1 running MacOS Sonoma (14.4.1), with R version 4.3.3 ("Angel Food Cake") and RStudio. I thought I had followed the instructions, but I got the following error:

install.packages(".../Downloads/aniMotum_1.1-04.tgz", repos=NULL, type="mac.binary", dependencies = TRUE)  
library(aniMotum)  
## Error: package or namespace load failed for ‘aniMotum’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), 
## versionCheck = vI[[j]]):  there is no package called ‘CircStats’

I installed CircStats and then about 7 more missing packages including TMB, broom, mtvnorm, patchwork, rnaturalearth, tmvtnorm, and traipse. Then I got this version error for TMB:

## Warning message:
## In checkTMBPackageVersion() : Package version inconsistency detected.
## aniMotum was built with TMB version 1.9.2
## Current TMB version is 1.9.11
## Please re-install 'aniMotum' from source using install.packages('aniMotum', type = 'source') or remove your current ## TMB version and re-install using remotes::install_version('TMB', version = '1.9.2')

At that point, I switched to installing from source, which worked.

optim() error

I upgraded to version 0.4.0 from CRAN and nowfit_ssm throws the following error for some of the tracks I've been working with but which are OK in version 0.2.2. I've attached an example and added details below. Any thoughts are appreciated!

## Error in optim(par = c(logD = 10, l_psi = 0), fn = function (x = last.par[-random],  : 
##  L-BFGS-B needs finite values of 'fn'

A short example (data: movedat.txt):

library(foieGras)
m1 <- read.table("movedat.txt", header = TRUE, sep = ',', stringsAsFactors = FALSE)
m1$date	<- as.POSIXct(m1$date, tz = "UTC")

# make a prediction df
dd <- as.numeric(m1$date)
step <- 6*60*60 # seconds

predtimes <- seq(
  ceiling(min(dd) / step) * step,
  floor  (max(dd) / step) * step,
  by = step
)

p1 <- data.frame(
  id = m1$id[1], 
  date = as.POSIXct(predtimes, tz = "UTC", origin = "1970-01-01")
)

# generate fit
fit <- foieGras::fit_ssm(
  m1,
  model = "crw",
  time.step = p1
)
## pre-filtering data...
## fitting SSM...
## Error in optim(par = c(logD = 10, l_psi = 0), fn = function (x = last.par[-random],  : 
##  L-BFGS-B needs finite values of 'fn'

And here is my session info.

sessionInfo()
## R version 3.6.2 (2019-12-12)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Catalina 10.15.2

## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     

## other attached packages:
## [1] foieGras_0.4.0

## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.3         pillar_1.4.3       compiler_3.6.2    
##  [4] TMB_1.7.16         class_7.3-15       tools_3.6.2       
##  [7] digest_0.6.23      lubridate_1.7.4    tibble_2.1.3      
## [10] lifecycle_0.1.0    gtable_0.3.0       lattice_0.20-38   
## [13] pkgconfig_2.0.3    rlang_0.4.3        Matrix_1.2-18     
## [16] DBI_1.1.0          parallel_3.6.2     e1071_1.7-3       
## [19] gridExtra_2.3      argosfilter_0.63   furrr_0.1.0       
## [22] dplyr_0.8.3        stringr_1.4.0      vctrs_0.2.2       
## [25] globals_0.12.5     classInt_0.4-2     grid_3.6.2        
## [28] tidyselect_0.2.5   glue_1.3.1         listenv_0.8.0     
## [31] sf_0.8-0           R6_2.4.1           tidyr_1.0.2       
## [34] ggplot2_3.2.1      purrr_0.3.3        magrittr_1.5      
## [37] units_0.6-5        scales_1.1.0       codetools_0.2-16  
## [40] assertthat_0.2.1   future_1.16.0      colorspace_1.4-1  
## [43] KernSmooth_2.23-16 stringi_1.4.3      lazyeval_0.2.2    
## [46] munsell_0.5.0      crayon_1.3.4 

ssm projection

Hi Ian

I want to use x.se and y.se, from the fit_ssm output to calculate the edge of the error ellipse around each data point.

grab output

out <- foieGras::fit_ssm(...)
ssm <- foieGras::grab(out, “predicted”, as_sf = FALSE)

track coordinates

ssm$lon # or ssm$x
ssm$lat # or ssm$y

find edges of ellipse

ssm$lon2 <- ssm$x+ssm$x.se
ssm$lat2 <- ssm$y+ssm$y.se
xy <- as.matrix(ssm[c('lon2', 'lat2')])
proj4string <- as.character(CRS('+init=EPSG:4326'))
ssm$lon2 <- project(xy, proj4string, inv=TRUE)[,1] # edge of ellipse along lon axis
ssm$lat2 <- project(xy, proj4string, inv=TRUE)[,2] # edge of ellipse along lat axis

However, the track data and coordinates of the 'ellipse boundaries' appear to have different projections.

ssm[,c('lon','lat','lon2','lat2')]
lon lat lon2 lat2
1 -26.01687 5.600394 75.76054 35587.20
2 -26.17290 5.237531 -55.06476 36493.35
3 -26.30081 4.958494 -10.90205 34711.58
4 -26.84735 4.559007 -136.02852 32288.30
5 -27.05270 4.411449 72.44271 32046.08
6 -27.31685 4.221786 -55.77494 30812.26
7 -27.58099 4.032076 -114.66851 28310.99
8 -27.87863 3.681396 43.44134 23356.09
9 -27.57547 3.946964 82.59072 27578.42
10 -26.80854 4.600780 121.77401 30990.43
11 -25.65469 5.361667 -146.98428 36572.13
12 -25.29457 5.653881 -74.58530 37407.11
13 -24.98268 5.881524 -81.03987 39731.08
14 -24.78388 6.113966 -20.48755 40574.67
15 -25.24602 6.174506 89.12844 41328.01
16 -25.69252 6.105850 -66.64888 40847.09
17 -25.80649 5.875334 -95.19035 40497.73
18 -25.91273 5.497413 111.19606 38681.79
19 -25.99331 5.248576 104.58948 36843.61
20 -26.32641 4.761293 147.82622 34288.65
21 -26.55639 4.434251 -84.89157 31936.47
22 -27.02737 3.970427 100.31919 29876.73
23 -27.49835 3.506338 -87.91668 27056.50
24 -27.96933 3.042016 -82.58127 23543.93
25 -28.07799 2.887690 -164.90769 22149.28
26 -27.53539 3.085527 -98.08894 23024.86
27 -27.31244 3.138100 -54.01810 22570.34
28 -27.35467 2.920236 166.46369 20728.95
29 -27.44570 2.669940 -101.61275 18425.00
30 -28.19315 2.157776 -163.50920 17065.89
31 -28.94061 1.645436 -50.06504 13281.10
32 -29.44954 1.324774 -54.04135 10655.61
33 -29.67303 1.185742 -102.63438 10013.83

Any help is greatly appreciated

Cheers

Malcolm

Error with sim_fit() using different gradient raster

Describe the bug
I am trying to run the sim_fit() function while supplying my own distance gradient raster like so:

sim_fit(ssm_crw, what = "predicted", grad = dist_grad_stack, beta = c(-300, -300), reps = 100)

but, I am getting this error Error in if (mu[2] < y_rng[1]) { : missing value where TRUE/FALSE needed.

To Reproduce
I created a gradient raster using terra::distance and converted it to a raster stack with two identical layers. It looks like this:

> dist_grad_stack
class      : RasterStack 
dimensions : 120, 144, 17280, 2  (nrow, ncol, ncell, nlayers)
resolution : 0.25, 0.25  (x, y)
extent     : -146, -110, 24, 54  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
names      : layer.1, layer.2 
min values :       0,       0 
max values : 1856233, 1856233 

I ran the function as described above and it generates the described error. When I use the grad file that is supplied with the package, the function runs as expected.

Desktop:

  • OS: Windows 10
  • RStudio
  • R Version 4.3.0

Failing to fit jmpm model

Hi Ian,

I'm working with shark Argos tracking data. I have no problems when trying to fit the crw model to the data using the function fit_ssm as follows:

fit <- fit_ssm(tbl, vmax = 2, ang = c(15, 25), model = "crw", time.step = 12, 
           control = ssm_control(se=FALSE))

But when I try to fit the jmpm model (as the selected mpm model) for one species using the function fit_mpm, I get an error. This is the code for the fit_mpm function I used and the error I got:

 fmp <- fit_mpm(fit, optim = "optim", what = "predicted", model = "jmpm", control = mpm_control(verbose = 0), coords=4:5)



 Error in nlminb(obj$par, ifelse(control$verbose == 1, myfn, obj$fn), obj$gr,  : 
  NA/NaN gradient evaluation

 Error in optimHess(par.fixed, obj$fn, obj$gr) : 
  gradient in optim evaluated to length 1 not 3

From reading the package manual, I think that it might have something to do with the control argument, but I'm not sure why nor how to fix it.

When I run the code for each track separately, I don't get any errors. Within the data set, there are tracks with quite different longitude data (ranging from ~-80º to 8º). I don't know if that is also a problem when analyzing all tracks together.

This is my first time analyzing this type of data and I am quite inexperienced with R, so I would appreciate any help.

Paola

Error in FUN(X[[i]], ...) : !anyNA(x) is not TRUE

I have a data frame in with multiple individuals. It looks like this:

    id                date             lc   lon         lat
1 Iris 2017-05-07 22:26:42  G -53.1867 69.2288
2 Iris 2017-05-08 00:48:20  G -53.0257 69.2377
3 Iris 2017-05-08 07:27:27  G -52.9513 69.2776
4 Iris 2017-05-08 08:20:10  G -52.9172 69.2785
5 Iris 2017-05-08 12:07:35  G -53.0159 69.2895
6 Iris 2017-05-08 12:47:04  G -53.0486 69.2759

I can fit a crw to this data and it gives me an fG_ssm object. Now the problem is when I try and plot or fit the mpm the following happens:

> plot(fit,type=2,what="fitted")
Error in FUN(X[[i]], ...) : !anyNA(x) is not TRUE

I have tested that this error does not occur when running the fits on the example data "sese". Also there are no NA's for me to find anywhere in the fit (particularly not under the predicted).

osar function not finishing the run

Hello, I attended a seminar given today by @jamesgrecian and I tried the code after the seminar because I had issues with installing TBM it seems, and I was only able to fit an ssm after the seminar.

I have followed the tutorial here https://github.com/eco4cast/Statistical-Methods-Seminar-Series/tree/main/grecian-aniMotum

but I get stuck at
res <- aniMotum::osar(fit)
using the harp seal dataset of 3 individuals.

My last attempt has been running for 2 hours and never stopped or had an error. The fit model from the fit_ssm() comes from the same dataset and it runs in 30 seconds. I do not know if this is bug in itself of just performance issues of my computer.

My computer specs here:
Processor Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz 2.40 GHz
Installed RAM 16.0 GB (15.8 GB usable)
System type 64-bit operating system, x64-based processor

And my Rversion
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 3.1
year 2023
month 06
day 16
svn rev 84548
language R
version.string R version 4.3.1 (2023-06-16 ucrt)
nickname Beagle Scouts

I would like to run the code on my own data, but I wonder what the issue is with this function. Thanks!

Error in strsplit(names(map), "_") : non-character argument

The bug
I am trying to run the move persistence models on a bunch of albatross tracks. I have some slightly "messy" data that I am using to see how/where things don't work. I am able to fit the crw and then mpm separately on two tracks, but when I try to run the models together on the working track I get the following error:
Error in strsplit(names(map), "_") : non-character argument

To Reproduce
Data file:
MovePersist_exampledata.csv

str(tracks_mp)
'data.frame': 6515 obs. of 5 variables:
$ id : chr "MIAT19_3" "MIAT19_3" "MIAT19_3" "MIAT19_3" ...
$ date: POSIXct, format: "2019-01-31 03:16:54" "2019-01-31 03:17:57" ...
$ lc : chr "G" "G" "G" "G" ...
$ lon : num -177 -177 -177 -177 -177 ...
$ lat : num 28.2 28.2 28.2 28.2 28.2 ...

CODE:
library(aniMotum)
library(dplyr)
library(ggplot2)
library(lubridate)

tracks_mp<-read.csv(MovePersist_exampledata.csv")
tracks_mp$date<-ymd_hms(tracks_mp$date)
str(tracks_mp)

wrap360 = function(lon) {lon360<-ifelse(lon<0,lon+360,lon);return(lon360)}

#quick visual of the three tracks
ggplot()+
geom_path(data=tracks_mp,aes(x=wrap360(lon),y=lat,group=id, color=id))

##Slightly messy data for testing:
#MIAT19_3 - crosses 180 & has long colony time not trimmed from track <-mpm not converging
#MIAT23_103 - crosses 180 & has three trips + colony time in the middle
#MIAT23_65 - no 180 cross, 1 long trip, mpm converging when crw & mp are run separately, but fails when run together

fit_crw <- fit_ssm(tracks_mp,
model = "crw",
vmax = 30,
time.step=.16,
control = ssm_control(verbose = 0)) #all converged ==true

fit_crw
summary(fit_crw)
plot(fit_crw, what = "fitted", type = 1, pages = 1)
plot(fit_crw, what = "predicted", type = 2, pages = 1) #all good!

fmp <- fit_mpm(fit_crw,
what = "predicted",
model = "mpm",
control = mpm_control(verbose = 0))

#Error in nlminb(obj$par, ifelse(control$verbose == 1, myfn, obj$fn), obj$gr, :NA/NaN gradient evaluation

#A tibble: 3 × 4
#id mpm converged model
#
#1 MIAT19_3 <try-errr [1]> FALSE mpm
#2 MIAT23_103 <mpm [8]> TRUE mpm
#3 MIAT23_65 <mpm [8]> TRUE mpm

#OK - so the tracks were a bit messy, so more data cleaning is clearly needed, but MIAT23_65 & MIAT23_103 were OK for both models above.

#all of the tracks fail when put in together
fit <- fit_ssm(tracks_mp,
vmax = 30,
model = "mp",
time.step = .16,
control = ssm_control(verbose = 0))
#Error in strsplit(names(map), "_") : non-character argument

#but so does MIAT23_65. Same thing with MIAT23_103
tracks_mp_65<-tracks_mp%>%filter(id=="MIAT23_65")
str(tracks_mp_65)
fit <- fit_ssm(tracks_mp_65,
vmax = 30,
model = "mp",
time.step = .16,
control = ssm_control(verbose = 0))
#Error in strsplit(names(map), "_") : non-character argument

Desktop

  • OS: MacOS 12.7.2
  • RStudio: Version 2023.06.1+524 (2023.06.1+524)
  • R Version: #R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
  • AniMomentum: 1.2-02
  • TMB 1.9.10

Allow non POSIX date sequences

Is your feature request related to a problem? Please describe.

When im specifying the Argos date into POSIX format the date time combination of "25/03/2018 01:42" is returning NA with as.POSIXct(). With as.POSIXlt() the "correct" date string is returned, however, oddly is.na() returns NA for that entry (not others).

I suspect this is due to some timezone/clock changing thing in the study region.

This doesn't seem to cause any particular issues with foiegras itself.

However, I would like to use an irregular time interval within the time.step argument, which has a POSIX requirement.
When generating the time interval I would like to use, this POSIX related NA problem is causing some problems.

Describe the solution you'd like

It would be useful if I could define an arbitrary time sequence to define record order within the time.step argument

Describe alternatives you've considered
N/A

Additional context
N/A

pDHess in fit object sometimes returns as named list

pdHess should always return TRUE or FALSE depending on whether TMB was able to solve the Hessian matrix and obtain standard errors. In some cases, (tested on RAATD MAPE data) a named list is returned with the logical (or a NULL in case of optimizer crash) as the single list element. We shouldn't have a named list here so investigate why that happens sometimes

plot returns error without advice

when f <- fit_ssm(data, model, time.step = NA) and plot(f, "predicted") is called, the error informs that predicted location do not exist because time.step = NA but this should either advise the appropriate call: plot(f, "fitted") or we should drop the error and automatically handle within call so that plot defaults to fitted values, throwing a message to console

when none of the input locations from any of the tracks are on land, route_path fails

When none of the locations from any of the tracks given to route_path are on land, route_path fails with the error message:
<simpleError in pathroutr::prt_visgraph(land_region, ...):barrier must be a simple feature collection with geometry type 'POLYGON' or 'MULTIPOLYGON>
If any of the paths have a point on land, this error does not occur.600

To Reproduce
library(data.table)
library(aniMotum)
toy_df=fread("id,date,lc,lon,lat
666,2003-06-27T12:08:11Z,1,-135.313,30.781
666,2003-06-29T08:47:31Z,A,-124.953,34.213
666,2003-07-01T03:23:14Z,B,-120.765,32.255
666,2003-07-01T08:03:51Z,B,-120.851,32.129
666,2003-07-01T11:21:58Z,A,-121.017,32.124
666,2003-07-01T13:02:27Z,B,-121.386,32.008
666,2003-07-02T01:29:54Z,A,-149.794,37.857
666,2003-07-02T04:44:40Z,A,-121.204,31.929
666,2003-07-02T05:03:28Z,B,-121.638,32.014
666,2003-07-02T06:00:16Z,0,-120.907,31.637
") # all these points are not on land
fit_rw=fit_ssm(x=toy_df,model='rw',time.step=24)
fit_rw_reroute=route_path(fit_rw)

results in the following error

Error in pathroutr::prt_visgraph(land_region, ...) :
barrier must be a simple feature collection with geometry type 'POLYGON' or 'MULTIPOLYGON

Expected behavior
Instead of crashing, route_path() should return the locations unchanged, if there are no points on land.
This is easier for users of the data, rather than having to be aware of this issue and check two places (fit_rw and fit_rw_reroute)

Desktop (please complete the following information):

  • OS: Arch Linux
  • R in a terminal
  • R Version 4.2.2

Additional context
If just one track in a collection of tracks has no points on land, and other tracks do have points on land, this bug is not triggered.
I am going to put in a pull request shortly.

Crossing 0 longitude

When individuals cross 0 degree longitude, the estimated locations are at -180/+180 longitude.

Fix for #2 might have caused a new issue.

[lmsa.zip](https://github.com/ianjonsen/foieGras/files/2850289/lmsa.zip)

library(foieGras)
library(dplyr)

dat <- read.csv("lmsa.csv") #in zip file attached.

output <- foieGras::fit_ssm(d = select(dat, id, date, lc, lon, lat),
                            vmax = 36,
                            min.dt = 120,
                            time.step = 2)

plot(output$ssm[[1]], est = "predicted")

Issue in installing foieGras package in RStudio

I have a dataset that needs to undergo regularization before being analyzed with moveHMM. I am trying to install the foieGras package into R studio but am receiving the following error:

>` install.packages("foieGras", depedencies = c("Imports","LinkingTo","Suggests"))
Installing package into ‘C:/Users/bhamilton/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘foieGras’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I am running the latest version of R (4.3.2) on Windows 10 in R Studio.

Based the foieGras vignette (https://www.rdocumentation.org/packages/foieGras/versions/0.7-6) suggestion of having R version >= 3.6.0 installed (preferably R 4.0.0 or higher), I should be able to use this package. What am I missing?

Errors fitting GPS data version 0.4.0

Hi Ian,
Not a bug most likely user error!
I am getting the following error when I try to fit GPS data

fit_ssm(gps,vmax = 3,model = "crw",time.step = 10)

pre-filtering data...

fitting SSM...
Error in optim(par = c(logD = 10, l_rho_o = 0), fn = function (x = last.par[-random], :
L-BFGS-B needs finite values of 'fn'
Error in optimHess(par.fixed, obj$fn, obj$gr) :
gradient in optim evaluated to length 1 not 2

A tibble: 1 x 3

id ssm converged

1 W8254 FALSE

Any pointers appreciated!

Cheers

Iain Staniland

Desktop :

  • Windows 10
  • RStudio
  • R VersionR-3.6.1

FoiegrasGPS.zip

Error loading `foieGras` for M1/M2 chip macs

Hi Ian, I'm using foiegras as part of a practical class for students and those who are using the newer macs with M1 or M2 chips are getting this error when they run library(foieGras)

Error: package or namespace load failed for ‘foieGras’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/gmm/libs/gmm.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2/Resources/library/gmm/libs/gmm.so, 0x0006): Library not loaded: /usr/local/gfortran/lib/libgomp.1.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/gmm/libs/gmm.so
  Reason: tried: '/usr/local/gfortran/lib/libgomp.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/Library/Frameworks/R.framework/Resources/lib/libgomp.1.dylib' (no such file), '/Users/kaitlyn/lib/libgomp.1.dylib' (no such file), '/usr/local/lib/libgomp.1.dylib' (no such file), '/usr/lib/libgomp.1.dylib' (no such file), '/lib/libgomp.1.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libgomp.1.dylib' (no such file), '/va

Not all of them have the exact same error (some more than others), but the common error among them is this part:

Error: package or namespace load failed for ‘foieGras’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/gmm/libs/gmm.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.2/Resources/library/gmm/libs/gmm.so, 0x0006): Library not loaded: /usr/local/gfortran/lib/libgomp.1.dylib
  • OS: MacOS >= 12 (Monterey)
  • RStudio (latest version RStudio Desktop 2022.07.1+554)
  • R Version (4.2)

Issue with grad object for sim_fit()

I'm having an issue with the gradient object used for simulations. Same error occurs even if I rebuild the grad object as you previously described in one of the (now closed) issues on GH. See below. Thanks!

library(aniMotum)
## fit ellie
fit <- fit_ssm(ellie, 
               model = "crw", 
               time.step = 24)

## load gradient
load(system.file("extdata/grad.rda", package = "aniMotum"))
grad <- terra::unwrap(grad)

## simulate
set.seed(pi)
st.pf <- sim_fit(fit, what = "predicted", reps=5, grad=grad, beta=c(-300,-300))

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'ext': no slot of name "ptr" for this object of class "SpatRaster"

Screenshot 2024-04-25 at 16 48 56
## re-calc Ian's grad object
## use World Mercator projection
proj <- "+proj=merc +units=km +datum=WGS84"

## create world land raster
wm <- rnaturalearth::ne_countries(scale = 10, returnclass = "sf")

y <- terra::rast(crs = sf::st_crs(wm)$wkt,
                 vals = 1,
                 resolution = c(0.5, 0.5),
                 xmin = -180,
                 xmax = 180,
                 ymin = -86,
                 ymax = 84)

x <- terra::rasterize(wm, y, fun = "min")
x <- terra::project(x, proj)

## generate gradient rasters
# set land to NA, water to 1 - if goal is to keep tracks off land, otherwise do the reverse
x[is.na(x)] <- -1
x[x == 1] <- NA
x[x == -1] <- 1

## calculate gradient rasters
dist <- terra::distance(x)
x1 <- terra::terrain(dist, v = "slope", unit = "radians")
y1 <- terra::terrain(dist, v = "aspect", unit = "radians")
grad.x <- -1 * x1 * cos(0.5 * pi - y1)
grad.y <- -1 * x1 * sin(0.5 * pi - y1)
grad <- c(grad.x, grad.y)
plot(grad)

Error in .local(x, ...) :
no slot of name "ptr" for this object of class "SpatRaster"

Screenshot 2024-04-25 at 16 48 37

sim_fit() for this rebuilt grad object results in the same error as before.

> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Pacific/Auckland
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] terra_1.7-71    aniMotum_1.2-04

loaded via a namespace (and not attached):
  [1] tidyselect_1.2.1              viridisLite_0.4.2            
  [3] dplyr_1.1.4                   farver_2.1.1                 
  [5] blob_1.2.4                    viridis_0.6.5                
  [7] fastmap_1.1.1                 spatstat.geom_3.2-9          
  [9] spatstat.explore_3.2-7        crsmeta_0.3.0                
 [11] tweenr_2.0.3                  timechange_0.3.0             
 [13] lifecycle_1.0.4               sf_1.0-16                    
 [15] spatstat.data_3.0-4           RSQLite_2.3.6                
 [17] magrittr_2.0.3                compiler_4.3.3               
 [19] CircStats_0.2-6               rlang_1.1.3                  
 [21] tools_4.3.3                   igraph_2.0.3                 
 [23] utf8_1.2.4                    data.table_1.15.4            
 [25] oce_1.8-2                     bit_4.0.5                    
 [27] sp_2.1-3                      classInt_0.4-10              
 [29] marmap_1.0.10                 trip_1.10.0                  
 [31] plyr_1.8.9                    abind_1.4-5                  
 [33] KernSmooth_2.23-22            withr_3.0.0                  
 [35] purrr_1.0.2                   proj4_1.0-14                 
 [37] grid_4.3.3                    polyclip_1.10-6              
 [39] stats4_4.3.3                  fansi_1.0.6                  
 [41] e1071_1.7-14                  colorspace_2.1-0             
 [43] ggplot2_3.5.0                 spatstat.utils_3.0-4         
 [45] scales_1.3.0                  MASS_7.3-60.0.1              
 [47] cli_3.6.2                     mvtnorm_1.2-4                
 [49] tmvtnorm_1.6                  generics_0.1.3               
 [51] rstudioapi_0.16.0             httr_1.4.7                   
 [53] reshape2_1.4.4                ncdf4_1.22                   
 [55] DBI_1.2.2                     cachem_1.0.8                 
 [57] ggforce_0.4.2                 proxy_0.4-27                 
 [59] stringr_1.5.1                 rnaturalearth_1.0.1          
 [61] vctrs_0.6.5                   boot_1.3-29                  
 [63] Matrix_1.6-5                  sandwich_3.1-0               
 [65] jsonlite_1.8.8                patchwork_1.2.0              
 [67] bit64_4.0.5                   gdistance_1.6.4              
 [69] tensor_1.5                    reproj_0.4.3                 
 [71] tidyr_1.3.1                   rnaturalearthhires_1.0.0.9000
 [73] units_0.8-5                   goftest_1.2-3                
 [75] spatstat.random_3.2-3         glue_1.7.0                   
 [77] adehabitatMA_0.3.16           codetools_0.2-19             
 [79] traipse_0.3.0                 lubridate_1.9.3              
 [81] stringi_1.8.3                 gmm_1.8                      
 [83] shape_1.4.6.1                 gtable_0.3.4                 
 [85] deldir_2.0-4                  raster_3.6-26                
 [87] munsell_0.5.1                 tibble_3.2.1                 
 [89] pillar_1.9.0                  R6_2.5.1                     
 [91] TMB_1.9.11                    lattice_0.22-5               
 [93] gsw_1.1-1                     memoise_2.0.1                
 [95] class_7.3-22                  geodist_0.0.8                
 [97] Rcpp_1.0.12                   nlme_3.1-164                 
 [99] spatstat.sparse_3.0-3         gridExtra_2.3                
[101] zoo_1.8-12                    pkgconfig_2.0.3  

optimiser crashes occasionally when `time.step = NA` and `model = "crw"`

optimiser crashes when time.step = NA, model = "crw" and Argos data are KF mainly caused by unidentifiable psi parameter. This scenario is probably rare, ie. when observations are sparse but have high precision so psi is driven to a very small value. Can we detect extremely low psi evaluations and return an error with the advice to fix psi with map = list(psi = factor(NA))?

Installation fails on Ubuntu

I'm unable to install the package from CRAN or Github on Ubuntu but works fine on Mac OS. I'm using the recommended install code and have all updated dependencies and suggests.

install.packages('foieGras')
## OR
remotes::install_github("ianjonsen/foieGras", dependencies = c("Imports","LinkingTo","Suggests"))

The process seems to hang during the installation when the following occurs:

...
/usr/local/lib/R/site-library/RcppEigen/include/Eigen/src/Core/CoreEvaluators.h:960:8: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type {aka __vector(2) double}’ [-Wignored-attributes]
> sessionInfo() 
R version 3.6.0 (2019-04-26) 
Platform: x86_64-pc-linux-gnu (64-bit) 
Running under: Ubuntu 18.04.2 LTS  
Matrix products: default BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so  
locale:  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8      [5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C               [9] LC_ADDRESS=C           LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C     

attached base packages: [1] stats     graphics  grDevices utils     datasets  methods   base      

 loaded via a namespace (and not attached):  [1] ps_1.3.0          prettyunits_1.0.2 withr_2.1.2       crayon_1.3.4      rprojroot_1.3-2    [6] assertthat_0.2.1  R6_2.4.0          backports_1.1.5   magrittr_1.5      rlang_0.4.1       [11] cli_1.1.0         curl_4.2          remotes_2.1.0     rstudioapi_0.10   callr_3.3.2       [16] tools_3.6.0       compiler_3.6.0    processx_3.4.1    pkgbuild_1.0.6

fit_ssm bug

Hi Ian

I am getting the following error message from the fit_ssm function:
Error in optim(par = c(logD = 10, l_psi = 0, l_tau = 0, l_tau = 0, l_rho_o= 0 : L-BFGS-B needs finite values of 'fn'

Here is the code I used:
fit_ssm(df2, model='crw', vmax=3, time.step=24)

The problem could be because the raw data are generated from simulated tracks:
test_track.txt
test_track_2.txt

Any thoughts would be appreciated.
Cheers

Malcolm

Error when running fit_ssm

I've recently updated to R v4 and foieGras v 0.6-9 and now get the following error when running fit_ssm

require(foieGras)
fit <- fit_ssm(ellies, vmax = 4, model = "crw", time.step = 24, verbose = 0)
Error in .Call("FreeADFunObject", ptr, PACKAGE = DLL) : 
  "FreeADFunObject" not available for .Call() for package "foieGras"

Has anyone had a similar error, and do you have any idea what might be causing the issue?

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] foieGras_0.6-9

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5           lubridate_1.7.9.2    lattice_0.20-41      tidyr_1.1.2          deldir_0.2-3         listenv_0.8.0        class_7.3-17         geodist_0.0.6        assertthat_0.2.1    
[10] digest_0.6.27        proj4_1.0-10         parallelly_1.23.0    wesanderson_0.3.6    R6_2.5.0             traipse_0.2.0        crsmeta_0.3.0        e1071_1.7-4          ggplot2_3.3.3       
[19] tensor_1.5           pillar_1.4.7         rlang_0.4.10         rstudioapi_0.13      furrr_0.2.1          raster_3.4-5         rpart_4.1-15         Matrix_1.3-2         goftest_1.2-2       
[28] reproj_0.4.2         splines_4.0.3        rgdal_1.5-19         stringr_1.4.0        foreign_0.8-81       TMB_1.7.18           polyclip_1.10-0      munsell_0.5.0        spatstat.data_1.7-0 
[37] compiler_4.0.3       pkgconfig_2.0.3      mgcv_1.8-33          globals_0.14.0       tidyselect_1.1.0     tibble_3.0.4         codetools_0.2-18     future_1.21.0        crayon_1.3.4        
[46] dplyr_1.0.2          sf_0.9-7             MASS_7.3-53          grid_4.0.3           nlme_3.1-151         gtable_0.3.0         lifecycle_0.2.0      DBI_1.1.0            magrittr_2.0.1      
[55] units_0.6-7          scales_1.1.1         KernSmooth_2.23-18   stringi_1.5.3        sp_1.4-5             spatstat_1.64-1      ellipsis_0.3.1       generics_0.1.0       vctrs_0.3.6         
[64] spatstat.utils_2.0-0 tools_4.0.3          trip_1.8.0           glue_1.4.2           purrr_0.3.4          abind_1.4-5          parallel_4.0.3       colorspace_2.0-0     maptools_1.0-2      
[73] classInt_0.4-3       patchwork_1.1.1 

Bathymetry constraint function

Problem
Many coastal species have erroneous positions or, more frequently, predicted locations from the model fit are on land.

Solution
example.zip
Is there a way to implement a constraint function that prevents land from even being an option? I've done this in adehabitatLT when generating simulated tracks like:

# consfun.r and internal data .rda object containing bdf attached as example.zip
# note bdf is passed to consfun as par argument and is a SpatialPixelsDataFrame based on bathymetry, where 1 is possible (water) and NA is not (land)

source('consfun.r')
load('sysdata.rda')
library(adehabitatLT); library(foieGras)

# filter, fit and predict for ellie
data(ellie)
bathy <- raster::raster(bdf) # make bathy raster
ellie$bathy <- raster::extract(bathy, cbind(ellie$lon, ellie$lat))
ellie <- filter(ellie, bathy == 1) # get rid of points where ellie is on land
fit <- fit_ssm(ellie[,1:8], model = "rw", time.step = 24)
fls <- foieGras::grab(fit, 'pred', as_sf=F) # need regular time res for ltraj

# build ltraj object
tr1 <- adehabitatLT::as.ltraj(cbind(fls$lon, fls$lat), date=fls$date, id=as.factor(fls$id),
                              proj4string = sp::CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))

crw <- adehabitatLT::NMs.randomCRW(na.omit(tr1), rangles=TRUE, rdist=TRUE,
                                   constraint.func = consfun,
                                   constraint.par = bdf, nrep = 10)

# simulate
tmp <- adehabitatLT::testNM(crw)

# add unique ids for each sim track for plotting
sim_out <- tmp[[1]] %>% do.call(rbind, .)
sim_out$id <- NA
idx <- c(1, which(diff(sim_out$date) < 1) + 1)
for (i in 1:(length(idx) - 1)) sim_out$id[c(idx[i]:(idx[i + 1] - 1))] <- i

# plot
data(countriesHigh, package = "rworldxtra", envir = environment())
wm <- suppressMessages(fortify(countriesHigh))
rm(countriesHigh)

xl <- extendrange(fls$lon, f = 0.1)
yl <- extendrange(sim_out$y, f = 0.1)

p1 <- ggplot() + geom_polygon(data = wm, aes_string(x = "long", y = "lat", group = "group"), fill = grey(0.3)) +
  coord_cartesian(xlim = xl, ylim = yl) + xlab("Longitude") + ylab("Latitude")
p1 <- p1 + geom_path(data = sim_out, aes_string(x = "x", y = "y", group = "id")) 
p1 <- p1 + geom_point(data = fls, aes_string(x = 'lon', y = 'lat', group = NULL))
p1

ellie_sims

Can't load foieGras after R update to 4.1.0

I updated R to Version 4.1.0 and am now unable to load the foieGras package. Alle other packages seem to be working fine.
I've tried downloading the package and it seems to work
image

However, when trying to load the package I get the following error message:
image

These are my settings:
image

I am relatively inexperienced with R and would appreciate any help.
Thanks in advance.
A

Date/time variable not detected in data

I formatted my data just like the overview page, it includes id, date, lat, lon, in order as shown.
When I run fit_ssm, I get the following error:
Error in format_data(BermudaChloe) :
A date/time variable must be included in the input data;
see vignette('Overview', package = 'aniMotum')

I have tried format_data on its own and get the same error.
Thank you for any help!!

When running function fit_ssm : Error in MakeADFun. Is someone familiar?

Hi!

I commented on issue 25 (closed) yesterday, but I figured it might be better to post this in a seperate issue. I'm running into the error below when running 'fit_ssm'; does somebody have an idea of whats going wrong?

Error in MakeADFun(data, parameters, map = map, random = rnd, hessian = TRUE,  : 
  Only numeric matrices, vectors, arrays, factors, lists or length-1-characters can be interfaced

I have run this script many times before, and it has always worked for me. Last week, I updated R to the latest version, after which this error occurred. I made sure to reinstall TMB and glmmTMB packages from source. I have tried reinstalling AniMotum, but the error stays the same. Some information on the session:


> sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: Europe/Amsterdam
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] glmmTMB_1.1.8       TMB_1.9.6           Matrix_1.6-2        ggspatial_1.1.9     ggplot2_3.4.4       stars_0.6-4         abind_1.4-5        
 [8] sf_1.0-14           adehabitatLT_0.3.27 CircStats_0.2-6     boot_1.3-28.1       MASS_7.3-60         adehabitatMA_0.3.16 ade4_1.7-22        
[15] sp_2.1-1            aniMotum_1.2        momentuHMM_1.5.5    lubridate_1.9.3     mapview_2.11.2      lattice_0.22-5      crawl_2.3.0        
[22] vtable_1.4.6        kableExtra_1.3.4    fuzzyjoin_0.1.6     tidyr_1.3.0         dplyr_1.1.3         data.table_1.14.8  

loaded via a namespace (and not attached):
 [1] DBI_1.1.3           sandwich_3.0-2      rlang_1.1.2         magrittr_2.0.3      e1071_1.7-13        compiler_4.3.2      mgcv_1.9-0         
 [8] png_0.1-8           systemfonts_1.0.5   vctrs_0.6.4         rvest_1.0.3         stringr_1.5.0       pkgconfig_2.0.3     fastmap_1.1.1      
[15] leafem_0.2.3        utf8_1.2.4          rmarkdown_2.25      nloptr_2.0.3        purrr_1.0.2         xfun_0.41           satellite_1.0.4    
[22] jsonlite_1.8.7      gmm_1.8             terra_1.7-55        parallel_4.3.2      R6_2.5.1            stringi_1.7.12      numDeriv_2016.8-1.1
[29] Rcpp_1.0.11         iterators_1.0.14    knitr_1.45          zoo_1.8-12          base64enc_0.1-3     splines_4.3.2       timechange_0.2.0   
[36] tidyselect_1.2.0    rnaturalearth_0.3.4 rstudioapi_0.15.0   doParallel_1.0.17   codetools_0.2-19    doRNG_1.8.6         tibble_3.2.1       
[43] withr_2.5.2         evaluate_0.23       tmvtnorm_1.5        units_0.8-4         proxy_0.4-27        xml2_1.3.5          pillar_1.9.0       
[50] rngtools_1.5.2      KernSmooth_2.23-22  traipse_0.3.0       foreach_1.5.2       stats4_4.3.2        generics_0.1.3      munsell_0.5.0      
[57] scales_1.2.1        minqa_1.2.6         class_7.3-22        glue_1.6.2          tools_4.3.2         lme4_1.1-35.1       webshot_0.5.5      
[64] mvtnorm_1.2-3       grid_4.3.2          crosstalk_1.2.0     colorspace_2.1-0    nlme_3.1-163        patchwork_1.1.3     raster_3.6-26      
[71] cli_3.6.1           fansi_1.0.5         viridisLite_0.4.2   svglite_2.1.2       Brobdingnag_1.2-9   gtable_0.3.4        digest_0.6.33      
[78] classInt_0.4-10     htmlwidgets_1.6.2   htmltools_0.5.7     lifecycle_1.0.4     leaflet_2.2.0       httr_1.4.7 

And some more info on the script I ran:


#---------------------------
# fitting SSM 
#---------------------------
str(data)

# 'data.frame':	241 obs. of  7 variables:
# $ id    : chr  "8-1" "8-1" "8-1" "8-1" ...
# $ date  : POSIXct, format: "2018-10-19 18:37:01" "2018-10-19 18:37:43" "2018-10-19 18:37:57" "2018-10-19 18:38:11" ...
# $ lon   : num  4.7 4.7 4.7 4.7 4.7 ...
# $ lat   : num  52.8 52.8 52.8 52.8 52.8 ...
# $ lonerr: num  0.01034 0.00773 0.00758 0.00783 0.00801 ...
# $ laterr: num  0.00626 0.00468 0.00458 0.00474 0.00484 ...
# $ lc    : chr  "GL" "GL" "GL" "GL" ...

ssm_ID <- fit_ssm(x=data, 
                  model="crw",
                  vmax=20, # m/s
                  time.step = as.numeric(1/60), # wants input in hours, I want one minute
                  spdf = FALSE)

# fitting crw SSM to 1 tracks...
# Problem with these data entries:
#   GLerr 
# 16 
# Error in MakeADFun(data, parameters, map = map, random = rnd, hessian = TRUE,  : 
#                      Only numeric matrices, vectors, arrays, factors, lists or length-1-characters can be interfaced

The first part of the error, 'problem with these data entries' is consistent for my tries in with different datasets I try (I run these separately for diff. animals), where these datasets worked fine before. Also, the required structure of the dataset seems to be correct. I don't think the true problem lies here. I don't know what to try to solve the 'MakeADFun' error. Does anyone have any ideas?

rep$pdHess : $ operator is invalid for atomic vector — Error when fitting ssm

Hi Ian —
I get the following issue when trying to run fit_ssm()
Error in rep$pdHess : $ operator is invalid for atomic vectors

Code as follows:

> fit_df <- 
+   fit_ssm(df, 
+           model = "mp", 
+           time.step = 6, 
+           spdf = FALSE, 
+           control = ssm_control(verbose = 0))
Guessing that all observations are GPS locations.

I have the latest TMB (1.9.10), Matrix (1.6-5), Animotum (1.2-02), R (4.3.2 )versions
Could you please advise on how to fix this. Cheers :)

unknown error code when fitting SSM

Addition to post # 25 Error when running fit_ssm - closed

I get a cryptic error message trying to run fit_SSM

fit <-fit_ssm(argos, vmax = 5, model ="crw", time.step = 6)
fitting crw...
Error in .Call("getParameterOrder", data, parameters, new.env(), NULL, : Incorrect number of arguments (4), expecting 3 for 'getParameterOrder'

Some googling later, I found people reporting issues with the matrix and TBM versions, so I followed the advice (post #25) to install tbm from the source, but the error remained.
Rv 4.1.1
foieGras (0.7.6)
matrix (1.4.0)
tbm (0.3.5)

Any advice?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.