flr / a4adiags

Diagnostics for FLa4a stock Assessment Models
0 stars 2 forks source link

a4ahcxval error due to character in window() function #8

Open danaim opened 2 years ago

danaim commented 2 years ago

a4ahcxval() throws an error: Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'FLStocks': assignment of an object of class “character” is not valid for @‘range’ in an object of class “FLStock”; is(value, "numeric") is not TRUE maybe replace lines 148 -149 in xval.R with: stocks <- FLStocks(lapply(names(stocks), function(x) window(stocks[[x]], end=an(x))))

Thank you, Danai

iagomosqueira commented 2 years ago

Is this with the objects in the package? Have you tried running a4adiags/demo/demo.R? I am adding an example run to xcval help page

data(sol274)

fmod <- ~te(replace(age, age > 8, 8), year, k = c(4, 22)) +
  s(replace(age, age > 8, 8), k=4) +
  s(year, k=22, by=as.numeric(age==1))
qmod <- list(~s(age, k=3), ~s(age, k=3))
vmod <- list(~s(age, k=3), ~s(age, k=3), ~s(age, k=3))
srmod <- ~factor(year)

xval <- a4ahcxval(stock, indices, fmodel=fmod, qmodel=qmod, vmodel=vmod)

plotXval(xval$indices)
danaim commented 2 years ago

I've tried to run the example in the vignette, using the data('sol274'). The an(x) solved the problem and now I am getting a xval output. But plotXval() is not found.

iagomosqueira commented 2 years ago

I'll check, but window works on character, the year dimname, so no need for an().

plotXval is in ggplotFL, which should be loaded by a4ahcxval

danaim commented 2 years ago

I reinstalled ggplotFL and plotXvar works fine now, Thanks a lot