iRSF with multiple categorial variables

143 views
Skip to first unread message

David Blount

unread,
Oct 10, 2023, 5:34:10 PM10/10/23
to ctmm R user group
Hey Chris, 
I'm working on doing several iRSF's with two categorial variables: land type and aspect. However, when I enter both into the rsf:

rsf.fit(bear1,UD=bear1ud, R=list( asp =as.factor(aspect), lt=as.factor(land_type)), error=0.1)

the output only treats the first variable (aspect in this case) as categorial and the second factor is treated as continuous in the output:

[1] "OUF"

$DOF
     mean      area            diffusion     speed
 18.77243  16.29699  64.95178  66.73829

$CI
                                                                      low           est         high
asp.5_1 (1/asp.5_1)                    -14.0278039   -2.66284869    8.7021065
asp.4_1 (1/asp.4_1)                     -1.4026997    0.01744136    1.4375824
asp.3_1 (1/asp.3_1)                     -1.4786380   -0.20157482    1.0754884
asp.2_1 (1/asp.2_1)                     -1.8943559   -0.34808122    1.1981934
lt (1/lt)                                             -0.7514167   -0.16677796    0.4178608
area (square kilometers)              1249.4396230 2173.19837322 3348.4230711
τ[position] (days)                               3.2395777    5.70768256   10.0561379
τ[velocity] (hours)                              2.5281282    3.08182397    3.7567870
speed (kilometers/day)                    15.6509262   17.78314120   19.9121871
diffusion (square kilometers/day)   28.6094049   37.07322960   46.6170842


both factors start with 1 are continuous throughout (i.e. aspect only has 1,2,3,4,5 and land use is 1,2,3,4,5 as well) and when I switch which is first, (i.e. list(lt= as.factor(land_type), asp=as.factor(aspect)) it successfully treats the first one like a factor.

Do you have any suggestions so it treats both as factors?

I am also using rsf.select for the final model, but for now I'm using rsf.fit to make sure the output is correct.

Thank you for your help,

David

Christen Fleming

unread,
Oct 14, 2023, 3:57:14 AM10/14/23
to ctmm R user group
Hi David,

This should be fixed on Github now. Please report any further issues.

Best,
Chris

David Blount

unread,
Oct 17, 2023, 2:08:09 PM10/17/23
to ctmm R user group
Just tried got the results back. It worked well. Thank you. Is it be possible to include random effects within the Mean() function?

Christen Fleming

unread,
Oct 17, 2023, 4:18:11 PM10/17/23
to ctmm R user group
Hi David,

For more complex analyses, I would recommend a more general tool like metafor. The RSF parameters and their variances are in the beta and COV slots of the model fit objects. Then you just need to be able to include those variances in the model as known variances in addition to the unknown natural/biological variation, which is straightforward in metafor, but also possible in other mixed-effect modeling packages.

Best,
Chris

David Blount

unread,
Oct 17, 2023, 8:44:00 PM10/17/23
to ctmm R user group
Thank you. I will look into that. I've noticed that rsf.fit seems to decrease my effective size by quite a margin. For example, when making the fit, my effective sample size is 32, when I put it into a weighted pHREML it is also 32, however after the RSF it is  0.6. This happens to all of my ~90 samples. For the home range only 1 has an effective sample size lower than 5, but after the RSF 70 do. Is this something I am doing wrong?

Christen Fleming

unread,
Oct 18, 2023, 3:58:36 PM10/18/23
to ctmm R user group
Hi David,

The effective sample size should decrease with every predictor that you include in the model. If you include too many unsupported parameters, then it can become too small. If you have two categorical variables, with 5 categories each, then that's 8 parameters added. You have to consider if your data can support that many parameters (e.g., does AIC go down? are the parameter estimates significant?). With categorical variables you often have to consider merging categories.

If your AIC is going down, your parameter estimates are significantly non-zero, and yet your effective sample size is also vanishing, then that would be more surprising to me - let me know if that's the case.

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