Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abesolberg opened this issue Mar 4, 2021 · 9 comments

Comments

@abesolberg
Copy link

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 (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!

@James-Thorson-NOAA
Copy link
Owner

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?

@abesolberg
Copy link
Author

Sure thing. Thank you!

@abesolberg
Copy link
Author

That worked. Cheers.

@Jason-Conner-NOAA
Copy link

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.

@yiorgoskerametsidis
Copy link

yiorgoskerametsidis commented Jan 31, 2022

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?

@James-Thorson-NOAA
Copy link
Owner

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.

@Carlos085824
Copy link

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?

@James-Thorson-NOAA
Copy link
Owner

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 ...?

@Carlos085824
Copy link

Carlos085824 commented Feb 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants