Error calculating 3D akde

98 views
Skip to first unread message

Elena Bravo

unread,
Dec 16, 2021, 7:38:55 PM12/16/21
to ctmm R user group
Hi Chris, 

I am trying to calculate the 3D home range of a few vultures. For that I have calculated the vertical variogram changing the axes to "z" and then I have used this variogram to calculate the automatic GUESS with this code: 

vertical_GUESS <- ctmm.guess(tel_object, variogram=vertical_variogram,interactive=FALSE)

After that I calculate also the vertical model with this code: 

vertical_model<-ctmm.fit(tel_object,CTMM=vertical_GUESS)

When I have then both models, the vertical and the horizontal calculated (the horizontal alone works fine, thats why I didn't add the code) I use the akde function this way: 

UDw <- akde( tel_object , horizontal_model ,weights=TRUE, VMM =vertical_model)

But I always get this error: 
Error in `[.data.frame`(extent(CTMM[[i]], level = 1 - error), , axes) : undefined columns selected

Do you know where could be the problem and what does it mean?

Thank you in advanced!

Christen Fleming

unread,
Dec 17, 2021, 3:43:01 PM12/17/21
to ctmm R user group
Hi Elena,

I'll try to get to this within a couple of days. I'll see about a basic plot3D function too.

Best,
Chris

Christen Fleming

unread,
Jan 5, 2022, 3:52:00 PMJan 5
to ctmm R user group
Hi Elena,

Sorry for the delay. I was in the middle of coding non-stationary RSFs. The 3D UDs are working again and I've implemented basic overhead plotting capability with plot() that has a z-axis slider. I didn't implement the grid options, or summary, or anything else, but tell me if you need anything. I started on code to calculate vertices for a 3D mesh of the coverage volume, but I didn't figure out how to plot that in rgl.

Best,
Chris

Elena Bravo

unread,
Jan 13, 2022, 8:38:15 AMJan 13
to ctmm R user group
Hi Chris, 

Don't worry about that. I have been trying these past days to run the code again, with different data sets, but I keep getting the same error for all of them: 
Error in `[.data.frame`(extent(CTMM[[i]], level = 1 - error), , axes) : undefined columns selected

My last ctmm version is 0.6.1.  Where do you think the error could be?

Also I wanted to ask you another doubt not related with the previous one. The thing is that sometimes, with very few individuals that I am processing (3 or 4) the akde function (for 2D data) doesn't work well. It does not give me errors or anything but it keeps processing the data for days without ending at any time. And it does not matter if the data is large or not. Also, I have tried to divide the data in two different data sets (i.e. the first 6 months and the last 6 months) and it that case it worked well. Do you know how I can fix this so that I can get the akde of those individuals in a whole? 

If you need the data or the code I am using to check this out just ask me. 

Thanks a lot and sorry for the trouble.

Christen Fleming

unread,
Jan 14, 2022, 8:29:31 AMJan 14
to ctmm R user group
Hi Elena,

Sorry that I wasn't clear.  This fix is not pushed to CRAN yet. I've updated the development version of the package on GitHub, which you will have to update via devtools::install_github("ctmm-initiative/ctmm")
The reported version should then by 0.6.2 (not final) and news(package="ctmm") should include the 3D bugfix, etc..

For the other issue, are you running akde() with weights=TRUE and trace=TRUE and, if so, is the reported grid size really small? There are some notes in help("bandwidth"). If this can't be easily resolved in the updated package, then I'd like to take a look at it.

Best,
Chris

Elena Bravo

unread,
Feb 4, 2022, 7:50:52 AMFeb 4
to ctmm R user group
Hi Chris, 

I could finally test the new version with the 3D bugfix and the previous problem I had finally disappeared, but now I am having another error which states the following: 
Error in apply(R - dH, 2, min) : dim(X) must have a positive length
Do you know what is it exactly that needs to have a positive length? I have tried with different individuals and with all of them I get the same result. 

Regarding the other doubt I am still working on it. So I will check it thoroughly before I ask you any more questions. 

Thanks a lot!

Christen Fleming

unread,
Feb 5, 2022, 4:22:17 PMFeb 5
to ctmm R user group
Hi Elena,

I'm not getting this error in my limited testing. Do you mind sending me a minimal working example (data+script) that can reproduce this?

Best,
Chris

Elena Bravo

unread,
Feb 5, 2022, 7:17:56 PMFeb 5
to ctmm R user group
Hi Chris, 

In this link I have uploaded the data for one individual and the script that I am using: https://drive.google.com/drive/folders/1uP-43w5ktDe06REyHbE9gISOJDUoJcYu?usp=sharing 

Thank you very much!

Christen Fleming

unread,
Feb 7, 2022, 7:40:29 AMFeb 7
to ctmm R user group
Thanks Elena,

That bug should be resolved on GitHub.

Also of note in your script: At least the vertical movement model needed ctmm.select() instead of ctmm.fit(), because the tau[velocity] parameter was not supported. And the grid argument in akde() was not named, which would likely run into issues.

Best,
Chris

Elena Bravo

unread,
Feb 9, 2022, 1:24:31 PMFeb 9
to ctmm R user group
Hi Chris, 

Now it works perflectly! Thanks a lot!!

Nevertheless I need to ask you one more question (I hope it's the last one). The thing is that after obtaining the 3D akde, I want to transform the UD object to raster and shapefiles to work with them in QGIS. The thing is that the code that I used with the 2D akde doesn't work anymore. 

My code is: 

Vulture_raster<-raster(UDw)
Error in h(simpleError(msg, call)) :
  error in evaluating the argument 'x' in selecting a method for function 'raster': incorrect number of dimensions

writeShapefile(UDw,folder=vulture_shp95,file=NULL,level.UD=0.95,level=0.95)
Error in grDevices::contourLines(UD$r, z = UD$CDF, levels = P[i]) :
  no proper 'z' matrix specified


I tried to look it up on the internet but I couldn't find anyone else with a similar error. ¿Do you know how to solve this?

Thanks in advanced!

Christen Fleming

unread,
Feb 9, 2022, 2:47:29 PMFeb 9
to ctmm R user group
Hi Elena,

I haven't coded those functions to work on 3D UDs, but I can. For rasters, I can easily code support to export to a raster stack, where the layers of the stack would be different heights. For shapefiles, that's kind of ambiguous, though. In 3D, the proper coverage volume output is a 3D mesh, which I'm not super familiar with computing at the moment. What were you envisioning with the shapefile output? A set of 2D polygons for every height?

Best,
Chris

Elena Bravo

unread,
Feb 9, 2022, 3:13:58 PMFeb 9
to ctmm R user group
Oh, in that case with the raster function will be more than enough for the analysis that I need to do. 

Thanks a lot! If you could send me a message when you have it (no need to hurry) I'll be grateful. 

Christen Fleming

unread,
Feb 13, 2022, 4:10:35 PMFeb 13
to ctmm R user group
Hi Elena,

In the development branch on GitHub, 3D UD objects should export as raster bricks now.

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