Issues with oSCR.fit

Skip to first unread message

Giacomo Rosa

unread,
Aug 30, 2023, 9:57:18 AM8/30/23
to oSCR

Hi,

I’m a PhD student and I’m working on a two years CMR data (collected from my PhD project) of a subterranean population of Strinati’s cave salamander. We performed the study inside a cave, equipped with a 1m square grid of 5x42 plots, where we captured and photographed the ventral patterns of individuals, noting sex (M, F and SA – subadults) and capture site. This protocol was done about once a month in the last two years (i.e., 1 session and 30 occasions). I added some of the trap covariates that we registered (i.e., surface temperature of cave wall during the peak activity and distance from the entrance).

I followed the RBS worked example for preparing and analyzing the data. I was able to create the data2oscr object and the state space object. However, I have troubles when I try to run models,  for example with the base model (m1) it says "Error in nlm(msLL.sex, scrFrame = scrFrame, p = pv, pn = pn, D = D, nG = nG,  : non-finite value supplied by 'nlm'.", while if I try to add trap covariates (m2) I receive the message “Error in dm.trap[[s]][[k]] %*% c(t.beta[s, ]) : non-conformable arguments”.

I’m wondering if there is an underlying problem with data setting, because I repeated multiple times data formatting and analysis and I believe those are correct. Attached the R code and scrFrame plot.

I would appreciate any advice, thank you in advance!

Giacomo Rosa 

library(devtools)

library(oSCR)

