Repository navigation
How do I run a Nearest Neighbors Gaussian Process spatial model in tinyVAST and compare the output to SPDE models #136
Closed
MorganJohnston4
started this conversation in
General
Replies: 2 comments 2 replies
|
I caught a similar bug for other non-SPDE domains recently, and fixed it in the tinyVAST@dev branch. However, I can't tell from my NEWS text whether it also applied to NNGP. Do you mind testing again using tinyVAST@dev branch rather than CRAN verison? |
1 reply
|
Thanks for reporting this bug! I confirm that the tinyVAST@dev branch had a typo, which I've now fixed. The I'm closing for now, but could you please report back with any further concerns? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Troubleshooting report:
pomega1_greturns constant value with NNGP domain despite non-trivial spatial parametersSummary
When fitting a
tinyVASTmodel withspatial_domainset to an NNGP domain (viamake_nngp_domain()), the spatial random effect component (predict(..., what = "pomega1_g")) returns a constant value across all locations — both at the original fitted data locations and on new prediction grids. This happens despite the model reporting a non-triviallog_kappaestimate (implying a finite, identified spatial range) and despitemu_gvarying appropriately across locations. The exact same model structure (single-variable SEM spatial term, no time dimension) works correctly when run using the package's own vignette example with a continuous SPDE mesh (fm_mesh_2d()) instead of an NNGP domain.Environment
tinyVASTinstalled fromvast-lib/tinyVAST@dev(per thepackageVersion("tinyVAST") < "1.6.0"guard in my script)sessionInfo()outputSteps to reproduce / debugging history
I'm including the full debugging path since each step ruled out a plausible alternative explanation.
1. Initial model
Note: I initially also passed
time_column = "Year", but my data has noYear/time column at all — removing this had no effect on the issue described below.Also, I have no idea if specifying the space_term is needed for the NNGP model. It seemed like a potential spot that might be restricting the spatial term output.
2. Model converges with sensible diagnostics
Max gradient is small, SEs look reasonable, and
log_kappahas a tight, well-identified estimate. Notespatial_sd(the name I assigned in the SEM string) does not appear in the output at all — only the generictheta_zetc. labels — so it's unclear whethertheta_zcorresponds tospatial_sdor whether the custom name is simply not being used insdreport()'s printed output.3.
pomega1_gis constant at original data locationsThis is constant across all 37,816 observations.
4.
mu_g(full predicted mean) varies normally5.
palpha1_g(fixed-effects-only linear predictor) also varies, and on its own does not span a wide enough range to explainmu_g's full variation aloneSo
mu_gvaries,palpha1_gvaries, butpomega1_g— the spatial-only component — is flat. This seems inconsistent: if there were truly no spatial signal, I'd expectpomega1_gto hover near zero, not sit at 1.69.6. Raw TMB report shows no per-observation spatial random effect array
No
omega-named or per-location field of length matching the data appears here.7. Sanity check: the package's own vignette example (continuous SPDE mesh, not NNGP) works correctly
Using the exact code from the "Spatial modeling" vignette (
spatial.Rmd), withfm_mesh_2d()instead of an NNGP domain:This varies correctly. So the bug (if it is one) appears specific to the NNGP domain code path, not the SEM string syntax or the
pomega1_gextraction mechanism in general.In addition, the sdmTMB model I ran as a comparison did report spatial vairaion, the fixed effects were similar to the fixed efects for NNGP, but the predicted density between the two models was off by a factor of 100x.
Other notes from debugging
sf_arealare on the same coordinate scale (UTM km) before suspecting a units issue, and confirmed mesh/grid resolution between my sdmTMB SPDE mesh (~4.2 km median edge length) and the NNGPsf_arealgrid (2 km cells) are broadly comparable, so I don't think this is a resolution mismatch.n = 4,8,16,32) did not changelog_kappameaningfully (1.486 to 1.493), so the constantpomega1_gdoesn't appear to be a too-few-neighbors artifact either.Question for you
Is
pomega1_gexpected to work for NNGP domains in the current dev branch, or is this a known gap/in-progress feature?testing_spde_vs_nngp.docx
All reactions