Using Move package and having trouble with ext argument.

I'm trying to obtain the utilization distribution of an animal using the 'move' package in R, specifically using the code line dynBGB . However, I'm getting this error message:
"> ambito_hogareno <- dynBGB(move_obj, window = extent(move_obj))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'raster': error in evaluating the argument 'x' in selecting a method for function 'extent': error in evaluating the argument 'ext' in selecting a method for function '.extcalc': argument "ext" is missing, with no default"
I have tried different approaches to change the method of obtaining ext , but I simply can't run this line of code. Can someone help me with this issue?.
P.D. This is my script:

Install and load the necessary packages

install.packages("move")
install.packages("ggplot2")
library(move)
library(ggplot2)

Read the data from the CSV file

datos <- read.csv("J587_Categorias.csv")

Create a date-time object from the date and time columns

datos$fecha_hora <- as.POSIXct(paste(datos$YEAR, datos$Month, datos$Day, datos$Hour, datos$MIN, datos$Seconds), format = "%Y %m %d %H %M %S")

Remove duplicated records by date and time

datos <- datos[!duplicated(datos$fecha_hora), ]

Sort the data by date and time

datos <- datos[order(datos$fecha_hora), ]

Create a Move object with spatial coordinates and timestamps

move_obj <- move(x = datos$Longitude, y = datos$Latitude, time = datos$fecha_hora)

Check for any discrepancy

if (nrow(move_obj@data) != length(move_obj@data$individual.local.identifier)) {

If there is a discrepancy, create a vector of identifiers with the correct length

new_identifiers <- rep("unnamed", nrow(move_obj@data))

Replace the values in the Move object

move_obj@data$individual.local.identifier <- new_identifiers
}

Correct the datum definition in the coordinate reference system

crs(move_obj) <- "+proj=longlat +datum=WGS84"

Calculate the home range using the dBBMM method

ambito_hogareno <- dynBGB(move_obj, window = extent(move_obj))

Visualize the home range using ggplot2

ggplot() +
geom_polygon(data = as(move_obj, "SpatialPixelsDataFrame"),
aes(x = x, y = y, fill = dynamics), alpha = 0.6) +
scale_fill_gradient(low = "lightblue", high = "darkblue") +
theme_void()

Without a reprex (see the FAQ), this is difficult to debug. So, we'll just look at the function signature.

## S4 method for signature 'dBGBvariance,RasterLayer,numeric'
dynBGB(move, raster, locErr, timeStep, ...)
## S4 method for signature '.MoveTrackSingle,RasterLayer,numeric'
dynBGB(move, raster, locErr, margin, windowSize, ...)
## S4 method for signature '.MoveTrackSingle,numeric,ANY'
dynBGB(move, raster, locErr, ext, ...)
## S4 method for signature '.MoveTrackSingle,missing,ANY'
dynBGB(move, raster, locErr, dimSize, ext, ...)

To begin \dots is not implmented, so we can set that aside.

The move parameter first, then. It must be a move or dBGBvariance object and

move_obj is given as its argument. Confirm that is conforms to the requirement that it be

a move or dBGBvariance object. This object must be in a projection different to longitude/latitude (one suitable for euclidean geometry), use spTransform to transform your coordinates.

by using

check(move_obj)

The second argument raster is missing. If used it must be

a RasterLayer object or a numeric value. If a RasterLayer is provided the dynBGB starts to calculate the UD based on that raster. If a numeric value is provided it is interpreted as the resolution of the square raster cells (in map units); the according raster will be calculated internally.

but if omitted dimSize must be provided

numeric. dimSize is only used if raster is not set. dimSize is interpreted as the number of cells along the largest dimension of the track. The according raster will be calculated internally.

The third argument locErr is also missing. It must be

a single numeric value or vector of the length of coordinates that describes the error of the location (sender/receiver) system in map units. Or a character string with the name of the column containing the location error can be provided.

timestep is optional, and if is not provided, it has a default value there is a default

it correspond[s] to the size of the timer intervals taken for every integration step (in minutes). If left NULL 20.1 steps are taken in the shortest time interval.

margin is needed if move_obj is a raster layer

The margin used for the behavioral change point analysis. This number has to be odd.

windowSize is also used for a raster layer

The size of the moving window along the track. Larger windows provide more stable/accurate estimates of the brownian motion variance but are less well able to capture more frequent changes in behavior. This number has to be odd.

window is not one of the permitted arguments

ext is required when the move argument is numeric rather than a raster or in conjunction with the dimSize argument and it must

Describes the amount of extension of the bounding box around the animal track. It can be numeric (same extension into all four directions), vector of two (first x, then y directional extension) or vector of four (xmin, xmax, ymin, ymax extension). Only considered in combination with a numeric raster argument or the dimSize argument.

dimSize is used when the move argument is not a raster. It is

numeric. dimSize is only used if raster is not set. dimSize is interpreted as the number of cells along the largest dimension of the track. The according raster will be calculated internally.

So, there's some care here that needs be taken with using dynBGB(). Argument choice depends on whether a raster-like object is being used and that dictates the combination of required and optional arguments that are available and the user must consider whether the optional arguments can be derived from objects provided to the function.

Than you, so much, you are helping me a lot, this is a part of my data,

OBJECTID Shape Asset.Name Asset.Id Data.Date..COT. Latitude Longitude YEAR Month Day Hour MIN Seconds GPS.Status Altitude Speed Air.Temperature Battery.Voltage Direction SATNUM Accel.X Accel.Y Accel.Z HDOP Mag.X Mag.Y Mag.Z Activity Notification Message.Type Bluetooth.Activity Sensor.only.lecture Report.Body RASTERVALU USV
1 Point Z 19.400783 -98.379107 2022 12 16 0 21 45 2524 0 North West 5 3.9 2 NA 4.329443 BOSQUE DE ENCINO-PINO
2 Point Z 19.400987 -98.379008 2022 12 15 21 56 47 2534 0 North West 5 1.1 2 NA 5.273428 CUERPO DE AGUA
3 Point Z 19.401215 -98.378635 2022 12 15 19 32 25 2521 0 North West 8 1.1 17 NA 4.328829 BOSQUE DE ENCINO-PINO
4 Point Z 19.401057 -98.379103 2022 12 15 17 6 45 2513 0 North West 8 0.8 2 NA 6.846828 AGRICULTURA DE TEMPORAL ANUAL
5 Point Z 19.401068 -98.379077 2022 12 15 14 42 1 2516 0 North West 5 1.7 2 NA 6.642709 AGRICULTURA DE TEMPORAL ANUAL

Add an argument

... animal = "leroy"

Confirm that this is a move object

class(move_obj)

Set the crs (substitute the name of your animal for leroy

spTransform(leroy, CRSobj="+proj=moll +ellps=WGS84")

Now convert to something to use for Euclidian distances

## change projection method to aeqd and center the coordinate system to the track
dataAeqd <- spTransform(leroy, CRSobj="+proj=aeqd +ellps=WGS84", center=TRUE)

Here's a worked example under Ubuntu (couldn't get it to work under macOS)

library(move)
#> Loading required package: geosphere
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
#> Loading required package: sp
#> Loading required package: raster
data(leroy)
leroy <- leroy[230:265,]

## change projection method to aeqd and center the coordinate system to the track
dataAeqd <- spTransform(leroy, CRSobj="+proj=aeqd +ellps=WGS84", center=TRUE)

dBGB <- dynBGB(dataAeqd, locErr=9, raster=10, ext=0.5, windowSize=31, margin=15, timeStep=15/20.1)
#> Warning in BGBvarbreak(move = move, locErr = locErr, paraBreaks = paraBreaks, :
#> Optimized to zero

#> Warning in BGBvarbreak(move = move, locErr = locErr, paraBreaks = paraBreaks, :
#> Optimized to zero
plot(dBGB, col=hsv(sqrt(1:700/1000)))
lines(dataAeqd)

Created on 2023-06-28 with reprex v2.0.2

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.