README.md

insectecol

R-CMD-check License: MIT

Introduction

insectecol (Insect Ecology Data Analysis Toolkit) is a collection of analytical tools for insect ecology research. It currently ships four modules:

Which main function should I use?

Each module has a main function for analysing data that are already loaded in R (a data frame or plain vectors) and a one-step batch function for processing csv files on disk:

| Module | Main function (data in R) | One-step batch (csv on disk) | |---|---|---| | Life table | lifeTable_analyze() | lifeTable_calculate() | | Bioassay | lc50_analyze() | lc50_export_auto() (tables), lc50_export_plot_auto() (figures) | | Degree-day | gdd_analyze() | gdd_analyze(path = ...) also reads files/folders, gdd_export() writes the tables, gdd_export_plot() the figure | | Emergence period | emergence_analyze() | emergence_analyze(path = ...) also reads files/folders, emergence_export() writes the tables, emergence_export_plot() the figure |

The main functions assemble the data, compute everything and optionally build the plots, but never write to disk - export is handled separately by lifeTable_export(), lc50_export() and lc50_export_plot(), so the results stay fully customisable inside R.

For full control, every module can also be driven step by step (lifeTable_read() -> lifeTable_calculate_all() -> lifeTable_plot() -> lifeTable_export(), and lc50_read() -> lc50_calculate() -> lc50_plot() -> lc50_export() / lc50_export_plot()); see the function reference below.

Planned extensions include more insect ecology indicators, such as the median lethal temperature/time (LT50).

Installation

# from CRAN (once accepted)
install.packages("insectecol")

# development version from GitHub
# install.packages("devtools")
devtools::install_github("SeaGhost-0/insectecol")

Quick start: life table

library(insectecol)

# example data shipped with the package
f <- system.file("extdata", "lifetable_example.csv", package = "insectecol")
d <- read.csv(f)

# analyse straight from the columns of the loaded data frame
out <- lifeTable_analyze(
  stages = d[2:8],           # one column per immature stage
  adult_days = d$Adult,      # adult survival days
  sex = d$gender,            # "F" / "M" / "N" (died before adult)
  oviposition = d[, 11:17],  # daily oviposition of the females
  file_name = "Example"
)

out$results$N        # cohort size
out$results$R0       # net reproductive rate
out$results$lambda   # finite rate of increase

# survival analysis only: skip the reproduction-related parameters
out2 <- lifeTable_analyze(
  stages = d[2:8],
  adult_days = d$Adult,
  sex = d$gender,
  fecundity = FALSE          # no oviposition data required
)

# with the age-stage survival curve (a ggplot object)
out3 <- lifeTable_analyze(
  stages = d[2:8], adult_days = d$Adult, sex = d$gender,
  oviposition = d[, 11:17], plot = TRUE
)
print(out3$plot)

Age-stage survival curve

To batch-process csv files on disk instead (each csv gets its own Excel workbook with all results and the survival curve; an additional all.xlsx summarises every file):

lifeTable_calculate("path/to/lifetable_data")

Quick start: bioassay (LC)

library(insectecol)

# three parallel vectors - no csv file involved
conc   <- c(0, 1.5, 3, 6, 12, 24)
tested <- c(120, 60, 60, 60, 60, 60)
dead   <- c(7, 9, 18, 32, 48, 57)

out <- lc50_analyze(
  concentration = conc,
  tested = tested,
  dead = dead,
  name = "trial1",
  method = "all",            # traditional + improved + probit in one call
  lc = 0.5                   # LC50; any proportion works (e.g. 0.9 = LC90)
)

out$results$summary_df       # estimate, 95% CI, slope, chi-square, ...

# ... or straight from the example csv shipped with the package
f <- system.file("extdata", "lc50_example.csv", package = "insectecol")
out_csv <- lc50_analyze(lc50_read(f), method = "all")
out_csv$results$summary_df

# with the regression plot (a named list of ggplot objects)
out2 <- lc50_analyze(
  concentration = conc, tested = tested, dead = dead,
  name = "trial1", method = "probit", plot = TRUE
)
print(out2$plot$trial1)

Probit regression with the LC values

To batch-process csv files on disk instead (one xlsx / one tiff per csv, written next to the raw data; non-default settings are appended to the file names, e.g. LB_48_LC90_probit.xlsx):

lc50_export_auto("path/to/bioassay_data", method = "probit")
lc50_export_plot_auto("path/to/bioassay_data", method = "probit")

Quick start: degree-day (thermal constants)

library(insectecol)

# example data shipped with the package
f <- system.file("extdata", "gdd_example.csv", package = "insectecol")
d <- read.csv(f)

# analyse straight from the columns of the loaded data frame
out <- gdd_analyze(
  temp     = d$temp,      # temperature (deg C)
  duration = d$duration,  # mean developmental duration (days)
  group    = d$stage      # optional grouping column (e.g. life stage)
)

