NA in likelihood calculations

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Re: NA in likelihood calculations

Postby bedford » Fri Nov 02, 2018 9:21 am

Okay, done! Thanks very much.
Nicole
bedford
 
Posts: 4
Joined: Thu Oct 25, 2018 5:10 pm

Re: NA in likelihood calculations

Postby murray.efford » Fri Nov 02, 2018 8:17 pm

Thanks for sending the data.

One issue I should have guessed before: there are enough long moves (hist(unlist(moves(mouse17)))) that detectfn = 'HN' struggles. Switching to detectfn = 'EX' allows fitting to proceed (non-missing log likelihood).

However, fitting is still a rocky road, and by default yields no variance for sigma-hat. This can be repaired by running with the more refined numerical algorithm
Code: Select all
mask <- make.mask(traps(mouse17), buffer = 80, type = 'trapbuffer')
fit17a <- secr.fit(mouse17, model = list(D~1, g0~1, sigma~1), buffer = 80,
                  detectfn = 'EX', mask = mask)
## doesn't converge well...
## default mask spacing is wider than trap spacing - disconcerting and possibly problematic
## try a finer mask
mask5 <- make.mask(traps(mouse17), buffer = 80, type = 'trapbuffer', spacing = 5)
nrow(mask5)
## this will be slow...
fit17b <- secr.fit(mouse17, model = list(D~1, g0~1, sigma~1), buffer=80,
                   detectfn = 'EX', mask = mask5)
## no SE for sigma-hat, so recompute
fit17c <- secr.fit(mouse17, model = list(D~1, g0~1, sigma~1), buffer=80,
                   detectfn = 'EX', mask = mask5, start=fit17b, method = 'none')

predict(fit17a)
# link   estimate SE.estimate       lcl        ucl
# D       log  2.1939802 0.408944556 1.5273081 3.15165579
# g0    logit  0.0550488 0.007925989 0.0414255 0.07281199
# sigma   log 18.1718790         NaN       NaN        NaN
predict(fit17b)
# link   estimate SE.estimate        lcl        ucl
# D       log  2.4744063 0.430321629 1.76417096 3.47057428
# g0    logit  0.0584761 0.008517707 0.04385152 0.07758227
# sigma   log 18.3024897         NaN        NaN        NaN
predict(fit17c)
# link   estimate SE.estimate         lcl        ucl
# D       log  2.4744063 0.423730612  1.77320388  3.4528948
# g0    logit  0.0584761 0.001954107  0.05476171  0.0624258
# sigma   log 18.3024897 0.186117364 17.94132677 18.6709229


