These functions tidy, filter, and calculate frequencies for ages or lengths over time for survey or commercial data. They can calculate raw frequencies or frequencies in which the samples are weighted. See weight_comps() for details on the weighting procedure.

tidy_ages_raw(...)

tidy_ages_weighted(...)

tidy_lengths_raw(...)

tidy_lengths_weighted(...)

tidy_comps(dat, survey = c("SYN WCHG", "SYN HS", "SYN QCS", "SYN WCVI",
  "HBLL OUT N", "HBLL OUT S", "IPHC FISS"), year_range = NULL,
  spp_cat_code = 1, area_grep_pattern = "*",
  ageing_method_codes = NULL, usability_codes = c(0, 1, 2, 6),
  bin_size = 2, age_length = c("age", "length"),
  sample_type = c("survey", "commercial"), frequency_type = c("raw",
  "weighted"), dat_survey_sets = NULL, dat_catch = NULL,
  remove_unsexed = TRUE)

Arguments

...

Arguments to pass to tidy_comps().

dat

The input samples data frame from get_commercial_samples() or get_survey_samples().

survey

A character vector of survey names to use. These should match the survey abbreviations in GFBio. All of the survey listed here will be rendered in the final plot in the order that they are specified to this argument.

year_range

An optional range of years to plot.

spp_cat_code

A numeric vector of species category codes to include for the commercial samples. Defaults to 1, which refers to unsorted samples.

area_grep_pattern

A grep() pattern to match the major statistical area descriptions. The pattern "*" will return all areas. For example, "5[CDE]+" would return areas 5C, 5D, and 5E. See base::regex().

ageing_method_codes

A numeric vector of ageing method codes to filter on. Default to NULL, which brings in all valid ageing codes. See get_age_methods().

usability_codes

An optional vector of usability codes. All usability codes not in this vector will be omitted. Set to NULL to include all samples.

bin_size

Bin size for length binning.

age_length

Should the function operate on ages or lengths?

sample_type

Are the samples from a commercial or survey source?

frequency_type

Should the frequencies or proportions be based on raw value or with weighted samples?

dat_survey_sets

A data frame from get_survey_sets(). Needed for weighted samples if sample_type = "survey".

dat_catch

A data frame from get_catch(). Needed for weighted samples if sample_type = "commercial".

remove_unsexed

Logical

Details

The function tidy_comps() is the main workhorse function, but as a user you can use the helper functions tidy_ages_raw(), tidy_ages_weighted(), tidy_lengths_raw(), and tidy_lengths_weighted(). These functions simply call tidy_comps() with appropriate argument values for age_length and frequency_type.

Note that the length_bin column will contain the mid value of that length bin. E.g. 13 with bin_size = 2 would represent a bin from 12 to 14.

Examples

# NOT RUN {
# # extract data with get_*() functions:
# # main age/length data:
# rs_comm_samples <- get_commercial_samples("redstripe rockfish",
#   discard_keepers = TRUE)
# rs_survey_samples <- get_survey_samples("redstripe rockfish")
#
# # for weighting:
# rs_catch <- get_catch("redstripe rockfish")
# rs_survey_sets <- get_survey_sets("redstripe rockfish")

# calculate raw age frequencies for survey data:
tidy_ages_raw(rs_survey_samples,
  sample_type = "survey")

# calculate weighted age frequencies for survey data:
tidy_ages_weighted(rs_survey_samples,
  sample_type = "survey",
  dat_survey_sets = rs_survey_sets)

# calculate raw length frequencies for survey data:
tidy_lengths_raw(rs_survey_samples,
  sample_type = "survey",
  bin_size = 2)

# calculate raw age frequencies for commercial data:
tidy_ages_raw(rs_comm_samples,
  sample_type = "commercial")

# calculate weighted age frequencies for commercial data:
tidy_ages_weighted(rs_comm_samples,
  sample_type = "commercial",
  dat_catch = rs_catch)

# calculate weighted length frequencies for commercial data:
tidy_lengths_weighted(rs_comm_samples,
  sample_type = "commercial",
  bin_size = 2,
  dat_catch = rs_catch)
# }