ctmm-initiative / ctmm

Continuous-Time Movement Modeling. Functions for identifying, fitting, and applying continuous-space, continuous-time stochastic movement models to animal tracking data.
http://biology.umd.edu/movement.html
47 stars 12 forks source link

Problem with variogram.fit #46

Closed kaijagahm closed 1 year ago

kaijagahm commented 1 year ago

I'm trying to run variogram.fit on a telemetry object and I keep getting an error that I don't know how to address. Here's an example with a very small subset of my data (20 gps fixes).

  # Here is some sample data
  dat <- new("telemetry", .Data = list(structure(c(1641823543, 1641824125, 
1641853409, 1641879239, 1641879887, 1641880457, 1641881039, 1641881648, 
1641882233, 1641882859, 1641883433, 1641884035, 1641884639, 1641885293, 
1641886439, 1641887035, 1641887629, 1641888230, 1641888839, 1641890050, 
1641890627), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
    c(34.9584072875977, 34.9584034729004, 34.9583576965332, 34.9583538818359, 
    34.958254699707, 34.9583767700195, 34.9583042907715, 34.958426361084, 
    34.9583195495605, 34.9583767700195, 34.9583157348633, 34.9585675048828, 
    34.9587048339844, 34.9590023803711, 34.9588040161133, 34.9588726806641, 
    34.9591664123535, 34.958182220459, 34.9554585266113, 34.9576290893555, 
    34.9593342590332), c(31.2438753509521, 31.2437837982178, 
    31.2439268493652, 31.2439497375488, 31.2441118621826, 31.2439478302002, 
    31.2440203094482, 31.2431600952148, 31.2440622711182, 31.2439688110352, 
    31.2440908813477, 31.2439688110352, 31.2440412902832, 31.2436769866943, 
    31.243736114502, 31.243636932373, 31.2439649963379, 31.2437971496582, 
    31.2404440307617, 31.2433946990967, 31.2457998657227), c(1641823543, 
    1641824125, 1641853409, 1641879239, 1641879887, 1641880457, 
    1641881039, 1641881648, 1641882233, 1641882859, 1641883433, 
    1641884035, 1641884639, 1641885293, 1641886439, 1641887035, 
    1641887629, 1641888230, 1641888839, 1641890050, 1641890627
    ), c(9923.78385454008, 9918.27656090272, 9922.62988523765, 
    9923.6148366204, 9924.66125039937, 9925.38762203172, 9923.5429164271, 
    9884.77483704082, 9927.1774005611, 9926.57786725216, 9928.48696581333, 
    9942.25278621207, 9957.65047375093, 9961.43658939366, 9948.48889253886, 
    9948.50531633682, 9991.2557298063, 9900.85106784011, 9486.78355635655, 
    9832.56253264949, 10109.1405569023), c(-4947.93536618949, 
    -4956.51856135085, -4940.58897504346, -4938.21107221311, 
    -4917.85506369397, -4939.50786400909, -4929.03783320704, 
    -5017.37066070079, -4925.76150419675, -4937.49832995967, 
    -4922.83554585765, -4946.78253319332, -4946.52510329108, 
    -4995.90130582351, -4980.58252108702, -4993.42446685281, 
    -4976.30013011704, -4944.47004127369, -5133.04320116039, 
    -4956.09194129219, -4808.72632132996)), info = list(identity = "E46", 
    timezone = "UTC", projection = "+proj=tpeqd +lat_1=30.8247095958804 +lon_1=34.8216940873186 +lat_2=30.968410428974 +lon_2=35.1037642653953 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"), 
    UERE = new("UERE", .Data = list(structure(10, dim = c(1L, 
    1L), dimnames = list("all", "horizontal")), structure(0, dim = c(1L, 
    1L), dimnames = list("all", "horizontal")), c(horizontal = Inf), 
        c(horizontal = Inf), c(horizontal = Inf), c(horizontal = 0)), 
        info = list()), names = c("timestamp", "longitude", "latitude", 
    "t", "x", "y"), row.names = 200:220, .S3Class = "data.frame")

Using that sample data, I try to open the interactive variogram fit module

    library(ctmm)
    plot(dat) # this works fine
    plot(variogram(dat)) # this also works fine; produces a weird result because we're only looking at 20 points, but it does work.

    variogram.fit(dat)
    > Error in data.frame(min = MIN, max = 1, initial = z, label = "zoom", step = log(min.step,  : 
  arguments imply differing number of rows: 1, 0

Any idea what's happening here? I get the same result with other animals, with other numbers of points, etc.

Thanks!

chfleming commented 1 year ago

Hi @kaijagahm , plot on a variogram object shows the first half of the variogram by default, which is convention, as the latter half has large uncertainties. You can use zoom instead or increase the fraction argument to increase that.

variogram.fit is for variogram objects and not telemetry objects, but I can add an error message for that. ctmm.guess is the more comprehensive function and works on telemetry objects (or both).

kaijagahm commented 1 year ago

Ah, of course! I'm re-reading the documentation, and it does say that it takes a variogram object. Not sure how I missed that. An informative error message would definitely help.

Thanks!