RSF Questions

422 views
Skip to first unread message

ross.co...@gmail.com

unread,
Jun 7, 2023, 10:49:00 AM6/7/23
to ctmm R user group

Hi Chris,

I started working through the new resource selection function analysis. I had a few questions. My 95% AKDE tortoise home ranges calculated with data obtained with VHF telemetry are a median of 3 ha (range <1 ha to 59 ha) and location fixes are separated by a minimum of 2 days (i.e., coarsely sampled). The resolution of my habitat predictor rasters and UD grid size are 25 sq m. I plan on using rsf.select() on all individuals as a third of my subjects required averaging of different periods of range resident behavior into a single home range (mentioned in this helpful thread). I have 7 habitat predictors of interest: distance to road, percent coverage of vegetation class A, B, and C, and patch density of vegetation class A, B, and C). 

Sample code for an individual: 

RSF_145 <- rsf.select(tortoise145.16, UD=wakde145.16_hscv, R=list(pland1=pland1, pland2=pland2, pland4=pland4, pd1=pd1, pd2=pd2, pd4=pd4, distance1=distance1),trace=2)

1. In my test runs, the rasters for my habitat predictors extend just beyond the 95% UD (say, 15-20 m). It seems like this may be insufficient and sampling during the analyses may reach beyond that. To remedy this, I'll follow your previously offered guidance of having the raster extend to the 99% UD for each individual, 

 ctmm::extent(UD,complete=TRUE,level=0.99,level.UD=0.99)

You can confirm if you think this is OK or a potential problem, but I'm particularly mentioning this in case it sheds light on an issue I bring up below.


I have received the following messages while running code that have not been brought up here in the threads.

2. When first importing rasters, warnings given on the first raster.

pland1 <- raster("pland1145.tif")

There were 33 warnings (use warnings() to see them)

Warning messages:

1: Not a validObject(): no slot of name "variable" for this object of class "UD"

3. I could not run the rsf code on one individual at all, and received the error

Error in if (!profile || any(STRUCT$error & !UERE.FIT)) { missing value where TRUE/FALSE needed

4. Lastly, for an individual with a large (~31 ha) home range I was unable to finish the analysis. On one computer I received a message something like "could not compute vector of size 400 xx" and on a different (faster) computer received the message 

In rsf.fit(data, UD, R = R, formula = FORM[[i]], trace = max(trace - : Calculation stopped before 1.6 Gb allocation.

In the latter, estimates were calculated for 2/7 habitat predictors. Is the resolution of my UD and rasters (25 sq m) too fine for this analysis? If so, do I have any alternatives before making the UD/rasters coarser to facilitate computation? I have been able to get the model to run on this individual with the large home range with one habitat predictor, but 7 bogs it down. I'm not sure if running different analyses on related habitat predictors would be appropriate (e.g. one rsf for vegetation class patch density (3 predictors), one rsf for vegetation class percent coverage (3 predictors), and one rsf for distance to road).

As always, thank you for your help! 

Ross

Christen Fleming

unread,
Jun 7, 2023, 4:25:43 PM6/7/23
to ctmm R user group
Hi Ross,
  1. Okay.
  2. That warning sounds like something got corrupted in your R session and some objects aren't loading correctly? Or maybe your UD objects are from a much older version of ctmm and lack the @variable slot?
  3. Please send me a minimal working example so that I can fix the error.
  4. You may find the terminal precision to be sufficient (it is stored in the output fit object, if you look in names(FIT) for it - I think it's VAR.loglike). Otherwise, there are a couple of potential solutions to this: (a) if you don't have time-dependent covariates or super low-resolution covariates then you can switch to integrator="Riemann" or if you have enough RAM you can increase the max.mem argument.
For multiple predictors, I would suggest using rsf.select().
If the 3 habitat types are colinear (i.e., A+B+C==1 because everything is either A, B, or C), then that will be an issue and you would need to omit one as a reference class.

Best,
Chris

ross.co...@gmail.com

unread,
Jun 12, 2023, 2:35:35 PM6/12/23
to ctmm R user group
Hi Chris,
I began preparing a consolidated script for you to recreate the error

Error in if (!profile || any(STRUCT$error & !UERE.FIT)) { missing value where TRUE/FALSE needed
I received immediately after running rsf.select(). In my exploration of this analysis thus far, I have been working off a saved environment containing the calculated UDs. My saved code dates to August 2021. I had the inclination to run everything from scratch, and for that one individual using that calculated UD with the most current version of ctmm I did not received messages from issues #2 (1: Not a validObject(): no slot of name "variable" for this object of class "UD") nor #3 (error mentioned above) I brought up above. So perhaps I should just rerun everything and create a new environment to work off of for the rsf analysis.

I tried increasing the  max.mem argument but the analysis was pushing 24 hrs of run-time and I cancelled it. I had mixed success with changing  integrator="Riemann". For one individual with a ~2 ha home range, I received the message

In cov.loglike(hess, grad) : MLE is near a boundary or optimizer failed.

For another individual with a large (~30 ha) home range, the analysis completed! However,  summary() of the rsf.select() object did not yield a complete list of predictors and their estimates. Is there a way to call those out?

Interested to hear your take on where I got with those suggestions. I wonder if home range size may not be my biggest limitation but rather data quality (given coarse data from VHF telemetry) in successfully completing the analysis. Also, luckily there are 4 vegetation classes and only 3 are of interest, so I don't have the collinearity issue you mentioned. 
Thanks Chris. 

Christen Fleming

unread,
Jun 12, 2023, 7:23:07 PM6/12/23
to ctmm R user group
Hi Ross,

Yes, you will want to re-run everything. Unfortunately, sometimes when adding new features, I have to modify object structures to accommodate those features.

That warning in most contexts is telling you that you need to be running *.select() instead of *.fit().

As with ctmm.select(), you can run rsf.select() with verbose=TRUE to get the full list of candidate models that were attempted and report the AIC difference with the kitchen-sink model. However, while I know that it is a common practice to fit a bunch of predictors in one big model and report all of the p-values, I do not recommend that. When you fit a model with unsupported parameters via maximum likelihood (which is pretty much any frequentist parametric model) then the standard errors based on the curvature of the likelihood function (again, the most common method) can become inaccurate because the Hessian of the likelihood function can become ill-conditioned.

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