Density covariates par.secr.fit

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

Density covariates par.secr.fit

Postby demarsea » Thu Oct 07, 2021 4:51 pm

Hi Murray,

I've been troubleshooting density covariates analysis for some time and can't seem to get the code to run properly.

I'm doing mark-resight of butterflies, and looking at 3 covariates Canopy, Elevation, and Ceanothus (host plant density), and interactions between canopy+ceanothus and elevation+ceanothus. Trap type is "count".

Code: Select all
base.args <- list(capthist = Ald2019aCH, mask = clippedmask, trace = FALSE, verify=FALSE, method='Nelder-Mead')
 args.0 <- c(base.args, model = D ~ 1)
 args.Dcan <- c(base.args, model = D ~ 'Canopy2')
 args.Delv <- c(base.args, model = D ~ 'Elvpcl_buff3')
 args.Dnjt <- c(base.args, model = D ~ 'Ceanothus2_num')
 args.Dnjtelv <- c(base.args, model = D ~ 'Ceanothus2_num' + 'Elvpcl_buff3')
 args.Dnjtcan <- c(base.args, model = D ~ 'Ceanothus2_num' + 'Canopy2')
arglist <- list(null = args.0, Dcan = args.Dcan, Delv = args.Delv, Dnjt = args.Dnjt, Dnjtelv = args.Dnjtelv, Dnjtcan = args.Dnjtcan)
fits <- par.secr.fit(arglist)


First I attempted without method=Nelder-Mead and then with it. Both had the same outcome:

Error in getmaskpar(!CL, D, data$m, sessnum, details$unmash, attr(data$capthist, :
bad densities in 'secrloglikfn' (try different optimisation method, link, or model?


I'm unclear how to troubleshoot ie "try different optimisation method, link, or model" exactly. Pretty new to R!

Thank you for any assistance.
Angela
demarsea
 
Posts: 4
Joined: Wed Mar 17, 2021 12:23 pm

Re: Density covariates par.secr.fit

Postby murray.efford » Thu Oct 21, 2021 5:37 pm

I have no idea either. Maybe some bad covariates in there? If you still want to pursue this, send me the data offline.
Murray
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Density covariates par.secr.fit

Postby demarsea » Mon Nov 07, 2022 11:32 am

Hi Murray,

I'm reviving this conversation as I've run into a new, but similar, issue relating to density covariate results.
I'm struggling to replicate results from a previous analysis. I suppose it's normal for density estimates to change slightly between analyses? But there's some major problems:

-Top density model ranked in AIC changes when analysis is repeated.

-The s.e. and CL estimates (at different levels of the covariate) are so large it isn't tenable for publication anymore. eg. at a density estimate = 0.0003, s.e.=6e^23.

I didn't have this issue originally back in March 2022 when I produced these results for my thesis. I might have lost some important piece of the code in my attempt to tidy it between now and then? Or maybe some R/Rstudio/secr/dependency updates since then might have thrown off the analysis?

My complete code is below. Please let me know if you notice anything that seems odd.

Code: Select all
captfile <- read.delim("CapAld21_fix.txt")
trapfile <- read.delim("TrapsAld21.txt")
Ald21CH <- read.capthist("CapAld21_fix.txt", "TrapsAld21.txt", fmt=c("trapID"),
                         detector="count", noccasions=43, markocc=c(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0))
Ald21CH <- addSightings(Ald21CH, nonID="TmAld21.txt",
                        unmarked="TuAld21.txt", uncertain="TnAld21.txt")
mask <- make.mask(traps(Ald21CH))
UsedHabitat2 <- rgdal::readOGR(dsn=".", layer="Useable_corrected")
traps<- traps(Ald21CH)
clippedmask <- make.mask(traps(Ald21CH), buffer=347, spacing=15, type="trapbuffer", poly=UsedHabitat2, poly.habitat=TRUE)
DENScov5 <- rgdal::readOGR(dsn=".", layer="NewCov_Burn_2021", stringsAsFactors =FALSE)
DENScov5@data$Ceanothus2 <- as.factor(DENScov5@data$Ceanothus2)
DENScov5@data$Canopy3cat <- as.factor(DENScov5@data$Canopy3cat)
clippedmask <- addCovariates (clippedmask, DENScov5, columns = 'Ceanothus2', strict = FALSE, replace = FALSE)
clippedmask <- addCovariates (clippedmask, DENScov5, columns = 'Canopy3cat', strict = FALSE, replace = FALSE)
base.args <- list(capthist = Ald21CH, mask = clippedmask, trace = FALSE, verify=TRUE, method='Nelder-Mead', details = list(nsim = 10000))
args.0 <- c(base.args, model = D ~ 1, g0 ~ 1)
args.Dcan <- c(base.args, model = D ~ Canopy3cat, g0 ~ 1)
args.Dcean <- c(base.args, model = D ~ Ceanothus2, g0 ~ 1)
args.Dceancan <- c(base.args, model = D ~ Ceanothus2:Canopy3cat, g0 ~ 1)
args.Dadd <- c(base.args, model = D ~ Ceanothus2+Canopy3cat, g0 ~ 1)
arglist <- list(null = args.0, Dcan = args.Dcan, Dcean = args.Dcean, Dceancan = args.Dceancan, Dadd = args.Dadd)
fits <- par.secr.fit(arglist,ncores = 4)
covAIC <- AIC(fits, criterion = "AIC", verify=TRUE)
Canopy3cat <- c(0,0,1,1,2,2)
Ceanothus2 <- c(4,5,4,5,4,5)
Canopy3cat <- as.factor(Canopy3cat)
Ceanothus2 <- as.factor(Ceanothus2)
covs <- data.frame(Canopy3cat, Ceanothus2)
covs
CIa21 <- predict(fits$fit.Dadd, newdata=covs,
                 realnames=NULL, type=c("response"),
                 se.fit=TRUE, alpha=0.05, savenew=FALSE)

demarsea
 
Posts: 4
Joined: Wed Mar 17, 2021 12:23 pm

Re: Density covariates par.secr.fit

Postby murray.efford » Tue Nov 15, 2022 6:32 pm

This question was answered elsewhere
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand


Return to analysis help

Who is online

Users browsing this forum: No registered users and 11 guests