jmsigner / amt

37 stars 13 forks source link

Error in track_resample #12

Closed Sadie-SE closed 4 years ago

Sadie-SE commented 4 years ago

Hi, I updated the package to the latest version, since then I'm getting the following error at resampling tracks and generating random steps using "track-resample" function:

codes: ssf<-tracks %>% mutate(rs=map(tracks, function(x){ x<-x %>% track_resample(hours(step_duration), tolerance=minutes(60)) %>% filter_min_n_burst%>% steps_by_burst %>% random_steps(n_control=100)

The error: Error in fitdistrplus::fitdist(x, "gamma", keepdata = FALSE, lower = 0) : the function mle failed to estimate the parameters, with the error code 100

I appreciate you help me solve the problem (I analysed this data in the past and it was not such error then).

jmsigner commented 4 years ago

This bug was introduced in version 0.0.8 but is fixed already in version 0.0.9 which was released on CRAN yesterday. There are two ways forward for you:

  1. Update to 0.0.9 (there might not be any binaries for windows and mac at this point).
  2. Slightly adjust the code from:
 random_steps(n_control=100)

to

mutate(sl_ = ifelse(sl_ == 0, 0.01, sl_))  %>%  random_steps(n_control=100)
tim-doherty commented 2 years ago

Hi, I am also experiencing this error when running the random_steps() function for multiple animals (with amt_0.1.5). The full error is pasted below, although if I add the ifelse statement as suggested above, the first warning goes away (before 'simpleError'). Are you able to provide any advice as to how to fix this? I have done some searching and experimentation, but am unsure how to proceed.

Many thanks Tim

Steps with length 0 are present. This will lead to an error when fitting a gamma distribution. 0 step lengths are replaced with the smallest non zero step length, which is: 2.99999999953116e-06 <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): non-finite finite-difference value [1]> Error in fitdistrplus::fitdist(x, "gamma", keepdata = FALSE, start = list(scale = scale_closed, : the function mle failed to estimate the parameters, with the error code 100

jmsigner commented 2 years ago

Hi Tim,

it seems that the step-length distribution for one animal is odd (i.e, fitdistr is unable to fit a Gamma distribution). Why this is the case is hard to diagnose without seeing the data from that individual. Two workarounds come to mind: 1) investigate the step lengths of the individual in question (either use a tryCatch() or for-loop to find the animal with the problem), or 2) you could fit the step length distribution to all animals before and then sample for each animal.

elianemccarthy commented 1 year ago

Hi,

I am experiencing the same error as described above by Tim. I am sampling for each individual animal already, and it is occurring for all my animals. I am happy to share my steps dataframe so that you can reproduce this error.

Many thanks in advance for your help.