Title: | Spatial Surplus Production Model Framework for Northern Shrimp Populations |
---|---|
Description: | Implement a GAM-based (Generalized Additive Models) spatial surplus production model (spatial SPM), aimed at modeling northern shrimp population in Atlantic Canada but potentially to any stock in any location. The package is opinionated in its implementation of SPMs as it internally makes the choice to use penalized spatial gams with time lags. However, it also aims to provide options for the user to customize their model. The methods are described in Pedersen et al. (2022, <https://www.dfo-mpo.gc.ca/csas-sccs/Publications/ResDocs-DocRech/2022/2022_062-eng.html>). |
Authors: | Valentin Lucet [aut, cre, cph], Eric Pedersen [aut] |
Maintainer: | Valentin Lucet <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.3 |
Built: | 2025-02-13 06:09:18 UTC |
Source: | https://github.com/pedersen-fisheries-lab/sspm |
WIP extract variables from sspm objects
## S4 method for signature 'sspm_boundary' x$name ## S4 method for signature 'sspm_discrete_boundary' x$name ## S4 method for signature 'sspm_dataset' x$name ## S4 method for signature 'sspm' x$name
## S4 method for signature 'sspm_boundary' x$name ## S4 method for signature 'sspm_discrete_boundary' x$name ## S4 method for signature 'sspm_dataset' x$name ## S4 method for signature 'sspm' x$name
x |
[sspm_...] An object from this package. |
name |
[character] The name of the column |
The data.frame
matching the request.
sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") bounds$area_sfa
sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") bounds$area_sfa
discretization_method
objectCast a character value into discretization_method
object, using the list of possible methods in spm_methods
.
as_discretization_method(name, method) ## S4 method for signature 'character,ANY' as_discretization_method(name) ## S4 method for signature 'missing,function' as_discretization_method(method)
as_discretization_method(name, method) ## S4 method for signature 'character,ANY' as_discretization_method(name) ## S4 method for signature 'missing,function' as_discretization_method(method)
name |
[character] The name of the method. |
method |
[character] If custom method, the function to use. See
|
An objectof class discretization_method
.
as_discretization_method("tesselate_voronoi")
as_discretization_method("tesselate_voronoi")
Simulated biomass data for test and practice.
borealis_simulated
borealis_simulated
A data frame:
Year as a factor
SFA ID number
Simualated biomass in kg per km2
Simulated water temperature
Longitude
Latitude
Row ID
Unique ID for simulated observation
Simulated catch data for test and practice.
catch_simulated
catch_simulated
A data frame:
Year as a factor
SFA ID number
Simualated catch in kg
Longitude
Latitude
Row ID
Unique ID for simulated observation
This class encapsulates a name and a method (function) used for discretization.
name
[character] Name of the discretization method.
method
[function] Function used for discretization.
discretization_method
model elementsAll methods described here allow to access the elements of contained in objects of class discretization_method.
method_func(sspm_object) ## S4 method for signature 'discretization_method' method_func(sspm_object) method_func(object) <- value ## S4 replacement method for signature 'discretization_method' method_func(object) <- value ## S4 method for signature 'discretization_method' spm_name(sspm_object) ## S4 replacement method for signature 'discretization_method' spm_name(object) <- value
method_func(sspm_object) ## S4 method for signature 'discretization_method' method_func(sspm_object) method_func(object) <- value ## S4 replacement method for signature 'discretization_method' method_func(object) <- value ## S4 method for signature 'discretization_method' spm_name(sspm_object) ## S4 replacement method for signature 'discretization_method' spm_name(object) <- value
sspm_object |
[discretization_method] An object of class discretization_method. |
object |
[discretization_method] An object of class discretization_method. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
method <- as_discretization_method("tesselate_voronoi") method_func(method)
method <- as_discretization_method("tesselate_voronoi") method_func(method)
sspm
objectsPlot methods for a range of sspm objects.
## S4 method for signature 'sspm_boundary,missing' plot(x, y, ...) ## S4 method for signature 'sspm_dataset,missing' plot( x, y, ..., var = NULL, point_size = 1, line_size = 1, use_sf = FALSE, interval = FALSE, page = "first", nrow = 2, ncol = 2, log = FALSE, scales = "fixed", show_PI = TRUE, show_CI = TRUE ) ## S4 method for signature 'sspm_fit,missing' plot( x, y, ..., point_size = 1, line_size = 1, train_test = FALSE, biomass = NULL, next_ts = FALSE, smoothed_biomass = FALSE, aggregate = FALSE, interval = FALSE, biomass_origin = NULL, use_sf = FALSE, page = "first", nrow = 2, ncol = 2, log = FALSE, scales = "fixed", show_PI = TRUE, show_CI = TRUE )
## S4 method for signature 'sspm_boundary,missing' plot(x, y, ...) ## S4 method for signature 'sspm_dataset,missing' plot( x, y, ..., var = NULL, point_size = 1, line_size = 1, use_sf = FALSE, interval = FALSE, page = "first", nrow = 2, ncol = 2, log = FALSE, scales = "fixed", show_PI = TRUE, show_CI = TRUE ) ## S4 method for signature 'sspm_fit,missing' plot( x, y, ..., point_size = 1, line_size = 1, train_test = FALSE, biomass = NULL, next_ts = FALSE, smoothed_biomass = FALSE, aggregate = FALSE, interval = FALSE, biomass_origin = NULL, use_sf = FALSE, page = "first", nrow = 2, ncol = 2, log = FALSE, scales = "fixed", show_PI = TRUE, show_CI = TRUE )
x |
[sspm_...] An object from this package. |
y |
NOT USED (from generic). |
... |
NOT USED (from generic). |
var |
[character] (For sspm_dataset) Variable to plot. |
point_size |
[numeric] Passed on to ggplot size parameter for point size. |
line_size |
[numeric] Passed on to ggplot size parameter for line size. |
use_sf |
[logical] Whether to produce a spatial plot. |
interval |
[logical] (For sspm_fit & sspm_dataset) Whether to plot CI and PI intervals. |
page |
The page to draw |
nrow |
Number of rows per page |
ncol |
Number of columns per page |
log |
[logical] For productivity, whether to plot log productivity, (default to FALSE) for others, whether to plot on a log scale (default to TRUE). |
scales |
Are scales shared across all facets (the default,
|
show_PI |
[character] Whether to show the PIs. |
show_CI |
[character] Whether to show the CIs. |
train_test |
[logical] (For sspm_fit) Whether to plot a train/test pair plot. |
biomass |
[character] (For sspm_fit) The biomass variable for predictions. |
next_ts |
[logical] (For sspm_fit) Whether to plot a predictions for next timestep. |
smoothed_biomass |
[logical] (For sspm_fit) Whether to plot a the smoothed biomass used for predictions. |
aggregate |
[logical] (For sspm_fit) For biomass predictions only, whether to aggregate the data to the boundary level. Default to FALSE. |
biomass_origin |
[character] Biomass variable to plot (from original dataset, optionnal). |
A ggplot2 plot object.
## Not run: # To plot a boundary object and visualize patches/points plot(sspm_boundary) # To plot a dataset variable plot(biomass_smooth, var = "weight_per_km2", log = FALSE) plot(biomass_smooth, var = "weight_per_km2", use_sf = TRUE) # To plot a fitted model # Test-train plot plot(sspm_model_fit, train_test = TRUE, scales = "free") # Timeseries plot plot(sspm_model_fit, log = T, scales = 'free') plot(sspm_model_fit, log = T, use_sf = TRUE) plot(sspm_model_fit, biomass = "weight_per_km2_borealis", scales = "free") plot(sspm_model_fit, biomass = "weight_per_km2_borealis", use_sf = TRUE) plot(sspm_model_fit, biomass = "weight_per_km2_borealis", next_ts = TRUE, aggregate = TRUE, scales = "free", interval = T) ## End(Not run)
## Not run: # To plot a boundary object and visualize patches/points plot(sspm_boundary) # To plot a dataset variable plot(biomass_smooth, var = "weight_per_km2", log = FALSE) plot(biomass_smooth, var = "weight_per_km2", use_sf = TRUE) # To plot a fitted model # Test-train plot plot(sspm_model_fit, train_test = TRUE, scales = "free") # Timeseries plot plot(sspm_model_fit, log = T, scales = 'free') plot(sspm_model_fit, log = T, use_sf = TRUE) plot(sspm_model_fit, biomass = "weight_per_km2_borealis", scales = "free") plot(sspm_model_fit, biomass = "weight_per_km2_borealis", use_sf = TRUE) plot(sspm_model_fit, biomass = "weight_per_km2_borealis", next_ts = TRUE, aggregate = TRUE, scales = "free", interval = T) ## End(Not run)
Simulated predator data for test and practice.
predator_simulated
predator_simulated
A data frame:
Year as a factor
SFA ID number
Simualated biomass in kg per km2
Longitude
Latitude
Row ID
Unique ID for simulated observation
Predict using a fitted SPM model on the whole data or on new data
## S4 method for signature 'sspm_fit' predict( object, new_data = NULL, biomass = NULL, aggregate = FALSE, interval = FALSE, next_ts = FALSE, type = "response" ) ## S4 method for signature 'sspm_dataset' predict( object, new_data = NULL, discrete = TRUE, type = "response", interval = FALSE )
## S4 method for signature 'sspm_fit' predict( object, new_data = NULL, biomass = NULL, aggregate = FALSE, interval = FALSE, next_ts = FALSE, type = "response" ) ## S4 method for signature 'sspm_dataset' predict( object, new_data = NULL, discrete = TRUE, type = "response", interval = FALSE )
object |
[sspm_fit] Fit object to predict from. |
new_data |
[data.frame] New data to predict with. |
biomass |
[character] Biomass variable. |
aggregate |
[logical] For biomass predictions only, whether to aggregate the data to the boundary level. Default to FALSE. |
interval |
[logical] Whether or not to calculate confidence, and when possible, prediction intervals. |
next_ts |
[logical] For biomass, predict next timestep. |
type |
When this has the value |
discrete |
[logical] If |
A dataframe
of predictions.
## Not run: # Predictions for a model fit (usually, productivity) predict(sspm_model_fit) # To get biomass predictions, provide the variable name predict(sspm_model_fit, biomass = "weight_per_km2_borealis") # To get the next timestep predictions predict(sspm_model_fit, biomass = "weight_per_km2_borealis", next_ts = TRUE) ## End(Not run)
## Not run: # Predictions for a model fit (usually, productivity) predict(sspm_model_fit) # To get biomass predictions, provide the variable name predict(sspm_model_fit, biomass = "weight_per_km2_borealis") # To get the next timestep predictions predict(sspm_model_fit, biomass = "weight_per_km2_borealis", next_ts = TRUE) ## End(Not run)
Computes CI from posterior, and PI for Tweedie and scat gams.
predict_intervals(object_fit, new_data, n = 1000, CI = TRUE, PI = TRUE, ...)
predict_intervals(object_fit, new_data, n = 1000, CI = TRUE, PI = TRUE, ...)
object_fit |
[gam OR bam] The fit to use for predictions. |
new_data |
[data.frame] The data to predict onto. |
n |
[numeric] The number of simulations to run for parameters. |
CI |
[logical] Whether to compute the CI. |
PI |
[logical] Whether to compute the PI. |
... |
further arguments passed to the quantile function. |
A data.frame
with intervals.
gam1 <- gam(cyl ~ mpg, data=mtcars, family = tw) predict_intervals(gam1)
gam1 <- gam(cyl ~ mpg, data=mtcars, family = tw) predict_intervals(gam1)
sspm_formula
model elementsAll methods described here allow to access the elements of contained in objects of class sspm_formula.
raw_formula(sspm_object) ## S4 method for signature 'sspm_formula' raw_formula(sspm_object) raw_formula(object) <- value ## S4 replacement method for signature 'sspm_formula' raw_formula(object) <- value translated_formula(sspm_object) ## S4 method for signature 'sspm_formula' translated_formula(sspm_object) translated_formula(object) <- value ## S4 replacement method for signature 'sspm_formula' translated_formula(object) <- value formula_vars(sspm_object) ## S4 method for signature 'sspm_formula' formula_vars(sspm_object) formula_vars(object) <- value ## S4 replacement method for signature 'sspm_formula' formula_vars(object) <- value formula_type(sspm_object) ## S4 method for signature 'sspm_formula' formula_type(sspm_object) formula_type(object) <- value ## S4 replacement method for signature 'sspm_formula' formula_type(object) <- value is_fitted(sspm_object) ## S4 method for signature 'sspm_formula' is_fitted(sspm_object) is_fitted(object) <- value ## S4 replacement method for signature 'sspm_formula' is_fitted(object) <- value spm_response(sspm_object) ## S4 method for signature 'sspm_formula' spm_response(sspm_object) spm_response(object) <- value ## S4 replacement method for signature 'sspm_formula' spm_response(object) <- value spm_lagged_vars(sspm_object) ## S4 method for signature 'sspm_formula' spm_lagged_vars(sspm_object) spm_lagged_vars(object) <- value ## S4 replacement method for signature 'sspm_formula' spm_lagged_vars(object) <- value
raw_formula(sspm_object) ## S4 method for signature 'sspm_formula' raw_formula(sspm_object) raw_formula(object) <- value ## S4 replacement method for signature 'sspm_formula' raw_formula(object) <- value translated_formula(sspm_object) ## S4 method for signature 'sspm_formula' translated_formula(sspm_object) translated_formula(object) <- value ## S4 replacement method for signature 'sspm_formula' translated_formula(object) <- value formula_vars(sspm_object) ## S4 method for signature 'sspm_formula' formula_vars(sspm_object) formula_vars(object) <- value ## S4 replacement method for signature 'sspm_formula' formula_vars(object) <- value formula_type(sspm_object) ## S4 method for signature 'sspm_formula' formula_type(sspm_object) formula_type(object) <- value ## S4 replacement method for signature 'sspm_formula' formula_type(object) <- value is_fitted(sspm_object) ## S4 method for signature 'sspm_formula' is_fitted(sspm_object) is_fitted(object) <- value ## S4 replacement method for signature 'sspm_formula' is_fitted(object) <- value spm_response(sspm_object) ## S4 method for signature 'sspm_formula' spm_response(sspm_object) spm_response(object) <- value ## S4 replacement method for signature 'sspm_formula' spm_response(object) <- value spm_lagged_vars(sspm_object) ## S4 method for signature 'sspm_formula' spm_lagged_vars(sspm_object) spm_lagged_vars(object) <- value ## S4 replacement method for signature 'sspm_formula' spm_lagged_vars(object) <- value
sspm_object |
[sspm_formula] An object of class sspm_formula. |
object |
[sspm_formula] An object of class sspm_formula. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
form <- new("sspm_formula", raw_formula = as.formula("weight_per_km2 ~ smooth_time()"), translated_formula = as.formula("weight_per_km2 ~ s(year_f, k = 24L, bs = 're', xt = list(penalty = pen_mat_time))"), vars = list(pen_mat_time = matrix(), pen_mat_space = matrix()), response = "weight_per_km2") translated_formula(form)
form <- new("sspm_formula", raw_formula = as.formula("weight_per_km2 ~ smooth_time()"), translated_formula = as.formula("weight_per_km2 ~ s(year_f, k = 24L, bs = 're', xt = list(penalty = pen_mat_time))"), vars = list(pen_mat_time = matrix(), pen_mat_space = matrix()), response = "weight_per_km2") translated_formula(form)
SFA boundaries.
sfa_boundaries
sfa_boundaries
A data frame and sf object:
SFA ID number
sf geometry
sf geometry area
A full sspm formula contains calls to the smoothing terms smooth_time()
,
smooth_space()
, smooth_space_time()
.
smooth_time( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "re", xt = NA, is_spm = FALSE, ... ) smooth_space( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "mrf", xt = NULL, is_spm = FALSE, ... ) smooth_space_time( data_frame, boundaries, time, type = "ICAR", k = c(NA, 30), bs = c("re", "mrf"), xt = list(NA, NULL), is_spm = FALSE, ... ) smooth_lag( var, data_frame, boundaries, time, type = "LINPRED", k = 5, m = 1, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_time( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "re", xt = NA, is_spm = FALSE, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_space( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "mrf", xt = NULL, is_spm = FALSE, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_space_time( data_frame, boundaries, time, type = "ICAR", k = c(NA, 30), bs = c("re", "mrf"), xt = list(NA, NULL), is_spm = FALSE, ... ) ## S4 method for signature 'ANY,sf,sspm_discrete_boundary' smooth_lag( var, data_frame, boundaries, time, type = "LINPRED", k = 5, m = 1, ... )
smooth_time( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "re", xt = NA, is_spm = FALSE, ... ) smooth_space( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "mrf", xt = NULL, is_spm = FALSE, ... ) smooth_space_time( data_frame, boundaries, time, type = "ICAR", k = c(NA, 30), bs = c("re", "mrf"), xt = list(NA, NULL), is_spm = FALSE, ... ) smooth_lag( var, data_frame, boundaries, time, type = "LINPRED", k = 5, m = 1, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_time( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "re", xt = NA, is_spm = FALSE, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_space( data_frame, boundaries, time, type = "ICAR", k = NULL, bs = "mrf", xt = NULL, is_spm = FALSE, ... ) ## S4 method for signature 'sf,sspm_discrete_boundary' smooth_space_time( data_frame, boundaries, time, type = "ICAR", k = c(NA, 30), bs = c("re", "mrf"), xt = list(NA, NULL), is_spm = FALSE, ... ) ## S4 method for signature 'ANY,sf,sspm_discrete_boundary' smooth_lag( var, data_frame, boundaries, time, type = "LINPRED", k = 5, m = 1, ... )
data_frame |
[sf data.frame] The data. |
boundaries |
[sspm_boundary] An object of class sspm_discrete_boundary. |
time |
[character] The time column. |
type |
[character] Type of smooth, currently only "ICAR" is supported. |
k |
[numeric] Size of the smooths and/or size of the lag. |
bs |
a two letter character string indicating the (penalized) smoothing basis to use.
(eg |
xt |
Any extra information required to set up a particular basis. Used
e.g. to set large data set handling behaviour for |
is_spm |
Whether or not an SPM is being fitted (used internally) |
... |
a list of variables that are the covariates that this
smooth is a function of. Transformations whose form depends on
the values of the data are best avoided here: e.g. |
var |
[symbol] Variable (only for smooth_lag). |
m |
The order of the penalty for this term (e.g. 2 for
normal cubic spline penalty with 2nd derivatives when using
default t.p.r.s basis). |
A list of 2 lists:
args
, contains the arguments to be passed on to the mgcv smooths
vars
, contains variables relevant to the evaluation of the smooth.
## Not run: # Not meant to be used directly smooth_time(borealis_data, bounds_voronoi, time = "year") ## End(Not run)
## Not run: # Not meant to be used directly smooth_time(borealis_data, bounds_voronoi, time = "year") ## End(Not run)
Fit an spm model to a sspm object
spm(sspm_object, formula, ...) ## S4 method for signature 'sspm,missing' spm(sspm_object, formula, ...) ## S4 method for signature 'sspm,formula' spm(sspm_object, formula, ...)
spm(sspm_object, formula, ...) ## S4 method for signature 'sspm,missing' spm(sspm_object, formula, ...) ## S4 method for signature 'sspm,formula' spm(sspm_object, formula, ...)
sspm_object |
[sspm_dataset] An object of class sspm_dataset. |
formula |
[formula] A formula definition of the form response ~ smoothing_terms + ... |
... |
Arguments passed on to
|
An object of type sspm_fit
.
## Not run: sspm_model_fit <- sspm_model %>% spm(log_productivity ~ sfa + weight_per_km2_all_predators_lag_1 + smooth_space(by = weight_per_km2_borealis_with_catch) + smooth_space(), family = mgcv::scat) ## End(Not run)
## Not run: sspm_model_fit <- sspm_model %>% spm(log_productivity ~ sfa + weight_per_km2_all_predators_lag_1 + smooth_space(by = weight_per_km2_borealis_with_catch) + smooth_space(), family = mgcv::scat) ## End(Not run)
Aggregate the data contained in a dataset or fit based on the discretized boundaries, using a function and a filling value.
spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,missing' spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,sspm_discrete_boundary' spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... )
spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,missing' spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,sspm_discrete_boundary' spm_aggregate( sspm_object, boundaries, level = "patch", type = "data", variable, fun, group_by = "spacetime", fill = FALSE, apply_to_df = FALSE, ... )
sspm_object |
[sspm_dataset or sspm_fit] The dataset object. |
boundaries |
[sspm_discrete_boundary] The boundaries object (optionnal). |
level |
[character] The aggregation level, "patch" or "boundary". |
type |
[character] The targeted type of aggregation, one of "data" for base data or "smoothed" for smoothed data. |
variable |
[character] Variable to aggregate (ignored in case
|
fun |
[function] Function to use to aggregate data. |
group_by |
[character] One of |
fill |
[logical OR numeric OR function] Whether to complete the
incomplete cases, default to |
apply_to_df |
[logical] Wether |
... |
More arguments passed onto |
Updated sspm_dataset
or sspm_fit
.
## Not run: spm_aggregate(sspm_object = catch, boundaries = spm_boundaries(biomass), variable = catch_variable, fun = fun, group_by = group_by, fill = fill, apply_to_df = apply_to_df, na.rm = TRUE, ...) ## End(Not run)
## Not run: spm_aggregate(sspm_object = catch, boundaries = spm_boundaries(biomass), variable = catch_variable, fun = fun, group_by = group_by, fill = fill, apply_to_df = apply_to_df, na.rm = TRUE, ...) ## End(Not run)
Aggregate the catch data contained in a catch dataset and update the biomass dataset with the subtracted catch.
spm_aggregate_catch( biomass, catch, biomass_variable, catch_variable, corrections = NULL, fun = sum, group_by = "spacetime", fill, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,sspm_dataset,character,character' spm_aggregate_catch( biomass, catch, biomass_variable, catch_variable, corrections = NULL, fun = sum, group_by = "spacetime", fill, apply_to_df = FALSE, ... )
spm_aggregate_catch( biomass, catch, biomass_variable, catch_variable, corrections = NULL, fun = sum, group_by = "spacetime", fill, apply_to_df = FALSE, ... ) ## S4 method for signature 'sspm_dataset,sspm_dataset,character,character' spm_aggregate_catch( biomass, catch, biomass_variable, catch_variable, corrections = NULL, fun = sum, group_by = "spacetime", fill, apply_to_df = FALSE, ... )
biomass |
[sspm_dataset (smoothed)] The dataset containing the biomass variable. |
catch |
[sspm_dataset] The dataset containing the catch variable. |
biomass_variable |
[character] The biomass variab of |
catch_variable |
[character] The catch column of |
corrections |
[data.frame] Optional landings corrections. |
fun |
[function] Function to use to aggregate data. |
group_by |
[character] One of |
fill |
[logical OR numeric OR function] Whether to complete the
incomplete cases, default to |
apply_to_df |
[logical] Wether |
... |
More arguments passed onto |
Updated sspm_dataset
.
## Not run: spm_aggregate_catch(biomass = biomass_smooth, catch = catch_dataset, biomass_variable = "weight_per_km2", catch_variable = "catch", fill = mean) ## End(Not run)
## Not run: spm_aggregate_catch(biomass = biomass_smooth, catch = catch_dataset, biomass_variable = "weight_per_km2", catch_variable = "catch", fill = mean) ## End(Not run)
Create a sspm_boundary object. A boundary object serves as a basis to encode the spatial extent of the model.
spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'missing,ANY,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'ANY,missing,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'sf,character,missing,missing' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'sf,character,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL )
spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'missing,ANY,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'ANY,missing,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'sf,character,missing,missing' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL ) ## S4 method for signature 'sf,character,ANY,ANY' spm_as_boundary( boundaries, boundary, patches = NULL, points = NULL, boundary_area = NULL, patch_area = NULL )
boundaries |
[sf] The sf object to cast. |
boundary |
[character] The column that contains the possible subdivisions of the boundaries. |
patches |
[sf] Patches resulting from discretization. |
points |
[sf] Sample points used for discretization. |
boundary_area |
[character] The column that contains the area of the subdivisions (optional). |
patch_area |
[character] The column that contains the area of the patches (optional). |
An object of class sspm_boundary or sspm_discrete_boundary.
sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") plot(bounds)
sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") plot(bounds)
sspm_dataset
dataset structureThis casts a data.frame
or sf
object into an object of class
sspm_dataset
. This object is the format the package
uses to manage and manipulate the modeling data.
spm_as_dataset(data, name, time, uniqueID, coords = NULL, ...) ## S4 method for signature 'data.frame,ANY,ANY,ANY,missingOrNULL' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = NULL, density_units = NULL ) ## S4 method for signature 'data.frame,ANY,ANY,ANY,list' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" ) ## S4 method for signature 'data.frame,ANY,ANY,ANY,character' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" ) ## S4 method for signature 'sf,ANY,ANY,ANY,ANY' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" )
spm_as_dataset(data, name, time, uniqueID, coords = NULL, ...) ## S4 method for signature 'data.frame,ANY,ANY,ANY,missingOrNULL' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = NULL, density_units = NULL ) ## S4 method for signature 'data.frame,ANY,ANY,ANY,list' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" ) ## S4 method for signature 'data.frame,ANY,ANY,ANY,character' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" ) ## S4 method for signature 'sf,ANY,ANY,ANY,ANY' spm_as_dataset( data, name, time, uniqueID, coords, crs = NULL, boundaries = NULL, biomass = NULL, density = NULL, biomass_units = "kg", density_units = "kg/km^2" )
data |
[data.frame OR sf] The dataset. |
name |
[character] The name of the dataset, default to "Biomass". |
time |
[character] The column of |
uniqueID |
[character] The column of |
coords |
[character] The column of |
... |
Arguments passed onto methods. |
crs |
Coordinate reference system, passed onto st_as_sf. |
boundaries |
[sspm_boundary] An object of class sspm_discrete_boundary. |
biomass |
[character] Columns to be encoded as biomasses (required). |
density |
[character] Columns to be encoded as densities (optionnal). |
biomass_units |
[character] Units for biomass columns, default to "kg". |
density_units |
[character] Units for density columns, default to "kg/km^2". |
An object of class sspm_dataset
.
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") biomass_dataset
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") biomass_dataset
sspm_boundary
model elementsAll methods described here allow to access the elements of contained in objects of class sspm_boundary.
## S4 method for signature 'sspm_boundary' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_boundary' spm_boundaries(object) <- value spm_discret_method(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_discret_method(sspm_object) spm_discret_method(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_discret_method(object) <- value spm_patches(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_patches(sspm_object) spm_patches(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_patches(object) <- value spm_points(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_points(sspm_object) spm_points(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_points(object) <- value spm_boundary(sspm_object) ## S4 method for signature 'sspm_boundary' spm_boundary(sspm_object) spm_boundary(object) <- value ## S4 replacement method for signature 'sspm_boundary' spm_boundary(object) <- value spm_boundary_area(sspm_object) ## S4 method for signature 'sspm_boundary' spm_boundary_area(sspm_object) spm_boundary_area(object) <- value ## S4 replacement method for signature 'sspm_boundary' spm_boundary_area(object) <- value spm_patches_area(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_patches_area(sspm_object) spm_patches_area(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_patches_area(object) <- value
## S4 method for signature 'sspm_boundary' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_boundary' spm_boundaries(object) <- value spm_discret_method(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_discret_method(sspm_object) spm_discret_method(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_discret_method(object) <- value spm_patches(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_patches(sspm_object) spm_patches(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_patches(object) <- value spm_points(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_points(sspm_object) spm_points(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_points(object) <- value spm_boundary(sspm_object) ## S4 method for signature 'sspm_boundary' spm_boundary(sspm_object) spm_boundary(object) <- value ## S4 replacement method for signature 'sspm_boundary' spm_boundary(object) <- value spm_boundary_area(sspm_object) ## S4 method for signature 'sspm_boundary' spm_boundary_area(sspm_object) spm_boundary_area(object) <- value ## S4 replacement method for signature 'sspm_boundary' spm_boundary_area(object) <- value spm_patches_area(sspm_object) ## S4 method for signature 'sspm_discrete_boundary' spm_patches_area(sspm_object) spm_patches_area(object) <- value ## S4 replacement method for signature 'sspm_discrete_boundary' spm_patches_area(object) <- value
sspm_object |
[sspm_boundary] An object of class sspm_boundary. |
object |
[sspm_boundary] An object of class sspm_boundary. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_boundaries(biomass_dataset)
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_boundaries(biomass_dataset)
sspm_dataset
model elementsAll methods described here allow to access the elements of contained in objects of class sspm_dataset.
spm_data(sspm_object) ## S4 method for signature 'sspm_dataset' spm_data(sspm_object) spm_data(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_data(object) <- value ## S4 method for signature 'sspm_dataset' spm_name(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_name(object) <- value ## S4 method for signature 'sspm_dataset' spm_unique_ID(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_unique_ID(object) <- value spm_coords_col(sspm_object) ## S4 method for signature 'sspm_dataset' spm_coords_col(sspm_object) spm_coords_col(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_coords_col(object) <- value ## S4 method for signature 'sspm_dataset' spm_time(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_time(object) <- value spm_biomass_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_biomass_vars(sspm_object) spm_biomass_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_biomass_vars(object) <- value spm_density_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_density_vars(sspm_object) spm_density_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_density_vars(object) <- value spm_formulas(sspm_object) ## S4 method for signature 'sspm_dataset' spm_formulas(sspm_object) spm_formulas(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_formulas(object) <- value ## S4 method for signature 'sspm_dataset' spm_smoothed_data(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_data(object) <- value spm_smoothed_fit(sspm_object) ## S4 method for signature 'sspm_dataset' spm_smoothed_fit(sspm_object) spm_smoothed_fit(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_fit(object) <- value spm_smoothed_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_smoothed_vars(sspm_object) spm_smoothed_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_vars(object) <- value is_mapped(sspm_object) ## S4 method for signature 'sspm_dataset' is_mapped(sspm_object) is_mapped(object) <- value ## S4 replacement method for signature 'sspm_dataset' is_mapped(object) <- value ## S4 method for signature 'sspm_dataset' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_boundaries(object) <- value
spm_data(sspm_object) ## S4 method for signature 'sspm_dataset' spm_data(sspm_object) spm_data(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_data(object) <- value ## S4 method for signature 'sspm_dataset' spm_name(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_name(object) <- value ## S4 method for signature 'sspm_dataset' spm_unique_ID(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_unique_ID(object) <- value spm_coords_col(sspm_object) ## S4 method for signature 'sspm_dataset' spm_coords_col(sspm_object) spm_coords_col(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_coords_col(object) <- value ## S4 method for signature 'sspm_dataset' spm_time(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_time(object) <- value spm_biomass_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_biomass_vars(sspm_object) spm_biomass_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_biomass_vars(object) <- value spm_density_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_density_vars(sspm_object) spm_density_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_density_vars(object) <- value spm_formulas(sspm_object) ## S4 method for signature 'sspm_dataset' spm_formulas(sspm_object) spm_formulas(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_formulas(object) <- value ## S4 method for signature 'sspm_dataset' spm_smoothed_data(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_data(object) <- value spm_smoothed_fit(sspm_object) ## S4 method for signature 'sspm_dataset' spm_smoothed_fit(sspm_object) spm_smoothed_fit(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_fit(object) <- value spm_smoothed_vars(sspm_object) ## S4 method for signature 'sspm_dataset' spm_smoothed_vars(sspm_object) spm_smoothed_vars(object) <- value ## S4 replacement method for signature 'sspm_dataset' spm_smoothed_vars(object) <- value is_mapped(sspm_object) ## S4 method for signature 'sspm_dataset' is_mapped(sspm_object) is_mapped(object) <- value ## S4 replacement method for signature 'sspm_dataset' is_mapped(object) <- value ## S4 method for signature 'sspm_dataset' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_dataset' spm_boundaries(object) <- value
sspm_object |
[sspm_dataset] An object of class sspm_dataset. |
object |
[sspm_dataset] An object of class sspm_dataset. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_data(biomass_dataset)
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_data(biomass_dataset)
sspm
model objectDiscretize a sspm model object with a function from a discretization_method object class. This function divides the boundary polygons into smaller patches.
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,missing,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,ANY,missing' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,character,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,function,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,discretization_method,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,missing,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,ANY,missing' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,character,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,function,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...) ## S4 method for signature 'sspm_boundary,discretization_method,ANY' spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
boundary_object |
[sspm] An object of class sspm_boundary. |
method |
[character OR method]
Either a |
with |
[sspm_dataset OR sf] Either an object of class sspm_dataset or a set of custom points. |
... |
[named list] Further arguments to be passed onto the function
used in |
Custom discretization functions can be written. The function must:
Accept at least 1 argument: boundaries (the sf
boundary object),
and optionnaly with (can be NULL) a separate object to be used for
discretization and boundary, the boundary column of
boundaries (these last 2 arguments are passed and connot be
overwritten but could be ignored).
Returns a named list with 2 elements: patches
. an sf
object that
stores the discretized polygons, and points
, an sf
object that
stores the points that were used for discretization.
An object of class sspm_discrete_boundary (the updated
and discretized sspm
object given as input).
# Voronoi tesselation sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") bounds_voronoi <- bounds %>% spm_discretize(method = "tesselate_voronoi", with = biomass_dataset, nb_samples = 10) # Custom method custom_func <- function(boundaries, ...){ args <- list(...) # Can access passed arguments with args$arg_name # Do your custom discretization # Careful: must return sf objects! return(list(patches = c(), points = c()) ) }
# Voronoi tesselation sfa_boundaries bounds <- spm_as_boundary(boundaries = sfa_boundaries, boundary = "sfa") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") bounds_voronoi <- bounds %>% spm_discretize(method = "tesselate_voronoi", with = biomass_dataset, nb_samples = 10) # Custom method custom_func <- function(boundaries, ...){ args <- list(...) # Can access passed arguments with args$arg_name # Do your custom discretization # Careful: must return sf objects! return(list(patches = c(), points = c()) ) }
This function is a wrapper around lag (note that not all arguments are supported). The default value for the lag is the mean of the series.
spm_lag(sspm_object, vars, n = 1, default = "mean", ...) ## S4 method for signature 'sspm' spm_lag(sspm_object, vars, n = 1, default = "mean", ...) ## S4 method for signature 'sspm_fit' spm_lag(sspm_object, vars, n = 1, default = "mean", ...)
spm_lag(sspm_object, vars, n = 1, default = "mean", ...) ## S4 method for signature 'sspm' spm_lag(sspm_object, vars, n = 1, default = "mean", ...) ## S4 method for signature 'sspm_fit' spm_lag(sspm_object, vars, n = 1, default = "mean", ...)
sspm_object |
[sspm_dataset] An object of class sspm_dataset. |
vars |
[character] Names of the variables to lag. |
n |
Positive integer of length 1, giving the number of positions to lag or lead by |
default |
The value used to pad |
... |
a list of variables that are the covariates that this
smooth is a function of. Transformations whose form depends on
the values of the data are best avoided here: e.g. |
Updated sspm_object
.
## Not run: sspm_model <- sspm_model %>% spm_lag(vars = c("weight_per_km2_borealis_with_catch", "weight_per_km2_all_predators"), n = 1) ## End(Not run)
## Not run: sspm_model <- sspm_model %>% spm_lag(vars = c("weight_per_km2_borealis_with_catch", "weight_per_km2_all_predators"), n = 1) ## End(Not run)
Currently, only one discretization method is supported:
* "tesselate_voronoi"
Voronoi tessellation using the function
tesselate_voronoi.
spm_methods()
spm_methods()
You can create your own method (tutorial TBD).
A character vector
of all available discretization methods.
sspm
model elementsAll methods described here allow to access the elements of contained in objects of the different classes of the package.
spm_name(sspm_object) spm_name(object) <- value spm_datasets(sspm_object) ## S4 method for signature 'sspm' spm_datasets(sspm_object) spm_datasets(object) <- value ## S4 replacement method for signature 'sspm' spm_datasets(object) <- value spm_boundaries(sspm_object) ## S4 method for signature 'sspm' spm_boundaries(sspm_object) spm_boundaries(object) <- value ## S4 replacement method for signature 'sspm' spm_boundaries(object) <- value spm_smoothed_data(sspm_object) ## S4 method for signature 'sspm' spm_smoothed_data(sspm_object) spm_smoothed_data(object) <- value ## S4 replacement method for signature 'sspm' spm_smoothed_data(object) <- value spm_time(sspm_object) ## S4 method for signature 'sspm' spm_time(sspm_object) spm_time(object) <- value ## S4 replacement method for signature 'sspm' spm_time(object) <- value is_split(sspm_object) ## S4 method for signature 'sspm' is_split(sspm_object) is_split(object) <- value ## S4 replacement method for signature 'sspm' is_split(object) <- value spm_unique_ID(sspm_object) ## S4 method for signature 'sspm' spm_unique_ID(sspm_object) spm_unique_ID(object) <- value ## S4 replacement method for signature 'sspm' spm_unique_ID(object) <- value
spm_name(sspm_object) spm_name(object) <- value spm_datasets(sspm_object) ## S4 method for signature 'sspm' spm_datasets(sspm_object) spm_datasets(object) <- value ## S4 replacement method for signature 'sspm' spm_datasets(object) <- value spm_boundaries(sspm_object) ## S4 method for signature 'sspm' spm_boundaries(sspm_object) spm_boundaries(object) <- value ## S4 replacement method for signature 'sspm' spm_boundaries(object) <- value spm_smoothed_data(sspm_object) ## S4 method for signature 'sspm' spm_smoothed_data(sspm_object) spm_smoothed_data(object) <- value ## S4 replacement method for signature 'sspm' spm_smoothed_data(object) <- value spm_time(sspm_object) ## S4 method for signature 'sspm' spm_time(sspm_object) spm_time(object) <- value ## S4 replacement method for signature 'sspm' spm_time(object) <- value is_split(sspm_object) ## S4 method for signature 'sspm' is_split(sspm_object) is_split(object) <- value ## S4 replacement method for signature 'sspm' is_split(object) <- value spm_unique_ID(sspm_object) ## S4 method for signature 'sspm' spm_unique_ID(sspm_object) spm_unique_ID(object) <- value ## S4 replacement method for signature 'sspm' spm_unique_ID(object) <- value
sspm_object |
[sspm OR adjacent] An object of class sspm or others derivative classes. |
object |
[sspm OR adjacent] An object of class sspm or others derivative classes. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_name(biomass_dataset)
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_name(biomass_dataset)
With a formula, smooth a variable in a sspm dataset. See Details for more explanations.
spm_smooth( sspm_object, formula, boundaries, keep_fit = TRUE, predict = TRUE, ... ) ## S4 method for signature 'sspm_dataset,formula,sspm_discrete_boundary' spm_smooth( sspm_object, formula, boundaries, keep_fit = TRUE, predict = TRUE, ... )
spm_smooth( sspm_object, formula, boundaries, keep_fit = TRUE, predict = TRUE, ... ) ## S4 method for signature 'sspm_dataset,formula,sspm_discrete_boundary' spm_smooth( sspm_object, formula, boundaries, keep_fit = TRUE, predict = TRUE, ... )
sspm_object |
[sspm_dataset] An object of class sspm_dataset. |
formula |
[formula] A formula definition of the form response ~ smoothing_terms + ... |
boundaries |
[sspm_boundary] An object of class sspm_discrete_boundary. |
keep_fit |
[logical] Whether or not to keep the fitted values and model (default to TRUE, set to FALSE to reduce memory footprint). |
predict |
[logical] Whether or not to generate the smoothed predictions (necessary to fit the final SPM model, default to TRUE). |
... |
Arguments passed on to
|
This functions allows to specify a model formula for a given discrete sspm
object. The formula makes use of specific smoothing terms smooth_time()
,
smooth_space()
, smooth_space_time()
. The formula can also contain fixed
effects and custom smooths, and can make use of specific smoothing terms
smooth_time()
, smooth_space()
, smooth_space_time()
.
An updated sspm_dataset.
## Not run: biomass_smooth <- biomass_dataset %>% spm_smooth(weight_per_km2 ~ sfa + smooth_time(by = sfa) + smooth_space() + smooth_space_time(), boundaries = bounds_voronoi, family = tw) ## End(Not run)
## Not run: biomass_smooth <- biomass_dataset %>% spm_smooth(weight_per_km2 ~ sfa + smooth_time(by = sfa) + smooth_space() + smooth_space_time(), boundaries = bounds_voronoi, family = tw) ## End(Not run)
Currently, only one smoothing method is supported:
* "ICAR"
: Intrinsic Conditional Auto-Regressive models.
* "LINPRED"
: LINear PREDictors (lag smooths).
spm_smooth_methods()
spm_smooth_methods()
A character vector
of all available smoothing methods.
Split data before fitting spm.
spm_split(sspm_object, ...) ## S4 method for signature 'sspm' spm_split(sspm_object, ...)
spm_split(sspm_object, ...) ## S4 method for signature 'sspm' spm_split(sspm_object, ...)
sspm_object |
[sspm] An object of class sspm. |
... |
[expression] Expression to evaluate to split data. |
The updated sspm object.
## Not run: sspm_model <- sspm_model %>% spm_split(year_f %in% c(1990:2017)) ## End(Not run)
## Not run: sspm_model <- sspm_model %>% spm_split(year_f %in% c(1990:2017)) ## End(Not run)
sspm_fit
model elementsAll methods described here allow to access the elements of contained in objects of class sspm_fit.
## S4 method for signature 'sspm_fit' spm_unique_ID(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_unique_ID(object) <- value ## S4 method for signature 'sspm_fit' spm_time(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_time(object) <- value ## S4 method for signature 'sspm_fit' spm_formulas(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_formulas(object) <- value ## S4 method for signature 'sspm_fit' spm_smoothed_data(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_smoothed_data(object) <- value spm_get_fit(sspm_object) ## S4 method for signature 'sspm_fit' spm_get_fit(sspm_object) spm_get_fit(object) <- value ## S4 replacement method for signature 'sspm_fit' spm_get_fit(object) <- value ## S4 method for signature 'sspm_fit' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_boundaries(object) <- value ## S4 method for signature 'sspm_fit' spm_boundary(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_boundary(object) <- value
## S4 method for signature 'sspm_fit' spm_unique_ID(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_unique_ID(object) <- value ## S4 method for signature 'sspm_fit' spm_time(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_time(object) <- value ## S4 method for signature 'sspm_fit' spm_formulas(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_formulas(object) <- value ## S4 method for signature 'sspm_fit' spm_smoothed_data(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_smoothed_data(object) <- value spm_get_fit(sspm_object) ## S4 method for signature 'sspm_fit' spm_get_fit(sspm_object) spm_get_fit(object) <- value ## S4 replacement method for signature 'sspm_fit' spm_get_fit(object) <- value ## S4 method for signature 'sspm_fit' spm_boundaries(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_boundaries(object) <- value ## S4 method for signature 'sspm_fit' spm_boundary(sspm_object) ## S4 replacement method for signature 'sspm_fit' spm_boundary(object) <- value
sspm_object |
[sspm_fit] An object of class sspm_fit. |
object |
[sspm_fit] An object of class sspm_fit. |
value |
typically an array-like R object of a similar class as
|
The object in the required slot.
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_formulas(biomass_dataset)
data(borealis_simulated, package = "sspm") biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis", density = "weight_per_km2", time = "year_f", coords = c('lon_dec','lat_dec'), uniqueID = "uniqueID") spm_formulas(biomass_dataset)
sspm
model objectCreate a sspm_model object.
sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,missing' sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,sspm_dataset' sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,list' sspm(biomass, predictors)
sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,missing' sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,sspm_dataset' sspm(biomass, predictors) ## S4 method for signature 'sspm_dataset,list' sspm(biomass, predictors)
biomass |
[sspm_dataset (smoothed)] The dataset containing the biomass variable. |
predictors |
[list OF sspm_dataset (smoothed)] The list of predictor datasets. |
An object of class sspm.
## Not run: sspm_model <- sspm(biomass = biomass_smooth_w_catch, predictors = predator_smooth) ## End(Not run)
## Not run: sspm_model <- sspm(biomass = biomass_smooth_w_catch, predictors = predator_smooth) ## End(Not run)
One of the first steps in the sspm
workflow is to create one or more
object(s) of class sspm_boundary
from an sf
object.
boundaries
[sf] Spatial boundaries (polygons).
boundary
[character] The column of data
that represents the
spatial boundaries.
boundary_area
[character] The column of data
that represents the
area of spatial boundaries.
One of the first step in the sspm
workflow is to create one or more
object(s) of class sspm_dataset
from a data.frame
, tibble
or sf
object.
name
[character] The name of the dataset, default to "Biomass".
data
[data.frame OR sf OR tibble] The dataset.
biomass
[character] The biomass columns of data
.
density
[character] The biomass density columns of data
.
time
[character] The column of data
that represents the
temporal dimension of the dataset.
coords
[character] The columns of data
that represent the
spatial dimension of the dataset: the two columns for longitude and
latitude of the observations.
uniqueID
[character] The column of data
that is unique for all
rows of the data matrix.
boundaries
[sspm_discrete_boundary] Spatial boundaries (polygons).
formulas
[list] List of sspm_formula objects that specifies the smoothed variables.
smoothed_data
[ANY (sf)] The smoothed data.
smoothed_vars
[character] A vector storing the smoothed vars.
smoothed_fit
[list] The fit from smoothing the data
is_mapped
[logical] Whether the dataset has been mapped to boundaries (used internally).
One of the first steps in the sspm
workflow is to create one or more
object(s) of class sspm_boundary
from an sf
object.
boundaries
[sf] Spatial boundaries (polygons).
boundary
[character] The column of data
that represents the
spatial boundaries.
boundary_area
[character] The column of data
that represents the
area of spatial boundaries.
method
[discretization_method] (if discrete) discretization method used.
patches
[sf] (if discrete) Patches resulting from discretization.
points
[sf or NULL] (if discrete) Sample points used for discretization.
patches_area
[character] The column of data
that represents the
area of patches.
The fit object for a sspm model
smoothed_data
[ANY (sf)] The smoothed data.
time
[character] The column of smoothed_data
that
represents the temporal dimension of the dataset.
uniqueID
[character] The column of smoothed_data
that is unique
for all rows of the data matrix.
formula
[list] The sspm_formula object that specifies the spm model.
boundaries
[sf] Spatial boundaries (polygons).
fit
[bam] The fit of the spm model.
This class is a wrapper around the formula
class. It is not intended for
users to directly manipulate and create new objects.
raw_formula
[formula] The raw formula call
translated_formula
[formula] The translated formula call ready to be evaluated.
vars
[list] List of relevant variables for the evaluation of the different smooths.
lag_vars
Smooth lag variables used for predictions
response
[charatcer] The response variable in the formula.
is_fitted
[logical] Whether this formula has already been fitted.
See the mgcv
function for defining smooths: s().
The sspm
model object, made from biomass, predictor and catch data.
datasets
[list] List of sspm_dataset that define variables in the SPM model.
time
[character] The column of data
that represents the
temporal dimension of the dataset.
uniqueID
[character] The column of datasets
that is unique for
all rows of the data matrix.
boundaries
[sf] Spatial boundaries (polygons).
smoothed_data
[ANY (sf)] The smoothed data.
smoothed_vars
[character] A vector storing the smoothed vars.
is_split
[logical] Whether this object has been split into train/test sets.
sspm_fit
objectsSummarises a sspm_fit
object, both in terms of productivity and biomass.
## S4 method for signature 'sspm_fit' summary(object, biomass = NULL)
## S4 method for signature 'sspm_fit' summary(object, biomass = NULL)
object |
[sspm_...] An object from this package. |
biomass |
[character] Biomass variable. |
Nothing is returned, but a summary is printed.
## Not run: summary(sspm_model_fit) summary(sspm_model_fit, biomass = "weight_per_km2_borealis") ## End(Not run)
## Not run: summary(sspm_model_fit) summary(sspm_model_fit, biomass = "weight_per_km2_borealis") ## End(Not run)
Generates voronoi polygons by first performing stratified sampling across boundary polygons, then by running the voronoisation with st_voronoi().
tesselate_voronoi( boundaries, with, boundary = "sfa", sample_surface = FALSE, sample_points = TRUE, nb_samples = NULL, min_size = 1500, stratify = TRUE, seed = 1 )
tesselate_voronoi( boundaries, with, boundary = "sfa", sample_surface = FALSE, sample_points = TRUE, nb_samples = NULL, min_size = 1500, stratify = TRUE, seed = 1 )
boundaries |
[sf] The boundaries to be used. |
with |
[sf] A set of data points to use for voronoisation. |
boundary |
[character] The column in |
sample_surface |
[logical] Whether to sample the surfaces in
|
sample_points |
[logical] Whether to sample points from |
nb_samples |
[named character vector] The number of samples to draw
by boundary polygons (must bear the levels of |
min_size |
[numeric] The minimum size for a polygon above which it will be merged (in km2). |
stratify |
[logical] Whether the discretization happens within the boundaries or whether the whole area is to be used (default to TRUE). |
seed |
[numeric] Passed onto |
A named list with three elements (each an sf
object):
* patches
, the voronoi polygons generated
* points
, the points used for the tessellation.
data(borealis_simulated, package = "sspm") data(sfa_boundaries, package = "sspm") tesselate_voronoi(sfa_boundaries, with = borealis, sample_surface = TRUE, boundary = "sfa", nb_samples = 10)
data(borealis_simulated, package = "sspm") data(sfa_boundaries, package = "sspm") tesselate_voronoi(sfa_boundaries, with = borealis, sample_surface = TRUE, boundary = "sfa", nb_samples = 10)
Generates delaunay triangles with ct_triangulate().
triangulate_delaunay( boundaries, with = NULL, boundary = "sfa", sample_surface = FALSE, sample_points = FALSE, nb_samples = NULL, min_size = 1000, seed = 1, ... )
triangulate_delaunay( boundaries, with = NULL, boundary = "sfa", sample_surface = FALSE, sample_points = FALSE, nb_samples = NULL, min_size = 1000, seed = 1, ... )
boundaries |
[sf] The boundaries to be used. |
with |
[sf] A set of data points to use for voronoisation. |
boundary |
[character] The column in |
sample_surface |
[logical] Whether to sample the surfaces in
|
sample_points |
[logical] Whether to sample points from |
nb_samples |
[named character vector] The number of samples to draw
by boundary polygons (must bear the levels of |
min_size |
[numeric] The minimum size for a triangle above which it will be merged (in km2). |
seed |
[numeric] Passed onto |
... |
Arguments passed on to
|
A named list with three elements (each an sf
object):
* patches
, the voronoi polygons generated
* points
, the points used for the tessellation.
data(borealis_simulated, package = "sspm") data(sfa_boundaries, package = "sspm") triangulate_delaunay(sfa_boundaries, with = borealis, sample_surface = TRUE, boundary = "sfa", nb_samples = 10)
data(borealis_simulated, package = "sspm") data(sfa_boundaries, package = "sspm") triangulate_delaunay(sfa_boundaries, with = borealis, sample_surface = TRUE, boundary = "sfa", nb_samples = 10)