Code for intensity()

98 views
Skip to first unread message

Lorenzo Frangini

unread,
May 24, 2023, 8:32:27 AM5/24/23
to ctmm R user group
Hi Chris,

I've just read about the instensity() function, great!

I'd like to ask you if you can provide some codes about since if I try to run it it returns some errors.

Here my code:

animal<-as.telemetry(animal)
projection(animal) <- median(animal)

#create a new variable to test selection during day and nighttime
animal <- annotate(animal)
animal$day <- animal$sunlight>0
animal$night<- animal$sunlight<=0


#after calculating UD with akde and importin my variables as raster files, I fit my model
wRSF_animal <- ctmm:::rsf.fit(animal, UD=UD, R=list(Var1=var1,Var2=var2,Var3=var3), formula=~scale(Var3):night + scale(Var3):day + scale(Var2):night + scale(I(Var2^2)):night + scale(Var2):day + + scale(I(Var2^2)):day + scale(Var1):night + scale(Var1):day + scale(I(Var1^2)):night + scale(I(Var1^2)):day,error=0.1,integrator = "MonteCarlo")

#the model is succesfully fit, but when I try to plot the instensity() it returns some errors

intensity(animal,UD=UD, R=list(Var1=var1,Var2=var2,Var3=var3),RSF=wRSF_animal,variable = Var1) Error in intensity(animal, UD = UD, R = list(Var1= var1, : object 'Var1' not found

What should I correct?
Best
Lorenzo

Christen Fleming

unread,
May 24, 2023, 7:12:57 PM5/24/23
to ctmm R user group
Hi Lorenzo,

The variable argument needs to be a character object. I'm guessing that variable="Var1" would probably work. Var1 does not reference a defined object outside of the list.

Tell me how the results come out. I'm not sure how convinced I am by the method so far.

Best,
Chris

Lorenzo Frangini

unread,
May 25, 2023, 4:16:07 AM5/25/23
to Christen Fleming, ctmm R user group
Hi Chris,

yes I was thinking the same, I tried but it returns error. Therefore, I tried different options and here you can fin d the errors:

1. if I write "Var1" as you suggest this is the error: Error in RM - MODEL : non-conformable arrays

2. I tried to edit something within the rsf.fit() code, so in the formula I removed the scale argument (e.g. from ~scale(Var1):day + scale(Var1):night + [...]  to ~Var1:day + Var1:night + [...] ) and the model is fit but there are some issues (I think because of the polynomial arguments (e.g. I(Var1^2)):
Warning message:
In cov.loglike(hess, grad) : MLE is near a boundary or optimizer failed.

3.  In the formula I removed the scale argument and the polynomial arguments (e.g. I(Var1^2)), and the error this time is:  


Error in plot.window(...) : Need Finite 'ylim' Values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
I'm wondering what I'm doing wrong

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/KadGyVheNH0/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/2d21721b-cd6f-4516-830c-e88489b8c8fan%40googlegroups.com.


--
Lorenzo Frangini

Christen Fleming

unread,
May 25, 2023, 6:54:48 AM5/25/23
to Lorenzo Frangini, ctmm R user group
Hi Lorenzo,

Can you send me a minimal working example to debug?

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