problems with variogram calculation

187 views
Skip to first unread message

Gianluca Roncalli

unread,
Mar 17, 2020, 9:59:49 AM3/17/20
to Christen Fleming, ctmm...@googlegroups.com
Hi,
Could I have some helps with this problem?
I'll attach my r script and my database. 
When calculating the variogram, I 'm having this error 
"Error in rep(CTMM$error^2/length(axes), n) : invalid 'times' argument"
I've timestamp in the correct way, so I'm not sure about what I'm doing in the wrong way. 
Thank you in advance for the help

--
Gianluca Roncalli

ISPRA (Istituto Superiore per la Protezione e la Ricerca Ambientale)
Area per l'Avifauna Migratrice (BIO-AVM)
Via Cà Fornacetta 9,  
40064 Ozzano dell'Emilia, BO 
Italy
 
example.r
example.csv

Christen Fleming

unread,
Mar 17, 2020, 1:10:34 PM3/17/20
to ctmm R user group
Hi Gianluca,

By supplying drop=FALSE to as.telemetry(), you ensure that the output is a list of telemetry objects, even if there is only one. Then you are feeding the list object into variogram() and not the variogram object. The following works:

variogramma<-variogram(bacucco181614_t[[1]])

Best,
Chris

Skye Fenton

unread,
Oct 8, 2020, 12:48:23 AM10/8/20
to ctmm R user group
Hello Chris and apologies, I cannot seem to start a new thread.

I'm new to the package and am trying to get home range area estimates and contours to plot for some animals.

I'm getting the same error as Gianluca but in response to a different command. I'm attempting to export my akde UD object using SpatialPolygonsDataFrame.telemetry() to get the 50% and 95% contours for plotting. But my command returns the error...

cass_sp_akde <- SpatialPolygonsDataFrame.telemetry(object = AKDE, level.UD = 0.95)

>Error in rep(CTMM$error^2/length(axes), n) : invalid 'times' argument

I successfully plotted AKDE with plot() so I'm not sure where the problem is. I am very willing to send you the data and script for assistance but wonder if I could send it directly rather than make it public.

Thanks so much in advance,

Skye

Christen Fleming

unread,
Oct 8, 2020, 12:05:09 PM10/8/20
to ctmm R user group
Hi Skye,

I'm not sure why you were not able to post, but I will say that I had to switch back to the "classic" Google group view because the revamped version is quite buggy and many features do not work or are missing.

SpatialPolygonsDataFrame.telemetry() is for telemetry objects. The command that you are looking for is probably SpatialPolygonsDataFrame.UD(). Ideally, you would just run SpatialPolygonsDataFrame() and it would just work, but the way these functions are coded in the sp package does not allow them to be cast as generic functions, unfortunately.

Best,
Chris

Skye Fenton

unread,
Oct 8, 2020, 12:30:24 PM10/8/20
to ctmm R user group
Hi Chris,

Thank you! I see my error. I'm now using SpatialPolygonsDataFrame.telemetry() to try and export the 50% and 95% estimate ellipses so I can plot them in ggplot. I'm using them on my telemetry object now, but when i try to plot the resulting SpatialPolygonsDataFrame, I get an error. When turning this spdf into a normal data frame, I see there are only two columns, one called 'identity' that says unknown for every row, and one with timestamps. Any suggestions about what I'm doing wrong there? I've attached a picture of the resulting data frame.  Thank you again!!

cnona_move <- move(x=cnona$x, y=cnona$y, 
                  time=as.POSIXct(cnona$date, format="%Y-%m-%d %H:%M:%S", tz="UTC"), 
                  proj=CRS("+init=epsg:3035"), 
                  data=cnona, animal=cnona$animal_id)

b <- as.telemetry(cnona_move)
cass_sp_akde <- SpatialPolygonsDataFrame.telemetry(object = b, level.UD = 0.95)
plot(cass_sp_akde)
>Error in as.double(y) : 
  cannot coerce type 'S4' to vector of type 'double'
Screen Shot 2020-10-08 at 12.28.23 PM.png

Skye Fenton

unread,
Oct 8, 2020, 12:33:48 PM10/8/20
to ctmm R user group
Additionally, is there a way to calculate the home range areas for UDs other than 95%? (e.g. 50% core area, 90%).... Apologies for the add on question, thank you so much for running this forum!

Christen Fleming

unread,
Oct 8, 2020, 12:38:58 PM10/8/20
to ctmm R user group
Hi Skye,

Did that data have error circle/ellipse information in it, which you can see when plotting the telemetry object?

Best,
Chris

Christen Fleming

unread,
Oct 8, 2020, 12:42:07 PM10/8/20
to ctmm R user group
Yes, check out the level.UD argument in any function that calculates with home-range areas.

Best,
Chris

Skye Fenton

unread,
Oct 8, 2020, 12:52:27 PM10/8/20
to ctmm R user group
There are no ellipses when I plot b by itself, but when I plot it with the UD object I made, plot(b, UD = AKDE), there are ellipses. When I try SpatialPolygonsDataFrame.UD(AKDE) with my UD object and try to plot the resulting spdf, I get the same error as before about the  's4' object. The spdf creates a data frame that is similarly unusual...

Thank you!!
Screen Shot 2020-10-08 at 12.48.50 PM.png
Screen Shot 2020-10-08 at 12.44.41 PM.png
Screen Shot 2020-10-08 at 12.44.58 PM.png

Christen Fleming

unread,
Oct 8, 2020, 1:28:23 PM10/8/20
to ctmm R user group
Hi Skye,

I don't see any error information being plotted in in your telemetry data, so I don't think there was anything there to be exported via SpatialPolygonsDataFrame.telemetry(). I will code that function to return an error when you try to do that. See vignette("error") for an example of what location errors look like. If you just want to export location data (with out error circle/ellipses) then you would want to use the spatial points functions instead of spatial polygons functions.

As for "unknown", that shouldn't be happening if you have the animal_id column in your data.frame, as your code suggests. Is this correct?

Best,
Chris

Skye Fenton

unread,
Oct 8, 2020, 1:37:09 PM10/8/20
to ctmm R user group
Hi Chris,
Thanks again for your response. I think I am confused; I want to export the 95% contour for the density function that I see when I plot my UD object as a spatial polygon or dataframe of points in order to plot them. Is that possible?

Screen Shot 2020-10-08 at 1.36.19 PM.png

Skye Fenton

unread,
Oct 8, 2020, 1:38:30 PM10/8/20
to ctmm R user group
And yes, the animal id column has a numeric value of 1.

--
You received this message because you are subscribed to a topic in the Google Groups "ctmm R user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ctmm-user/ZHN-pzKHA0g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ctmm-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ctmm-user/a0b9b3f0-b239-49ef-a683-a0a805a38306n%40googlegroups.com.

Skye Fenton

unread,
Oct 8, 2020, 1:39:41 PM10/8/20
to ctmm R user group
* in order to plot the contours in ggplot rather that the plot function

Christen Fleming

unread,
Oct 8, 2020, 5:10:48 PM10/8/20
to ctmm R user group
Hi Skye

You should be able to export the AKDE contours by applying SpatialPolygonsDataFrame.UD() to the AKDE object. Have you tried running sp::plot() instead of just plot() to avoid namepsace collision. Often times R becomes confused with multiple packages loaded that all have dispatch methods of the same name, even if their object classes are different.

As for the naming issue, if you can send me a copy of the data, then I can take a look at that. I can look at the other issues too, if they still aren't resolved.

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