out$fit$results    # C, K, SE and 95% CI per group (linear degree-day law)
summary(out$fit)   # detailed coefficient tables

# nonlinear models with AICc selection and a publication png
out2 <- gdd_analyze(temp = d$temp, duration = d$duration, group = d$stage,
                    model = "auto",          # best of six models per group
                    plot = TRUE, plot_file = "gdd.png",
                    plot_units = "cm", plot_width = 16, plot_res = 300)
out2$fit$comparison   # full model comparison table, best flag included

Degree-day linear fits

Without plot_file the figure is drawn on the current device and stays fully customisable via gdd_plot() (custom titles/axis labels, named per-group titles, family font). The exported png size is physical (plot_units = "in"/"cm"/"px") so plot_res only changes the sharpness and the recorded dpi, never the layout.

For batch csv processing, gdd_analyze(path = "folder") reads every csv/xlsx in a folder (combined with a source_file column), and gdd_export() writes the result tables (gdd_export_plot() the figure):

out3 <- gdd_analyze(path = "path/to/gdd_data", model = "auto")
gdd_export(out3$fit, file = "gdd_results.csv")
gdd_export_plot(out3$fit, file = "gdd.png")

Quick start: emergence period (stage-grading method)

library(insectecol)

# example data shipped with the package: one survey of the pupal
# grade structure (Tianyang overwintering generation, 40 individuals)
f <- system.file("extdata", "emergence_example.csv", package = "insectecol")
d <- read.csv(f)
#   stage        count  days     # days = days from this stage to
#   Pupal exuviae   2      0     # adult eclosion at the current
#   Pupa 7          3      2     # temperature (most developed first)
#   ...

# analyse straight from the columns of the loaded data frame
out <- emergence_analyze(
  stage = d$stage, count = d$count, days = d$days,
  survey_date = "2026-03-20"
)

out$fit$predictions   # dates of the beginning (16%), peak (50%)
                      # and end (84%) of the emergence period
predict(out$fit, c(0.25, 0.75))          # arbitrary quantiles
summary(out$fit)                         # full cumulative table

# larval hatch: eclosion + pre-oviposition period + egg duration
out2 <- emergence_analyze(data = d, survey_date = "2026-03-20",
                          pre_ovip = 3, egg_days = 10,
                          plot = TRUE, plot_file = "emergence.png")
out2$fit$predictions$hatch_date

Emergence-period projection

The three quantile dates are interpolated on the cumulative development curve built from the survey; a survey that misses stages simply renormalises the shares, while a quantile below the share of the most developed stage (partly eclosed before the survey) is extrapolated backwards with an explicit warning. Tables are exported with emergence_export(fit, file = "emergence_results.csv"), the figure with emergence_export_plot(fit, file = "emergence.png").

Example data

Four example csv files ship with the package in inst/extdata/; the examples in this README and in the help pages are built on them:

system.file("extdata", "lifetable_example.csv", package = "insectecol")      # life table
system.file("extdata", "lc50_example.csv", package = "insectecol")     # bioassay
system.file("extdata", "gdd_example.csv", package = "insectecol")  # degree-day
system.file("extdata", "emergence_example.csv",
            package = "insectecol")                                # emergence

The file layouts are described in detail under Data formats.

Data formats

Life table csv

One row per individual. If the sex column is at position n:

| Column | Content | |---|---| | 1 | individual ID (header ID) | | 2 ... n-2 | days spent in each immature stage (egg, instars, prepupa, pupa) | | n-1 | adult survival days | | n | sex: F, M or N (died before the adult stage); header gender | | n+1 ... | daily oviposition of the females (one column per day) |

The first line must contain the stage names as headers. The sex column is located automatically, and the file encoding is detected automatically (UTF-8 and GBK are both supported).

Bioassay csv

One row per concentration group (replicates = repeated concentration values):

| Column | Content | |---|---| | Concentration | the concentration (0 = control group, used for the Abbott correction) | | Tested | number of insects tested | | Dead | number of dead insects |

Headers are matched loosely, so a header like Concentration (mg/L) is recognised as well. UTF-8 (with BOM) and GBK encodings are supported.

Degree-day csv

One row per temperature (long format):

| Column | Content | |---|---| | temperature | rearing temperature in deg C (e.g. temp, temperature, T, 温度) | | duration | mean developmental duration in days (e.g. duration, days, D, 发育天数, 历期) | | group (optional) | grouping variable, e.g. the life stage |

The temperature and duration columns are auto-detected (English and Chinese headers are recognised); ambiguous files accept explicit temp_col / duration_col. UTF-8 (with BOM) and GBK encodings are supported; the csv delimiter (, ; tab) is auto-detected, and xlsx files are read via readxl.

