Error in ctmm:::rsf.fit: "missing value where TRUE/FALSE needed" with NaN likelihood

13 views
Skip to first unread message

jessica comley

unread,
Aug 11, 2025, 5:44:19 PMAug 11
to ctmm R user group

Dear CTMM Community,

I’m working on a weighted Resource Selection Function (RSF) analysis for leopard movement data using the development version of ctmm (ctmm:::rsf.fit). Despite ensuring that my telemetry data and raster are aligned in WGS84 (+proj=longlat +datum=WGS84 +no_defs), I’m encountering the following error:

text
Maximizing likelihood @ n=1×4467=4467
SD[log(l)] = NaN
Δlog(l) = NaN
Δß/SD[ß] = 0 0 0 0 0 0
Error in while (ERROR.BIG) { : missing value where TRUE/FALSE needed
In addition: There were 15 warnings (use warnings() to see them)
Warning messages: In max(SAMP, na.rm = TRUE) : no non-missing arguments to max; returning -Inf

Data Details:

  • Telemetry: 4,467 GPS points for a leopard in WGS84 (longitude: 19.09 to 19.34, latitude: -32.50 to -32.37).
  • Raster: Slope raster masked to a study area, projected to WGS84 (resolution: 0.002 degrees, ~200m), with 4,912,059 non-NA cells out of 9,129,591 (46% NA due to non-terrestrial areas). All telemetry points have non-NA slope values (mean: 20.24, range: 1.84 to 37.97).
  • Workflow: I load the telemetry object, correct its projection to WGS84, mask a UTM slope raster to the study area, project it to WGS84, convert to RasterLayer, and filter telemetry points to ensure non-NA slope values. I then fit an OU anisotropic model, compute a weighted AKDE, and run ctmm:::rsf.fit.

Steps Taken:

  • Verified telemetry and raster are in WGS84.
  • Ensured all telemetry points have non-NA slope values using raster::extract.
  • Tried finer raster resolution (0.002 degrees) and checked alignment with plots.
  • Confirmed valid AKDE output (area: 70.72 km², DOF: 420.71).

Any guidance on debugging this error or correctly setting up rsf.fit would be greatly appreciated. I can share additional code or outputs if needed.

Thank you,

Jess

Christen Fleming

unread,
Aug 27, 2025, 12:34:54 PMAug 27
to ctmm R user group
Hi Jessica,

The telemetry object would have to be projected in meters and probably is if you check the output of projection().
as.telemetry() and projection()<- shouldn't let you project the location data into long-lat without giving an error.

If that part is okay, feel free to send me a minimal working example (data & code) so that I can reproduce the error.

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