Response curves and interaction among covariates in rsf.fit()

119 views
Skip to first unread message

Lorenzo Frangini

unread,
Feb 22, 2023, 9:06:14 AM2/22/23
to ctmm R user group
Hi Chris,

after succesfully fitting my models using rsf.fit(), I was wondering if it is possible to:

1. Plot the response curves for each covariate

2. Investigate the interaction among covariates, i.e., the moltiplicative effect

3. I would like to investigate if locations during the day differ in selection from those during the night (which I'm pretty sure they are), which I think it is a particolar case of the point above (2.).

Thank you very much.

Best
Lorenzo

Christen Fleming

unread,
Feb 22, 2023, 3:55:06 PM2/22/23
to ctmm R user group
Hi Lorenzo,

1. I haven't coded this yet, but I had planned to work on some diagnostic curves (and response curves) at some point.
2. You can presently use the formula argument to add interactions between covariates.
3. You can also do this presently, by using annotate() to help make a day/night column in the tracking data, and then referencing that column in the formula.

Best,
Chris

Lorenzo Frangini

unread,
Feb 23, 2023, 8:02:41 AM2/23/23
to Christen Fleming, ctmm R user group
Hi Chris,

thank you very much!

Just another little thing: for points 2. and 3. can you provide an example on how should I write the script for the formula argument? Because I searched for it but I couldn't find it

In other words, if I have:

rsf.fit(data,UD,R=list(),formula=NULL)

What should I replace to "NULL"?

Thank you again 

Best
Lorenzo
        

--
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/ZFvq6-4WTwk/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/c4f9aa58-1bdf-4f8e-af09-d7b593248000n%40googlegroups.com.


--
Lorenzo Frangini

Christen Fleming

unread,
Feb 23, 2023, 9:01:02 AM2/23/23
to ctmm R user group
Hi Lorenzo,

Something like this should work:

# DATA is a telemetry object
# TREE is a raster object for tree cover
# create a boolean for day/night
DATA <- annotate(DATA)
DATA$day <- DATA$sunlight>0
DATA$night<- DATA$sunlight<=0

This would be the obvious interaction term

RSF <- rsf.fit(DATA,UD,R=list(tree=TREE),formula=~tree + tree:day)

But this model would be more interpretable:

RSF <- rsf.fit(DATA,UD,R=list(tree=TREE),formula=~tree:night + tree:day)

A difference with regular formula construction is that you want to avoid '*' because "tree*day" would expand into "tree + day + tree:day", and a 'day' term makes absolutely no sense for a spatial process model.

Best,
Chris

Lorenzo Frangini

unread,
Mar 22, 2023, 4:46:54 AM3/22/23
to Christen Fleming, ctmm R user group
Hi Chris, 

thank you again and sorry for the very late response. 

I was able to try your script only yesterday and performing a "classic" wRSF (without the formula argument) the analysis went well.

However, the problems raised when I try to use the formula argument inspecting the effect of day/night on the selection of only one covariate. 
If I try to use the formula argument it returns an error for an animal with few GPS locations (~130 locations):
"RSF code is isotropic for the moment.
Some rasters are not loaded in RAM and may be slow to process. See help("raster::readAll").
Users are responsible for standardizing rasters when formula argument is supplied.
Error in dim(RET) <- c(nrow(data), dim(envir)[1], length(term)) :  
dims [product 6528] do not match the length of object [8]"

If I try with an animal with much more locations (~1400 locations) it is very time consuming (I started 20 hours ago, and it is still running) and honestly I do not know if it will work. It seems like too much time, perhaps something is not going well:
"RSF code is isotropic for the moment.
Maximizing likelihood.
Calculating Hessian.
Calculating REML gradient.
Calculating REML Hessian.
Some rasters are not loaded in RAM and may be slow to process. See help("raster::readAll").
Users are responsible for standardizing rasters when formula argument is supplied. 
Maximizing likelihood @ n=46715"

If you need, I can privately provide you all the files and scripts I'm using.

Best,
Lorenzo



--
Lorenzo Frangini

Christen Fleming

unread,
Mar 22, 2023, 9:12:37 AM3/22/23
to ctmm R user group
Hi Lorenzo,

I think I fixed this error a little while back. Would you mind updating from GitHub and trying again?
remotes::install_github("ctmm-initiative/ctmm")

Best,
Chris
Reply all
Reply to author
Forward
Message has been deleted
0 new messages