From 1dfb163f39d2d48dde05f1c151739350b9092b02 Mon Sep 17 00:00:00 2001 From: Kathryn Doering Date: Tue, 30 Jul 2024 21:59:30 +0000 Subject: [PATCH] r4ss colname change: Gender to sex --- R/initOM.R | 6 +++--- R/manipulate_EM.R | 12 ++++++------ R/red_noise_funcs.R | 24 ++++++++++++------------ R/sample_struct.R | 6 +++--- tests/testthat/test-extendOM.R | 4 ++-- tests/testthat/test-initOM.R | 4 ++-- tests/testthat/test-sample_struct.R | 10 +++++----- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/R/initOM.R b/R/initOM.R index 5ec7b050..af0c86cc 100644 --- a/R/initOM.R +++ b/R/initOM.R @@ -540,7 +540,7 @@ rm_sample_struct_hist <- function(sample_struct_hist, dat) { compare_obj = sample_struct_hist, name_in_obj = "lencomp", colnames = c( - "Yr", "Seas", "FltSvy", "Gender", + "Yr", "Seas", "FltSvy", "sex", "Part" ) ) @@ -549,7 +549,7 @@ rm_sample_struct_hist <- function(sample_struct_hist, dat) { compare_obj = sample_struct_hist, name_in_obj = "agecomp", colnames = c( - "Yr", "Seas", "FltSvy", "Gender", + "Yr", "Seas", "FltSvy", "sex", "Part", "Ageerr", "Lbin_lo", "Lbin_hi" ) @@ -564,7 +564,7 @@ rm_sample_struct_hist <- function(sample_struct_hist, dat) { return_obj = dat, compare_obj = sample_struct_hist, name_in_obj = "MeanSize_at_Age_obs", - colnames = c("Yr", "Seas", "FltSvy", "Gender", "Part", "AgeErr", "N_") + colnames = c("Yr", "Seas", "FltSvy", "sex", "Part", "AgeErr", "N_") ) dat } diff --git a/R/manipulate_EM.R b/R/manipulate_EM.R index 356d62b9..297ffaf5 100644 --- a/R/manipulate_EM.R +++ b/R/manipulate_EM.R @@ -78,7 +78,7 @@ get_EM_dat <- function(OM_dat, EM_dat, do_checks = TRUE) { lcomps <- lapply(dat, function(x) { tmp <- combine_cols( x, "lencomp", - c("Yr", "Seas", "FltSvy", "Gender", "Part") + c("Yr", "Seas", "FltSvy", "sex", "Part") ) }) matches_l <- which(lcomps[[1]][, "combo"] %in% lcomps[[2]][, "combo"]) @@ -89,7 +89,7 @@ get_EM_dat <- function(OM_dat, EM_dat, do_checks = TRUE) { acomps <- lapply(dat, function(x) { tmp <- combine_cols( x, "agecomp", - c("Yr", "Seas", "FltSvy", "Gender", "Part", "Lbin_lo", "Lbin_hi") + c("Yr", "Seas", "FltSvy", "sex", "Part", "Lbin_lo", "Lbin_hi") ) }) matches_a <- which(acomps[[1]][, "combo"] %in% acomps[[2]][, "combo"]) @@ -111,7 +111,7 @@ get_EM_dat <- function(OM_dat, EM_dat, do_checks = TRUE) { size_at_age <- lapply(dat, function(x) { tmp <- combine_cols( x, "MeanSize_at_Age_obs", - c("Yr", "Seas", "FltSvy", "Gender", "Part", "Ageerr") + c("Yr", "Seas", "FltSvy", "sex", "Part", "Ageerr") ) }) matches_size_at_age <- which(size_at_age[[1]][, "combo"] %in% size_at_age[[2]][, "combo"]) @@ -231,14 +231,14 @@ add_new_dat <- function(OM_dat, by_val <- switch(df_name, "catch" = c("year", "seas", "fleet"), "CPUE" = c("year", "seas", "index"), - "lencomp" = c("Yr", "Seas", "FltSvy", "Gender", "Part"), + "lencomp" = c("Yr", "Seas", "FltSvy", "sex", "Part"), "agecomp" = c( - "Yr", "Seas", "FltSvy", "Gender", "Part", "Ageerr", + "Yr", "Seas", "FltSvy", "sex", "Part", "Ageerr", "Lbin_lo", "Lbin_hi" ), "meanbodywt" = c("Year", "Seas", "Fleet", "Partition", "Type"), "MeanSize_at_Age_obs" = c( - "Yr", "Seas", "FltSvy", "Gender", "Part", + "Yr", "Seas", "FltSvy", "sex", "Part", "AgeErr" ) ) diff --git a/R/red_noise_funcs.R b/R/red_noise_funcs.R index 355f7ef7..4828a01c 100644 --- a/R/red_noise_funcs.R +++ b/R/red_noise_funcs.R @@ -36,9 +36,9 @@ calc_comp_var <- function(data_obs, data_exp, bins, fleets = NULL, years = NULL, # Check if select genders are specified if not select all genders in the input composition data frame if (!is.null(genders)) { - genders <- genders[is.element(genders, unique(data_obs[["Gender"]]))] + genders <- genders[is.element(genders, unique(data_obs[["sex"]]))] } else { - genders <- unique(data_obs[["Gender"]]) + genders <- unique(data_obs[["sex"]]) } # Check if select fleets are specified if not select all fleets in the input composition data frame @@ -50,8 +50,8 @@ calc_comp_var <- function(data_obs, data_exp, bins, fleets = NULL, years = NULL, # Subset the input observed and selected data to retain only the year, season, gender, and fleet # elements specified above - data_obs <- data_obs[is.element(data_obs[["Yr"]], years) & is.element(data_obs[["FltSvy"]], fleets) & is.element(data_obs[["Seas"]], seasons) & is.element(data_obs[["Gender"]], genders) & data_obs[["Yr"]] > 0, ] - data_exp <- data_exp[is.element(data_exp[["Yr"]], years) & is.element(data_exp[["FltSvy"]], fleets) & is.element(data_exp[["Seas"]], seasons) & is.element(data_exp[["Gender"]], genders) & data_exp[["Yr"]] > 0, ] + data_obs <- data_obs[is.element(data_obs[["Yr"]], years) & is.element(data_obs[["FltSvy"]], fleets) & is.element(data_obs[["Seas"]], seasons) & is.element(data_obs[["sex"]], genders) & data_obs[["Yr"]] > 0, ] + data_exp <- data_exp[is.element(data_exp[["Yr"]], years) & is.element(data_exp[["FltSvy"]], fleets) & is.element(data_exp[["Seas"]], seasons) & is.element(data_exp[["sex"]], genders) & data_exp[["Yr"]] > 0, ] # If merge fleets was set as true change all fleets to 0 so that data will be aggregated across them all if (merge_fleets == TRUE) { @@ -63,8 +63,8 @@ calc_comp_var <- function(data_obs, data_exp, bins, fleets = NULL, years = NULL, # If merge genders was set as true change all genders to 0 so that data will be aggregated across them all if (merge_genders == TRUE) { genders <- 0 - data_obs[["Gender"]] <- 0 - data_exp[["Gender"]] <- 0 + data_obs[["sex"]] <- 0 + data_exp[["sex"]] <- 0 } # If merge seasons was set as true change all seasons to 0 so that data will be aggregated across them all @@ -90,8 +90,8 @@ calc_comp_var <- function(data_obs, data_exp, bins, fleets = NULL, years = NULL, for (l in 1:length(seasons)) { Comp_uncert[[2]][[i]][[j]][[l]] <- list() # For each fleet, gender, and season combination subset the data for analysis - sub_dat_obs <- data_obs[data_obs[["FltSvy"]] == fleets[i] & data_obs[["Gender"]] == genders[j] & data_obs[["Seas"]] == seasons[l], ((length(data_obs[1, ]) - length(bins) + 1):length(data_obs[1, ]))] - sub_dat_exp <- data_exp[data_exp[["FltSvy"]] == fleets[i] & data_exp[["Gender"]] == genders[j] & data_obs[["Seas"]] == seasons[l], ((length(data_exp[1, ]) - length(bins) + 1):length(data_exp[1, ]))] + sub_dat_obs <- data_obs[data_obs[["FltSvy"]] == fleets[i] & data_obs[["sex"]] == genders[j] & data_obs[["Seas"]] == seasons[l], ((length(data_obs[1, ]) - length(bins) + 1):length(data_obs[1, ]))] + sub_dat_exp <- data_exp[data_exp[["FltSvy"]] == fleets[i] & data_exp[["sex"]] == genders[j] & data_obs[["Seas"]] == seasons[l], ((length(data_exp[1, ]) - length(bins) + 1):length(data_exp[1, ]))] # Calculate the total observed and expected samples to allow scaling and unlisting of matrix data total_obs <- apply(sub_dat_obs, 1, sum) @@ -227,9 +227,9 @@ Sim_comp <- function(Comp_uncert, data_exp, bins, years = NULL, seasons = NULL, } if (!is.null(genders)) { - genders <- genders[is.element(genders, unique(data_exp[["Gender"]]))] + genders <- genders[is.element(genders, unique(data_exp[["sex"]]))] } else { - genders <- unique(data_exp[["Gender"]]) + genders <- unique(data_exp[["sex"]]) } if (!is.null(fleets)) { @@ -240,7 +240,7 @@ Sim_comp <- function(Comp_uncert, data_exp, bins, years = NULL, seasons = NULL, # Subset the expected data to only include the selected fleet, year, season, gender range and the replicate this as the # observed data object to be filled with new random observations - data_exp <- data_exp[is.element(data_exp[["Yr"]], years) & is.element(data_exp[["FltSvy"]], fleets) & is.element(data_exp[["Seas"]], seasons) & is.element(data_exp[["Gender"]], genders) & data_exp[["Yr"]] > 0, ] + data_exp <- data_exp[is.element(data_exp[["Yr"]], years) & is.element(data_exp[["FltSvy"]], fleets) & is.element(data_exp[["Seas"]], seasons) & is.element(data_exp[["sex"]], genders) & data_exp[["Yr"]] > 0, ] data_obs <- data_exp # offset assumes that the observed composition bins are represented buy the final columns of the data frame @@ -252,7 +252,7 @@ Sim_comp <- function(Comp_uncert, data_exp, bins, years = NULL, seasons = NULL, # For each of fleet, season, and gender select the corresponding reference link to the uncertainty list object fleet_ref <- which(Comp_uncert[[1]][[1]] == data_obs[["FltSvy"]][i]) season_ref <- which(Comp_uncert[[1]][[2]] == data_obs[["Seas"]][i]) - gender_ref <- which(Comp_uncert[[1]][[3]] == data_obs[["Gender"]][i]) + gender_ref <- which(Comp_uncert[[1]][[3]] == data_obs[["sex"]][i]) # Extract the variance and bias information for the referenced fleet, gender, season sub_var <- Comp_uncert[[2]][[fleet_ref]][[gender_ref]][[season_ref]][[2]] sub_bias <- Comp_uncert[[2]][[fleet_ref]][[gender_ref]][[season_ref]][[3]] diff --git a/R/sample_struct.R b/R/sample_struct.R index 2086b52c..3434c79f 100644 --- a/R/sample_struct.R +++ b/R/sample_struct.R @@ -24,7 +24,7 @@ convert_to_r4ss_names <- function(sample_struct, # currently SSMSE only allows repeating the same sample sizes. "year", "month", "fleet", "sex", "part", "ageerr", "N_" # Tags releases - # "Area", "Yr", "Season", "Gender", "Age", "Nrelease", + # "Area", "Yr", "Season", "sex", "Age", "Nrelease", # Morph comp ), sample_struct_name = c( @@ -191,7 +191,7 @@ create_sample_struct <- function(dat, nyrs, rm_NAs = FALSE) { } if (name %in% c("lencomp", "agecomp", "MeanSize_at_Age_obs")) { # Sex - sex_col <- grep("Sex|Gender", colnames(df), + sex_col <- grep("Sex|sex", colnames(df), ignore.case = TRUE, value = TRUE ) @@ -417,7 +417,7 @@ get_full_sample_struct <- function(sample_struct, ) x[["Sex"]] <- NA for (i in unique(x[["FltSvy"]])) { - tmp_sx <- unique(tmp_dat[tmp_dat[[flt_colname]] == i, "Gender"]) + tmp_sx <- unique(tmp_dat[tmp_dat[[flt_colname]] == i, "sex"]) if (length(tmp_sx) == 1) { x[x[["FltSvy"]] == i, "Sex"] <- tmp_sx } else { diff --git a/tests/testthat/test-extendOM.R b/tests/testthat/test-extendOM.R index bc22a651..1e8eeac7 100644 --- a/tests/testthat/test-extendOM.R +++ b/tests/testthat/test-extendOM.R @@ -40,12 +40,12 @@ extend_vals <- list( ), lencomp = data.frame( Yr = 101:103, Seas = 1, FltSvy = 1, - Gender = 0, Part = 0, + sex = 0, Part = 0, Nsamp = c(25, 50, 100) ), agecomp = data.frame( Yr = 101:104, Seas = 1, FltSvy = 2, - Gender = 0, Part = 0, Ageerr = 1, + sex = 0, Part = 0, Ageerr = 1, Lbin_lo = -1, Lbin_hi = -1, Nsamp = c(25, 50, 100, 150) ) diff --git a/tests/testthat/test-initOM.R b/tests/testthat/test-initOM.R index 8e200948..5ec1e5eb 100644 --- a/tests/testthat/test-initOM.R +++ b/tests/testthat/test-initOM.R @@ -42,13 +42,13 @@ test_that("create_OM can modify model", { new_dat[["CPUE"]][, c("year", "seas", "index")], unique(new_dat[["CPUE"]][, c("year", "seas", "index")]) ) - cols_lencomp <- c("Yr", "Seas", "FltSvy", "Gender", "Part") + cols_lencomp <- c("Yr", "Seas", "FltSvy", "sex", "Part") expect_equal( new_dat[["lencomp"]][, cols_lencomp], unique(new_dat[["lencomp"]][, cols_lencomp]) ) cols_agecomp <- c( - "Yr", "Seas", "FltSvy", "Gender", "Part", "Ageerr", "Lbin_lo", + "Yr", "Seas", "FltSvy", "sex", "Part", "Ageerr", "Lbin_lo", "Lbin_hi" ) expect_equal( diff --git a/tests/testthat/test-sample_struct.R b/tests/testthat/test-sample_struct.R index 50939a83..1bdbb934 100644 --- a/tests/testthat/test-sample_struct.R +++ b/tests/testthat/test-sample_struct.R @@ -25,11 +25,11 @@ test_that("assumptions about r4ss colnames are true.", { CPUE = data.frame(year = c(102, 105), seas = 7, index = 2, se_log = 0.2), lencomp = data.frame( Yr = c(102, 105), Seas = 1, FltSvy = 1, - Gender = 0, Part = 0, Nsamp = 125 + sex = 0, Part = 0, Nsamp = 125 ), agecomp = data.frame( Yr = c(102, 105), Seas = 1, FltSvy = 2, - Gender = 0, Part = 0, Ageerr = 1, + sex = 0, Part = 0, Ageerr = 1, Lbin_lo = -1, Lbin_hi = -1, Nsamp = 500 ), meanbodywt = data.frame( @@ -44,7 +44,7 @@ test_that("assumptions about r4ss colnames are true.", { Yr = c(1971, 1995), Seas = 7, FltSvy = c(1, 1, 2, 2), - Gender = 3, + sex = 3, Part = 0, AgeErr = 1 ) @@ -73,11 +73,11 @@ test_that("convert_to_r4ss_names works", { expect_equal(names(r4ss_sample_struct[["CPUE"]]), c("year", "seas", "index", "se_log")) expect_equal(names(r4ss_sample_struct[["lencomp"]]), c( "Yr", "Seas", "FltSvy", - "Gender", "Part", "Nsamp" + "sex", "Part", "Nsamp" )) expect_equal(names(r4ss_sample_struct[["agecomp"]]), c( "Yr", "Seas", "FltSvy", - "Gender", "Part", "Ageerr", + "sex", "Part", "Ageerr", "Lbin_lo", "Lbin_hi", "Nsamp" )) })