Emergence csv

One row per stage, ordered most-developed-first (the rows are sorted by days internally anyway):

| Column | Content | |---|---| | stage | stage name, e.g. the pupal grade (stage, grade, 虫态, 阶段) | | count or percent | individuals observed in that stage, or its share (count, n, 数量, 虫数 / percent, 占比) | | days | average days from that stage to adult eclosion (days, 天数, 历期, 距羽化天数) |

The columns are auto-detected (English and Chinese headers are recognised); ambiguous files accept explicit stage_col / count_col / percent_col / days_col. Exactly one of count / percent is used (count wins with a message when both are present). UTF-8 (with BOM) and GBK encodings are supported; the csv delimiter is auto-detected, and xlsx files are read via readxl.

Function reference

Life table module

| Function | Purpose | |---|---| | lifeTable_analyze() | main function - analyse data in R (build + compute + optional plot) | | lifeTable_build() | build a life_table object from user-supplied columns | | lifeTable_read() | read and validate a life table csv file | | lifeTable_calculate() | batch: analyse every csv in a folder and export to Excel | | lifeTable_calculate_all() | all parameters of one life_table object | | calc_N(), calc_F(), calc_sxj(), calc_lx(), calc_fxj(), calc_mx(), calc_ex(), calc_R0(), calc_r(), calc_lambda(), calc_T() | individual indicators | | lifeTable_plot() | age-stage survival rate curves | | lifeTable_export() | export one analysis to Excel | | lifeTable_check(), get_stage_names(), default_stage_names() | helpers |

Bioassay module

| Function | Purpose | |---|---| | lc50_analyze() | main function - analyse data in R (build + compute + optional plots) | | lc50_read() | read bioassay csv file(s) | | lc50_calculate() | compute the LC values; several methods (or "all") in one call | | lc50_plot() | regression plots | | lc50_export() | export results to Excel | | lc50_export_plot() | export figures | | lc50_export_auto() | one-step batch: csv file(s) -> Excel workbook(s) | | lc50_export_plot_auto() | one-step batch: csv file(s) -> tiff figure(s) | | check_path_type() | path helper (folder / csv file) |

Degree-day module

| Function | Purpose | |---|---| | gdd_analyze() | main function - read/check/fit/plot in one call (column vectors, data frame, or path) | | gdd_read() | read a gdd csv/xlsx file or a folder of them (batch) | | gdd_check() | validate the data; linear-range check (rate decline warning) | | gdd_calc() | fit one model per group, or model = "auto" (AICc selection) | | gdd_compare() | pairwise comparison of the groups | | gdd_plot() | fitted line/curve per group (custom titles, font family, size/dpi) | | gdd_predict() | predicted developmental duration at given temperatures | | gdd_daily() | degree-day accumulation from daily Tmin/Tmax (avg / triangle method) | | gdd_export() | export the result tables to csv/xlsx | | gdd_export_plot() | export the fitted line/curve figure as png |

Emergence module

| Function | Purpose | |---|---| | emergence_analyze() | main function - read/compute/plot in one call (column vectors, data frame, or path) | | emergence_read() | read an emergence csv/xlsx file or a folder of them (batch) | | emergence_calc() | cumulative development + quantile dates from a survey table | | emergence_export() | export the prediction and stage tables to csv/xlsx | | emergence_export_plot() | export the projection figure as png | | print() / summary() / predict() / plot() | S3 methods for the emergence object (predict(fit, p) interpolates arbitrary quantiles) |

Updates

1.1.1 (CRAN submission round)

Version 1.1.1 adds the emergence-period module, standardises the function naming across all modules (<module>_<verb> with the same verbs everywhere, see below) and removes the no-longer-needed gdd_from_lifetable() bridge.

Function naming unified across modules

New module: emergence-period projection (stage-grading method)

New module: degree-day / thermal constants

New: bootstrap for the life table

Improved

Internal changes

1.0.1 (CRAN submission round)

New features

CRAN fixes

Internal changes

1.0.0

Note on bundled fonts

This package bundles the Liberation Serif font (SIL Open Font License 1.1) in inst/fonts/ for publication-quality figures. The full license text is shipped as inst/fonts/OFL.txt. All other components of the package are licensed under MIT.

License

MIT (see LICENSE). The bundled Liberation Serif font is licensed under the SIL Open Font License 1.1.

Citation

citation("insectecol")

If you use the life table module in a publication, please also cite the method papers behind the age-stage, two-sex theory (Chi & Liu 1985; Chi 1988 - see the references of lifeTable_read()), and for probit analysis Finney (1971) together with Abbott (1925) for the correction of natural mortality.



Try the insectecol package in your browser

Any scripts or data that you put into this service are public.

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