sample_ages: Add observation error to numbers-at-age data

View source: R/sample_ages.R

sample_agesR Documentation

Add observation error to numbers-at-age data

Description

Create sampled data from numbers-at-age data to add observation error to data from and Atlantis scenario. todo: add more information here later

Usage

sample_ages(dat, prop, ageErr = NULL)

Arguments

dat

A data.frame of numbers at age containing the following columns:

  • species

  • agecl

  • polygon

  • layer

  • time

  • atoutput

The data.frame is generated from either create_survey or create_fishery_subset.

prop

Percentage of samples for each species: a matrix with nrow=length(species). Columns: species: the species name. Matches names in species prop: the percentage of age samples for each species (for example, 01 if 1 out of every 10 lengthed fish is sampled for age). Max of 1.

ageErr

ageErr is a list with elements containing a matrix for each species list element name is species name matrix rows are true age, columns are assigned age species that are missing will be assigned no ageing error (so a value of NULL means no ageing error for all species)

Details

The function takes numbers-at-age data from an Atlantis scenario where the data was read in from Atlantis output using load_nc within run_truth, and then run through sample_fish. One does not need to use these functions to create dat, rather you must only ensure that the structure of dat is the same. Currently, the function takes output from sample_fish and subsamples those fish given the proportion supplied by prop. You can also apply ageing error to the data, using the ageErr argument.

Author(s)

Poseidon

Examples

	directory <- system.file("extdata", "SETAS_Example", package = "atlantisom")
	scenario <- "outputs"
	groups <- load_fgs(dir = directory, "Functional_groups.csv")
	groups <- groups[groups$IsTurnedOn > 0, "Name"]
	results <- run_truth(scenario = scenario,
	dir = directory,
	file_fgs = "Functional_groups.csv",
	file_bgm = "Geography.bgm",
	select_groups = groups,
	file_init = "Initial_condition.nc",
	file_biolprm = "Biology.prm",
	file_runprm = "Run_settings.xml",
   file_fish = "Fisheries.csv")

	species=c("Pisciv_T_Fish","Pisciv_S_Fish")
    boxes <- 1:3
	effic <- data.frame(species=c("Pisciv_T_Fish","Pisciv_S_Fish"), efficiency=c(0.3,0.1))
	selex <- data.frame(species=c(rep("Pisciv_T_Fish",10),rep("Pisciv_S_Fish",10)),
	                agecl=c(1:10,1:10),
	                selex=c(0,0,0.1,0.5,0.8,1,1,1,1,1,0,0,0.1,0.3,0.5,0.7,0.9,1,1,1))

	tmp <- create_survey(dat=results$nums, time=seq(10,55,3), species=species, boxes=boxes, effic=effic, selex=selex)
	effN <- data.frame(species=species, effN=c(200, 500))
	samp <- sample_fish(tmp, effN=effN)

    prop <- data.frame(species=species, prop=c(0.5,1)) #should be same as input when prop=1, but with ageing error
     sample_ages(samp,prop,ageErr=NULL)

r4atlantis/atlantisom documentation built on Nov. 12, 2023, 2:59 a.m.