VAST icon indicating copy to clipboard operation
VAST copied to clipboard

Error in: Testing model at initial values Error in if (any(Gradient0 == 0)) { : missing value where TRUE/FALSE needed

Open abesolberg opened this issue 3 years ago • 9 comments

I am trying to run the covariate.R example code from the Feb. 2020 VAST training in Seattle, that is available on the google drive here, and written below.

## Load packages
library(VAST)

## load data set
## see `?load_example` for list of stocks with example data
## that are installed automatically with `FishStatsUtils`.
example = load_example(data_set="covariate_example")
dat <- data.frame(example$sampling_data)
X <- data.frame(example$covariate_data)

## Convert years to numbers since some years are missing
dat$Year <- as.numeric(as.factor(dat$Year))
X$Year <- as.numeric(as.factor(X$Year))

## Make settings (turning off bias.correct to save time for example)
settings = make_settings(n_x=200, Region=example$Region,
                         purpose="index", use_anisotropy=FALSE,
                         strata.limits=example$strata.limits,
                         bias.correct=FALSE, fine_scale=TRUE)
## Normalize covariates to have mean=0, SD=1 for numerical stability
X$BOT_DEPTH = (X$BOT_DEPTH-mean(X$BOT_DEPTH)) / sd(X$BOT_DEPTH)
X$BOT_TEMP = (X$BOT_TEMP-mean(X$BOT_TEMP)) / sd(X$BOT_TEMP)
settings$FieldConfig[2, ] <- 0 # turn off spatiotemporal so faster

## Run model
dir.create('mod1')
wd <- paste0(getwd(), '/mod1/')
## Define formula
formula = ~ BOT_DEPTH + I(BOT_DEPTH^2)
fit1 = fit_model(settings=settings, Lat_i=dat$Lat, Lon_i=dat$Lon,
                 t_i=dat$Year,
                 b_i=dat$Catch_KG, a_i=dat$AreaSwept_km2,
                 formula=formula, getsd=FALSE, newtonsteps=0,
                 covariate_data=X , working_dir=wd)
plot(fit1, plot_set=c(3,11,13,14), working_dir=wd, check_residuals=FALSE)
fit1$parameter_estimates$AIC

I am getting an error that (any(Gradient0 == 0)) { : missing value where TRUE/FALSE needed. I am using VAST version 3.6.1, that I downloaded on 2021-03-01 from Github (james-thorson/VAST@c6c60b7). Session info is below:

version R version 4.0.3 (2020-10-10) os macOS Big Sur 10.16
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_CA.UTF-8
ctype en_CA.UTF-8
tz America/St_Johns
date 2021-03-04

Thank you!

abesolberg avatar Mar 04 '21 16:03 abesolberg

Hmm. I just ran using the development branch (which I had installed) and it worked fine. you willing to try the devleopment branch of VAST/FishStatsUtils before I dig more?

James-Thorson-NOAA avatar Mar 04 '21 18:03 James-Thorson-NOAA

Sure thing. Thank you!

abesolberg avatar Mar 04 '21 18:03 abesolberg

That worked. Cheers.

abesolberg avatar Mar 05 '21 12:03 abesolberg

I encountered this error as well. Running age composition for Bering Sea Pacific cod. However, updating the environment did not resolve the issue, and we are restricted on the versions we can use each year.

I believe this error is thrown by the function: tmb_list$Obj$gr() when there is not enough RAM to handle the Hessian, then gradients aren't calculated possibly?

To resolve this, I reduced max_cells from Inf to 2000.

Jason-Conner-NOAA avatar May 06 '21 20:05 Jason-Conner-NOAA

I encountered this error when attempting to run a EOF model (although the example here works fine). I recently updated VAST to its latest version "3.8.2" and FishStatsUtils "2.10.2".

Up until last week and using the previous versions of these packages ("3.8.0" and "2.10.0", respectively), I had no problems with my models.

Could you kindly provide some imput?

yiorgoskerametsidis avatar Jan 31 '22 13:01 yiorgoskerametsidis

Do you mind sending me a minimal reproducible example by email?

I continue to encapsulate logical calculations in a single pre-processing step, and recently changed some of the "years with no data" calculations from multiple plotting to a single pre-processing step implemented using amend_output. I'm guessing it might have arisen in some boundary condition there, but would need to replicate the problem before trying to fix it.

James-Thorson-NOAA avatar Jan 31 '22 17:01 James-Thorson-NOAA

I have a similar problem. I have installed VAST and FishStatsUtils, but when I try to test with the example code in here I get the message "Error in if (any(Gradient0 == 0)) { : missing value where TRUE/FALSE needed" What I am doing wrong?

Carlos085824 avatar Feb 12 '24 23:02 Carlos085824

have you confirmed that Matrix and TMB have matching versions, e.g., using code here: https://github.com/pfmc-assessments/geostatistical_delta-GLMM/wiki/Steps-to-install-TMB ...?

James-Thorson-NOAA avatar Feb 12 '24 23:02 James-Thorson-NOAA

Thank you for your reply. I will try your suggestion.

Carlos Díaz

On Mon, Feb 12, 2024 at 5:59 PM Jim Thorson @.***> wrote:

have you confirmed that Matrix and TMB have matching versions, e.g., using code here: https://github.com/pfmc-assessments/geostatistical_delta-GLMM/wiki/Steps-to-install-TMB ...?

— Reply to this email directly, view it on GitHub https://github.com/James-Thorson-NOAA/VAST/issues/286#issuecomment-1939815559, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGDTJAV3D6OSIV47MNMWQCLYTKUGHAVCNFSM4YTQZGJKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTHE4DCNJVGU4Q . You are receiving this because you commented.Message ID: @.***>

--


Carlos Díaz Avalos Departamento de Probabilidad y Estadística IIMAS, UNAM

Carlos085824 avatar Feb 13 '24 00:02 Carlos085824