Computes the paired tests on difference in weight per catch category

f_test_paired(tab_diff, sp, cat)

Arguments

tab_diff

data.frame. A dataframe containing the computed differences in weight between TEST and STD device per catch category

sp

character. The species to use in test

cat

character. The category to use in test

Value

data.frame. The summary table of the statistical tests

Examples

# Create tmp folder
output_dir <- tempfile(pattern = "inser")
dir.create(output_dir)

# Setup input OTT data
OTT_data_folder <- system.file("script_origin","Data","Example_OTT", package = "inser")

TR <- readr::read_delim(
  file = file.path(OTT_data_folder, "TR.csv"),
  delim = ";",
  escape_double = FALSE,
  locale = readr::locale(encoding = "WINDOWS-1252"),
  trim_ws = TRUE
)
#> Rows: 2 Columns: 31
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ";"
#> chr (12): sampling_type, landing_country, vessel_flag_country, project, harb...
#> dbl (11): trip_code, year, vessel_length, vessel_power, vessel_size, vessel_...
#> lgl  (8): number_of_sets, days_at_sea, departure_date_time, return_date_time...
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.

HH<-read.table(
  file.path(OTT_data_folder, "HH.csv"),
  sep=";",
  header=TRUE,
  encoding = "WINDOWS-1252")#,colClasses = colClasses)

SL<-read.table(
  file.path(OTT_data_folder, "SL.csv"),
  sep=";",
  header=TRUE,
  encoding = "WINDOWS-1252")

HL<-read.table(
  file.path(OTT_data_folder, "HL.csv"),
  sep=";",
  header=TRUE,
  encoding = "WINDOWS-1252")

colClasses<-rep(NA,ncol(HH))
colClasses[which(names(HH)=="statistical_rectangle")]<-"character"

HH<-read.table(
  file.path(OTT_data_folder, "HH.csv"),
  sep=";",
  header=TRUE,
  colClasses = colClasses,
  encoding = "WINDOWS-1252")

# create selectivity data object
data <- prep_sel_data(data=list(TR,HH,SL,HL))

# extract weight data per species
weight_species <- data %>%
  dplyr::group_by(
    project,
    vessel_identifier,
    trip_code,
    station_number,
    gear_label,
    catch_category,
    species
  ) %>%
  dplyr::summarize(weight = sum(weight) * 10 ^ (-3)) %>%
  as.data.frame()
#> `summarise()` has grouped output by 'project', 'vessel_identifier',
#> 'trip_code', 'station_number', 'gear_label', 'catch_category'. You can override
#> using the `.groups` argument.

weight_species <- as.data.frame(tidyr::complete(
  weight_species,
  tidyr::nesting(project, vessel_identifier, trip_code, station_number),
  gear_label,
  catch_category,
  species,
  fill = list(weight = 0)
))

tab_diff <- weight_species %>% dplyr::group_by(project,
                                               vessel_identifier,
                                               trip_code,
                                               station_number,
                                               catch_category,
                                               species) %>%
  dplyr::summarize(
    diff_weight = weight[gear_label == "TEST"] - weight[gear_label == "STD"],
    weight_STD = weight[gear_label == "STD"],
    weight_TEST = weight[gear_label == "TEST"]
  )
#> `summarise()` has grouped output by 'project', 'vessel_identifier',
#> 'trip_code', 'station_number', 'catch_category'. You can override using the
#> `.groups` argument.

# run f_test
f_test_paired(tab_diff = tab_diff,
       sp = "Solea solea",
       cat = "LAN")
#>   pvalue   moyenne   mediane   test Taux_Var_Tot Taux_Var_OP
#> 1 0.1283 -101.1143 -50.17634 Fisher       -82.21      -70.44

# Clear tmp folder
unlink(output_dir, recursive = TRUE)