James-Thorson-NOAA / VAST

Spatio-temporal analysis of univariate or multivariate data, e.g., standardizing data for multiple species or stages
http://www.FishStats.org
GNU General Public License v3.0
124 stars 54 forks source link

Add fine-scale variation in covariates #22

Closed James-Thorson closed 5 years ago

James-Thorson commented 7 years ago

For next major release (non-backwards compatible):

Redefine x as extrapolation-grid rather than knot, n_x as the number of extrapolation-grid cells, n_knot as user-defined number of interior knots, and n_s as the number of interior and boundary knots.

  1. replace n_x with n_knots, and use n_knots to calculate the number of interior knots (identical to previous definition of n_x)
  2. replace s_i with x_i and s_x, where x_i(i) is returns the value of x for each observation i (as used in density covariates) and s_x(x) gives the SPDE vertex s associated with each piecewise-constant knot x, so that s_x(x_i(i)) gives the SDPE vertex s associated with each observation i. By default, s_x=1:TmbData$n_x-1 and x_i is identical to previous s_i (i.e., each piecewise-constant knot is associated with only one SPDE vertex)
  3. Add new option use_fine_scale_covariates where use_fine_scale_covariates=FALSE works as previously, but use_fine_scale_covariates=TRUE redefines n_x to be the number of cells in the extrapolation grid and calculates X_xtp, X_xp, a_xl, and Z_xm appropriately

This will then allow covariates to be inputted at the scale of the extrapolation-grid, where linear predictors are a combination of coarse-scale random fields and fine-scale covariates.

James-Thorson commented 5 years ago

Exploring this topic a bit further, and the supporting functions needing to be changed are:

  1. FishStatsUtils::make_spatial_info -- change n_x input
  2. FishStatsUtils::format_covariates -- add input use_fine_scale_covariates=TRUE which triggers using Extrapolation_List[["Data_Extrap"]][,c('Lat','Lon')] instead of Spatial_List$loc_x\
  3. FishStatsUtils::make_map_info -- must be changed to be compatible with new option.

I'll keep adding to this list as I explore

James-Thorson commented 5 years ago

At the same time as adding fine-scale covariates, I will likely want to add a feature to interpolate values of random-fields for each grid cells x given three nearby knots s. This would require the following changes:

  1. FishStatsUtils:::Calc_Anisotropic_Mesh -- add projection matrix A = INLA::inla.spde.make.A( anisotropic_mesh, as.matrix(Extrapolation_List$Data_Extrap[,c("E_km","N_km")]) ). However, some extrapolation-grid cells are currently outside of the INLA boundary mesh and therefore are not associated with any knots.

I would need to expand the boundary outside the extrapolation-grid. However, I can't seem to do this in INLA, e.g., mesh <- inla.mesh.2d( Extrapolation_List$Data_Extrap[,c("E_km","N_km")], max.n.strict=100, n=20 ) doesn't seem to work.

James-Thorson commented 5 years ago

I have finally addressed this in a series of changes in release 3.0.0 using option fine_scale=TRUE and please see the User Manual and other documentation for details if interested.