lc50_analyze: Analyse Bioassay Data for LC Estimation (Main Function)

View source: R/lc50_main.R

lc50_analyzeR Documentation

Analyse Bioassay Data for LC Estimation (Main Function)

Description

Non-interactive, fully parameter-driven entry point for the LC (lethal concentration) analysis. It (1) assembles the standardised data list from a data frame, a named list of data frames or three parallel vectors, (2) computes the LC estimates with the selected method(s) via lc50_calculate and (3) optionally builds the regression plot(s) in the style of lc50_plot, optionally written to disk as png when plot_file is supplied. Tabular export is handled separately by lc50_export.

Usage

lc50_analyze(
  d = NULL,
  concentration = NULL,
  tested = NULL,
  dead = NULL,
  name = "bioassay",
  lc = 0.5,
  method = "traditional",
  plot = FALSE,
  plot_file = NULL,
  plot_width = 12,
  plot_height = 8,
  plot_units = "cm",
  plot_res = 300,
  plot_method = NULL,
  font = "TNM",
  unit = NULL,
  shape = c("sigmoid", "linear"),
  ci = TRUE,
  ci_level = 0.95,
  error_bar = TRUE,
  move_thres = 0.5,
  lc_ci = TRUE,
  lc_p = TRUE,
  lc_lab_gap = 0.35,
  lc_lab_gap_right = 0.1,
  lc_lab_dy = 0.1,
  lc_lab_lh = 1.05
)

Arguments

d

Optional; the bioassay data: a data frame with the columns Concentration, Tested and Dead (headers are matched loosely, as in lc50_read, so a header like "Concentration (mg/L)" works), a named list of such data frames (e.g. the return value of lc50_read), or NULL to build the data from the three vectors below.

concentration, tested, dead

Numeric vectors; the concentration, the number of insects tested and the number of dead insects, one entry per concentration group (replicates = repeated values). Used only when d is NULL.

name

Character; the data set name used in the results and the saved plot file names when d is a single data frame or the vectors are used (default "bioassay"); ignored for a named list input.

lc

Numeric; the lethal proportion (default 0.5 = LC50, e.g. 0.9 = LC90), passed to lc50_calculate.

method

Character; one or several of "traditional", "improved", "probit" or "all", passed to lc50_calculate.

plot

Logical; whether to build the regression plot(s) (default FALSE). The ggplot objects are only returned - not printed, not saved unless plot_file is supplied.

plot_file

Optional png path: when supplied together with plot = TRUE the figure(s) are written as png via lc50_export_plot - one data set gives exactly this file, several data sets write LC50_<name>.png files into this folder. When NULL nothing is written.

plot_width, plot_height, plot_units, plot_res

Physical size and resolution of the exported png (only used when plot_file is supplied); defaults 12 x 8 cm at 300 dpi.

plot_method

Character; which of the computed methods to plot (default NULL = the first method that succeeded). Ignored when plot = FALSE.

font, unit, shape, ci, ci_level, error_bar, move_thres, lc_ci, lc_p, lc_lab_gap, lc_lab_gap_right, lc_lab_dy, lc_lab_lh

Plot settings, passed to the internal plot engine exactly as in lc50_plot (unit = NULL means "mg/L", unit = "" shows no unit).

Value

A list with elements data (the standardised data list, one data frame per data set), results (the list returned by lc50_calculate: results, summary_df, lc), plot (a named list of ggplot objects when plot = TRUE, otherwise NULL) and plot_file (the written path(s) when plot_file was supplied, otherwise NULL).

See Also

lc50_read, lc50_calculate, lc50_plot, lc50_export, lc50_export_plot

Examples

## way 1: data frame straight from the package example csv
f <- system.file("extdata", "lc50_example.csv", package = "insectecol")
out1 <- lc50_analyze(lc50_read(f), method = "probit")
out1$results$summary_df

## way 2: three parallel vectors, no csv involved; all three methods
conc <- c(0, 1.5, 3, 6, 12, 24)
n    <- c(120, 60, 60, 60, 60, 60)
dead <- c(7, 9, 18, 32, 48, 57)
out2 <- lc50_analyze(concentration = conc, tested = n, dead = dead,
                     name = "trial1", method = "all")
out2$results$summary_df

## way 3: LC90, improved regression, plot on the linear axis
out3 <- lc50_analyze(concentration = conc, tested = n, dead = dead,
                     name = "trial1", lc = 0.9, method = "improved",
                     plot = TRUE, plot_method = "improved",
                     shape = "linear")
out3$plot$trial1        # ggplot object: print(), customise or export

insectecol documentation built on Oct. 5, 2026, 5:08 p.m.