flr / FLa4a

The repository for the JRC initiative on stock assessment
https://fishreg.jrc.ec.europa.eu/web/a4a
12 stars 6 forks source link

Error in a4aInternal (only non-zero survey indices allowed) Question #95

Closed esanchezll closed 7 years ago

esanchezll commented 7 years ago

Hello all,

I'm trying to run an assessment but when I run:

fit <- sca(aStk, aIdx)

(being aStk and aIdx the stock and the index object respectively)

I get that error:

Note: Seasonal M's are summed: i.e. we assume that the values are M * season length. Note: we do not use stock.n to weight the seasonal stock.wt or maturity. Error in a4aInternal(fmodel = fmodel, qmodel = qmodel, srmodel = srmodel, : only non-zero survey indices allowed.

Could you help me with it?

Thank you a lot in advance!

ejardim commented 7 years ago

Hi, sorry, missed this question. Did you work it out ?

esanchezll commented 7 years ago

Hello Ernesto,

I still with the same doubt... have you any idea about why is the problem?

ejardim commented 7 years ago

You have zeros in your index. Because we use a log transform it can't cope with zeros. If they're missing observations you should replace it by NA, otherwise replace the zeros with a small value, like 0.25*min.

ejardim commented 7 years ago

Here is some code that does it index(idx)[index(idx)==0] <- 0.25*min(index(idx)[index(idx)>0], na.rm=TRUE) it issues a warning but it's fine try and check

esanchezll commented 7 years ago

I will try it as soon as possible, but I think that I had already check in this way. I tried also to "cut" the last 2 ages of a 7+ group letting the index as 5+ to remove the years and it didn't work... I will keep you informed, Thanks!

ejardim commented 7 years ago

Hhmmm, if it doesn't work send me the objects and I'll take a look.

esanchezll commented 7 years ago

Hello Ernesto, I tried and it doesn't works... Here is the data in case you can try it

rstudio-export (1).zip

Thanks a lot

ejardim commented 7 years ago

Hi,

Sorry, my code is wrong, it should be

index(HKE.idx)[index(HKE.idx)==0] <- 0.25*min(index(HKE.idx)[index(HKE.idx)>0], na.rm=TRUE)

also you have to keep the index and the stock with the same dimensions, or else a4a will try to run a forecast, which requires a stock-recruitment, etc.

Note that you have 10000 iterations in your FLStock object, which means you'll be running 10000 assessments. It's not a problem, but it takes time.

fit <- sca(iter(aStk, 1), FLIndices(HKE.idx[1:5, ac(2010:2012)]), fmodel=~factor(age) + factor(year))

Best

EJ

On Tue, 6 Dec 2016 at 15:37 Eduardo Sánchez notifications@github.com wrote:

Hello Ernesto, I tried and it doesn't works... Here is the data in case you can try it

rstudio-export (1).zip https://github.com/flr/FLa4a/files/634119/rstudio-export.1.zip

Thanks a lot

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/flr/FLa4a/issues/95#issuecomment-265165330, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXwv3rIBOwajxsbrrYFhc4DF-0cy-s3ks5rFXM1gaJpZM4KV8AL .

esanchezll commented 7 years ago

Hello Ernesto,

I still having the same problem, but now starting with length structure data...

When I transform the data from length to age structured is built perfectly (8 ages), but the index file no (70 ages with 0's since age 8 until age 70).

When I try to set the plusgroup in the slot "Range", it's setted but I still having 70 ages. When I tried to run the assessment there is always the same error: "Error in a4aInternal(fmodel = fmodel, qmodel = qmodel, srmodel = srmodel, : only non-zero survey indices allowed."

As you suggest me, we tried also swapping the 0 values for 0.1 or 0.01 or "0.25*min(index(HKE.idx)" and doing a "trimming" of the 0 values to obtain just the fist 8 ages, but the same error always.

To run the model I tried with sca and a4aSCA (and with many different configurations), but the same error was in both.

Can you help me with that?

Thanks a lot in advance, really

ejardim commented 7 years ago

Hi, Our option for the index is to keep all ages when converting from length to ages. You need to trim the index to keep the ages and years you're interested in. In principle the range of the index should be equal or shorter than the range of the stock object. If there's still zeros you'll have to replace them or remove (with NA). Best EJ

esanchezll commented 7 years ago

Hi, Thanks for the quick response,

I think we did some progressions with this method, but an error message remains. Now running the a4aSCA simulations appears an extra error:

"Estimated covariance matrix may not be positive definite (with a list of numbers)"

and it ends the simulation with the same error:

Error in a4aInternal(fmodel = fmodel, qmodel = qmodel, srmodel = srmodel, : only non-zero catches allowed. In addition: Warning message: In a4aInternal(fmodel = fmodel, qmodel = qmodel, srmodel = srmodel, : Hessian was not positive definite.

Thanks!

ejardim commented 7 years ago

Damn' only now saw this message. Is it sorted out ?