ss.edf<-read.table("str.edf”,header=1)

ss.tdf<-read.table("str.tdf ",header = 1)

head(ss.edf)

Detector Session ID Sex Occasion

1       B4       1  1  SA        1

2       B5       1  3  SA        1

3       B8       1  4   M        1

4       B9       1  5  SA        1

5      A10       1  6   F        1

6      E10       1  7   M        1

head(ss.tdf)

Detector X Y t.oper sep  Temp Distance

1     A1 1 1      1   / 12.87        1

2     A2 1 2      1   / 12.83        2

3     A3 1 3      1   / 11.97        3

4     A4 1 4      1   / 11.83        4

5     A5 1 5      1   / 11.70        5

6     A6 1 6      1   / 11.73        6

ss.data<-data2oscr(edf=ss.edf,

                    sess.col=2,

                    id.col=3,

                    occ.col=5,

                    trap.col=1,

                    sex.col=4,

                    tdf=list(ss.tdf),

                    K=c(30),

                    ntraps= 210,

                    trapcov.names=c("Temp","Distance"),

                    sex.nacode = "SA",

                    tdf.sep="/")

 

names(ss.data)

ss.sf<-ss.data$scrFrame

names(ss.sf)

caphist <- ss.sf$caphist

traps <- ss.sf$traps

trapCovs <-ss.sf$trapCovs

indCovs<-ss.sf$indCovs

sf<-make.scrFrame(caphist = caphist, traps = traps, indCovs=indCovs, trapCovs = trapCovs, type = "scr")

plot(sf,jit=2)

ss.ss<-make.ssDF(scrFrame=sf,buffer=3,res=0.5)

str(ss.ss)

plot(ssDF=ss.ss,scrFrame=sf)

 

m1<-oSCR.fit(model=list(D~1, #density

                        p0~1,#detection

                        sig~1), #spaceuse

             scrFrame=sf,ssDF=ss.ss)

 

m2<- oSCR.fit(model=list(D~1, #density

                        p0~Temp,#detection

                        sig~1), #spaceuse

             scrFrame=sf,ssDF=ss.ss)

Rplot.jpeg

Jeffrey Royle

unread,
Aug 30, 2023, 10:10:26 AM8/30/23
to oscr_p...@googlegroups.com
hello,
 The error here might be poor starting values for the model parameters.  You should try to ballpark those as best you can and see if that makes a difference.   If you run oSCR.fit with the getStarts = TRUE option then it will tell you what should be the order of the starting values.
regards
andy


--
You received this message because you are subscribed to the Google Groups "oSCR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oscr_package...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/oscr_package/33e8a756-a887-438e-aef4-150e8db50f3an%40googlegroups.com.

Giacomo Rosa

unread,
Aug 31, 2023, 8:24:16 AM8/31/23
to oSCR
Dear Andy Royle,

thank you very much for the quick answer!
I followed you suggestion, but now I receive the message "Error in solve.default(myfit$hessian) : Lapack routine dgesv: system is exactly singular: U[1,1] = 0". I tried to change buffer and resolution of the SSDFrame (and consequently also the starting values for the new model to fit), but I continue to receive the same error and not the warning "Something went wrong! Try better starting values."
I think the problem is in the ssDF, but I'm not sure. Do you have any suggestions?

Thank for your time and availability.

Kind regards,

Giacomo

Jeffrey Royle

unread,
Sep 1, 2023, 10:35:26 PM9/1/23
to oscr_p...@googlegroups.com
If you send me your data and R script exactly as you're using, so that I can reproduce the error, I'll give it a shot this weekend...
regards
andy


Filipe Rocha

unread,
Jan 10, 2025, 11:50:59 AM1/10/25
to oSCR
Hi,

I'm getting the same error message as Giacomo:
model3 <- oSCR.fit(model = list(D ~ 1, # model describing variation pixel density (D(si))
p0 ~ offset(log.effort) + placement, # model describing variation in baseline encounter prob/rate (p0) sig ~ 1), # model describing variation in sigma (space use) encmod = "P", scrFrame = reduced.cheetah, # the scrFrame object ssDF = state.space.cheetah) #, # the ssDF object Fitting model: D~1, p0~placement + offset(log.effort), sigma~1, asu~1 Using ll function 'msLL.nosex' Hold on tight! 2025-01-10 16:06:02.521526 p0.(Intercept) | sig.(Intercept) | t.beta.placementrandom | t.beta.placementtrail | t.beta.placementwaterhole | d0.(Intercept) | Error in solve.default(myfit$hessian) : Lapack routine dgesv: system is exactly singular: U[3,3] = 0

I am estimating cheetah abundance from camera trapping data. The problem might be from the covariate placement (which is a factorial covariate indicating whether each camera is placed by a playing tree, water hole, trail or in a riverbank), as the error only occurs when I include this covariate. I tried to reduce the buffer of the SSDF and the error message changes to a warning message:

model3 <- oSCR.fit(model = list(D ~ 1, # model describing variation pixel density (D(si)) p0 ~ offset(log.effort) + placement, # model describing variation in baseline encounter prob/rate (p0) sig ~ 1), # model describing variation in sigma (space use) encmod = "P", scrFrame = reduced.cheetah, # the scrFrame object ssDF = state.space.cheetah) ) #, # the ssDF object Fitting model: D~1, p0~placement + offset(log.effort), sigma~1, asu~1 Using ll function 'msLL.nosex' Hold on tight! 2025-01-10 16:27:40.604548 p0.(Intercept) | sig.(Intercept) | t.beta.placementrandom | t.beta.placementtrail | t.beta.placementwaterhole | d0.(Intercept) | Model: D ~ 1 p0 ~ offset(log.effort) + placement sig ~ 1 Run time: 7.565 minutes AIC: 170.6243 Summary table: Estimate SE z P(>|z|) p0.(Intercept) -5.836 0.374 -15.613 0.000 t.beta.placementrandom -21.452 NaN NaN NaN t.beta.placementtrail -1.913 0.660 -2.898 0.004 t.beta.placementwaterhole 1.042 0.471 2.212 0.027 sig.(Intercept) 9.193 0.197 46.683 0.000 d0.(Intercept) -5.736 0.352 -16.304 0.000 *Density intercept is log(individuals per pixel) Nhat(state-space) = exp(d0.)*nrow(ssDF) (caution is warranted when model contains density covariates) Warning message: In sqrt(diag(solve(myfit$hessian))) : NaNs produced

Do you have any thoughts on how I can fix this issue?

Thanks a lot for your help.
Filipe Rocha

Jeffrey Royle

unread,
Jan 10, 2025, 11:57:35 AM1/10/25
to oscr_p...@googlegroups.com
hi Filipe,
 I will be glad to take a look in the next few days if you send me the script/data so that I can exactly reproduce what you're doing easily.
 regards
andy


Chris Sutherland

unread,
Jan 10, 2025, 2:40:32 PM1/10/25
to oscr_p...@googlegroups.com

Hi Filipe,

Can I check two things. First, does the null model work? I.e., no covariates at all, not even an offset. Second, if the null model does work, what happens when you add the offset?

The reason I ask is that something happened a little while ago that caused the offset to sometimes produce strange results (errors).

Chris


filipe.pi...@gmail.com

unread,
Jan 10, 2025, 7:34:51 PM1/10/25
to oscr_p...@googlegroups.com

Dear Andy and Chris,

Thanks for your quick reply.

 

I did run the full null model and the model with only the offset and both work.

 

model1 <- oSCR.fit(model = list(D ~ 1,     #  model describing variation pixel density (D(si))

                                p0 ~ 1,    #  model describing variation in baseline encounter prob/rate (p0)

                                sig ~ 1),   #  model describing variation in sigma (space use)

                   encmod = "P",

                   scrFrame = reduced.cheetah, # the scrFrame object

                   ssDF = state.space.cheetah, # the ssDF object

                   trimS = 1.5*buffer)

Fitting model: D~1, p0~1, sigma~1, asu~1

Using ll function 'msLL.nosex'

Hold on tight!

2025-01-10 23:41:47.396115

p0.(Intercept) |  sig.(Intercept) |  d0.(Intercept) | 

 

 Model:  D ~ 1 p0 ~ 1 sig ~ 1

Run time:  0.7168333  minutes

AIC:  203.998

Summary table:

                Estimate    SE       z P(>|z|)

p0.(Intercept)    -1.087 0.319  -3.412   0.001

sig.(Intercept)    9.015 0.178  50.592   0.000

d0.(Intercept)    -5.994 0.328 -18.302   0.000

*Density intercept is log(individuals per pixel)

  Nhat(state-space) = exp(d0.)*nrow(ssDF)

  (caution is warranted when model contains density covariates)

model2 <- oSCR.fit(model = list(D ~ 1,     #  model describing variation pixel density (D(si))

                                p0 ~ offset(log.effort),    #  model describing variation in baseline encounter prob/rate (p0)

                                sig ~ 1),   #  model describing variation in sigma (space use)

                   encmod = "P",

                   scrFrame = reduced.cheetah, # the scrFrame object

                   ssDF = state.space.cheetah, # the ssDF object

                   trimS = 1.5*buffer)

Fitting model: D~1, p0~offset(log.effort), sigma~1, asu~1

Using ll function 'msLL.nosex'

Hold on tight!

2025-01-10 23:44:53.359599

p0.(Intercept) |  sig.(Intercept) |  d0.(Intercept) | 

 

 Model:  D ~ 1 p0 ~ offset(log.effort) sig ~ 1

Run time:  0.959  minutes

AIC:  188.5243

Summary table:

                Estimate    SE       z P(>|z|)

p0.(Intercept)    -6.049 0.310 -19.499       0

sig.(Intercept)    9.082 0.178  50.969       0

d0.(Intercept)    -5.921 0.335 -17.701       0

*Density intercept is log(individuals per pixel)

  Nhat(state-space) = exp(d0.)*nrow(ssDF)

  (caution is warranted when model contains density covariates)

 

The error only occurs when I include the ‘placement’; that’s why I connected the error to the ‘placement’ covariate.

 

model3 <- oSCR.fit(model = list(D ~ 1,     #  model describing variation pixel density (D(si))
                                p0 ~ offset(log.effort) + placement,    #  model describing variation in baseline encounter prob/rate (p0)
                                sig ~ 1),   #  model describing variation in sigma (space use)
                   encmod = "P",
                   scrFrame = reduced.cheetah, # the scrFrame object
                   ssDF = state.space.cheetah, # the ssDF object 
                   trimS = 1.5*buffer) )
Fitting model: D~1, p0~placement + offset(log.effort), sigma~1, asu~1 
Using ll function 'msLL.nosex' 
Hold on tight!
2025-01-10 23:57:02.156934
p0.(Intercept) |  sig.(Intercept) |  t.beta.placementriverbank |  t.beta.placementtrail |  t.beta.placementwaterhole |  d0.(Intercept) |  
 
Error in solve.default(myfit$hessian) : 
  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

 

I read the topic in the group regarding the strange results with the offset. Do you suggest using solely log(effort) without the offset? I tried, and it ran without errors, but I got a warning message and NAs in ‘t.beta.placementriverbank’.

model5 <- oSCR.fit(model = list(D ~ ndvi.z,     #  model describing variation pixel density (D(si))
                                p0 ~ log.effort + placement,    #  model describing variation in baseline encounter prob/rate (p0)
                                sig ~ 1),   #  model describing variation in sigma (space use)
                   encmod = "P",
                   scrFrame = reduced.cheetah, # the scrFrame object
                   ssDF = state.space.cheetah,
                   trimS = 1.5*buffer) )
Fitting model: D~ndvi.z, p0~log.effort + placement, sigma~1, asu~1 
Using ll function 'msLL.nosex' 
Hold on tight!
2025-01-11 00:18:51.164638
p0.(Intercept) |  sig.(Intercept) |  t.beta.log.effort |  t.beta.placementriverbank |  t.beta.placementtrail |  t.beta.placementwaterhole |  d0.(Intercept) |  d.beta.ndvi.z |  
 
 Model:  D ~ ndvi.z p0 ~ log.effort + placement sig ~ 1
 Run time:  8.552833  minutes
 AIC:  173.0383
 
Summary table: 
                          Estimate    SE       z P(>|z|)
p0.(Intercept)              -8.077 0.000    -Inf   0.000
t.beta.log.effort            1.463 0.082  17.898   0.000
t.beta.placementriverbank  -18.855   NaN     NaN     NaN
t.beta.placementtrail       -1.891 0.660  -2.865   0.004
t.beta.placementwaterhole    1.289 0.509   2.535   0.011
sig.(Intercept)              9.249 0.152  60.908   0.000
d0.(Intercept)              -5.667 0.394 -14.383   0.000
d.beta.ndvi.z                0.778 0.420   1.855   0.064
*Density intercept is log(individuals per pixel) 
  Nhat(state-space) = exp(d0.)*nrow(ssDF)
  (caution is warranted when model contains density covariates)
Warning message:
In sqrt(diag(solve(myfit$hessian))) : NaNs produced

 

Thanks for your assistance,

Best,

Filipe

 

 

--

Filipe Rocha, PhD

Associação BIOPOLIS /CIBIO - Research Center in Biodiversity and Genetic Resources

University of Porto

e-mail: filipe...@cibio.up.pt

Campus de Vairão,
Rua Padre Armando Quintas
4485-661, Vairão

Portugal

--
You received this message because you are subscribed to a topic in the Google Groups "oSCR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/oscr_package/vbZ1OqfQe6A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to oscr_package...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/oscr_package/CANjB3vRgwpEynbV0tYZwwzVRBOy%2BcVmx7eQ_f_5ytHmuy1h6oQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages