% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/LFD.r
\name{LFD}
\alias{LFD}
\title{Length Frequency Distribution (LFD) Estimation and Plotting}
\usage{
LFD(
  mTATC,
  sex = "all",
  GSA,
  country = "all",
  depth_range,
  strata_scheme,
  stratification,
  wd = NA,
  save = TRUE,
  verbose = TRUE
)
}
\arguments{
\item{mTATC}{Data frame resulting from the merge of TA and TC datasets using `merge_TATBTC()`. It must include raised numbers.}

\item{sex}{Character. Target sex for the analysis. Allowed values: `"F"`, `"M"`, `"I"`, `"N"`, or `"all"` (default) for combined sexes.}

\item{GSA}{Numeric. The GSA (Geographical Sub-Area) code of reference for the analysis.}

\item{country}{Character vector. Reference country or countries for the analysis. Use `"all"` (default) to include all countries available in the data.}

\item{depth_range}{Numeric vector of length 2, specifying the minimum and maximum depths (in meters) to filter the hauls used in the analysis.}

\item{strata_scheme}{Data frame containing the stratification scheme. Must include `CODE`, `MIN_DEPTH`, `MAX_DEPTH`, `GSA`, `COUNTRY`.}

\item{stratification}{Data frame with surface areas per stratum. Must include columns: `GSA`, `CODE`, `COUNTRY`, `SURF`.}

\item{wd}{Character. Working directory used to save output plots and tables. Required if `save = TRUE`.}

\item{save}{Logical. If `TRUE` (default), the function saves output tables and plots to `wd/output/`. If `FALSE`, no files are saved.}

\item{verbose}{Logical. If `TRUE` (default), informative messages are printed to the console to trace the function steps.}
}
\value{
A named list with two elements:
\describe{
  \item{`LFD`}{A data frame of total LFD by year across all strata.}
  \item{`LFD by stratum`}{A data frame of LFD by year and by stratum.}
}

A \code{list} of \code{ggplot} objects representing the length-frequency distributions.
}
\description{
Input parameters include biological and haul data, stratification schemes,
reference filters (e.g., sex, GSA, country, depth), and output control options (working directory, saving, verbosity).
}
\details{
This function estimates and plots the length frequency distribution (LFD) by year and by stratum,
based on merged biological and haul data from MEDITS surveys. It computes raised numbers,
applies stratification weights, and generates publication-ready plots and CSV outputs.
Stratification weighting is based on swept area and surface area of the strata.


The function:
\itemize{
  \item Filters hauls by depth and country.
  \item Computes raised numbers per haul.
  \item Applies stratified weights based on the area per stratum.
  \item Outputs and/or plots the length frequency distribution by year and stratum.
  \item Handles sex-specific or combined-sex analyses.
}

The plot outputs include:
\itemize{
  \item Combined LFD by year across all strata.
  \item LFD by stratum (faceted), stratified by year.
}

Output files are saved as CSV and high-resolution JPEGs if `save = TRUE` and `wd` is defined.
}
\examples{
data(TA)
data(TC)
# Create a merged dataset for GSA 10
mTATC <- merge_TATC(TA[TA$AREA==10,], TC[TC$AREA==10,], "MERLMER")
LFD(mTATC, sex="all", GSA=10, country="all", depth_range=c(10,800),
    strata_scheme=BioIndex::strata_scheme,
    stratification=BioIndex::stratification, wd=tempdir(), save=FALSE)
}