Also, the layout rings some alarm bells about the mask: the layout has 70 columns of traps in the east-west direction, and the default mask divides this plus 2 x buffer by 64, so the default mask has spacing (13.3 m) wider than the trap layout (10 m) and a large fraction of sigma-hat. SECR models are fairly robust to spatial discretization (https://www.otago.ac.nz/density/pdfs/secr-habitatmasks.pdf) but some caution is called for (I shifted to a 5-m mask spacing).

[Note sigma-hat and g0 should not be compared between HN and EX fits]
Murary
murray.efford
 
Posts: 715
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: NA in likelihood calculations

Postby Alisha Mosloff » Tue Sep 23, 2025 5:05 pm

Hello,

I am running in to a similar issue.

I have mark-recapture data from 5 sites trapped over 4 years with 8-11 trap nights per session. Not every site was trapped in every year. I also have 1 habitat mask which includes covariate data. When I run even simple models, all parameter estimates are NA. My code is below. Any insight is appreciated.

coonCH=read.capthist(captfile="RaccoonCaptureHistory.csv", trapfile=
list("Cole2021_Raccoons_TrapFile.csv", "Cole2022_Raccoons_TrapFile.csv",
"Cole2024_Raccoons_TrapFile.csv", "Hinkle2021_Raccoons_TrapFile.csv",
"Hinkle2022_Raccoons_TrapFile.csv", "Hinkle2023_Raccoons_TrapFile.csv",
"Hinkle2024_Raccoons_TrapFile.csv", "RebelsCove2021_Raccoons_TrapFile.csv",
"RebelsCove2022_Raccoons_TrapFile.csv", "RebelsCove2023_Raccoons_TrapFile.csv",
"RebelsCove2024_Raccoons_TrapFile.csv", "Roesline2023_Raccoons_TrapFile.csv",
"LakeThunderhead2022_Raccoons_TrapFile.csv",
"LakeThunderhead2023_Raccoons_TrapFile.csv", "LakeThunderhead2024_Raccoons_TrapFile.csv"), detector="single",
# noccasions=c(10, 10, 8, 11),
skip=1, covnames=c('Age', 'Sex', 'Date', 'Temp', 'Management', 'SunsetLocal', 'SunriseLocal', 'MoonriseLocal',
'MoonsetLocal', 'MeanMoonlightIntensity', 'nightstart', 'nightend', 'nightduration',
'moonstart', 'moonend', 'moonduration', 'proportion', 'propnocloud', 'MRI'))

coonCH=shareFactorLevels(coonCH)

summary(coonCH, terse=TRUE)
# Cole21 Cole22 Cole24 Hinkle21 Hinkle22 Hinkle23 Hinkle24 Rebels21 Rebels22 Rebels23 Rebels24
# Occasions 10 11 10 10 11 10 10 10 7 10 11
# Detections 23 17 18 29 9 38 17 33 18 40 24
# Animals 12 15 16 16 9 22 16 23 15 26 15
# Detectors 41 41 41 43 43 43 41 38 38 38 38
# Roesline23 Thunderhead22 Thunderhead23 Thunderhead24
# Occasions 8 11 9 8
# Detections 36 23 1 2
# Animals 20 9 1 2
# Detectors 46 37 37 37

mask_points=read.csv("RaccoonHabitatMaskData.csv", sep=",")

my_mask=read.mask(data=mask_points, spacing=100)

covariates(my_mask)
#All covariates plot as expected

MRI <- secr.fit(
coonCH,
model = list(
D ~ predicted_counts, # Density depends on Management
g0 ~ MRI, # Detection depends on covariates
sigma ~ 1
),
mask = my_mask,
detectfn = "HN", # e.g., Half-normal detection function
CL=TRUE
)
MRI

secr.fit(capthist = coonCH, model = list(D ~ predicted_counts,
g0 ~ MRI, sigma ~ 1), mask = my_mask, CL = TRUE, detectfn = "HN")
secr 5.2.4, 16:01:25 23 Sep 2025

$Cole21
Detector type single
Detector number 41
Average spacing 93.05912 m
x-range 471908 472906 m
y-range 4486651 4487356 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 1 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Cole22
Detector type single
Detector number 41
Average spacing 93.05912 m
x-range 471908 472906 m
y-range 4486651 4487356 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10 11
min 0 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1 1

$Cole24
Detector type single
Detector number 41
Average spacing 93.05912 m
x-range 471908 472906 m
y-range 4486651 4487356 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Hinkle21
Detector type single
Detector number 43
Average spacing 100 m
x-range 509752 510462 m
y-range 4480629 4481757 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Hinkle22
Detector type single
Detector number 43
Average spacing 100 m
x-range 509752 510462 m
y-range 4480629 4481757 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10 11
min 0 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1 1

$Hinkle23
Detector type single
Detector number 43
Average spacing 100 m
x-range 509752 510462 m
y-range 4480629 4481757 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Hinkle24
Detector type single
Detector number 41
Average spacing 100 m
x-range 509752 510462 m
y-range 4480629 4481647 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Rebels21
Detector type single
Detector number 38
Average spacing 99.22405 m
x-range 524452.9 525354.1 m
y-range 482918.6 484620 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Rebels22
Detector type single
Detector number 38
Average spacing 99.19116 m
x-range 525254 526952 m
y-range 4489765 4490671 m

Usage range by occasion
1 2 3 4 5 6 7
min 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1

$Rebels23
Detector type single
Detector number 38
Average spacing 99.19116 m
x-range 525254 526952 m
y-range 4489765 4490671 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10
min 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1

$Rebels24
Detector type single
Detector number 38
Average spacing 99.19116 m
x-range 525254 526952 m
y-range 4489765 4490671 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10 11
min 0 0 0 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1 1

$Roesline23
Detector type single
Detector number 46
Average spacing 75.88004 m
x-range 507302.6 507760 m
y-range 4477152 4477759 m

Usage range by occasion
1 2 3 4 5 6 7 8
min 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1

$Thunderhead22
Detector type single
Detector number 37
Average spacing 94.02127 m
x-range 497152 497873 m
y-range 4485956 4486656 m

Usage range by occasion
1 2 3 4 5 6 7 8 9 10 11
min 0 0 0 1 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1 1 1 1

$Thunderhead23
Detector type single
Detector number 37
Average spacing 94.02127 m
x-range 497152 497873 m
y-range 4485956 4486656 m

Usage range by occasion
1 2 3 4 5 6 7 8 9
min 0 0 0 1 0 0 0 1 0
max 1 1 1 1 1 1 1 1 1

$Thunderhead24
Detector type single
Detector number 37
Average spacing 94.02127 m
x-range 497152 497873 m
y-range 4485956 4486656 m

Usage range by occasion
1 2 3 4 5 6 7 8
min 0 0 0 0 0 0 0 0
max 1 1 1 1 1 1 1 1


Cole21 Cole22 Cole24 Hinkle21 Hinkle22 Hinkle23 Hinkle24 Rebels21 Rebels22 Rebels23
Occasions 10 11 10 10 11 10 10 10 7 10
Detections 23 17 18 29 9 38 17 33 18 40
Animals 12 15 16 16 9 22 16 23 15 26
Detectors 41 41 41 43 43 43 41 38 38 38
Rebels24 Roesline23 Thunderhead22 Thunderhead23 Thunderhead24
Occasions 11 8 11 9 8
Detections 24 36 23 1 2
Animals 15 20 9 1 2
Detectors 38 46 37 37 37

Model : D~predicted_counts g0~MRI sigma~1
Fixed (real) : none
Detection fn : halfnormal
N parameters : 4
Log likelihood : -1e+10
AIC : 2e+10
AICc : 2e+10

Beta parameters (coefficients)
beta SE.beta lcl ucl
D.predicted_counts NA NA NA NA
g0 NA NA NA NA
g0.MRI NA NA NA NA
sigma NA NA NA NA

Variance-covariance matrix of beta parameters
NULL

Fitted (real) parameters evaluated at base levels of covariates
Error in beta.vcv[is.na(fb[row(beta.vcv)]) & is.na(fb[col(beta.vcv)])] <- object$beta.vcv :
replacement has length zero
Alisha Mosloff
 
Posts: 1
Joined: Tue Sep 23, 2025 3:52 pm

Re: NA in likelihood calculations

Postby murray.efford » Tue Sep 23, 2025 5:15 pm

Please start a new thread rather than tacking question onto an old one to which it may or may not be related.

Just guessing, but this may be as simple as finding better starting values for maximisation. What version of 'secr' are you using? I may be able to sort it out if you send the complete data offline.
Murray
murray.efford
 
Posts: 715
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: NA in likelihood calculations

Postby murray.efford » Fri Sep 26, 2025 11:25 pm

Alisha sent data offine. The trap locations for one session were wrong and did not match the mask provided. Correctly specified starting values also seemed to help.
murray.efford
 
Posts: 715
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Previous

Return to analysis help

Who is online

Users browsing this forum: No registered users and 0 guests