You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
remove lat, lon filter from example; rewrite code to do so; remove file_name and species code from function, just create file name from common_name; cleanup some vignette output
Copy file name to clipboardExpand all lines: vignettes/a-simple-example.Rmd
+20-19Lines changed: 20 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -29,14 +29,13 @@ performs several essential tasks:
29
29
-**Package Management**: It installs and loads all the necessary R packages, including surveyresamplr, dplyr, purrr, ggplot2, and flextable. A helper function, `pkg_install()`, is used to check for and install packages if they're not already present.
30
30
-**Memory Allocation**: The `options(future.globals.maxSize = 1 * 1024^4)` line is crucial for parallel processing. It increases the memory limit for global variables to 1 TB, preventing memory-related errors when running complex models or processing large datasets.
31
31
32
-
```{r setup}
32
+
```{r setup, message = FALSE, warning = FALSE}
33
33
# Get rid of memory limits -----------------------------------------------------
34
34
options(future.globals.maxSize = 1 * 1024^4) # Allow up to 1 TB for globals
# Here we list all the packages we will need for this vignette
38
38
PKG <- c(
39
-
"surveyresamplr",
40
39
"dplyr",
41
40
"purrr",
42
41
"ggplot2",
@@ -51,6 +50,9 @@ pkg_install <- function(p) {
51
50
require(p, character.only = TRUE)
52
51
}
53
52
base::lapply(unique(PKG), pkg_install)
53
+
54
+
devtools::load_all()
55
+
library(surveyresamplr)
54
56
```
55
57
56
58
## Defining the Species and Model in `spp_list`
@@ -63,10 +65,6 @@ For this example, we've defined a model for eastern Bering Sea (EBS) walleye pol
63
65
64
66
-**`common_name`**: The common name of the species(s)
65
67
66
-
-**`file_name`**:
67
-
68
-
-**`species_code`**:
69
-
70
68
-**`model_fn`**: The model formula: total_catch_wt_kg ~ 0 + factor(year). This tells the model to fit catch weight in kg as a function of year, without an intercept.
71
69
72
70
-**`model_family`**: The statistical distribution family for the model, "delta_gamma". This is an advanced family from the sdmTMB package that models both the probability of catching a species (presence/absence) and the magnitude of the catch.
@@ -79,8 +77,6 @@ For this example, we've defined a model for eastern Bering Sea (EBS) walleye pol
@@ -173,13 +178,11 @@ Here we load the data for the model run, cropping it to the data we would like t
173
178
174
179
```{r load-data}
175
180
### Load survey data -----------------------------------------------------------
176
-
177
181
catch <- surveyresamplr::noaa_afsc_catch |>
178
182
dplyr::filter(srvy == "EBS") |>
179
183
dplyr::filter(year >= 2020)
180
184
181
185
### Load grid data -------------------------------------------------------------
182
-
183
186
grid_yrs <- sdmTMB::replicate_df(
184
187
dat = surveyresamplr::noaa_afsc_ebs_pred_grid_depth,
185
188
time_name = "year",
@@ -191,6 +194,7 @@ The resulting `grid_yrs` data frame now contains a year column, allowing the mod
191
194
192
195
```{r grid-yrs}
193
196
head(grid_yrs) |>
197
+
dplyr::mutate(year = as.character(year)) |>
194
198
flextable::flextable()
195
199
```
196
200
@@ -210,7 +214,6 @@ The code below defines key parameters that control the resampling process:
210
214
211
215
For this example, we are creating the following effort levels: 0.5, 0.75, and 1 which translates to 50% effort, 75% effort, and 100% effort. We then specify that we want 7 replicates for each effort.
212
216
213
-
214
217
tot_dataframes = effort x replicates - (replicates - 1). TOLEDO: is this hard and fast?
215
218
216
219
```{r set-vars}
@@ -242,9 +245,6 @@ The `purrr::map` function is used to apply the `clean_and_resample` function to
242
245
The number you input for `n_knots` can make or break your model. We have more details on considerations when choosing `n_knots` or allowing the function to select the number of knots for you in the [Importance of `n_knots` in `{sdmTMB}` Models section](#importance-of-sdmtmb-models).
243
246
:::
244
247
245
-
TODO: explain why `purrr::map` is important, what the sink files are for.
246
-
TODO: n_knots is lower here because the sample size is small
0 commit comments