biodiverse / spOccupancy

Single-species, Multi-species, and Integrated Spatial Occupancy Models
https://www.jeffdoser.com/files/spoccupancy-web/
GNU General Public License v3.0
52 stars 8 forks source link

c++ error: dpotrf A.alpha failed, when running spPGOcc #9

Closed agentilis closed 2 years ago

agentilis commented 2 years ago

Thank you so much for the excellent work. I was excited to see 0.3.0 come out with random intercepts in the occupancy formulas. I have run into an issue with model execution and am stuck with how to resolve it. Any advice would be appreciated.

I receive the error "c++ error: dpotrf A.alpha failed", when running spPGOcc. Sometimes it fails on chain 1, and sometimes on chain 2. I have n.report = 80. When it fails, it fails before the first update (at 25%).

spOccupancy 0.3.0, R 4.1.3, Windows 11, 64-bit, Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz, 32.0 GB RAM.

Dataset: 3360 survey points, up to 15 replicates, across 6 western states.

Settings n.batch = 320 # will increase later batch.length = 25 NNGP = TRUE n.neighbors = 8 n.burn = 2000 n.thin = 4 n.chains = 2 # will increase later

This runs fine: m._.bjns2 <- spPGOcc(occ.formula = ~ (1|year) + (1|stratum), det.formula = ~ broad + julian + noise + start + I(start^2), data = flowList, n.omp.threads=n.omp.threads,k.fold.threads=k.fold.threads, n.batch = n.batch, batch.length = batch.length, accept.rate = 0.43, cov.model = "exponential", NNGP = NNGP, n.neighbors = n.neighbors, n.burn = n.burn, n.thin = n.thin, n.chains = n.chains, verbose = T, n.report=n.report) #, , k.fold = k.fold)

This causes the error (adding "elev" to the occupancy formula): m.e <- spPGOcc(occ.formula = ~ (1|year) + (1|stratum) + elev, det.formula = broad + julian + noise + start + I(start^2), data = flowList, n.omp.threads=n.omp.threads,k.fold.threads=k.fold.threads, n.batch = n.batch, batch.length = batch.length, accept.rate = 0.43, cov.model = "exponential", NNGP = NNGP, n.neighbors = n.neighbors, n.burn = n.burn, n.thin = n.thin, n.chains = n.chains, verbose = T, n.report=n.report)#, k.fold = k.fold)

However, this runs fine (keeping "elev", but removing "I(start^2)" from detection model). m.e <- spPGOcc(occ.formula = ~ (1|year) + (1|stratum) + elev, det.formula = broad + julian + noise + start, data = flowList, n.omp.threads=n.omp.threads,k.fold.threads=k.fold.threads, n.batch = n.batch, batch.length = batch.length, accept.rate = 0.43, cov.model = "exponential", NNGP = NNGP, n.neighbors = n.neighbors, n.burn = n.burn, n.thin = n.thin, n.chains = n.chains, verbose = T, n.report=n.report)#, k.fold = k.fold)

Any suggestions?

I would be happy to share my dataset privately, or to help debug the issue.

Thank you for your time and effort.

doserjef commented 2 years ago

Hi Rob,

Thanks for reaching out with the error, and for providing all the really useful info. Sorry you're running into this issue. That error indicates that there is a problem when computing the detection regression coefficients in the MCMC, although it could be caused by a problem somewhere else in the code. All the code you have there looks fine, so would you be able to send me the data set and R script via email (doserjef@msu.edu) and I'll take a look more closely? My guess is there is something with your specific data set that spPGOcc isn't expecting when including that specific combination of covariates.

Thanks,

Jeff

doserjef commented 2 years ago

Error was occurring as a result of very large, non-standardized covariates in the model, which was resolved by standardizing the variables or scaling them to smaller values.