Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date/time variable not detected in data #57

Closed
nikkisharks opened this issue Feb 11, 2024 · 6 comments
Closed

Date/time variable not detected in data #57

nikkisharks opened this issue Feb 11, 2024 · 6 comments

Comments

@nikkisharks
Copy link

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!!

@ianjonsen
Copy link
Owner

Hi, You'll have to include the code you are using & some example data that reproduces the error. Without this, I can only guess at what's causing the problem.

Thanks, Ian

@nikkisharks
Copy link
Author

nikkisharks commented Feb 14, 2024 via email

@ianjonsen
Copy link
Owner

Ok, half-way there. You will have to save your data as a .csv file (eg. using write.csv within R, generate a .csv file from your excel spreadsheet, etc...) and attach it to your reply using the "paperclip" icon at the top right of the "Add a comment" window. Once I have your data then I can reproduce the error and determine what is going wrong.

@nikkisharks
Copy link
Author

BermudaChloe.csv

Sorry, I replied to the email with the attachment, I guess that doesn't work!

@ianjonsen
Copy link
Owner

There are a few issues going on here. First, you have a mix of uppercase and lowercase variable names so you either have to edit these so they are all lowercase prior to using aniMotum functions or you have to call format_data() and provide the exact variable names, eg:

data <- aniMotum::format_data(BermudaChloe, date = "Date", coord = c("lon", "Lat"))

But this also results in an error because you have missing entries, not classed as NA's in the Date variable:

d$Date
  [1] "2017-08-13 23:35:40" "2017-08-14 10:00:09" "2017-08-15 09:14:24" "2017-08-15 10:17:39" "2017-08-15 10:44:45" "2017-08-16 02:00:38" "2017-08-16 09:03:25" "2017-08-16 22:00:01"
  [9] "2017-08-16 22:00:01" "2017-08-17 07:09:34" "2017-08-17 09:11:36" "2017-08-17 10:29:04" "2017-08-17 10:29:04" "2017-08-17 21:43:33" "2017-08-18 21:03:09" "2017-08-19 02:36:02"
 [17] "2017-08-19 09:34:01" "2017-08-19 19:52:10" "2017-08-20 02:16:22" "2017-08-20 10:55:15" "2017-08-20 22:53:11" ""                    ""                    ""                   
 [25] ""                    "2017-08-25 21:42:11" "2017-08-25 21:59:54" "2017-08-25 22:23:26" "2017-08-26 01:01:35" "2017-08-26 07:10:59" "2017-08-26 09:39:09" "2017-08-26 22:54:58"
 [33] "2017-08-26 23:35:07" "2017-08-27 08:38:59" "2017-08-27 09:09:41" "2017-08-27 11:45:22" "2017-08-27 22:35:36" "2017-08-27 23:07:18" ""                    ""                   
 [41] "2017-08-30 21:20:28" "2017-08-30 22:35:10" "2017-08-30 22:57:21" "2017-08-30 23:05:32" "2017-08-31 08:00:28" "2017-08-31 08:37:00" "2017-08-31 13:21:40" "2017-08-31 20:52:19"
 [49] "2017-08-31 20:52:19" "2017-08-31 22:31:13" "2017-09-01 07:44:57" "2017-09-01 23:44:14" "2017-09-02 00:18:55" "2017-09-02 23:57:48" "2017-09-03 10:23:45" "2017-09-03 21:52:22"
 [57] "2017-09-03 23:04:09" "2017-09-04 02:56:34" "2017-09-04 08:18:46" "2017-09-04 09:42:21" "2017-09-04 18:28:16" "2017-09-04 20:13:17" "2017-09-04 21:40:34" "2017-09-04 23:16:30"
 [65] "2017-09-05 09:29:58" ""                    "2017-09-07 10:02:28" ""                    ""                    ""                    ""                    ""                   
 [73] ""                    ""                    ""                    ""                    ""                    "2017-09-18 01:26:47" "2017-09-18 19:11:10" "2017-09-18 23:59:59"
 [81] "2017-09-19 23:04:55" "2017-09-20 02:24:18" ""                    ""                    ""                    ""                    ""                    ""                   
 [89] ""                    ""                    ""                    ""                    "2017-10-01 00:11:53" "2017-10-01 23:12:49" ""                    ""                   
 [97] ""                    ""                    ""                    ""                    ""                    ""                    ""                    ""                   
[105] ""                    ""                    ""                    ""                    ""                    ""                    ""                    ""                   
[113] ""                    "2017-10-21 10:33:03" ""                    ""                  

So you need to remove these, as all other variables apart from id are NA. Then you can run format_data(), and then fit the SSM:

d <- subset(BermudaChloe, Date != "")

data <- aniMotum::format_data(d, date = "Date", coord = c("lon", "Lat"))
fit <- aniMotum::fit_ssm(data, max = 4, model = "mp", time.step = 24)
plot(fit, "p")

Rplot

But this shows that you have a few fairly large data gaps, which can be problematic for estimating sensible locations and move persistence. Finally, the first and last observed locations are substantially far away from the rest of the observed locations - you can see these in the x and y plot panels above, and both in the map below. Suggesting that these observations may be erroneous (highlighted in red):

aniMotum::map(fit, what = "f")

Rplot01

Hope this helps

@nikkisharks
Copy link
Author

nikkisharks commented Feb 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants