fit_model | R Documentation |
This function is the user-interface for the multiple mid-level functions that perform separate components of a spatio-temporal analysis:
determine the extrapolation-grid make_extrapolation_info
,
define spatial objects make_spatial_info
,
build covariates from a formula interface make_covariates
,
assemble data make_data
,
build model make_model
,
estimate parameters fit_tmb
, and
check for obvious problems with the estimates check_fit
.
Please see reference documetation for each of those functions (e.g., ?make_extrapolation_info
) to see a list of arguments used by each mid-level function.
fit_model(
settings,
Lat_i,
Lon_i,
t_i,
b_i,
a_i,
c_iz = rep(0, length(b_i)),
v_i = rep(0, length(b_i)),
working_dir = tempdir(),
X1config_cp = NULL,
X2config_cp = NULL,
covariate_data,
X1_formula = ~0,
X2_formula = ~0,
Q1config_k = NULL,
Q2config_k = NULL,
catchability_data,
Q1_formula = ~0,
Q2_formula = ~0,
newtonsteps = 1,
silent = TRUE,
build_model = TRUE,
run_model = TRUE,
test_fit = TRUE,
category_names = NULL,
year_labels = NULL,
framework = "TMBad",
use_new_epsilon = TRUE,
...
)
settings |
Output from |
Lat_i |
Numeric vector, providing latitude for each sample |
Lon_i |
Numeric vector, providing longitude for each sample |
t_i |
Vector of integers, providing the time (e.g., calendar year) for each observation i.
The first modeled interval will be |
b_i |
Vector, providing sampled value (biomass, counts, etc.) for each observation i.
Users should provide values as class |
a_i |
Vector containing values greater than zero, providing sampled area for each
observation i, e.g., |
c_iz |
Vector of integers ranging from 0 to the number of variables minus 1, providing the category (e.g., species, length-bin) for each observation i. This can be specified as a matrix, such that each observation is associated with multiple categories. Such specification treats samples as arising from the sum across multiple categories, e.g., to account for unlabeled multispecies data. |
v_i |
Vector of integers ranging from 0 to the number of vessels minus 1,
providing sampling category (e.g., vessel or tow) associated with overdispersed variation for each observation i
(by default |
X1config_cp |
matrix of settings for each density covariate for the 1st lienar predictor, where the row corresponds to model category, and column corresponds to each density covariate
|
X2config_cp |
Same as argument |
covariate_data |
data frame of covariate values with columns |
X1_formula |
right-sided formula affecting the 1st linear predictor
which is then estimated independently for each model category |
X2_formula |
same as |
Q1config_k |
Same as argument |
Q2config_k |
Same as argument |
catchability_data |
data-frame of covariates for use when specifying |
Q1_formula |
Similar to |
Q2_formula |
same as |
newtonsteps |
Integer specifying the number of extra newton steps to take
after optimization (alternative to |
build_model |
Boolean indicating whether to build the model, |
run_model |
Boolean indicating whether to run the model or simply return the inputs and built TMB object |
test_fit |
Boolean indicating whether to apply |
category_names |
character vector specifying names for labeling categories |
year_labels |
character vector specifying names for labeling times |
framework |
Which AD framework to use ('TMBad' or 'CppAD') |
... |
additional arguments to pass to |
Specifically, the mid-level functions called by fit_model(.)
look for arguments in the following order of precedence (from highest to lowest precedence):
fit_model(.)
prioritizes using named arguments passed directly to fit_model(.)
. If arguments are passed this way, they are used instead of other options below.
If an argument is not passed supplied directly to fit_model(.)
, then fit_model(.)
looks for elements in input settings
, as typically created by make_settings
.
If an argument is not supplied via (1) or (2) above, then each mid-level function uses default values defined in those function arguments, e.g., see args(make_extrapolation_info)
for defaults for function make_extrapolation_info(.)
Collectively, this order of precedence allows users to specify inputs for a specific project via input method (1), the package author to change defaults through changes in the settings
defined for a given purpose in make_settings(.)
via input method (2), while still defaulting to package defaults via option (3).
Variables are indexed internally for locations g
, categories c
, and times y
.
Location index g
represents Longitude-Latitude fit$extrapolation_list$Data_Extrap[which(fit$spatial_list$g_e==g),c('Lon','Lat')]
;
Time index y
represents time fit$year_labels
; and
Category g
corresponds to values in fit$data_list$g_i
.
Object of class fit_model
, containing formatted inputs and outputs from VAST
parameter_estimates
Output from fit_tmb
; see that documentation for definition of contents
extrapolation_list
Output from make_extrapolation_info
; see that documentation for definition of contents
spatial_list
Output from make_spatial_info
; see that documentation for definition of contents
data_list
Output from make_data
; see that documentation for definition of contents
tmb_list
Output from make_model
; see that documentation for definition of contents
ParHat
Tagged list of maximum likelihood estimatesion of fixed effects and empirical Bayes estimates of random effects, following format of initial values generated by make_parameters
; see that documentation for definition of contents
Report
Tagged list of VAST outputs. For example, estimated density for grid g
, category c
, and time y
is available as fit$Report$D_gcy[g,c,y]
; see Details section for description of indexing
VAST
for general documentation, make_settings
for generic settings, fit_model
for model fitting, and plot_results
for generic plots
VAST wiki https://github.com/James-Thorson-NOAA/VAST/wiki for examples documenting many different use-cases and features.
GitHub mainpage https://github.com/James-Thorson-NOAA/VAST#description for a list of user resources and publications documenting features
summary.fit_model
for methods to summarize output, including obtain a dataframe of estimated densities and an explanation of DHARMa Probability-Integral-Transform residuals
predict.fit_model
for methods to predict at new locations using existing or updated covariate values
Other wrapper functions:
make_settings()
,
plot_results()
## Not run:
# Load packages
library(VAST)
# load data set
# see `?load_example` for list of stocks with example data
# that are installed automatically with `VAST`.
example = load_example( data_set="EBS_pollock" )
# Make settings
settings = make_settings( n_x=50,
Region=example$Region,
purpose="index",
strata.limits=example$strata.limits )
# Run model
fit = fit_model( "settings"=settings,
"Lat_i"=example$sampling_data[,'Lat'],
"Lon_i"=example$sampling_data[,'Lon'],
"t_i"=example$sampling_data[,'Year'],
"c_i"=rep(0,nrow(example$sampling_data)),
"b_i"=example$sampling_data[,'Catch_KG'],
"a_i"=example$sampling_data[,'AreaSwept_km2'],
"v_i"=example$sampling_data[,'Vessel'] )
# Plot results
plot_results( settings=settings, fit=fit )
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.