James-Thorson-NOAA / FishStatsUtils

Shared resources for spatio-temporal models
GNU General Public License v3.0
10 stars 16 forks source link

Error in summary(fit_model) when what="residuals" #72

Closed N-DucharmeBarth closed 3 years ago

N-DucharmeBarth commented 3 years ago

Hi Jim, I've come across the following error in the summary function for a _'fitmodel' object.

Error in DHARMa::createDHARMa(simulatedResponse = b_iz, observedResponse = x$data_list$b_i, : object 'fit' not found

It looks like the error is being thrown from the DHARMa::createDHARMa call in the summary.fit_model function of fit_model.R (line 518)

      dharmaRes = DHARMa::createDHARMa(simulatedResponse=b_iz, # + 1e-10*array(rnorm(prod(dim(b_iz))),dim=dim(b_iz)),
        observedResponse=x$data_list$b_i,
        fittedPredictedResponse=fit$Report$D_i,
        integer=FALSE)

because fittedPredictedResponse is hard coded to look for the global variable 'fit' instead of the local variable 'x'.

Changing line 518 of fit_model.R to

fittedPredictedResponse=x$Report$D_i,

should solve the problem but this should be checked by running your https://github.com/James-Thorson-NOAA/VAST/wiki/Index-standardization example with the output from fit_model named something other than 'fit'. It also looks like this same hard coding to an expected global variable 'fit' occurs on lines 540 & 550.

For reference I'm using R version 4.0.3, FishStatsUtils version 2.9.1 and VAST version 3.7.1.

James-Thorson-NOAA commented 3 years ago

Thanks for reporting the bug (which threw an uninformative error message).

I have fixed it on the dev branch, and feel free to report any further issues with the fix on this thread but I'm closing it for now.

N-DucharmeBarth commented 3 years ago

Thanks for the quick fix @James-Thorson-NOAA !!