CTMM model fitting question

759 views
Skip to first unread message

Jill Shephard

unread,
Jun 1, 2017, 9:28:50 PM6/1/17
to ctmm R user group

Dear Chris

 

I have been analysing all my tagging data using ctmm. But it seems that when I use a variogram to check the fit of the chosen model that the fit is terrible. It appears as though it is fitting a model without the optimised GUESS parameters.

 

The figure below is the variogram.fit with the GUESS parameters (which I save, so I know the function is there).




I then  perform the model selection based on the GUESStimates.


MGUESS <- ctmm.fit(B2058a,GUESS)

summary(MGUESS)


and create the FITZ object. Actually I have tried GUESS and MGUESS in the code below but the result is identical..


FITZ <- ctmm.select(B2058a, MGUESS, verbose = TRUE, level = 1)

summary(FITZ)


Then use a variogram to check that the ML process has selected the best model - this looks really bad


par(mfcol=1:2)

plot(SVF,CTMM=FITZ,col.CTMM=c("blue","red","purple"),fraction=0.65,level=0.5)

title("zoomed out")

plot(SVF,CTMM=FITZ,col.CTMM=c("red","purple","blue"),fraction=0.1,level=0.5)

title("zoomed in")





 

Can you please look at my script and tell me if I have got some of the syntax wrong……? 


I have emailed my full script and data for this individual to you.


Thank you for your help.


Jill

 

Christen Fleming

unread,
Jun 2, 2017, 12:40:58 PM6/2/17
to ctmm R user group

Hi Jill,

This data has some 4 minute intervals. When you have time intervals over which the real movement is comparable to the telemetry errors, then you need an error model. Otherwise the telemetry errors (which are very discontinuous in time) will be attributed to movement and deflect the variogram down initially.

I didn't see any error/DOP columns in your CSV, so I fit with homoscedastic errors (which may not be valid if the animal is not in an open area) by setting error=TRUE in the model guess. The AIC dropped by 60, the variogram point estimate looks pretty good, and the error was estimated at around 400 meters (so fitting will be much faster if you set error=400). I don't know if this is reasonable or not for your data. Without structure on the errors (which DOP values provide), you can get the opposite problem of attributing movement to error. E.g., if your animal darts around from location to location on intervals < 4 minutes, then that kind of movement looks indistinguishable from telemetry error in an unstructured model.

We are going to have a paper on this stuff within the next few months.

Best,
Chris

Jill Shephard

unread,
Jun 12, 2017, 11:22:24 PM6/12/17
to ctmm R user group
Hi Chris

thanks for your reply, apologies for the delay in getting back to you I have been in the field.

I can not reproduce what you did. I have trawled through the vignettes, but its unclear to me where you are putting the error information. I do have the DOP information, but it was not included in my previous file. I understand from the vignette that this is recognised at the as.telemetry import stage, but then is it necessary to run a calibration? 

If I use the variogram.fit(SVF) option I only get the ability to apply an error up to 100m. I would have thought with the DOP information the this would not be necessary to use.....

Do I need to fit all the models manually?

I am afraid I am quite confused by how to proceed; or which parts of the script require the additional information... 

I have sent the data and script to you separately.

Thank you for your help Chris.

Jill

Christen Fleming

unread,
Jun 13, 2017, 4:00:12 PM6/13/17
to ctmm R user group
Hi Jill,

On your GUESS object from variogram.fit, you can just set GUESS$error=400, before feeding it into ctmm.fit with the data. error=100 with the slider would also work, it would just take a little longer to fit. The manipulate sliders in R-studio are fairly limited, but the new shiny sliders will have the ability to update the limits on the fly.

Errors should work within ctmm.select if that's what you mean about fitting the models manually. I would just caution to be a little more careful when fitting with errors because R's optim doesn't find solutions as well. E.g., you can re-run the first fit object through as a new initial guess and see if optim can make any more improvement.

Regarding DOP values, they are not errors but only proportional to errors. The proportionality constant (UERE) is specific to your device and unless you know it a priori, the UERE has to be fit either from calibration data or simultaneously with the movement model.

Fitting with errors is not a published feature of the package and it will have its own manuscript and vignette within a few months, clarifying many of these issues.

Best,
Chris

Jill Shephard

unread,
Jun 15, 2017, 5:12:00 AM6/15/17
to ctmm R user group
Hi Chris

well, that's the problem, I cant figure out how to add this information to the GUESS object.

Can you please supply the code?

I tried the alternative which was to use the slider to set the error at 100m. 

I used the following code which all looked great.

> variogram.fit(SVF)
> #check the fit of the model
> plot(SVF,CTMM=GUESS,fraction=0.01,level=c(0.5,0.95),col.CTMM="green")
> title("GUESS - small")
> plot(SVF,CTMM=GUESS,fraction=0.65,level=c(0.5,0.95),col.CTMM="green")
> title("GUESS - large")

I then ran:

> MGUESS <- ctmm.fit(B2058a,GUESS)
> summary(MGUESS)

which returned this(confirming the 400m error you stated earlier):

$DOF
     mean      area 
 3.221186 15.901257 

$CI
                               low         ML        high
area (square kilometers)  17.51056 2757.97063 10173.82119
tau position (hours)           NaN   19.87721         NaN
tau velocity (minutes)    14.20458   18.20405    23.32962
speed (kilometers/day)   175.88171  191.49467   207.09093
error (meters)           358.73558  414.85546   470.88406

Warning messages:
1: In sqrt(COV) : NaNs produced
2: In sqrt(COV/tau^4) : NaNs produced
3: In chisq.ci(GM.sigma, COV = COV, alpha = alpha) :
  VAR[Area] = -1350150177891592 < 0

I carried on and ran:

> FITZ <- ctmm.select(B2058a, MGUESS, verbose = TRUE, level = 1)

Which returned this error, fails to create the Fitz object, and prevents any further analysis.

Error in stats::optim(par = par, fn = fn, method = method, lower = lower,  : 
  non-finite value supplied by optim
In addition: Warning message:
In sqrt(diag(control$covariance)) : NaNs produced


So my questions are:

1. What do these errors mean?
2. Can I circumvent this happening if I add the GUESS$error=400 information in to the GUESS object (remembering that I don't know how to do this!).
3. I am intrigued by the fact that the GUESS object  $ error information is listed as 'num 0.5' irrespective of whether I set the error with the slider or not. Why? Shouldnt this say 100 or 400 (if I could edit it successfully).

Help!

Jill

Christen Fleming

unread,
Jun 15, 2017, 4:27:53 PM6/15/17
to ctmm R user group

Hi Jill,

Fitting with errors is more taxing and I think optim failed to find a solution for you here, because with the initial data you sent me without HDOP I got an error of 459 meters, and because you have some negative variance estimates. However, from your error report, I could identify a line of my code that could be more robust and should fix that potential error with ctmm.select and ctmm.fit when feeding in an initial guess with a bad covariance matrix. I'm going to try and upload that fix to GitHub tonight.

When I ran the data you gave me I didn't get any errors because of luck with optim or better initial parameters, or maybe something in the package has been improved recently over the version you are running. The code I used is attached.


The bad news is that this data looks like a central place forager with a suite of vastly different movement behaviors. ctmm so far only has stationary movement models, which assume 1 movement behavior or a large average of movement behaviors. The home-range plot above should be better than conventional KDE because some autocorrelation is taken into account, but I do not think it is very good objectively. Multiple behavioral modes is going to be our next be project in a few months, but for the time being you would want to break up data like this into different behavioral modes. Specifically, for the outgoing/ingoing movements between the foraging grounds and the nest the effective sample size here looks to be only 4-5, which is inflated here in the OUF model by the much smaller foraging and nesting movements. A better foray/foraging distribution is going to be larger with much wider confidence intervals. One approach to breaking up the data might be to use the speed estimates from predict.

Best,
Chris
B2058a script_SHEPHARD.R

Christen Fleming

unread,
Jun 15, 2017, 6:28:32 PM6/15/17
to ctmm R user group
I forgot to add that the error slider in variogram.fit seems to be working fine in the recent versions of the package on GitHub. Some of that was re-coded recently so if it was broken at some point, it might have been fixed already.

Best,
Chris
Reply all
Reply to author
Forward
0 new messages