Overlap and captures data are prepared and loaded into an sefraData object for an sefra model run. Captures and overlap are summed over duplicate rows.
Usage
data_prep(object, data, ...)
# S4 method for class 'sefraData,data.frame'
data_prep(object, data, ...)Arguments
- object
sefraDataobject- data
Input data frame containing overlap data per species.
- ...
Additional (optional) data frames containing captures or overlap data.
Note
When preparing observer data, captures and overlap should both be provided to the function call. This allows the appropriate checks to ensure the data are consistent. If only one overlap data frame is provided, it is treated as un-observed effort data.
Examples
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# create sefraData object
dat <- sefraData(c('DIW', 'DQS', 'TWD'))
#> species codes input: including all species-dependent capture codes
#> constructed 'sefraData' object
# captures data.frame
captures_dfr <- data.frame(n_captures = sample(0:1, 10, replace = TRUE),
year = sample(2000:2020, 10, replace = TRUE),
code = 'BLZ',
month = sample(month.abb, 10, replace = TRUE),
flag = sample(c('F1', 'F2'), 10, replace = TRUE))
captures_dfr <- data.frame(captures_dfr,
n_captures_alive = captures_dfr$n_captures,
n_captures_dead = 0)
captures_dfr <- data.frame(captures_dfr, id_species_group = 1,
id_month = match(captures_dfr$month, sefra:::months),
id_fishery_group = match(captures_dfr$flag, c('F1', 'F2')))
# assign values
fishery_groups(dat) <- captures_dfr
fishery_groups(dat)
#> 2 fishery groups
#> fishery_group id_fishery_group
#> 1 fishery_1 1
#> 2 fishery_2 2
species_groups(dat) <- rep('group_1', 3)
#> Warning: assumption that vector of group names is ordered by species in object
species_groups(dat)
#> 1 species group
#> species_group id_species_group
#> 1 group_1 1
capture_codes(dat) <- captures_dfr
capture_codes(dat)
#> 1 capture code:
#> (empty captures data frame)
#> code id_code resolution id_resolution
#> 1 BLZ 40 species 1
#> 2 BLZ 40 species 1
#> 3 BLZ 40 species 1
#> 4 BLZ 40 complex 2
#> 5 BLZ 40 complex 2
#> 6 BLZ 40 complex 2
#> 7 BLZ 40 genus 3
#> 8 BLZ 40 genus 3
#> 9 BLZ 40 family 4
#> 10 BLZ 40 class 5
# separate overlap data frame
overlap_dfr <- captures_dfr %>% select(contains('id_')) %>%
mutate(cell = sample(1:1224, 10), year = sample(2000:2020, 10, replace = TRUE),
overlap = runif(10) / 1e3, species = sample(c('DIW', 'DQS', 'TWD'), 10, replace = TRUE))
# combined data frame
combined_dfr <- captures_dfr %>%
mutate(cell = sample(1:1224, 10), overlap = runif(10) / 1e3,
species = sample(c('DIW', 'DQS', 'TWD'), 10, replace = TRUE))
# assume overlap is observed and
# input separate data frames
dat <- dat %>% data_prep(captures_dfr, overlap_dfr)
#> Prepared observer captures and overlap data
captures(dat)
#> # A tibble: 3 × 6
#> captures_k captures_live_k captures_dead_k code_k month_k fishery_group_k
#> <int> <int> <int> <int> <int> <int>
#> 1 1 1 0 40 9 1
#> 2 1 1 0 40 6 2
#> 3 1 1 0 40 7 2
overlap(dat)
#> # A tibble: 10 × 5
#> overlap_i species_i species_group_i month_i fishery_group_i
#> <dbl> <int> <int> <int> <int>
#> 1 0.000241 1 1 5 1
#> 2 0.000213 1 1 6 1
#> 3 0.000519 2 1 9 1
#> 4 0.000997 2 1 5 2
#> 5 0.000846 2 1 6 2
#> 6 0.0000586 2 1 7 2
#> 7 0.000401 2 1 9 2
#> 8 0.000718 2 1 10 2
#> 9 0.000672 2 1 11 2
#> 10 0.000149 13 1 6 1
# assume data is observed and
# input as combined data frame
dat <- dat %>% data_prep(combined_dfr)
#> Prepared observer captures and overlap data
captures(dat)
#> # A tibble: 3 × 6
#> captures_k captures_live_k captures_dead_k code_k month_k fishery_group_k
#> <int> <int> <int> <int> <int> <int>
#> 1 1 1 0 40 9 1
#> 2 1 1 0 40 6 2
#> 3 1 1 0 40 7 2
overlap(dat)
#> # A tibble: 10 × 5
#> overlap_i species_i species_group_i month_i fishery_group_i
#> <dbl> <int> <int> <int> <int>
#> 1 0.000663 1 1 6 1
#> 2 0.000927 1 1 7 2
#> 3 0.000165 1 1 9 2
#> 4 0.0000446 1 1 10 2
#> 5 0.000910 2 1 5 1
#> 6 0.000552 2 1 5 2
#> 7 0.000245 2 1 6 2
#> 8 0.000577 13 1 6 1
#> 9 0.000687 13 1 9 1
#> 10 0.000857 13 1 11 2
# assume data is not observed
dat <- dat %>% data_prep(overlap_dfr)
#> Prepared commercial (total) overlap data
overlap(dat)
#> $observer
#> # A tibble: 10 × 5
#> overlap_i species_i species_group_i month_i fishery_group_i
#> <dbl> <int> <int> <int> <int>
#> 1 0.000663 1 1 6 1
#> 2 0.000927 1 1 7 2
#> 3 0.000165 1 1 9 2
#> 4 0.0000446 1 1 10 2
#> 5 0.000910 2 1 5 1
#> 6 0.000552 2 1 5 2
#> 7 0.000245 2 1 6 2
#> 8 0.000577 13 1 6 1
#> 9 0.000687 13 1 9 1
#> 10 0.000857 13 1 11 2
#>
#> $fishery
#> # A tibble: 10 × 5
#> overlap_j species_j species_group_j month_j fishery_group_j
#> <dbl> <int> <int> <int> <int>
#> 1 0.000241 1 1 5 1
#> 2 0.000213 1 1 6 1
#> 3 0.000519 2 1 9 1
#> 4 0.000997 2 1 5 2
#> 5 0.000846 2 1 6 2
#> 6 0.0000586 2 1 7 2
#> 7 0.000401 2 1 9 2
#> 8 0.000718 2 1 10 2
#> 9 0.000672 2 1 11 2
#> 10 0.000149 13 1 6 1
#>